From c79afc0e0b80d5c45bc2f2dd98c1e80b5b3a9eba Mon Sep 17 00:00:00 2001 From: deltragon Date: Tue, 4 Mar 2025 15:54:37 +0100 Subject: [PATCH 1/3] donotdisturb: x11: don't crash if _NET_WM_STATE property does not exist --- safeeyes/plugins/donotdisturb/plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/safeeyes/plugins/donotdisturb/plugin.py b/safeeyes/plugins/donotdisturb/plugin.py index 0ecb4790..2886fe15 100644 --- a/safeeyes/plugins/donotdisturb/plugin.py +++ b/safeeyes/plugins/donotdisturb/plugin.py @@ -71,7 +71,7 @@ def is_active_window_skipped_xorg(pre_break): NET_WM_STATE_FULLSCREEN = x11_display.intern_atom("_NET_WM_STATE_FULLSCREEN") props = active_window.get_full_property(NET_WM_STATE, Xlib.Xatom.ATOM) - is_fullscreen = props.value and NET_WM_STATE_FULLSCREEN in props.value.tolist() + is_fullscreen = props and props.value and NET_WM_STATE_FULLSCREEN in props.value.tolist() process_names = active_window.get_wm_class() From 9654175d5f842662beb5383a8bde54b403c6529b Mon Sep 17 00:00:00 2001 From: deltragon Date: Tue, 4 Mar 2025 16:01:17 +0100 Subject: [PATCH 2/3] donotdisturb: x11: use EWMH to detect active window --- safeeyes/plugins/donotdisturb/plugin.py | 30 ++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/safeeyes/plugins/donotdisturb/plugin.py b/safeeyes/plugins/donotdisturb/plugin.py index 2886fe15..1dfc3f54 100644 --- a/safeeyes/plugins/donotdisturb/plugin.py +++ b/safeeyes/plugins/donotdisturb/plugin.py @@ -63,15 +63,39 @@ def is_active_window_skipped_xorg(pre_break): """ logging.info("Searching for full-screen application") + def get_window_property(window, prop, proptype): + result = window.get_full_property(prop, proptype) + if result: + return result.value + + return None + + def get_active_window(x11_display): + """Get active window using EWMH hints. + + Returns None if there is no active window. + This always returns None if the window manager does not use EWMH hints. + However, GTK3 also used this method to get the active window. + """ + root = x11_display.screen().root + NET_ACTIVE_WINDOW = x11_display.intern_atom("_NET_ACTIVE_WINDOW") + + active_windows = get_window_property(root, NET_ACTIVE_WINDOW, Xlib.Xatom.WINDOW) + if active_windows and active_windows[0]: + active_window = active_windows[0] + return x11_display.create_resource_object('window', active_window) + return None + x11_display = Xlib.display.Display() - active_window = x11_display.get_input_focus().focus + + active_window = get_active_window(x11_display) if active_window: NET_WM_STATE = x11_display.intern_atom("_NET_WM_STATE") NET_WM_STATE_FULLSCREEN = x11_display.intern_atom("_NET_WM_STATE_FULLSCREEN") - props = active_window.get_full_property(NET_WM_STATE, Xlib.Xatom.ATOM) - is_fullscreen = props and props.value and NET_WM_STATE_FULLSCREEN in props.value.tolist() + props = get_window_property(active_window, NET_WM_STATE, Xlib.Xatom.ATOM) + is_fullscreen = props and NET_WM_STATE_FULLSCREEN in props.tolist() process_names = active_window.get_wm_class() From 17bbcaa295cb7c67e7642cfc47f51b7fa81f6d98 Mon Sep 17 00:00:00 2001 From: Archisman Panigrahi Date: Tue, 4 Mar 2025 11:34:42 -0500 Subject: [PATCH 3/3] Update debian/control with gtk4 dependency --- debian/control | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/control b/debian/control index e96dc223..da665f0b 100644 --- a/debian/control +++ b/debian/control @@ -9,7 +9,7 @@ Homepage: https://github.com/slgobinath/SafeEyes/ Package: safeeyes Architecture: all -Depends: ${misc:Depends}, ${python3:Depends}, python3 (>= 3.10.0), python3-xlib, gir1.2-notify-0.7, python3-babel, x11-utils, xprintidle, alsa-utils, python3-psutil, python3-croniter, python3-packaging +Depends: ${misc:Depends}, ${python3:Depends}, python3 (>= 3.10.0), python3-xlib, gir1.2-notify-0.7, python3-babel, x11-utils, xprintidle, alsa-utils, python3-psutil, python3-croniter, python3-packaging, gir1.2-gtk-4.0 Description: Prevent eye strain with Safe Eyes – an essential screen break reminder. Safe Eyes is a simple tool to remind you to take periodic breaks for your eyes. This is essential for anyone spending more time on the computer to avoid eye strain and other physical problems. .