Toggle lxpanelctrl menu in lubuntu?

Solution 1:

Alternative way to toggle the menu

This answer is only "half" of the answer that was posted here . Since that question was on Gnome, and tagged likewise, I think it is legitimate to post a slightly edited version here to cover Lubuntu (lxde), or any other window manager.

I tested it on Lubuntu 14.04, and (as expected) did exactly what it should do.

The solution is actually a script that you can easily set up to automatically (virtually) click on any position on your screen, including the menu. Since clicking the menu once will open it, clicking it again will close it, placing the command under your key, as you did, will do exactly what you are after.

The script

#!/usr/bin/env python3
import subprocess
import time
import sys
import os

option = sys.argv[1]
datafile = os.path.join(os.environ["HOME"], ".run_click")

def get_mousepos():
    cursordata = subprocess.check_output(["xdotool", "getmouselocation"]).decode("utf-8").split()
    return [d.split(":")[1] for d in cursordata[:2]]

if option == "-run":
    try:
        data = open(datafile).read()
        coords = (" ").join([l for l in data.splitlines()])
    except FileNotFoundError:
        message = "Please run the command: 'run_click -set' first, to set the click position"
        subprocess.Popen(["zenity", "--info", "--text", message])
    else:
        cmd1 = "xdotool mousemove "+coords; cmd2 = "xdotool click 1"; cmd3 = "xdotool mousemove "+(" ").join(get_mousepos())
        for cmd in [cmd1, cmd2, cmd3]:
            subprocess.Popen(["/bin/bash", "-c", cmd])
            time.sleep(0.05)
elif option == "-set":
    open(datafile, "wt").write(("\n").join(get_mousepos()))

About the script; how to set up

  1. The script needs xdotool:

    sudo apt-get install xdotool
    
  2. Copy the script above into an empty file, save it as click_menu.py

  3. Now you need to make the script remember the menu position to (virtually) click:

    The script needs to be run with the option -set, with the mouse in position:

    • open a terminal window, type the command:

      sleep 5 && python3 /path/to/click_menu.py -set
      
    • immediatley position the mouse above the menu (do not click)

    • after the 5 seconds have passed, the menu position is "remembered". The position is written to an invisible file, so you will only need to do this once.
  4. Test if all works fine with the command:

    python3 /path/to/click_menu.py -run
    

    enter image description here

    The menu should open, as shown in th image above.

  5. If all works fine add the command:

    python3 /path/to/click_menu.py -run
    

    to the key, as you did with the other command you mentioned in your question. Now pressing the key should toggle the menu.