Created
November 12, 2015 01:15
-
-
Save mzizzi/1c5dddf90811830c3941 to your computer and use it in GitHub Desktop.
Subscribe to X11 PropertyChange events
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Subscribe to X11 PropertyChange events and print "Window Changed!" when a | |
_NET_ACTIVE_WINDOW property has been changed. | |
Unfortunately no event is received events when _NET_WM_NAME is changed so this | |
would only partially solve https://github.com/dictation-toolbox/aenea/issues/103 | |
You'll have to `pip install python-xlib` to run this script. | |
(Tested with the Cinnamon 2.2.16 desktop) | |
""" | |
import Xlib | |
from Xlib.display import Display | |
import Xlib.XK | |
from time import sleep | |
display = Display(':0') | |
NET_WM_NAME = display.intern_atom('_NET_WM_NAME') | |
NET_ACTIVE_WINDOW = display.intern_atom('_NET_ACTIVE_WINDOW') | |
root = display.screen().root | |
root.change_attributes(event_mask=Xlib.X.PropertyChangeMask) | |
print('Running...') | |
while True: | |
while display.pending_events(): | |
event = display.next_event() | |
if type(event) == Xlib.protocol.event.PropertyNotify: | |
atom_name = display.get_atom_name(event.atom) | |
if atom_name == '_NET_ACTIVE_WINDOW': | |
print 'Window changed!' | |
elif atom_name == '_NET_WM_NAME': | |
print 'Window name changed!' | |
sleep(0.1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
thanks for nice snippet! Do you have clue why not all windows report wm_name? For me Opera, HipChat and some other apps return empty string on get_wm_name()