site  contact  subhomenews

Emulate key press to popup drives menu

April 10, 2022 — BarryK

In JWM-mode icon-free-desktop, there are two extra menus in the tray, a drives menu and a containers menu.

I want the drives menu to popup automatically whenever there is some drive/partition activity, such as a USB-stick plugged in, or a partition unmounted. In Easy 3.4.5, this is achieved in script /usr/local/ui/jwm/popup-drives-menu.

The script moves the mouse pointer over the drives-menu icon in the tray, then emulates a mouse middle-button click. This causes the drives menu to popup.

Forum member 'rufwoof' suggested to assign a key combination to the menu, and emulate that key combination to popup the menu, instead of relying on the mouse pointer being accurately placed over the drives icon in the tray:

Yes, good idea. Firstly, to assign a key-combination to the drives and containers menus, I have inserted these two lines into /etc/xdg/templates/_root_.jwmrc and /root/.jwm/jwmrc-personal:

	<Key mask="A" key="F7">root:2</Key>
<Key mask="A" key="F8">root:4</Key>

...redundant putting that into both of those files.

To complete the explanation, those "root:2" and "root:4" mean mouse middle-button-click and mouse scroll-up, and also assign to drives menu and containers menu respectively. In JWM-mode, you will see these specified in /root/.jwmrc-tray:

<TrayButton popup="Drives" icon="drives48.png">root:2</TrayButton>
<TrayButton popup="Containers" icon="container48.png">root:4</TrayButton>

And, a further detail, those lines are inserted by /usr/local/ui/jwm/jwmrc-insert-menu

In the case of the drives menu, I then modified /usr/local/ui/jwm/popup-drives-menu, as shown in bold:

#20220209 popup drives menu. called from:
# /usr/local/pup_event/frontend_change, frontend_funcs
# /usr/local/ui/unmount-all, unmount-part, jwm/rescan-drives-menu
#20220406 fix position to move mouse pointer.
#20220410 emulate key combination to popup menu.

SCRN_X=$(cat /tmp/pup_event_frontend_scrn_x)
SCRN_Y=$(cat /tmp/pup_event_frontend_scrn_y)

Twidth0="$(grep -m 1 -o 'width="[^"]*' /root/.jwmrc-tray)" #ex: width="1172
if [ "$Twidth" == "0" -o "$Twidth" == "" ];then
Xoff=$(((($SCRN_X - $Twidth) / 2) + 53))

grep -q '<Tray .*valign="top"' /root/.jwmrc-tray
if [ $? -eq 0 ];then
#tray is at top of screen.
Yoff=$(($SCRN_Y - 20))

xdotool mousemove ${Xoff} ${Yoff} #on top of drives icon.

#20220410 /root/.jwmrc (via /etc/xdg/templates/_root_.jwmrc and /root/.jwm/jwmrc-personal,
# have assigned ALT-F7 to popup drives menu. anyway, still good to have mouse
# pointer over icon, so menu pops up in expected place.
#right, so do not popup menu by emulating middle-button-click...
#xdotool click 2 #middle button
xdotool key Alt+F7

I kept the code to move the mouse pointer over the drives icon in the tray, so that the menu will popup in its usual place, rather than wherever the mouse pointer happens to be.    

Tags: easy