diff options
author | nickodei <[email protected]> | 2024-11-08 18:25:37 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2024-11-08 17:25:37 +0000 |
commit | 3b66351eeb76e802bac37cc892529549efc49905 (patch) | |
tree | 542b30d41f4f34c3c239910cb7a789e8dfd171ff | |
parent | e58e97b0a38b8ccc87a4304c9e4e2b37c9966875 (diff) | |
download | Hyprland-3b66351eeb76e802bac37cc892529549efc49905.tar.gz Hyprland-3b66351eeb76e802bac37cc892529549efc49905.zip |
input: Refocus window on scrolling if follows mouse (#8361)
-rw-r--r-- | src/managers/input/InputManager.cpp | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index af725927..b12a6e03 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -759,6 +759,7 @@ void CInputManager::onMouseWheel(IPointer::SAxisEvent e) { static auto PINPUTSCROLLFACTOR = CConfigValue<Hyprlang::FLOAT>("input:scroll_factor"); static auto PTOUCHPADSCROLLFACTOR = CConfigValue<Hyprlang::FLOAT>("input:touchpad:scroll_factor"); static auto PEMULATEDISCRETE = CConfigValue<Hyprlang::INT>("input:emulate_discrete_scroll"); + static auto PFOLLOWMOUSE = CConfigValue<Hyprlang::INT>("input:follow_mouse"); auto factor = (*PTOUCHPADSCROLLFACTOR <= 0.f || e.source == WL_POINTER_AXIS_SOURCE_FINGER ? *PTOUCHPADSCROLLFACTOR : *PINPUTSCROLLFACTOR); @@ -774,24 +775,33 @@ void CInputManager::onMouseWheel(IPointer::SAxisEvent e) { const auto MOUSECOORDS = g_pInputManager->getMouseCoordsInternal(); const auto PWINDOW = g_pCompositor->vectorToWindowUnified(MOUSECOORDS, RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING); - if (PWINDOW && PWINDOW->checkInputOnDecos(INPUT_TYPE_AXIS, MOUSECOORDS, e)) - return; + if (PWINDOW) { + if (PWINDOW->checkInputOnDecos(INPUT_TYPE_AXIS, MOUSECOORDS, e)) + return; + + if (*POFFWINDOWAXIS != 1) { + const auto BOX = PWINDOW->getWindowMainSurfaceBox(); - if (PWINDOW && *POFFWINDOWAXIS != 1) { - const auto BOX = PWINDOW->getWindowMainSurfaceBox(); + if (!BOX.containsPoint(MOUSECOORDS) && !PWINDOW->hasPopupAt(MOUSECOORDS)) { + if (*POFFWINDOWAXIS == 0) + return; - if (!BOX.containsPoint(MOUSECOORDS) && !PWINDOW->hasPopupAt(MOUSECOORDS)) { - if (*POFFWINDOWAXIS == 0) - return; + const auto TEMPCURX = std::clamp(MOUSECOORDS.x, BOX.x, BOX.x + BOX.w - 1); + const auto TEMPCURY = std::clamp(MOUSECOORDS.y, BOX.y, BOX.y + BOX.h - 1); - const auto TEMPCURX = std::clamp(MOUSECOORDS.x, BOX.x, BOX.x + BOX.w - 1); - const auto TEMPCURY = std::clamp(MOUSECOORDS.y, BOX.y, BOX.y + BOX.h - 1); + if (*POFFWINDOWAXIS == 3) + g_pCompositor->warpCursorTo({TEMPCURX, TEMPCURY}, true); + + g_pSeatManager->sendPointerMotion(e.timeMs, Vector2D{TEMPCURX, TEMPCURY} - BOX.pos()); + g_pSeatManager->sendPointerFrame(); + } + } - if (*POFFWINDOWAXIS == 3) - g_pCompositor->warpCursorTo({TEMPCURX, TEMPCURY}, true); + if (g_pSeatManager->state.pointerFocus) { + const auto PCURRWINDOW = g_pCompositor->getWindowFromSurface(g_pSeatManager->state.pointerFocus.lock()); - g_pSeatManager->sendPointerMotion(e.timeMs, Vector2D{TEMPCURX, TEMPCURY} - BOX.pos()); - g_pSeatManager->sendPointerFrame(); + if (*PFOLLOWMOUSE == 1 && PCURRWINDOW && PWINDOW != PCURRWINDOW) + simulateMouseMovement(); } } } |