Skip to content

Commit

Permalink
feat: add workspace swipe from edge
Browse files Browse the repository at this point in the history
  • Loading branch information
horriblename committed Jan 3, 2024
1 parent ac9868b commit ec98685
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 17 deletions.
62 changes: 46 additions & 16 deletions src/GestureManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,34 @@ bool GestureManager::handleCompletedGesture(const CompletedGesture& gev) {
}

bool GestureManager::handleDragGesture(const DragGesture& gev) {
static auto* const WORKSPACE_SWIPE_FINGERS =
&HyprlandAPI::getConfigValue(PHANDLE, "plugin:touch_gestures:workspace_swipe_fingers")->intValue;
static auto* const WORKSPACE_SWIPE_EDGE =
&HyprlandAPI::getConfigValue(PHANDLE, "plugin:touch_gestures:workspace_swipe_edge")->strValue;

switch (gev.type) {
case DragGestureType::SWIPE:
return this->handleWorkspaceSwipe(gev);
if (*WORKSPACE_SWIPE_FINGERS != gev.finger_count) {
return false;
}
return this->handleWorkspaceSwipe(gev.direction);

case DragGestureType::EDGE_SWIPE:
if (*WORKSPACE_SWIPE_EDGE == "l" && gev.direction == DIRECTION_LEFT) {
return this->handleWorkspaceSwipe(gev.direction);
}
if (*WORKSPACE_SWIPE_EDGE == "r" && gev.edge_origin == DIRECTION_RIGHT) {
return this->handleWorkspaceSwipe(gev.direction);
}
if (*WORKSPACE_SWIPE_EDGE == "u" && gev.edge_origin == DIRECTION_UP) {
return this->handleWorkspaceSwipe(gev.direction);
}
if (*WORKSPACE_SWIPE_EDGE == "d" && gev.edge_origin == DIRECTION_DOWN) {
return this->handleWorkspaceSwipe(gev.direction);
}

return false;

default:
break;
}
Expand Down Expand Up @@ -146,6 +171,9 @@ void GestureManager::handleCancelledGesture() {
return;
case DragGestureType::LONG_PRESS:
break;
case DragGestureType::EDGE_SWIPE:
this->emulateSwipeEnd(0, false);
break;
}
}

Expand All @@ -165,6 +193,9 @@ void GestureManager::dragGestureUpdate(const wf::touch::gesture_event_t& ev) {
g_pLayoutManager->getCurrentLayout()->onMouseMove(Vector2D(pos.x, pos.y));
return;
}
case DragGestureType::EDGE_SWIPE:
emulateSwipeUpdate(ev.time);
return;
}
}

Expand All @@ -179,30 +210,29 @@ void GestureManager::handleDragGestureEnd(const DragGesture& gev) {
return;
case DragGestureType::LONG_PRESS:
break;
case DragGestureType::EDGE_SWIPE:
emulateSwipeEnd(0, false);
return;
}

handleGestureBind(gev.to_string(), false);
}

bool GestureManager::handleWorkspaceSwipe(const DragGesture& gev) {
static auto* const PWORKSPACEFINGERS =
&HyprlandAPI::getConfigValue(PHANDLE, "plugin:touch_gestures:workspace_swipe_fingers")->intValue;
bool GestureManager::handleWorkspaceSwipe(const GestureDirection direction) {
const auto VERTANIMS = g_pCompositor->getWorkspaceByID(g_pCompositor->m_pLastMonitor->activeWorkspace)
->m_vRenderOffset.getConfig()
->pValues->internalStyle == "slidevert";

if (gev.type == DragGestureType::SWIPE && gev.finger_count == *PWORKSPACEFINGERS) {
const auto horizontal = GESTURE_DIRECTION_LEFT | GESTURE_DIRECTION_RIGHT;
const auto vertical = GESTURE_DIRECTION_UP | GESTURE_DIRECTION_DOWN;
const auto workspace_directions = VERTANIMS ? vertical : horizontal;
const auto anti_directions = VERTANIMS ? horizontal : vertical;

if (gev.direction & workspace_directions && !(gev.direction & anti_directions)) {
// FIXME time arg of @emulateSwipeBegin should probably be assigned
// something useful (though its not really used later)
this->emulateSwipeBegin(0);
return true;
}
const auto horizontal = GESTURE_DIRECTION_LEFT | GESTURE_DIRECTION_RIGHT;
const auto vertical = GESTURE_DIRECTION_UP | GESTURE_DIRECTION_DOWN;
const auto workspace_directions = VERTANIMS ? vertical : horizontal;
const auto anti_directions = VERTANIMS ? horizontal : vertical;

if (direction & workspace_directions && !(direction & anti_directions)) {
// FIXME time arg of @emulateSwipeBegin should probably be assigned
// something useful (though its not really used later)
this->emulateSwipeBegin(0);
return true;
}

return false;
Expand Down
3 changes: 2 additions & 1 deletion src/GestureManager.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once
#include "./gestures/Gestures.hpp"
#include "gestures/Shared.hpp"
#include "globals.hpp"
#include <hyprland/src/debug/Log.hpp>
#include <hyprland/src/helpers/Monitor.hpp>
Expand Down Expand Up @@ -45,7 +46,7 @@ class GestureManager : public IGestureManager {
void emulateSwipeUpdate(uint32_t time);

wf::touch::point_t wlrTouchEventPositionAsPixels(double x, double y) const;
bool handleWorkspaceSwipe(const DragGesture& gev);
bool handleWorkspaceSwipe(const GestureDirection direction);

bool handleDragGesture(const DragGesture& gev) override;
void dragGestureUpdate(const wf::touch::gesture_event_t&) override;
Expand Down

0 comments on commit ec98685

Please sign in to comment.