From fec5ff333ee7ae9283421cf256e1d94bcb9f3319 Mon Sep 17 00:00:00 2001 From: Sniffy Gumbles <155901370+SGumbles@users.noreply.github.com> Date: Sun, 22 Mar 2026 16:24:03 -0700 Subject: [PATCH] compositor: be more selective about how we expand the window box in getting coord (#13720) * Be more selective about how we expand the window box here so that we're not overlapping with any neighbouring windows. * Don't use getWindowInDirection to see if we're clear to expand the hit box. Instead, just see if our edge is close to the edge of the workspace. * Clang-format changes --- src/Compositor.cpp | 51 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 4f8809aa7..e089df462 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -1033,8 +1033,55 @@ PHLWINDOW CCompositor::vectorToWindowUnified(const Vector2D& pos, uint8_t proper if (!w->m_isFloating && w->m_isMapped && w->workspaceID() == WSPID && !w->isHidden() && !w->m_X11ShouldntFocus && !w->m_ruleApplicator->noFocus().valueOrDefault() && w != pIgnoreWindow && !isShadowedByModal(w)) { CBox box = (properties & Desktop::View::USE_PROP_TILED) ? w->getWindowBoxUnified(properties) : CBox{w->m_position, w->m_size}; - if ((properties & Desktop::View::INPUT_EXTENTS) && BORDER_GRAB_AREA > 0 && !w->isX11OverrideRedirect()) - box.expand(BORDER_GRAB_AREA); + if ((properties & Desktop::View::INPUT_EXTENTS) && BORDER_GRAB_AREA > 0 && !w->isX11OverrideRedirect()) { + const auto WORKAREA = PWORKSPACE->m_space->workArea(); + static auto isWindowCloseToWorkAreaEdge = [&](const Math::eDirection dir) -> bool { + constexpr double STICK_THRESHOLD = 2.0; // This constant is taken from isAdjacent in CCompositor::getWindowInDirection + double aEdge = -1; + double bEdge = -1; + + switch (dir) { + case Math::DIRECTION_LEFT: + aEdge = WORKAREA.x; + bEdge = box.x; + break; + case Math::DIRECTION_RIGHT: + aEdge = WORKAREA.x + WORKAREA.width; + bEdge = box.x + box.width; + break; + case Math::DIRECTION_UP: + aEdge = WORKAREA.y; + bEdge = box.y; + break; + case Math::DIRECTION_DOWN: + aEdge = WORKAREA.y + WORKAREA.height; + bEdge = box.y + box.height; + break; + default: break; + } + const double delta = aEdge - bEdge; + if (std::abs(delta) < STICK_THRESHOLD) + return true; + else + return false; + }; + + if (isWindowCloseToWorkAreaEdge(Math::eDirection::DIRECTION_LEFT)) { + box.x -= BORDER_GRAB_AREA; + box.width += BORDER_GRAB_AREA; + } + + if (isWindowCloseToWorkAreaEdge(Math::eDirection::DIRECTION_RIGHT)) + box.width += BORDER_GRAB_AREA; + + if (isWindowCloseToWorkAreaEdge(Math::eDirection::DIRECTION_UP)) { + box.y -= BORDER_GRAB_AREA; + box.height += BORDER_GRAB_AREA; + } + + if (isWindowCloseToWorkAreaEdge(Math::eDirection::DIRECTION_DOWN)) + box.height += BORDER_GRAB_AREA; + } if (box.containsPoint(pos)) return w; }