Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from slgobinath:master #99

Merged
merged 4 commits into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -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.
.
Expand Down
30 changes: 27 additions & 3 deletions safeeyes/plugins/donotdisturb/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down