diff --git a/src/input/cursor.cpp b/src/input/cursor.cpp index a3f7abe..52e3732 100644 --- a/src/input/cursor.cpp +++ b/src/input/cursor.cpp @@ -22,6 +22,7 @@ #include #include "wlr.h" // clang-format on +#include "wlr/util/edges.h" #include "workspace/scratchpad.h" #include "workspace/workspace.h" @@ -1689,24 +1690,19 @@ namespace umbriel { const int y = view->sceneTree()->node.y + geo.y; const double cx = m_cursor->x; const double cy = m_cursor->y; - const double distLeft = std::abs(cx - x); - const double distRight = std::abs(cx - (x + geo.width)); - const double distTop = std::abs(cy - y); - const double distBottom = std::abs(cy - (y + geo.height)); - const double nearestH = std::min(distLeft, distRight); - const double nearestV = std::min(distTop, distBottom); + const double px = cx - x; + const double py = cy - y; uint32_t edges = 0; - if (nearestH <= nearestV) { - edges |= distLeft <= distRight ? WLR_EDGE_LEFT : WLR_EDGE_RIGHT; - } else { - edges |= distTop <= distBottom ? WLR_EDGE_TOP : WLR_EDGE_BOTTOM; - } - // Prefer a corner when the cursor is near both axes. - constexpr double kCornerSlop = 32.0; - if (nearestH < kCornerSlop && nearestV < kCornerSlop) { - edges = (distLeft <= distRight ? WLR_EDGE_LEFT : WLR_EDGE_RIGHT) - | (distTop <= distBottom ? WLR_EDGE_TOP : WLR_EDGE_BOTTOM); + if (px < geo.width / 3.0) { + edges |= WLR_EDGE_LEFT; + } else if (px > 2.0 * geo.width / 3.0) { + edges |= WLR_EDGE_RIGHT; + } + if (py < geo.height / 3.0) { + edges |= WLR_EDGE_TOP; + } else if (py > 2.0 * geo.height / 3.0) { + edges |= WLR_EDGE_BOTTOM; } return edges; } diff --git a/tests/unit/presentation.cpp b/tests/unit/presentation.cpp index c30d060..848203e 100644 --- a/tests/unit/presentation.cpp +++ b/tests/unit/presentation.cpp @@ -6,10 +6,10 @@ #include "wlr.h" // clang-format on -// A fullscreen client whose buffer does not match the output is centered rather than scaled, and that centering lives in -// the scene node's position. The wlroots xdg scene helper rewrites that position to (-geometry.x, -geometry.y) on every -// commit, so the offset has to be re-applied afterwards or an oversized fullscreen buffer drifts to the top left on the -// next frame the client draws. +// A fullscreen client whose buffer does not match the output is centered rather than scaled, and that centering lives +// in the scene node's position. The wlroots xdg scene helper rewrites that position to (-geometry.x, -geometry.y) on +// every commit, so the offset has to be re-applied afterwards or an oversized fullscreen buffer drifts to the top left +// on the next frame the client draws. UMBRIEL_TEST(fullscreenCenteringSurvivesSceneReconfiguration) { wlr_scene* scene = wlr_scene_create(); CHECK(scene != nullptr);