diff options
| author | Barrett Ruth <62671086+barrettruth@users.noreply.github.com> | 2026-05-01 19:02:01 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-05-02 00:02:01 +0100 |
| commit | f9723133cc909874999e6181bddf286033070e0c (patch) | |
| tree | 18f7ba9eaa2cb38676ee114ea4485b2b61f28ecc /src/managers | |
| parent | c7b8fe13c10d6a4392bfda9bcfc041e0ea0b7c00 (diff) | |
gestures: add live pinch cursor zoom (#14049)
Diffstat (limited to 'src/managers')
| -rw-r--r-- | src/managers/input/trackpad/gestures/CursorZoomGesture.cpp | 57 | ||||
| -rw-r--r-- | src/managers/input/trackpad/gestures/CursorZoomGesture.hpp | 5 |
2 files changed, 57 insertions, 5 deletions
diff --git a/src/managers/input/trackpad/gestures/CursorZoomGesture.cpp b/src/managers/input/trackpad/gestures/CursorZoomGesture.cpp index 515edbb6..418b8f7a 100644 --- a/src/managers/input/trackpad/gestures/CursorZoomGesture.cpp +++ b/src/managers/input/trackpad/gestures/CursorZoomGesture.cpp @@ -2,19 +2,40 @@ #include "../../../../Compositor.hpp" #include "../../../../helpers/Monitor.hpp" +#include "../../../../managers/input/InputManager.hpp" +#include <hyprutils/string/Numeric.hpp> CCursorZoomTrackpadGesture::CCursorZoomTrackpadGesture(const std::string& first, const std::string& second) { - try { - m_zoomValue = std::stof(first); - } catch (...) { ; } + if (const auto n = Hyprutils::String::strToNumber<float>(first); n) + m_zoomValue = n.value(); if (second == "mult") m_mode = MODE_MULT; + else if (second == "live") + m_mode = MODE_LIVE; } void CCursorZoomTrackpadGesture::begin(const ITrackpadGesture::STrackpadGestureBegin& e) { ITrackpadGesture::begin(e); + if (m_mode == MODE_LIVE) { + if (!e.pinch) + return; + + m_monitor = g_pCompositor->getMonitorFromCursor(); + if (!m_monitor) + return; + + const auto PMONITOR = m_monitor.lock(); + if (!PMONITOR) + return; + + m_zoomBegin = std::clamp(PMONITOR->m_cursorZoom->value(), 1.0F, 100.0F); + PMONITOR->m_cursorZoom->setValueAndWarp(m_zoomBegin); + PMONITOR->m_zoomController.pinAnchor(g_pInputManager->getMouseCoordsInternal() - PMONITOR->m_position); + return; + } + if (m_mode == MODE_TOGGLE) m_zoomed = !m_zoomed; @@ -25,9 +46,35 @@ void CCursorZoomTrackpadGesture::begin(const ITrackpadGesture::STrackpadGestureB *m->m_cursorZoom = m_zoomed ? m_zoomValue : *PZOOMFACTOR; break; case MODE_MULT: *m->m_cursorZoom = std::clamp(m->m_cursorZoom->goal() * m_zoomValue, 1.0F, 100.0F); break; + case MODE_LIVE: break; } } } -void CCursorZoomTrackpadGesture::update(const ITrackpadGesture::STrackpadGestureUpdate& e) {} -void CCursorZoomTrackpadGesture::end(const ITrackpadGesture::STrackpadGestureEnd& e) {} +void CCursorZoomTrackpadGesture::update(const ITrackpadGesture::STrackpadGestureUpdate& e) { + if (m_mode != MODE_LIVE || !m_monitor || !e.pinch) + return; + + const auto PMONITOR = m_monitor.lock(); + if (!PMONITOR) + return; + + auto zoom = std::clamp(m_zoomBegin * static_cast<float>(e.pinch->scale), 1.0F, 100.0F); + + if (zoom < 1.05F) + zoom = 1.0F; + + PMONITOR->m_cursorZoom->setValueAndWarp(zoom); +} + +void CCursorZoomTrackpadGesture::end(const ITrackpadGesture::STrackpadGestureEnd& e) { + if (m_mode != MODE_LIVE || !m_monitor) + return; + + const auto PMONITOR = m_monitor.lock(); + if (!PMONITOR) + return; + + PMONITOR->m_zoomController.clearAnchor(); + m_monitor.reset(); +} diff --git a/src/managers/input/trackpad/gestures/CursorZoomGesture.hpp b/src/managers/input/trackpad/gestures/CursorZoomGesture.hpp index b53c81e9..3def907f 100644 --- a/src/managers/input/trackpad/gestures/CursorZoomGesture.hpp +++ b/src/managers/input/trackpad/gestures/CursorZoomGesture.hpp @@ -2,6 +2,8 @@ #include "ITrackpadGesture.hpp" +#include "../../../../desktop/DesktopTypes.hpp" + class CCursorZoomTrackpadGesture : public ITrackpadGesture { public: CCursorZoomTrackpadGesture(const std::string& zoomLevel, const std::string& mode); @@ -14,10 +16,13 @@ class CCursorZoomTrackpadGesture : public ITrackpadGesture { private: float m_zoomValue = 1.0; inline static bool m_zoomed = false; + PHLMONITORREF m_monitor; + float m_zoomBegin = 1.0; enum eMode : uint8_t { MODE_TOGGLE = 0, MODE_MULT, + MODE_LIVE, }; eMode m_mode = MODE_TOGGLE; |
