op_menu: try to be a bit more useful
[openpandora.oe.git] / recipes / pandora-system / pandora-scripts / op_menu.sh
1 #!/bin/bash
2 #actions done when the menu button is pressed
3 #only argument is the time the button was pressed in  seconds
4
5 if [ -x /usr/pandora/scripts/op_menu_custom.sh ]; then
6   exec /usr/pandora/scripts/op_menu_custom.sh "$@"
7 fi
8
9 do_kill()
10 {
11   for PID in "$@"; do
12     kill $PID
13   done
14   sleep 1
15   for PID in "$@"; do
16     kill -9 $PID
17   done
18 }
19
20 if [ "$1" -ge "2" ]; then #button was pressed 3 sec or longer, show list of apps to kill instead of launcher
21   killist=y
22
23   # if something uses fb1 or SGX, try killing them instead
24   fb_users=`lsof -t /dev/fb1 /dev/pvrsrvkm`
25   if [ -n "$fb_users" ]; then
26     do_kill $fb_users
27   fi
28   exit 1
29 fi
30
31 xpid=$(pidof xfce4-session)
32 if [ $xpid ]; then
33   echo "xfce4 is running"
34   # note: max username length ps can output is 19, otherwise it prints uid
35   xfceuser=$(ps -o user:20= -C xfce4-session | tail -n1 | awk '{print $1}')
36   if [ $killist ]; then
37     echo "displaying kill list"
38     pidlist=$(pstree -lpA | grep pnd_run.sh | sed -ne 's/.*-\(.*\)(\([0-9]\+\))/\2\n \1/p' | su -c 'DISPLAY=:0.0 zenity --list --multiple --column "pid" --column "name" --title "kill" --text "which apps should be killed"' - $xfceuser | sed 's/|/\n/')
39     do_kill $pidlist
40   else
41     # echo "starting appfinder"
42     # invoke the appfinder; nice app, but it takes a few seconds to come up
43     #su -c 'DISPLAY=:0.0 xfce4-appfinder' - $xfceuser
44     # invoke the bottom-left popup menu, for launching new apps, instead.
45     su -c 'DISPLAY=:0.0 /usr/pandora/scripts/op_xfcemenu.sh' - $xfceuser
46   fi
47 else
48   echo "no x, killing all pnd aps so x or DE gets restarted"
49   pidlist=$(pstree -lpA | grep pnd_run.sh | sed -ne 's/.*(\([0-9]\+\))/\1/p')
50   do_kill $pidlist
51 fi