#!/bin/ash
#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.

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
Twidth="${Twidth0/*\"/}"
if [ "$Twidth" == "0" -o "$Twidth" == "" ];then
 Xoff=53
else
 Xoff=$(((($SCRN_X - $Twidth) / 2) + 53))
fi

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

xdotool mousemove ${Xoff} ${Yoff} #on top of drives icon.
xdotool click 2 #middle button
