gestures: add cursor zoom (#13033)

This commit is contained in:
Luke Barkess 2026-02-01 14:32:47 +00:00 committed by GitHub
parent 95c8f8b299
commit d9d9d9358f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 62 additions and 1 deletions

View file

@ -39,6 +39,7 @@
#include "../managers/input/trackpad/gestures/CloseGesture.hpp"
#include "../managers/input/trackpad/gestures/FloatGesture.hpp"
#include "../managers/input/trackpad/gestures/FullscreenGesture.hpp"
#include "../managers/input/trackpad/gestures/CursorZoomGesture.hpp"
#include "../managers/HookSystemManager.hpp"
#include "../protocols/types/ContentType.hpp"
@ -2917,7 +2918,10 @@ std::optional<std::string> CConfigManager::handleGesture(const std::string& comm
else if (data[startDataIdx] == "fullscreen")
result = g_pTrackpadGestures->addGesture(makeUnique<CFullscreenTrackpadGesture>(std::string{data[startDataIdx + 1]}), fingerCount, direction, modMask, deltaScale,
disableInhibit);
else if (data[startDataIdx] == "unset")
else if (data[startDataIdx] == "cursorZoom") {
result = g_pTrackpadGestures->addGesture(makeUnique<CCursorZoomTrackpadGesture>(std::string{data[startDataIdx + 1]}, std::string{data[startDataIdx + 2]}), fingerCount,
direction, modMask, deltaScale, disableInhibit);
} else if (data[startDataIdx] == "unset")
result = g_pTrackpadGestures->removeGesture(fingerCount, direction, modMask, deltaScale, disableInhibit);
else
return std::format("Invalid gesture: {}", data[startDataIdx]);

View file

@ -0,0 +1,33 @@
#include "CursorZoomGesture.hpp"
#include "../../../../Compositor.hpp"
#include "../../../../helpers/Monitor.hpp"
CCursorZoomTrackpadGesture::CCursorZoomTrackpadGesture(const std::string& first, const std::string& second) {
try {
m_zoomValue = std::stof(first);
} catch (...) { ; }
if (second == "mult")
m_mode = MODE_MULT;
}
void CCursorZoomTrackpadGesture::begin(const ITrackpadGesture::STrackpadGestureBegin& e) {
ITrackpadGesture::begin(e);
if (m_mode == MODE_TOGGLE)
m_zoomed = !m_zoomed;
for (auto const& m : g_pCompositor->m_monitors) {
switch (m_mode) {
case MODE_TOGGLE:
static auto PZOOMFACTOR = CConfigValue<Hyprlang::FLOAT>("cursor:zoom_factor");
*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;
}
}
}
void CCursorZoomTrackpadGesture::update(const ITrackpadGesture::STrackpadGestureUpdate& e) {}
void CCursorZoomTrackpadGesture::end(const ITrackpadGesture::STrackpadGestureEnd& e) {}

View file

@ -0,0 +1,24 @@
#pragma once
#include "ITrackpadGesture.hpp"
class CCursorZoomTrackpadGesture : public ITrackpadGesture {
public:
CCursorZoomTrackpadGesture(const std::string& zoomLevel, const std::string& mode);
virtual ~CCursorZoomTrackpadGesture() = default;
virtual void begin(const ITrackpadGesture::STrackpadGestureBegin& e);
virtual void update(const ITrackpadGesture::STrackpadGestureUpdate& e);
virtual void end(const ITrackpadGesture::STrackpadGestureEnd& e);
private:
float m_zoomValue = 1.0;
inline static bool m_zoomed = false;
enum eMode : uint8_t {
MODE_TOGGLE = 0,
MODE_MULT,
};
eMode m_mode = MODE_TOGGLE;
};