From a3fc61b0782800a42ff0829ec3cda65b50431bd7 Mon Sep 17 00:00:00 2001 From: Tin Date: Fri, 10 Nov 2023 03:20:18 +0100 Subject: [PATCH] Cleanup focus handling code on propagation Signed-off-by: Tin --- src/x11.cc | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/x11.cc b/src/x11.cc index 5a31d71a..3dff77f6 100644 --- a/src/x11.cc +++ b/src/x11.cc @@ -1371,12 +1371,16 @@ void propagate_x11_event(XEvent &ev) { i_ev->common.y = i_ev->common.y_root; } XSendEvent(display, window.desktop, False, window.event_mask, &ev); - // FIXME (before-merge): Should we be setting input focus after forwarding - // events? - if (false && ev.type == ButtonPress) { - XSetInputFocus(display, window.desktop, RevertToNone, i_ev->common.time); - } else if (false && ev.type == MotionNotify) { - XSetInputFocus(display, window.window, RevertToParent, i_ev->common.time); + + int _revert_to; + Window focused; + XGetInputFocus(display, &focused, &_revert_to); + if (focused == window.window) { + Time time = CurrentTime; + if (i_ev != nullptr) { + time = i_ev->common.time; + } + XSetInputFocus(display, window.desktop, RevertToPointerRoot, time); } } @@ -1384,12 +1388,12 @@ void propagate_x11_event(XEvent &ev) { // Assuming parent has a simple linear stack of descendants, this function // returns the last leaf on the graph. inline Window last_descendant(Display* display, Window parent) { - Window ignored, *children; + Window _ignored, *children; uint32_t count; Window current = parent; - while (XQueryTree(display, current, &ignored, &ignored, &children, &count) && count != 0) { + while (XQueryTree(display, current, &_ignored, &_ignored, &children, &count) && count != 0) { current = children[count - 1]; XFree(children); }