From 1e9796838899302213de3fae7457a7c1aaea5be6 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 25 Sep 2022 02:20:05 +0200 Subject: Use NET_ACTIVE_WINDOW instead of getinputfocus --- src/QuickMedia.cpp | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index c9e52c1..54a85de 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -3005,10 +3005,33 @@ namespace QuickMedia { || is_soundcloud(url); } - void Program::redirect_focus_to_video_player_window(mgl::WindowHandle video_player_window) { + static Window get_input_focus(Display *display) { Window focused_window = None; - int dummy; - XGetInputFocus(disp, &focused_window, &dummy); + + Atom net_active_window_atom = XInternAtom(display, "_NET_ACTIVE_WINDOW", False); + Atom type; + unsigned long len, bytes_left; + int format; + unsigned char *properties = NULL; + if(XGetWindowProperty(display, DefaultRootWindow(display), net_active_window_atom, 0, 1024, False, XA_WINDOW, &type, &format, &len, &bytes_left, &properties) == Success) { + if(properties) { + if(len > 0) + focused_window = *(Window*)properties; + XFree(properties); + } + } + + if(!focused_window) { + int rev; + if(!XGetInputFocus(display, &focused_window, &rev)) + focused_window = None; + } + + return focused_window; + } + + void Program::redirect_focus_to_video_player_window(mgl::WindowHandle video_player_window) { + Window focused_window = get_input_focus(disp); if(focused_window != window.get_system_handle()) return; -- cgit v1.2.3