Mercurial > code > home > repos > homeauto
diff lib/localdisplay.py @ 81:ef639d892e77
Xorg display number fetcher for use by xidle and dpms
Ignore-this: eaef4d7fa8277e88c65d83343a46f866
author | drewp@bigasterisk.com |
---|---|
date | Wed, 29 May 2013 00:44:36 -0700 |
parents | |
children | 9155e9a605ec |
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")