From fcce9177e356bb27283926451433130a8809fcb0 Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Sun, 27 Aug 2023 16:41:10 +0200 Subject: Send the whole keymap to the device --- xlib.py | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) (limited to 'xlib.py') diff --git a/xlib.py b/xlib.py index b86a8b1..3e43e51 100644 --- a/xlib.py +++ b/xlib.py @@ -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 -- cgit v1.2.3