From ae6d3f21031a5d6311c7d9dbace9b275b4924485 Mon Sep 17 00:00:00 2001 From: mar77i Date: Fri, 27 Dec 2024 10:24:47 +0100 Subject: [PATCH] also call event-specific event handlers on UIParent subclasses, drag along Stylus devices --- ui.py | 2 +- xinput.py | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/ui.py b/ui.py index 5f8f208..c4300dd 100644 --- a/ui.py +++ b/ui.py @@ -29,7 +29,7 @@ class UIParent: self.running = False return False method_name = f"handle_{pygame.event.event_name(ev.type).lower()}" - for child in self.children: + for child in (self, *self.children): if not hasattr(child, method_name): continue getattr(child, method_name)(ev) diff --git a/xinput.py b/xinput.py index 6a78d0d..5c6f4ef 100644 --- a/xinput.py +++ b/xinput.py @@ -13,6 +13,11 @@ class XinputConf: "output": "eDP-1", "type": "touchpad", }, + "ELAN9008:00 04F3:425B Stylus": { + "output": "eDP-1", + "type": "stylus", + "ignore_result": True, + }, "ELAN9008:00 04F3:425B Stylus Pen (0)": { "output": "eDP-1", "type": "stylus", @@ -25,6 +30,11 @@ class XinputConf: "output": "eDP-2", "type": "touchpad", }, + "ELAN9009:00 04F3:425A Stylus": { + "output": "eDP-2", + "type": "stylus", + "ignore_result": True, + }, "ELAN9009:00 04F3:425A Stylus Pen (0)": { "output": "eDP-2", "type": "stylus", @@ -63,7 +73,10 @@ class XinputConf: enable = device["enabled"] if enable: subprocess.run(["xinput", "enable", device["id"]]) - subprocess.run(["xinput", "map-to-output", device["id"], device["output"]]) + subprocess.run( + ["xinput", "map-to-output", device["id"], device["output"]], + stderr=subprocess.DEVNULL if device.get("ignore_result") else None, + ) else: subprocess.run(["xinput", "disable", device["id"]]) self.conf = self.get_conf() @@ -91,7 +104,11 @@ class XinputConf: outputs = {o["name"]: o for o in self.xrandr_conf.get_relevant_outputs()} state = None for device in self.conf: - if device["type"] != device_type or not outputs[device["output"]]["active"]: + if ( + device["type"] != device_type + or not outputs[device["output"]]["active"] + or device.get("ignore_result") + ): continue new_state = device["enabled"] if state is not None and new_state != state: -- 2.47.1