From 3c21f5e07b853b1b37a7aa38a5084a114f0c1983 Mon Sep 17 00:00:00 2001 From: Zach DeCook Date: Sun, 17 Mar 2024 11:43:59 -0400 Subject: swipe: Touchscreen workspace swipe (#4489) * Workspace Swipe: Refactor update and end functions * Touch: Implement workspace swipe better ignoring additional fingers and new touches allow gaps-right and gaps-left to be different --- src/managers/input/Swipe.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src/managers/input/Swipe.cpp') diff --git a/src/managers/input/Swipe.cpp b/src/managers/input/Swipe.cpp index 937266af..68f7aa25 100644 --- a/src/managers/input/Swipe.cpp +++ b/src/managers/input/Swipe.cpp @@ -44,7 +44,10 @@ void CInputManager::beginWorkspaceSwipe() { void CInputManager::onSwipeEnd(wlr_pointer_swipe_end_event* e) { if (!m_sActiveSwipe.pWorkspaceBegin) return; // no valid swipe + endWorkspaceSwipe(); +} +void CInputManager::endWorkspaceSwipe() { static auto PSWIPEPERC = CConfigValue("gestures:workspace_swipe_cancel_ratio"); static auto PSWIPEDIST = CConfigValue("gestures:workspace_swipe_distance"); static auto PSWIPEFORC = CConfigValue("gestures:workspace_swipe_min_speed_to_force"); @@ -192,11 +195,18 @@ void CInputManager::onSwipeEnd(wlr_pointer_swipe_end_event* e) { } void CInputManager::onSwipeUpdate(wlr_pointer_swipe_update_event* e) { + static auto PSWIPEINVR = CConfigValue("gestures:workspace_swipe_invert"); + const bool VERTANIMS = m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.getConfig()->pValues->internalStyle == "slidevert" || + m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.getConfig()->pValues->internalStyle.starts_with("slidefadevert"); if (!m_sActiveSwipe.pWorkspaceBegin) return; + const double delta = m_sActiveSwipe.delta + (VERTANIMS ? (*PSWIPEINVR ? -e->dy : e->dy) : (*PSWIPEINVR ? -e->dx : e->dx)); + updateWorkspaceSwipe(delta); +} + +void CInputManager::updateWorkspaceSwipe(double delta) { static auto PSWIPEDIST = CConfigValue("gestures:workspace_swipe_distance"); - static auto PSWIPEINVR = CConfigValue("gestures:workspace_swipe_invert"); static auto PSWIPENEW = CConfigValue("gestures:workspace_swipe_create_new"); static auto PSWIPEDIRLOCK = CConfigValue("gestures:workspace_swipe_direction_lock"); static auto PSWIPEDIRLOCKTHRESHOLD = CConfigValue("gestures:workspace_swipe_direction_lock_threshold"); @@ -209,10 +219,10 @@ void CInputManager::onSwipeUpdate(wlr_pointer_swipe_update_event* e) { const auto YDISTANCE = m_sActiveSwipe.pMonitor->vecSize.y + *PWORKSPACEGAP; const bool VERTANIMS = m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.getConfig()->pValues->internalStyle == "slidevert" || m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.getConfig()->pValues->internalStyle.starts_with("slidefadevert"); + const double d = m_sActiveSwipe.delta - delta; + m_sActiveSwipe.delta = delta; - m_sActiveSwipe.delta += VERTANIMS ? (*PSWIPEINVR ? -e->dy : e->dy) : (*PSWIPEINVR ? -e->dx : e->dx); - - m_sActiveSwipe.avgSpeed = (m_sActiveSwipe.avgSpeed * m_sActiveSwipe.speedPoints + abs(e->dx)) / (m_sActiveSwipe.speedPoints + 1); + m_sActiveSwipe.avgSpeed = (m_sActiveSwipe.avgSpeed * m_sActiveSwipe.speedPoints + abs(d)) / (m_sActiveSwipe.speedPoints + 1); m_sActiveSwipe.speedPoints++; std::string wsname = ""; -- cgit v1.2.3