view lib/localdisplay.py @ 1052:2434e88d8bb0

add bed buttons Ignore-this: 912a92f7a8e173fe64aa4c1df9ef7dba darcs-hash:2e4031a9cacedb28f57c36708d69d6ec3610ef9d
author drewp <drewp@bigasterisk.com>
date Mon, 08 Feb 2016 23:48:29 -0800
parents 3184772368a5
children 3657e3f0d5d0
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
        break
    else:
        raise ValueError("didn't find an Xorg process")