view lib/localdisplay.py @ 997:b24885725f59

support for pwm board Ignore-this: 4bf59699c590c75c79e6ae72d719343a darcs-hash:20150830081929-312f9-45f7134e807c5de2bb0dad13a5a9d1fa032bf471
author drewp <drewp@bigasterisk.com>
date Sun, 30 Aug 2015 01:19:29 -0700
parents 4620a5d2f337
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")