Mercurial > code > home > repos > homeauto
view lib/localdisplay.py @ 280:c192d37b2bc8
lots of logging updates (patch may be imprecise)
Ignore-this: cfe81299fe9a1e2b6b1140e9ec46aaf7
author | drewp@bigasterisk.com |
---|---|
date | Fri, 06 May 2016 17:32:41 -0700 |
parents | 3657e3f0d5d0 |
children | 9ee169ba3f0e |
line wrap: on
line source
import psutil, os def setDisplayToLocalX(): """ set DISPLAY env var in this process to the id of the X process on localhost I might need something like xauth merge /run/gdm/auth-for-gdm-xxxxxx/database too and this isn't automated yet """ 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']: 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" assert display.startswith(':'), display os.environ['DISPLAY'] = display os.environ['XAUTHORITY'] = os.path.expanduser('~/.Xauthority') break else: raise ValueError("didn't find an Xorg process")