From d3a18bb85fa9514d2dfcae3af9588e8da0667932 Mon Sep 17 00:00:00 2001 From: SiDevesh Date: Fri, 9 Apr 2021 00:29:05 +0530 Subject: [PATCH] rules: match WM_CLASS also for process matching in rules --- lib/logitech_receiver/diversion.py | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/lib/logitech_receiver/diversion.py b/lib/logitech_receiver/diversion.py index aecb69ac..5966a24d 100644 --- a/lib/logitech_receiver/diversion.py +++ b/lib/logitech_receiver/diversion.py @@ -59,13 +59,15 @@ if x11: # determine name of active process NET_ACTIVE_WINDOW = disp_prog.intern_atom('_NET_ACTIVE_WINDOW') NET_WM_PID = disp_prog.intern_atom('_NET_WM_PID') + WM_CLASS = disp_prog.intern_atom('WM_CLASS') root2 = disp_prog.screen().root root2.change_attributes(event_mask=Xlib.X.PropertyChangeMask) active_process_name = None +active_wm_class_name = None -def active_program(): +def active_program_name(): try: window_id = root2.get_full_property(NET_ACTIVE_WINDOW, Xlib.X.AnyPropertyType).value[0] window = disp_prog.create_resource_object('window', window_id) @@ -75,17 +77,30 @@ def active_program(): return None -def determine_active_program(): +def active_program_wm_class(): + try: + window_id = root2.get_full_property(NET_ACTIVE_WINDOW, Xlib.X.AnyPropertyType).value[0] + window = disp_prog.create_resource_object('window', window_id) + window_wm_class = window.get_wm_class()[0] + return window_wm_class + except (Xlib.error.XError, AttributeError): # simplify dealing with BadWindow + return None + + +def determine_active_program_and_wm_class(): global active_process_name - active_process_name = active_program() + global active_wm_class_name + active_process_name = active_program_name() + active_wm_class_name = active_program_wm_class() while True: event = disp_prog.next_event() if event.type == Xlib.X.PropertyNotify and event.atom == NET_ACTIVE_WINDOW: - active_process_name = active_program() + active_process_name = active_program_name() + active_wm_class_name = active_program_wm_class() if x11: - _thread.start_new_thread(determine_active_program, ()) + _thread.start_new_thread(determine_active_program_and_wm_class, ()) # determine current key modifiers # there must be a better way to do this @@ -285,7 +300,9 @@ class Process(Condition): return 'Process: ' + str(self.process) def evaluate(self, feature, notification, device, status, last_result): - return active_process_name.startswith(self.process) if isinstance(self.process, str) else False + if not isinstance(self.process, str): + return False + return active_process_name.startswith(self.process) or active_wm_class_name.startswith(self.process) def data(self): return {'Process': str(self.process)}