#!/bin/bash
-POSMENU=`DISPLAY=:0.0 xwininfo -name xfce4-menu-plugin | egrep 'Absolute upper-left X|Absolute upper-left Y' | awk '{print $4}'`
-Xold=`DISPLAY=:0.0 xdotool getmouselocation | awk '{print $1}' | sed 's/^..//'`
-Yold=`DISPLAY=:0.0 xdotool getmouselocation | awk '{print $2}' | sed 's/^..//'`
-Xnew=`echo $POSMENU|awk '{print $1}'`
-Ynew=`echo $POSMENU|awk '{print $2}'`
-DISPLAY=:0.0 xdotool mousemove $Xnew $Ynew
-DISPLAY=:0.0 xdotool click 1
-DISPLAY=:0.0 xdotool mousemove $Xold $Yold
+
+#
+# Show or hide XFCE application/popup menu when Pandora key is pressed.
+# Enhanced by bsp
+#
+
+function loc_menu_show {
+ xfce4-popup-menu
+}
+
+function loc_menu_hide {
+ WINID=`xwininfo -name xfce4-menu-plugin|grep 'Window id:'|awk '{print $4}'`
+ xdotool keydown --window $WINID Escape
+}
+
+MENU_SY=`xwininfo -name xfce4-menu-plugin|grep Height|awk '{print $2}'`
+
+if [ 1 -eq $MENU_SY ]; then
+ # panel is in auto-hide mode and the menu is currently invisible
+ loc_menu_show
+else
+ # hack to determine whether the menu is visible, regardless of the panel auto-hide mode
+ NUM_MENU_WINDOWS=`xwininfo -tree -root | grep 'xfce4-menu-plugin' | wc -l`
+ echo $NUM_MENU_WINDOWS
+ if [ $NUM_MENU_WINDOWS -gt 4 ]; then
+ loc_menu_hide
+ else
+ loc_menu_show
+ fi
+fi