rules: match WM_CLASS also for process matching in rules

This commit is contained in:
SiDevesh 2021-04-09 00:29:05 +05:30 committed by Peter F. Patel-Schneider
parent 1cb8f0c874
commit d3a18bb85f
1 changed files with 23 additions and 6 deletions

View File

@ -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)}