diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index fffa61a01..908f15ffb 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -219,16 +219,18 @@ void CConfigManager::setDefaultVars() { configValues["binds:allow_workspace_cycles"].intValue = 0; configValues["binds:focus_preferred_method"].intValue = 0; - configValues["gestures:workspace_swipe"].intValue = 0; - configValues["gestures:workspace_swipe_fingers"].intValue = 3; - configValues["gestures:workspace_swipe_distance"].intValue = 300; - configValues["gestures:workspace_swipe_invert"].intValue = 1; - configValues["gestures:workspace_swipe_min_speed_to_force"].intValue = 30; - configValues["gestures:workspace_swipe_cancel_ratio"].floatValue = 0.5f; - configValues["gestures:workspace_swipe_create_new"].intValue = 1; - configValues["gestures:workspace_swipe_forever"].intValue = 0; - configValues["gestures:workspace_swipe_numbered"].intValue = 0; - configValues["gestures:workspace_swipe_use_r"].intValue = 0; + configValues["gestures:workspace_swipe"].intValue = 0; + configValues["gestures:workspace_swipe_fingers"].intValue = 3; + configValues["gestures:workspace_swipe_distance"].intValue = 300; + configValues["gestures:workspace_swipe_invert"].intValue = 1; + configValues["gestures:workspace_swipe_min_speed_to_force"].intValue = 30; + configValues["gestures:workspace_swipe_cancel_ratio"].floatValue = 0.5f; + configValues["gestures:workspace_swipe_create_new"].intValue = 1; + configValues["gestures:workspace_swipe_direction_lock"].intValue = 1; + configValues["gestures:workspace_swipe_direction_lock_threshold"].intValue = 10; + configValues["gestures:workspace_swipe_forever"].intValue = 0; + configValues["gestures:workspace_swipe_numbered"].intValue = 0; + configValues["gestures:workspace_swipe_use_r"].intValue = 0; configValues["xwayland:use_nearest_neighbor"].intValue = 1; configValues["xwayland:force_zero_scaling"].intValue = 0; diff --git a/src/helpers/WLClasses.hpp b/src/helpers/WLClasses.hpp index b84c96572..7b7eecbdd 100644 --- a/src/helpers/WLClasses.hpp +++ b/src/helpers/WLClasses.hpp @@ -309,6 +309,7 @@ struct SSwipeGesture { double delta = 0; + int initialDirection = 0; float avgSpeed = 0; int speedPoints = 0; diff --git a/src/managers/input/Swipe.cpp b/src/managers/input/Swipe.cpp index 5fe91b65e..b7a4a74bf 100644 --- a/src/managers/input/Swipe.cpp +++ b/src/managers/input/Swipe.cpp @@ -174,7 +174,8 @@ void CInputManager::onSwipeEnd(wlr_pointer_swipe_end_event* e) { PWORKSPACER->m_bForceRendering = false; m_sActiveSwipe.pWorkspaceBegin->m_bForceRendering = false; - m_sActiveSwipe.pWorkspaceBegin = nullptr; + m_sActiveSwipe.pWorkspaceBegin = nullptr; + m_sActiveSwipe.initialDirection = 0; g_pInputManager->refocus(); @@ -188,14 +189,16 @@ void CInputManager::onSwipeUpdate(wlr_pointer_swipe_update_event* e) { if (!m_sActiveSwipe.pWorkspaceBegin) return; - static auto* const PSWIPEDIST = &g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe_distance")->intValue; - static auto* const PSWIPEINVR = &g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe_invert")->intValue; - static auto* const PSWIPENEW = &g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe_create_new")->intValue; - static auto* const PSWIPEFOREVER = &g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe_forever")->intValue; - static auto* const PSWIPENUMBER = &g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe_numbered")->intValue; - static auto* const PSWIPEUSER = &g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe_use_r")->intValue; + static auto* const PSWIPEDIST = &g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe_distance")->intValue; + static auto* const PSWIPEINVR = &g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe_invert")->intValue; + static auto* const PSWIPENEW = &g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe_create_new")->intValue; + static auto* const PSWIPEDIRLOCK = &g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe_direction_lock")->intValue; + static auto* const PSWIPEDIRLOCKTHRESHOLD = &g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe_direction_lock_threshold")->intValue; + static auto* const PSWIPEFOREVER = &g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe_forever")->intValue; + static auto* const PSWIPENUMBER = &g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe_numbered")->intValue; + static auto* const PSWIPEUSER = &g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe_use_r")->intValue; - const bool VERTANIMS = m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.getConfig()->pValues->internalStyle == "slidevert" || + const bool VERTANIMS = m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.getConfig()->pValues->internalStyle == "slidevert" || m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.getConfig()->pValues->internalStyle.find("slidefadevert") == 0; m_sActiveSwipe.delta += VERTANIMS ? (*PSWIPEINVR ? -e->dy : e->dy) : (*PSWIPEINVR ? -e->dx : e->dx); @@ -225,6 +228,13 @@ void CInputManager::onSwipeUpdate(wlr_pointer_swipe_update_event* e) { return; } + if (*PSWIPEDIRLOCK) { + if (m_sActiveSwipe.initialDirection != 0 && m_sActiveSwipe.initialDirection != (m_sActiveSwipe.delta < 0 ? -1 : 1)) + m_sActiveSwipe.delta = 0; + else if (m_sActiveSwipe.initialDirection == 0 && abs(m_sActiveSwipe.delta) > *PSWIPEDIRLOCKTHRESHOLD) + m_sActiveSwipe.initialDirection = m_sActiveSwipe.delta < 0 ? -1 : 1; + } + if (m_sActiveSwipe.delta < 0) { const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(workspaceIDLeft);