comparison 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
comparison
equal deleted inserted replaced
80:855deb1509a5 81:ef639d892e77
1 import psutil, os
2
3 def setDisplayToLocalX():
4 """
5 set DISPLAY env var in this process to the id of the X process on localhost
6 """
7 for pid in psutil.get_pid_list():
8 try:
9 proc = psutil.Process(pid)
10 if proc.exe not in ['/usr/bin/Xorg', '/usr/bin/X']:
11 continue
12 except (psutil.error.AccessDenied, psutil.error.NoSuchProcess):
13 continue
14 display = proc.cmdline[1]
15 assert display.startswith(':'), display
16 os.environ['DISPLAY'] = display
17 break
18 else:
19 raise ValueError("didn't find an Xorg process")