Skip to content

Commit cf4c792

Browse files
Merge pull request slgobinath#685 from deltragon/fix-dnd-x11
donotdisturb: fix fullscreen window detection on Cinnamon
2 parents c26293f + 9654175 commit cf4c792

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

safeeyes/plugins/donotdisturb/plugin.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,39 @@ def is_active_window_skipped_xorg(pre_break):
6363
"""
6464
logging.info("Searching for full-screen application")
6565

66+
def get_window_property(window, prop, proptype):
67+
result = window.get_full_property(prop, proptype)
68+
if result:
69+
return result.value
70+
71+
return None
72+
73+
def get_active_window(x11_display):
74+
"""Get active window using EWMH hints.
75+
76+
Returns None if there is no active window.
77+
This always returns None if the window manager does not use EWMH hints.
78+
However, GTK3 also used this method to get the active window.
79+
"""
80+
root = x11_display.screen().root
81+
NET_ACTIVE_WINDOW = x11_display.intern_atom("_NET_ACTIVE_WINDOW")
82+
83+
active_windows = get_window_property(root, NET_ACTIVE_WINDOW, Xlib.Xatom.WINDOW)
84+
if active_windows and active_windows[0]:
85+
active_window = active_windows[0]
86+
return x11_display.create_resource_object('window', active_window)
87+
return None
88+
6689
x11_display = Xlib.display.Display()
67-
active_window = x11_display.get_input_focus().focus
90+
91+
active_window = get_active_window(x11_display)
6892

6993
if active_window:
7094
NET_WM_STATE = x11_display.intern_atom("_NET_WM_STATE")
7195
NET_WM_STATE_FULLSCREEN = x11_display.intern_atom("_NET_WM_STATE_FULLSCREEN")
7296

73-
props = active_window.get_full_property(NET_WM_STATE, Xlib.Xatom.ATOM)
74-
is_fullscreen = props.value and NET_WM_STATE_FULLSCREEN in props.value.tolist()
97+
props = get_window_property(active_window, NET_WM_STATE, Xlib.Xatom.ATOM)
98+
is_fullscreen = props and NET_WM_STATE_FULLSCREEN in props.tolist()
7599

76100
process_names = active_window.get_wm_class()
77101

0 commit comments

Comments
 (0)