Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions src/input/cursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <linux/input-event-codes.h>
#include "wlr.h"
// clang-format on
#include "wlr/util/edges.h"
#include "workspace/scratchpad.h"
#include "workspace/workspace.h"

Expand Down Expand Up @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/presentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down