diff options
| author | memchr <118117622+memchr@users.noreply.github.com> | 2024-06-07 17:52:15 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-07 19:52:15 +0200 |
| commit | 41e1147dfc3319ccac0ed11bbbe8f3c77f8b635f (patch) | |
| tree | b9152be3997de2005f57635b78efca1383f6c965 /src/desktop/Window.cpp | |
| parent | 9bc00897fcc896c49a83f55da9de2427e878401a (diff) | |
input: add cursor:persistent_warps to maintain relative position within a window (#6338)
Allows the cursor to return to its last relative position within a window when the window is refocused.
Allows the cursor to retain its relative position within a window when the window is swapped, moved, changed workspace, added to or removed from groups.
controlled with cursor:persistent_warps
Diffstat (limited to 'src/desktop/Window.cpp')
| -rw-r--r-- | src/desktop/Window.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/desktop/Window.cpp b/src/desktop/Window.cpp index 9f5f9dd3..c478b766 100644 --- a/src/desktop/Window.cpp +++ b/src/desktop/Window.cpp @@ -1356,7 +1356,7 @@ void CWindow::activate(bool force) { g_pCompositor->changeWindowZOrder(m_pSelf.lock(), true); g_pCompositor->focusWindow(m_pSelf.lock()); - g_pCompositor->warpCursorTo(middle()); + warpCursor(); } void CWindow::onUpdateState() { @@ -1530,3 +1530,14 @@ void CWindow::onX11Configure(CBox box) { g_pHyprRenderer->damageWindow(m_pSelf.lock()); } + +void CWindow::warpCursor() { + static auto PERSISTENTWARPS = CConfigValue<Hyprlang::INT>("cursor:persistent_warps"); + const auto coords = m_vRelativeCursorCoordsOnLastWarp; + m_vRelativeCursorCoordsOnLastWarp.x = -1; // reset m_vRelativeCursorCoordsOnLastWarp + + if (*PERSISTENTWARPS && coords.x > 0 && coords.y > 0 && coords < m_vSize) // don't warp cursor outside the window + g_pCompositor->warpCursorTo(m_vPosition + coords); + else + g_pCompositor->warpCursorTo(middle()); +} |
