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. . diff --git a/safeeyes/plugins/donotdisturb/plugin.py b/safeeyes/plugins/donotdisturb/plugin.py index 0ecb4790..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.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()