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 Nov 14, 2024
1 parent f97b6ac commit 0e5a19b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 8 deletions.
53 changes: 45 additions & 8 deletions src/GestureManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,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 @@ -123,11 +124,21 @@ 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)) {
this->previousSwipePoint = this->m_sGestureState.get_center().delta();
IPointer::SSwipeBeginEvent ev = {
.fingers = (uint32_t)gev.finger_count,
};
EMIT_HOOK_EVENT("hyprgrass:swipeStart", ev);
this->hookHandled = true;
} else {
this->hookHandled = false;
}
}
return this->handleWorkspaceSwipe(gev.direction);
return true;
}

case DragGestureType::EDGE_SWIPE:
if (workspace_swipe_edge_str == "l" && gev.edge_origin == GESTURE_DIRECTION_LEFT) {
Expand Down Expand Up @@ -243,8 +254,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 @@ -260,9 +277,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 @@ -321,6 +344,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
4 changes: 4 additions & 0 deletions src/GestureManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "HyprLogger.hpp"
#include "VecSet.hpp"
#include "gestures/Shared.hpp"
#include <hyprutils/math/Vector2D.hpp>
#include <memory>

#define private public
Expand Down Expand Up @@ -51,6 +52,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 +68,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 0e5a19b

Please sign in to comment.