4b1c7e3b57b8a0263561f48462d965c9aab55404
[shutils.git] / X / getXenv.inc
1 # Extracted from /etc/acpi/powerbtn.sh
2
3
4 # Taken from Debian's 2.0.4-1 diff file. This version handles KDE4.
5 # Power Button event handler.
6 # Checks to see if gnome or KDE are already handling the power button.
7 # If not, initiates a plain shutdown.
8
9 # getXuser gets the X user belonging to the display in $displaynum.
10 # If you want the foreground X user, use getXconsole!
11 # Input:
12 # displaynum - X display number
13 # Output:
14 # XUSER - the name of the user
15 # XAUTHORITY - full pathname of the user's .Xauthority file
16 getXuser() {
17 user=`pinky -fw | awk '{ if ($2 == ":'$displaynum'" || $(NF) == ":'$displaynum'" ) { print $1; exit; } }'`
18 if [ x"$user" = x"" ]; then
19 startx=`pgrep -n startx`
20 if [ x"$startx" != x"" ]; then
21 user=`ps -o user --no-headers $startx`
22 fi
23 fi
24 if [ x"$user" != x"" ]; then
25 userhome=`getent passwd $user | cut -d: -f6`
26 export XAUTHORITY=$userhome/.Xauthority
27 else
28 export XAUTHORITY=""
29 fi
30 export XUSER=$user
31 }
32
33 # Gets the X display number for the active virtual terminal.
34 # Output:
35 # DISPLAY - the X display number
36 # See getXuser()'s output.
37 getXconsole() {
38 console=`fgconsole`;
39 displaynum=`ps t tty$console | sed -n -re 's,.*/X .*:([0-9]+).*,\1,p'`
40 if [ x"$displaynum" != x"" ]; then
41 export DISPLAY=":$displaynum"
42 getXuser
43 fi
44 }