changeset 886:2d055bce2e60

Xorg display number fetcher for use by xidle and dpms Ignore-this: eaef4d7fa8277e88c65d83343a46f866 darcs-hash:20130529074436-312f9-82b723dfcb487deee25ca2beab344631b09c0243
author drewp <drewp@bigasterisk.com>
date Wed, 29 May 2013 00:44:36 -0700
parents 096ecee75e0b
children 64a2ba088665
files lib/localdisplay.py
diffstat 1 files changed, 19 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/localdisplay.py	Wed May 29 00:44:36 2013 -0700
@@ -0,0 +1,19 @@
+import psutil, os
+
+def setDisplayToLocalX():
+    """
+    set DISPLAY env var in this process to the id of the X process on localhost
+    """
+    for pid in psutil.get_pid_list():
+        try:
+            proc = psutil.Process(pid)
+            if proc.exe not in ['/usr/bin/Xorg', '/usr/bin/X']:
+                continue
+        except (psutil.error.AccessDenied, psutil.error.NoSuchProcess):
+            continue
+        display = proc.cmdline[1]
+        assert display.startswith(':'), display
+        os.environ['DISPLAY'] = display
+        break
+    else:
+        raise ValueError("didn't find an Xorg process")