Skip to content

Commit

Permalink
one to one workspace swipes
Browse files Browse the repository at this point in the history
  • Loading branch information
horriblename committed Jun 8, 2024
1 parent 6a8fc0f commit 3802638
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
39 changes: 34 additions & 5 deletions src/GestureManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <hyprland/src/managers/input/InputManager.hpp>
#undef private

#include <algorithm>
#include <hyprlang.hpp>
#include <memory>
#include <optional>
Expand Down Expand Up @@ -181,8 +182,19 @@ void GestureManager::dragGestureUpdate(const wf::touch::gesture_event_t& ev) {
g_pInputManager->m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.getConfig()
->pValues->internalStyle.starts_with("slidefadevert");

const auto delta = this->m_sGestureState.get_center().delta();
g_pInputManager->updateWorkspaceSwipe(VERTANIMS ? -delta.y : -delta.x);
static auto const PSWIPEDIST =
(Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "gestures:workspace_swipe_distance")
->getDataStaticPtr();
const auto SWIPEDISTANCE = std::clamp(**PSWIPEDIST, (int64_t)1LL, (int64_t)UINT32_MAX);

const auto delta_percent =
this->pixelPositionToPercentagePosition(this->m_sGestureState.get_center().delta());
const auto swipe_delta = delta_percent * SWIPEDISTANCE;

Debug::log(LOG, "PSWIPEDIST: {}, SWIPEDIST: {}, delta: {}, swipe_delta: {}", **PSWIPEDIST, SWIPEDISTANCE,
delta_percent, swipe_delta);

g_pInputManager->updateWorkspaceSwipe(VERTANIMS ? -swipe_delta.y : -swipe_delta.x);
return;
}
case DragGestureType::LONG_PRESS: {
Expand All @@ -193,16 +205,28 @@ void GestureManager::dragGestureUpdate(const wf::touch::gesture_event_t& ev) {
g_pInputManager->mouseMoveUnified(ev.time);
return;
}
case DragGestureType::EDGE_SWIPE:
case DragGestureType::EDGE_SWIPE: {
const bool VERTANIMS =
g_pInputManager->m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.getConfig()->pValues->internalStyle ==
"slidevert" ||
g_pInputManager->m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.getConfig()
->pValues->internalStyle.starts_with("slidefadevert");

const auto delta = this->m_sGestureState.get_center().delta();
g_pInputManager->updateWorkspaceSwipe(VERTANIMS ? -delta.y : -delta.x);
static auto const PSWIPEDIST =
(Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "gestures:workspace_swipe_distance")
->getDataStaticPtr();
const auto SWIPEDISTANCE = std::clamp(**PSWIPEDIST, (int64_t)1LL, (int64_t)UINT32_MAX);

const auto delta_percent =
this->pixelPositionToPercentagePosition(this->m_sGestureState.get_center().delta());
const auto swipe_delta = delta_percent * SWIPEDISTANCE;

Debug::log(LOG, "PSWIPEDIST: {}, SWIPEDIST: {}, delta: {}, swipe_delta: {}", **PSWIPEDIST, SWIPEDISTANCE,
delta_percent, swipe_delta);

g_pInputManager->updateWorkspaceSwipe(VERTANIMS ? -swipe_delta.y : -swipe_delta.x);
return;
}
}
}

Expand Down Expand Up @@ -394,6 +418,11 @@ wf::touch::point_t GestureManager::wlrTouchEventPositionAsPixels(double x, doubl
return wf::touch::point_t{x * area.w + area.x, y * area.h + area.y};
}

Vector2D GestureManager::pixelPositionToPercentagePosition(wf::touch::point_t point) const {
auto monitorArea = this->getMonitorArea();
return Vector2D((point.x - monitorArea.x) / monitorArea.w, (point.y - monitorArea.y) / monitorArea.h);
}

void GestureManager::touchBindDispatcher(std::string args) {
auto argsSplit = splitString(args, ',', 4);
if (argsSplit.size() < 4) {
Expand Down
4 changes: 4 additions & 0 deletions src/GestureManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ class GestureManager : public IGestureManager {

bool handleGestureBind(std::string bind, bool pressed);

// converts wlr touch event positions (number between 0.0 to 1.0) to pixel position,
// takes into consideration monitor size and offset
wf::touch::point_t wlrTouchEventPositionAsPixels(double x, double y) const;
// reverse of wlrTouchEventPositionAsPixels
Vector2D pixelPositionToPercentagePosition(wf::touch::point_t) const;
bool handleWorkspaceSwipe(const GestureDirection direction);

bool handleDragGesture(const DragGesture& gev) override;
Expand Down

0 comments on commit 3802638

Please sign in to comment.