From 7442c52c2038c5e8046923fea2929919333da545 Mon Sep 17 00:00:00 2001 From: "Peter F. Patel-Schneider" Date: Thu, 13 Jan 2022 12:54:32 -0500 Subject: [PATCH] rules: defend against problems when determining focus program --- lib/logitech_receiver/diversion.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/logitech_receiver/diversion.py b/lib/logitech_receiver/diversion.py index e7ce71ae..88083dab 100644 --- a/lib/logitech_receiver/diversion.py +++ b/lib/logitech_receiver/diversion.py @@ -293,7 +293,10 @@ def x11_focus_prog(): if wm_class and pid: break window = window.query_tree().parent - name = psutil.Process(pid.value[0]).name() if pid else '' + try: + name = psutil.Process(pid.value[0]).name() if pid else '' + except Exception: + name = '' return (wm_class[0], wm_class[1], name) if wm_class else (name, ) @@ -323,7 +326,8 @@ class Process(Condition): def evaluate(self, feature, notification, device, status, last_result): if not isinstance(self.process, str): return False - result = any(bool(s and s.startswith(self.process)) for s in x11_focus_prog()) + focus = x11_focus_prog() + result = any(bool(s and s.startswith(self.process)) for s in focus) if focus else None return result def data(self):