Python Xlib CreateNotify - Catch new window
Why this code doesn't work? When I start new program (e.g. lxappearance) nothing happens, but if开发者_如何学Go I do something in program's window, code works
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)
精彩评论