diff options
author | dec05eba <dec05eba@protonmail.com> | 2025-01-03 01:57:30 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2025-01-03 01:57:30 +0100 |
commit | 2a07c741121e737aec9bdd5214ba66efbf252da0 (patch) | |
tree | a717b3328ec4bfcf87d7aa7281261f3e42519537 /src/WindowUtils.cpp | |
parent | f526c175f6e2b852c8fe19b666505cfeac36b667 (diff) |
Fix some application (using xi) receiving mouse input when UI is shown
Diffstat (limited to 'src/WindowUtils.cpp')
-rw-r--r-- | src/WindowUtils.cpp | 47 |
1 files changed, 42 insertions, 5 deletions
diff --git a/src/WindowUtils.cpp b/src/WindowUtils.cpp index 1560d3e..057e95f 100644 --- a/src/WindowUtils.cpp +++ b/src/WindowUtils.cpp @@ -29,19 +29,56 @@ namespace gsr { return window_has_atom(dpy, window, net_wm_state_atom) || window_has_atom(dpy, window, wm_state_atom); } + static Window window_get_target_window_child(Display *display, Window window) { + if(window == None) + return None; + + if(window_is_user_program(display, window)) + return window; + + Window root; + Window parent; + Window *children = nullptr; + unsigned int num_children = 0; + if(!XQueryTree(display, window, &root, &parent, &children, &num_children) || !children) + return None; + + Window found_window = None; + for(int i = num_children - 1; i >= 0; --i) { + if(children[i] && window_is_user_program(display, children[i])) { + found_window = children[i]; + goto finished; + } + } + + for(int i = num_children - 1; i >= 0; --i) { + if(children[i]) { + Window win = window_get_target_window_child(display, children[i]); + if(win) { + found_window = win; + goto finished; + } + } + } + + finished: + XFree(children); + return found_window; + } + static Window get_window_at_cursor_position(Display *dpy) { Window root_window = None; Window window = None; int dummy_i; unsigned int dummy_u; - int cursor_pos_x = 0; - int cursor_pos_y = 0; - XQueryPointer(dpy, DefaultRootWindow(dpy), &root_window, &window, &dummy_i, &dummy_i, &cursor_pos_x, &cursor_pos_y, &dummy_u); + XQueryPointer(dpy, DefaultRootWindow(dpy), &root_window, &window, &dummy_i, &dummy_i, &dummy_i, &dummy_i, &dummy_u); + if(window) + window = window_get_target_window_child(dpy, window); return window; } Window get_focused_window(Display *dpy, WindowCaptureType cap_type) { - const Atom net_active_window_atom = XInternAtom(dpy, "_NET_ACTIVE_WINDOW", False); + //const Atom net_active_window_atom = XInternAtom(dpy, "_NET_ACTIVE_WINDOW", False); Window focused_window = None; if(cap_type == WindowCaptureType::FOCUSED) { @@ -68,7 +105,7 @@ namespace gsr { } focused_window = get_window_at_cursor_position(dpy); - if(focused_window && focused_window != DefaultRootWindow(dpy) && window_is_user_program(dpy, focused_window)) + if(focused_window && focused_window != DefaultRootWindow(dpy)) return focused_window; return None; |