diff options
author | Sébastien Dailly <sebastien@dailly.me> | 2023-08-27 16:41:10 +0200 |
---|---|---|
committer | Sébastien Dailly <sebastien@dailly.me> | 2023-08-27 16:41:10 +0200 |
commit | fcce9177e356bb27283926451433130a8809fcb0 (patch) | |
tree | ff1aecf99be053f1681bd8965ae3f33c2a42169f /xlib.py | |
parent | 02d676bda89c2fb8469ea81f7429c19c1e29df7c (diff) |
Send the whole keymap to the device
Diffstat (limited to 'xlib.py')
-rw-r--r-- | xlib.py | 44 |
1 files changed, 32 insertions, 12 deletions
@@ -36,27 +36,47 @@ class Listener(Thread): component.handle(Debug("Waiting for xlib event"))
self.running = True
while self.running:
+ event = disp.next_event()
try:
window_id = root.get_full_property(NET_ACTIVE_WINDOW, Xlib.X.AnyPropertyType).value[0]
window = disp.create_resource_object('window', window_id)
window.change_attributes(event_mask=Xlib.X.PropertyChangeMask)
- window_name = str(window.get_full_property(NET_WM_NAME, 0).value).lower()
+ window_prop = window.get_full_property(NET_WM_NAME, 0)
+ if window_prop is None:
+ continue
+ window_name = str(window_prop.value).lower()
class_name = str(window.get_full_property(WM_CLASS, 0).value).lower()
except Xlib.error.XError:
- window_name = None
- class_name = None
+ continue
- if window_name is not None and window_name != self.active_window:
+ if window_name is None or window_name == self.active_window:
+ continue
- self.active_window = window_name
- for pattern, code in self.mapping.items():
- if (pattern in window_name or pattern in class_name) and code != self.last_code:
+ self.active_window = window_name
+ found = False
+ for pattern, code in self.mapping.items():
+ # Ignore the default layout
+ if pattern == "default":
+ continue
+ if not (pattern in window_name or pattern in class_name):
+ continue
+ # We found something. At this point, even if we do not update
+ # the layer (because it is the same as the previous) we do not
+ # switch back to the default layer.
+ found = True
+ if code != self.last_code:
- component.handle(Debug("Switching to '%s' for '%s'" % (code, window_name)))
- self.queue.put ( (code, None) )
- self.last_code = code
- break
- event = disp.next_event()
+ component.handle(Debug("Switching to '%s' for '%s'" % (code, window_name)))
+ self.queue.put ( (code, None) )
+ self.last_code = code
+ break
+ if not found and self.last_code != "default":
+ default = self.mapping.get("default", None)
+ if default is None:
+ continue
+
+ self.queue.put ( (default, None) )
+ self.last_code = "default"
def stop(self):
self.running = False
|