In ROX-Filer, when a script file is clicked, the script is executed. However when the Shift key is pressed while clicking, the script is opened in an editor.
Same with text based image files like SVG or XPM. Shift+Click would open them in the designated editor.
I wonder if such functionality can be achieved with gtkdialog. It would greatly increase the possibilities to execute commands or start applications.
Though gtkdialog knows key events and mouse button events, there is no way to combine both. Or is it?
I tried my luck reading /proc/bus/input/devices and the output of xinput. The challenge is to find the correct name of the attached keyboard before examining the status of the Shift keys. On a laptop with attached external keyboard or with keyboards attached to a USB hub this can be a bit tricky.
I managed to write a function that works for me, but I'm not sure how robust this function is. I'm keen to know if this works for other users and also if there are better ways. I'm especially interested to know where it does not work (In this case I would need output of cat /proc/bus/input/devices
and xinput
The following demo fills a tree with XPM icon files. Double clicking should trigger the usual ROX handler (normally an image viewer) and Shift+Doubleclick should trigger leafpad with the XPM source code. Instead of using mouse pressing Spacebar and Shift+Spacebar also works. Pressing Enter works, Shift+Enter does not.
Code: Select all
#!/bin/sh
function shift_is_down {
if xinput | grep -q Keyboard0 ;then
KEYBDNAME=Keyboard0
else
KEYBDNAME=$(< /proc/bus/input/devices)
KEYBDNAME=${KEYBDNAME%\"*LED*}
KEYBDNAME=${KEYBDNAME##*\"}
fi
xinput query-state "$KEYBDNAME" | grep -Eq "\[(50|62)\]=down" #should return 0 if keycode 50 or 62 (left/right Shift key) is down
}; export -f shift_is_down
echo '
<window width-request="500" height-request="500">
<tree>
<variable>vTREE</variable>
<input>'find /usr/share -type f -name "*.xpm"'</input>
<action>shift_is_down && (leafpad "$vTREE" &) || rox "$vTREE"</action>
</tree>
</window>'|gtkdialog -sc