Skip to content

Commit

Permalink
feat(hooks): emit hooks of a swipe gesture
Browse files Browse the repository at this point in the history
  • Loading branch information
matt1432 committed Dec 9, 2024
1 parent c56756a commit 76dbaa0
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 8 deletions.
59 changes: 51 additions & 8 deletions src/GestureManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <hyprland/src/config/ConfigValue.hpp>
#include <hyprland/src/debug/Log.hpp>
#include <hyprland/src/devices/ITouch.hpp>
#include <hyprland/src/managers/HookSystemManager.hpp>
#include <hyprland/src/managers/KeybindManager.hpp>
#include <hyprland/src/managers/LayoutManager.hpp>
#include <hyprland/src/managers/SeatManager.hpp>
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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));
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/GestureManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 76dbaa0

Please sign in to comment.