view lib/localdisplay.py @ 1140:f349fe25789c

rgb strip animation support in arduinoNode Ignore-this: 5f50c7b54ce1588243735c43d2cbea0f darcs-hash:0e2e1e2156b181c83d6e4f2f85afc849dc07fec0
author drewp <drewp@bigasterisk.com>
date Sat, 03 Mar 2018 17:55:37 -0800
parents 0cd92c2f8cf4
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")