aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorvaxerski <[email protected]>2022-11-20 17:35:07 +0000
committervaxerski <[email protected]>2022-11-20 17:35:13 +0000
commit137cf9e5825fbead1d78110cb16480ccb9105931 (patch)
tree7241645a03f066b2794dd7d45310548ee81ec7d7
parent11e841580fdd630e8cfd32c2a7d89f71999cb67a (diff)
downloadHyprland-137cf9e5825fbead1d78110cb16480ccb9105931.tar.gz
Hyprland-137cf9e5825fbead1d78110cb16480ccb9105931.zip
improve constraint handling
-rw-r--r--src/defines.hpp2
-rw-r--r--src/managers/input/InputManager.cpp33
2 files changed, 17 insertions, 18 deletions
diff --git a/src/defines.hpp b/src/defines.hpp
index e16bb019..c6bd7d6e 100644
--- a/src/defines.hpp
+++ b/src/defines.hpp
@@ -31,6 +31,8 @@
const auto RECTSARR = pixman_region32_rectangles(region, &rectsNum); \
for (int i = 0; i < rectsNum; ++i)
+#define PIXMAN_REGION_FOREACH(region) PIXMAN_DAMAGE_FOREACH(region)
+
#define interface class
diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp
index ed96cb64..2aa2f7a5 100644
--- a/src/managers/input/InputManager.cpp
+++ b/src/managers/input/InputManager.cpp
@@ -73,6 +73,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) {
// XWayland windows sometimes issue constraints weirdly.
// TODO: We probably should search their parent. wlr_xwayland_surface->parent
const auto CONSTRAINTWINDOW = g_pCompositor->getConstraintWindow(g_pCompositor->m_sSeat.mouse);
+ const auto PCONSTRAINT = g_pCompositor->m_sSeat.mouse->currentConstraint;
if (!CONSTRAINTWINDOW) {
unconstrainMouse();
@@ -82,27 +83,23 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) {
const auto CONSTRAINTPOS = CONSTRAINTWINDOW->m_bIsX11 ? Vector2D(CONSTRAINTWINDOW->m_uSurface.xwayland->x, CONSTRAINTWINDOW->m_uSurface.xwayland->y) : CONSTRAINTWINDOW->m_vRealPosition.vec();
const auto CONSTRAINTSIZE = CONSTRAINTWINDOW->m_bIsX11 ? Vector2D(CONSTRAINTWINDOW->m_uSurface.xwayland->width, CONSTRAINTWINDOW->m_uSurface.xwayland->height) : CONSTRAINTWINDOW->m_vRealSize.vec();
- if (!VECINRECT(mouseCoords, CONSTRAINTPOS.x, CONSTRAINTPOS.y, CONSTRAINTPOS.x + CONSTRAINTSIZE.x - 1.0, CONSTRAINTPOS.y + CONSTRAINTSIZE.y - 1.0)) {
- if (g_pCompositor->m_sSeat.mouse->constraintActive) {
- Vector2D newConstrainedCoords = mouseCoords;
+ if (g_pCompositor->m_sSeat.mouse->currentConstraint->type == WLR_POINTER_CONSTRAINT_V1_LOCKED) {
+ // we just snap the cursor to where it should be.
- if (mouseCoords.x < CONSTRAINTPOS.x)
- newConstrainedCoords.x = CONSTRAINTPOS.x;
- else if (mouseCoords.x >= CONSTRAINTPOS.x + CONSTRAINTSIZE.x)
- newConstrainedCoords.x = CONSTRAINTPOS.x + CONSTRAINTSIZE.x - 1.0;
+ Vector2D hint = { PCONSTRAINT->current.cursor_hint.x, PCONSTRAINT->current.cursor_hint.y };
- if (mouseCoords.y < CONSTRAINTPOS.y)
- newConstrainedCoords.y = CONSTRAINTPOS.y;
- else if (mouseCoords.y >= CONSTRAINTPOS.y + CONSTRAINTSIZE.y)
- newConstrainedCoords.y = CONSTRAINTPOS.y + CONSTRAINTSIZE.y - 1.0;
-
- wlr_cursor_warp_closest(g_pCompositor->m_sWLRCursor, g_pCompositor->m_sSeat.mouse->mouse, newConstrainedCoords.x, newConstrainedCoords.y);
-
- mouseCoords = newConstrainedCoords;
- }
+ wlr_cursor_warp_closest(g_pCompositor->m_sWLRCursor, g_pCompositor->m_sSeat.mouse->mouse, CONSTRAINTPOS.x + hint.x, CONSTRAINTPOS.y + hint.y);
} else {
- if ((!CONSTRAINTWINDOW->m_bIsX11 && PMONITOR && CONSTRAINTWINDOW->m_iWorkspaceID == PMONITOR->activeWorkspace) || (CONSTRAINTWINDOW->m_bIsX11)) {
- g_pCompositor->m_sSeat.mouse->constraintActive = true;
+ // we restrict the cursor to the confined region
+ if (!pixman_region32_contains_point(&PCONSTRAINT->region, mouseCoords.x - CONSTRAINTPOS.x, mouseCoords.y - CONSTRAINTPOS.y, nullptr)) {
+ if (g_pCompositor->m_sSeat.mouse->constraintActive) {
+ wlr_cursor_warp_closest(g_pCompositor->m_sWLRCursor, NULL, mouseCoords.x, mouseCoords.y);
+ mouseCoords = getMouseCoordsInternal();
+ }
+ } else {
+ if ((!CONSTRAINTWINDOW->m_bIsX11 && PMONITOR && CONSTRAINTWINDOW->m_iWorkspaceID == PMONITOR->activeWorkspace) || (CONSTRAINTWINDOW->m_bIsX11)) {
+ g_pCompositor->m_sSeat.mouse->constraintActive = true;
+ }
}
}