summaryrefslogtreecommitdiff
path: root/src/managers/input/trackpad/gestures/FloatGesture.cpp
diff options
context:
space:
mode:
authorVaxry <43317083+vaxerski@users.noreply.github.com>2025-08-28 11:20:29 +0200
committerGitHub <noreply@github.com>2025-08-28 11:20:29 +0200
commit81bf4eccba449bfe2b6adfb51260108aec710d4f (patch)
tree215c5b536cbcf1df9888081aadd3de16eb4b3ebe /src/managers/input/trackpad/gestures/FloatGesture.cpp
parent378e130f1426648d8d734049800128f9882805bf (diff)
input: Add fully configurable trackpad gestures (#11490)
Adds configurable trackpad gestures
Diffstat (limited to 'src/managers/input/trackpad/gestures/FloatGesture.cpp')
-rw-r--r--src/managers/input/trackpad/gestures/FloatGesture.cpp88
1 files changed, 88 insertions, 0 deletions
diff --git a/src/managers/input/trackpad/gestures/FloatGesture.cpp b/src/managers/input/trackpad/gestures/FloatGesture.cpp
new file mode 100644
index 00000000..97e4c98f
--- /dev/null
+++ b/src/managers/input/trackpad/gestures/FloatGesture.cpp
@@ -0,0 +1,88 @@
+#include "FloatGesture.hpp"
+
+#include "../../../../Compositor.hpp"
+#include "../../../../managers/LayoutManager.hpp"
+#include "../../../../render/Renderer.hpp"
+
+constexpr const float MAX_DISTANCE = 250.F;
+
+//
+static Vector2D lerpVal(const Vector2D& from, const Vector2D& to, const float& t) {
+ return Vector2D{
+ from.x + ((to.x - from.x) * t),
+ from.y + ((to.y - from.y) * t),
+ };
+}
+
+CFloatTrackpadGesture::CFloatTrackpadGesture(const std::string_view& data) {
+ std::string lc = std::string{data};
+ std::ranges::transform(lc, lc.begin(), ::tolower);
+
+ if (lc.starts_with("float"))
+ m_mode = FLOAT_MODE_FLOAT;
+ else if (lc.starts_with("tile"))
+ m_mode == FLOAT_MODE_TILE;
+ else
+ m_mode = FLOAT_MODE_TOGGLE;
+}
+
+void CFloatTrackpadGesture::begin(const ITrackpadGesture::STrackpadGestureBegin& e) {
+ ITrackpadGesture::begin(e);
+
+ m_window = g_pCompositor->m_lastWindow;
+
+ if (!m_window)
+ return;
+
+ if ((m_window->m_isFloating && m_mode == FLOAT_MODE_FLOAT) || (!m_window->m_isFloating && m_mode == FLOAT_MODE_TILE)) {
+ m_window.reset();
+ return;
+ }
+
+ m_window->m_isFloating = !m_window->m_isFloating;
+ g_pLayoutManager->getCurrentLayout()->changeWindowFloatingMode(m_window.lock());
+
+ m_posFrom = m_window->m_realPosition->begun();
+ m_sizeFrom = m_window->m_realSize->begun();
+
+ m_posTo = m_window->m_realPosition->goal();
+ m_sizeTo = m_window->m_realSize->goal();
+
+ m_lastDelta = 0.F;
+}
+
+void CFloatTrackpadGesture::update(const ITrackpadGesture::STrackpadGestureUpdate& e) {
+ if (!m_window)
+ return;
+
+ g_pHyprRenderer->damageWindow(m_window.lock());
+
+ m_lastDelta += distance(e);
+
+ const auto FADEPERCENT = std::clamp(m_lastDelta / MAX_DISTANCE, 0.F, 1.F);
+
+ m_window->m_realPosition->setValueAndWarp(lerpVal(m_posFrom, m_posTo, FADEPERCENT));
+ m_window->m_realSize->setValueAndWarp(lerpVal(m_sizeFrom, m_sizeTo, FADEPERCENT));
+
+ g_pDecorationPositioner->onWindowUpdate(m_window.lock());
+
+ g_pHyprRenderer->damageWindow(m_window.lock());
+}
+
+void CFloatTrackpadGesture::end(const ITrackpadGesture::STrackpadGestureEnd& e) {
+ if (!m_window)
+ return;
+
+ const auto COMPLETION = std::clamp(m_lastDelta / MAX_DISTANCE, 0.F, 1.F);
+
+ if (COMPLETION < 0.2F) {
+ // revert the animation
+ g_pHyprRenderer->damageWindow(m_window.lock());
+ m_window->m_isFloating = !m_window->m_isFloating;
+ g_pLayoutManager->getCurrentLayout()->changeWindowFloatingMode(m_window.lock());
+ return;
+ }
+
+ *m_window->m_realPosition = m_posTo;
+ *m_window->m_realSize = m_sizeTo;
+}