changeset 1157:6d67b23f3a75

better X detection in localdisplay Ignore-this: 883e8946dfb27ea4ef71df7beb4c7d01 darcs-hash:754a1ee006a86339dc236e87a57694a2763ee882
author drewp <drewp@bigasterisk.com>
date Mon, 03 Sep 2018 00:47:10 -0700
parents ee168d55524a
children ff1dc038665a
files lib/localdisplay.py
diffstat 1 files changed, 16 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/lib/localdisplay.py	Mon Sep 03 00:45:34 2018 -0700
+++ b/lib/localdisplay.py	Mon Sep 03 00:47:10 2018 -0700
@@ -10,13 +10,25 @@
     for pid in psutil.get_pid_list():
         try:
             proc = psutil.Process(pid)
-            if proc.exe not in ['/usr/bin/Xorg', '/usr/bin/X', '/usr/bin/X11/X']:
+            if proc.exe not in ['/usr/bin/Xorg', '/usr/bin/X', '/usr/bin/X11/X', '/usr/lib/xorg/Xorg']:
                 continue
         except (psutil.error.AccessDenied, psutil.error.NoSuchProcess):
             continue
-        display = [arg for arg in proc.cmdline if not arg.startswith('-')][1]
-        if display == 'tcp': # ??
-            display = ":0.0"
+        argIter = iter(proc.cmdline)
+        while True:
+            arg = argIter.next()
+            if arg in ['-background']:
+                argIter.next()
+                continue
+            if arg in ['-nolisten']:
+                continue
+            if arg.startswith(':'):
+                display = arg
+                break
+            if arg == 'tcp':
+                display = ':0.0'
+                break
+
         assert display.startswith(':'), display
         os.environ['DISPLAY'] = display
         os.environ['XAUTHORITY'] = os.path.expanduser('~/.Xauthority')