From 1edd66618f45a2e042260e4af81933d532e82394 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Mon, 1 Aug 2022 18:50:16 +0200 Subject: [PATCH] added general:no_cursor_warps --- src/Compositor.cpp | 16 +++++++++++++++- src/Compositor.hpp | 1 + src/config/ConfigManager.cpp | 1 + src/managers/KeybindManager.cpp | 8 ++++---- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 52dd634c..13689193 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -1501,4 +1501,18 @@ void CCompositor::startHyprCtlTick() { hyprCtlTickSource = wl_event_loop_add_timer(m_sWLEventLoop, hyprCtlTick, nullptr); wl_event_source_timer_update(hyprCtlTickSource, 16); -} \ No newline at end of file +} + +void CCompositor::warpCursorTo(const Vector2D& pos) { + + // warpCursorTo should only be used for warps that + // should be disabled with no_cursor_warps + + static auto *const PNOWARPS = &g_pConfigManager->getConfigValuePtr("general:no_cursor_warps")->intValue; + + if (*PNOWARPS) + return; + + wlr_cursor_warp(m_sWLRCursor, m_sSeat.mouse->mouse, pos.x, pos.y); +} + diff --git a/src/Compositor.hpp b/src/Compositor.hpp index 15e22014..5d46141c 100644 --- a/src/Compositor.hpp +++ b/src/Compositor.hpp @@ -152,6 +152,7 @@ public: void addToFadingOutSafe(SLayerSurface*); void addToFadingOutSafe(CWindow*); CWindow* getWindowByRegex(const std::string&); + void warpCursorTo(const Vector2D&); std::string explicitConfigPath; diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 291b31e8..f5294a8c 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -45,6 +45,7 @@ void CConfigManager::setDefaultVars() { configValues["general:col.active_border"].intValue = 0xffffffff; configValues["general:col.inactive_border"].intValue = 0xff444444; configValues["general:cursor_inactive_timeout"].intValue = 0; + configValues["general:no_cursor_warps"].intValue = 0; configValues["general:layout"].strValue = "dwindle"; diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 155cc38b..895e7600 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -510,7 +510,7 @@ void CKeybindManager::changeworkspace(std::string args) { // If the monitor is not the one our cursor's at, warp to it. if (PMONITOR != g_pCompositor->getMonitorFromCursor()) { Vector2D middle = PMONITOR->vecPosition + PMONITOR->vecSize / 2.f; - wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, middle.x, middle.y); + g_pCompositor->warpCursorTo(middle); } // set active and deactivate all other in wlr @@ -744,7 +744,7 @@ void CKeybindManager::moveFocusTo(std::string args) { auto switchToWindow = [&](CWindow* PWINDOWTOCHANGETO) { g_pCompositor->focusWindow(PWINDOWTOCHANGETO); Vector2D middle = PWINDOWTOCHANGETO->m_vRealPosition.goalv() + PWINDOWTOCHANGETO->m_vRealSize.goalv() / 2.f; - wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, middle.x, middle.y); + g_pCompositor->warpCursorTo(middle); }; if (!g_pCompositor->windowValidMapped(PLASTWINDOW)) { @@ -1245,7 +1245,7 @@ void CKeybindManager::circleNext(std::string arg) { const auto MIDPOINT = g_pCompositor->m_pLastWindow->m_vRealPosition.goalv() + g_pCompositor->m_pLastWindow->m_vRealSize.goalv() / 2.f; - wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, MIDPOINT.x, MIDPOINT.y); + g_pCompositor->warpCursorTo(MIDPOINT); } void CKeybindManager::focusWindow(std::string regexp) { @@ -1262,7 +1262,7 @@ void CKeybindManager::focusWindow(std::string regexp) { const auto MIDPOINT = PWINDOW->m_vRealPosition.goalv() + PWINDOW->m_vRealSize.goalv() / 2.f; - wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, MIDPOINT.x, MIDPOINT.y); + g_pCompositor->warpCursorTo(MIDPOINT); } void CKeybindManager::setSubmap(std::string submap) {