view lib/localdisplay.py @ 120:2c4ad7fc542e

laundry try to output trig graph Ignore-this: d58dce74920c6179161bc79b8d6e6b91
author drewp@bigasterisk.com
date Sun, 22 Sep 2013 00:33:11 -0700
parents 9155e9a605ec
children 2f8ba398f958
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']:
                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")