From 76dbaa02c9ac7ed5c6b9e15bb558617cd58bb1a9 Mon Sep 17 00:00:00 2001 From: matt1432 Date: Mon, 11 Nov 2024 03:33:23 -0500 Subject: [PATCH] feat(hooks): emit hooks of a swipe gesture --- src/GestureManager.cpp | 59 ++++++++++++++++++++++++++++++++++++------ src/GestureManager.hpp | 3 +++ 2 files changed, 54 insertions(+), 8 deletions(-) diff --git a/src/GestureManager.cpp b/src/GestureManager.cpp index 09d60de..0d488e5 100644 --- a/src/GestureManager.cpp +++ b/src/GestureManager.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -124,11 +125,27 @@ bool GestureManager::handleDragGesture(const DragGestureEvent& gev) { auto const workspace_swipe_edge_str = std::string{*WORKSPACE_SWIPE_EDGE}; switch (gev.type) { - case DragGestureType::SWIPE: - if (**WORKSPACE_SWIPE_FINGERS != gev.finger_count) { - return false; + case DragGestureType::SWIPE: { + if (**WORKSPACE_SWIPE_FINGERS == gev.finger_count) { + if (!g_pGestureManager->handleWorkspaceSwipe(gev.direction)) { + static auto* const PEVENTVEC = g_pHookSystem->getVecForEvent("hyprgrass:swipeStart"); + SCallbackInfo info; + + g_pHookSystem->emit(PEVENTVEC, info, + IPointer::SSwipeBeginEvent{.fingers = (uint32_t)gev.finger_count}); + + if (!info.cancelled) { + this->hookHandled = true; + this->previousSwipePoint = this->m_sGestureState.get_center().delta(); + return true; + } + } else { + this->hookHandled = false; + return true; + } } - return this->handleWorkspaceSwipe(gev.direction); + return false; + } case DragGestureType::EDGE_SWIPE: if (workspace_swipe_edge_str == "l" && gev.edge_origin == GESTURE_DIRECTION_LEFT) { @@ -244,8 +261,14 @@ void GestureManager::dragGestureUpdate(const wf::touch::gesture_event_t& ev) { } switch (this->getActiveDragGesture()->type) { - case DragGestureType::SWIPE: - this->updateWorkspaceSwipe(); + case DragGestureType::SWIPE: { + if (this->hookHandled) { + this->updateHookSwipe(); + } else { + this->updateWorkspaceSwipe(); + } + return; + } case DragGestureType::LONG_PRESS: { const auto pos = this->m_sGestureState.get_center().current; g_pCompositor->warpCursorTo(Vector2D(pos.x, pos.y)); @@ -261,9 +284,15 @@ void GestureManager::handleDragGestureEnd(const DragGestureEvent& gev) { Debug::log(LOG, "[hyprgrass] Drag gesture ended: {}", gev.to_string()); switch (gev.type) { - case DragGestureType::SWIPE: - g_pInputManager->endWorkspaceSwipe(); + case DragGestureType::SWIPE: { + if (this->hookHandled) { + IPointer::SSwipeEndEvent ev = {}; + EMIT_HOOK_EVENT("hyprgrass:swipeEnd", ev); + } else { + g_pInputManager->endWorkspaceSwipe(); + } return; + } case DragGestureType::LONG_PRESS: if (this->resizeOnBorderInfo.active) { g_pKeybindManager->changeMouseBindMode(eMouseBindMode::MBIND_INVALID); @@ -322,6 +351,20 @@ void GestureManager::updateWorkspaceSwipe() { return; } +void GestureManager::updateHookSwipe() { + auto gev = this->getActiveDragGesture().value(); + + const auto currentPoint = this->m_sGestureState.get_center().delta(); + const auto delta = currentPoint - this->previousSwipePoint; + this->previousSwipePoint = currentPoint; + + IPointer::SSwipeUpdateEvent ev = { + .fingers = (uint32_t)gev.finger_count, + .delta = Vector2D(delta.x, delta.y), + }; + EMIT_HOOK_EVENT("hyprgrass:swipeUpdate", ev); +} + void GestureManager::updateLongPressTimer(uint32_t current_time, uint32_t delay) { this->long_press_next_trigger_time = current_time + delay + 1; wl_event_source_timer_update(this->long_press_timer, delay); diff --git a/src/GestureManager.hpp b/src/GestureManager.hpp index f5808af..8127bd1 100644 --- a/src/GestureManager.hpp +++ b/src/GestureManager.hpp @@ -51,6 +51,8 @@ class GestureManager : public IGestureManager { PHLMONITOR m_pLastTouchedMonitor; SMonitorArea m_sMonitorArea; wl_event_source* long_press_timer; + bool hookHandled = false; + wf::touch::point_t previousSwipePoint; struct { bool active = false; CCssGapData old_gaps_in; @@ -65,6 +67,7 @@ class GestureManager : public IGestureManager { Vector2D pixelPositionToPercentagePosition(wf::touch::point_t) const; bool handleWorkspaceSwipe(const GestureDirection direction); void updateWorkspaceSwipe(); + void updateHookSwipe(); bool handleDragGesture(const DragGestureEvent& gev) override; void dragGestureUpdate(const wf::touch::gesture_event_t&) override;