]> git.sthu.org Git - shutils.git/commitdiff
getXenv.inc: Do not work on current console
authorStefan Huber <shuber@sthu.org>
Wed, 5 Feb 2014 10:10:36 +0000 (11:10 +0100)
committerStefan Huber <shuber@sthu.org>
Wed, 5 Feb 2014 10:10:36 +0000 (11:10 +0100)
X/getXenv.inc

index 4b1c7e3b57b8a0263561f48462d965c9aab55404..c079af9e5d55d7eb9d030c93f772b1f285daa046 100644 (file)
@@ -1,4 +1,5 @@
-# Extracted from /etc/acpi/powerbtn.sh
+# Extracted from /etc/acpi/powerbtn.sh and modified
+# shuber@sthu.org
 
 
 # Taken from Debian's 2.0.4-1 diff file.  This version handles KDE4.
 #   XUSER - the name of the user
 #   XAUTHORITY - full pathname of the user's .Xauthority file
 getXuser() {
-        user=`pinky -fw | awk '{ if ($2 == ":'$displaynum'" || $(NF) == ":'$displaynum'" ) { print $1; exit; } }'`
-        if [ x"$user" = x"" ]; then
-                startx=`pgrep -n startx`
-                if [ x"$startx" != x"" ]; then
-                        user=`ps -o user --no-headers $startx`
-                fi
-        fi
-        if [ x"$user" != x"" ]; then
-                userhome=`getent passwd $user | cut -d: -f6`
-                export XAUTHORITY=$userhome/.Xauthority
-        else
-                export XAUTHORITY=""
-        fi
-        export XUSER=$user
+       user=`pinky -fw | awk '{ if ($2 == ":'$displaynum'" || $(NF) == ":'$displaynum'" ) { print $1; exit; } }'`
+       if [ x"$user" = x"" ]; then
+               startx=`pgrep -n startx`
+               if [ x"$startx" != x"" ]; then
+                       user=`ps -o user --no-headers $startx`
+               fi
+       fi
+       if [ x"$user" != x"" ]; then
+               userhome=`getent passwd $user | cut -d: -f6`
+               export XAUTHORITY=$userhome/.Xauthority
+       else
+               export XAUTHORITY=""
+       fi
+       export XUSER=$user
 }
 
 # Gets the X display number for the active virtual terminal.
@@ -35,10 +36,12 @@ getXuser() {
 #   DISPLAY - the X display number
 #   See getXuser()'s output.
 getXconsole() {
-        console=`fgconsole`;
-        displaynum=`ps t tty$console | sed -n -re 's,.*/X .*:([0-9]+).*,\1,p'`
-        if [ x"$displaynum" != x"" ]; then
-                export DISPLAY=":$displaynum"
-                getXuser
-        fi
+       pid=$(pgrep -x X | head -n 1)
+       if [ x"$pid" != x"" ]; then
+               displaynum=`ps -p "$pid" -o args | sed -n -re 's,.*/X .*:([0-9]+).*,\1,p'`
+               if [ x"$displaynum" != x"" ]; then
+                       export DISPLAY=":$displaynum"
+                       getXuser
+               fi
+       fi
 }