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
This commit is contained in:
Sniffy Gumbles 2026-03-22 16:24:03 -07:00 committed by Vaxry
parent aaea8547d6
commit fec5ff333e
Signed by: vaxry
GPG key ID: 665806380871D640

View file

@ -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;
}