Python Xlib CreateNotify - Поймать новое окно - PullRequest
0 голосов
/ 20 сентября 2011

Почему этот код не работает? Когда я запускаю новую программу (например, lxappearance), ничего не происходит, но если я что-то делаю в окне программы, код работает

from Xlib.display import Display
from Xlib import X, Xatom

def get_window_list():
    return [x for x in root.get_full_property(display.intern_atom('_NET_CLIENT_LIST'), Xatom.WINDOW).value]

def handle_event(aEvent):
    if aEvent.type == X.CreateNotify:
        for window in get_window_list():
            if window not in windows:
                windows.append(window)
                window_resource = display.create_resource_object('window', window)
                window_resource.configure(width = display.screen().width_in_pixels, height = display.screen().height_in_pixels-100, x = 0, y = 100)

display = Display()
root = display.screen().root
windows = get_window_list()
root.change_attributes(event_mask = X.SubstructureNotifyMask)
while True:
    ev = display.next_event()
    handle_event(ev)
...