From 803e8f4de5562238d2de01863a7dbf316262e104 Mon Sep 17 00:00:00 2001 From: Ali Hatami Tajik Date: Sat, 25 Feb 2023 16:06:47 +0330 Subject: [PATCH] Add UsbHandler This handler runs callback on usb events. When a usb is connected following events will capture: - add - change - add - bind - bind and when usb mouse is removed following will captured: - unbind - remove - unbind - remove these effects are tested with device logitech (R) B100 mouse. --- src/scripts/python/udevhandle.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/scripts/python/udevhandle.py b/src/scripts/python/udevhandle.py index 3aed6c8..5891dac 100644 --- a/src/scripts/python/udevhandle.py +++ b/src/scripts/python/udevhandle.py @@ -1,5 +1,5 @@ from abc import ABC, abstractmethod -from pyudev import Context, Monitor, MonitorObserver +from pyudev import Context, Monitor, MonitorObserver, Device class Handler(ABC): @@ -26,7 +26,7 @@ class Handler(ABC): self.observer.start() @abstractmethod - def callback(self, device): + def callback(self, device: Device): """Callback This method must be implemented by child calsses. This method is @@ -43,4 +43,23 @@ class Handler(ABC): Args: device (pyudev.Device): modified device passed by self.observer """ - self.callback(device) \ No newline at end of file + self.callback(device) + + +class MouseHandler(Handler): + def __init__(self) -> None: + """Initiate UsbHanlder + + Initialization contains two major steps. First it would do a + configuration for currently available devices and then it would wait for + USB udev events to reconfigure the settings. configurations would be + done by (This part is not decided yet. it could be done by BASH SCRIPTS + or we can invoke xinput binaries via python itself. a bash script + solution would be benefitial since it can used as utility). + """ + # TODO: use somthing that only captures + super().__init__('usb') + + + def callback(self, device): + print(device.action) \ No newline at end of file