# HG changeset patch # User drewp@bigasterisk.com # Date 1369813476 25200 # Node ID ef639d892e77e1cc06074160041673a0027a883c # Parent 855deb1509a50b60320741409bfa6b4bac065f85 Xorg display number fetcher for use by xidle and dpms Ignore-this: eaef4d7fa8277e88c65d83343a46f866 diff -r 855deb1509a5 -r ef639d892e77 lib/localdisplay.py --- /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")