From b6c1f7fb51a6745ef974af3b6154e3d56b82e2b4 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Wed, 21 Aug 2024 11:37:57 +0300 Subject: [PATCH] Re-arrange code in X11Window::restackWindow() Above and Below modes should be handled as follows: if (sibling) { workspace_stack_below/above(window, sibling); } else { workspace_lower/raise(window); } But with the current code, it's difficult to see. This change rearranges the code in the restackWindow() so it's more clear how the Above and the Below modes are implemented. It also moves workspace()->findClient(Predicate::WindowMatch, above); to the top because all branches have it. --- src/x11window.cpp | 61 +++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/src/x11window.cpp b/src/x11window.cpp index 96f913e101..e92d6ad3c1 100644 --- a/src/x11window.cpp +++ b/src/x11window.cpp @@ -5437,9 +5437,8 @@ bool X11Window::allowWindowActivation(xcb_timestamp_t time, bool focus_in) void X11Window::restackWindow(xcb_window_t above, int detail, NET::RequestSource src, xcb_timestamp_t timestamp, bool send_event) { - X11Window *other = nullptr; + X11Window *other = workspace()->findClient(Predicate::WindowMatch, above); if (detail == XCB_STACK_MODE_OPPOSITE) { - other = workspace()->findClient(Predicate::WindowMatch, above); if (!other) { workspace()->raiseOrLowerWindow(this); return; @@ -5457,57 +5456,57 @@ void X11Window::restackWindow(xcb_window_t above, int detail, NET::RequestSource ++it; } } else if (detail == XCB_STACK_MODE_TOP_IF) { - other = workspace()->findClient(Predicate::WindowMatch, above); if (other && other->frameGeometry().intersects(frameGeometry())) { workspace()->raiseWindowRequest(this, src, timestamp); } return; } else if (detail == XCB_STACK_MODE_BOTTOM_IF) { - other = workspace()->findClient(Predicate::WindowMatch, above); if (other && other->frameGeometry().intersects(frameGeometry())) { workspace()->lowerWindowRequest(this, src, timestamp); } return; } - if (!other) { - other = workspace()->findClient(Predicate::WindowMatch, above); - } + if (detail == XCB_STACK_MODE_ABOVE) { + if (other) { + auto it = workspace()->stackingOrder().constEnd(), + begin = workspace()->stackingOrder().constBegin(); + while (--it != begin) { - if (other && detail == XCB_STACK_MODE_ABOVE) { - auto it = workspace()->stackingOrder().constEnd(), - begin = workspace()->stackingOrder().constBegin(); - while (--it != begin) { + if (*it == other) { // the other one is top on stack + it = begin; // invalidate + src = NET::FromTool; // force + break; + } + X11Window *window = qobject_cast(*it); - if (*it == other) { // the other one is top on stack - it = begin; // invalidate - src = NET::FromTool; // force - break; - } - X11Window *window = qobject_cast(*it); + if (!window || !((*it)->isNormalWindow() && window->isShown() && (*it)->isOnCurrentDesktop() && (*it)->isOnCurrentActivity() && (*it)->isOnOutput(output()))) { + continue; // irrelevant windows + } - if (!window || !((*it)->isNormalWindow() && window->isShown() && (*it)->isOnCurrentDesktop() && (*it)->isOnCurrentActivity() && (*it)->isOnOutput(output()))) { - continue; // irrelevant windows + if (*(it - 1) == other) { + break; // "it" is the one above the target one, stack below "it" + } } - if (*(it - 1) == other) { - break; // "it" is the one above the target one, stack below "it" + if (it != begin && (*(it - 1) == other)) { + other = qobject_cast(*it); + } else { + other = nullptr; } } - if (it != begin && (*(it - 1) == other)) { - other = qobject_cast(*it); + if (other) { + workspace()->stackBelow(this, other); } else { - other = nullptr; + workspace()->raiseWindowRequest(this, src, timestamp); } - } - - if (other) { - workspace()->stackBelow(this, other); } else if (detail == XCB_STACK_MODE_BELOW) { - workspace()->lowerWindowRequest(this, src, timestamp); - } else if (detail == XCB_STACK_MODE_ABOVE) { - workspace()->raiseWindowRequest(this, src, timestamp); + if (other) { + workspace()->stackBelow(this, other); + } else { + workspace()->lowerWindowRequest(this, src, timestamp); + } } if (send_event) {