gestures: fix gesture direction detection (#11852)

This commit is contained in:
Vaxry 2025-09-29 13:29:40 +02:00 committed by GitHub
parent f854b5bffb
commit 43fb4753fc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 4 deletions

View file

@ -108,6 +108,7 @@ void CTrackpadGestures::gestureBegin(const IPointer::SSwipeBeginEvent& e) {
} }
m_gestureFindFailed = false; m_gestureFindFailed = false;
m_currentTotalDelta = {};
// nothing here. We need to wait for the first update to determine the delta. // nothing here. We need to wait for the first update to determine the delta.
} }
@ -116,8 +117,10 @@ void CTrackpadGestures::gestureUpdate(const IPointer::SSwipeUpdateEvent& e) {
if (m_gestureFindFailed) if (m_gestureFindFailed)
return; return;
m_currentTotalDelta += e.delta;
// 5 was chosen because I felt like that's a good number. // 5 was chosen because I felt like that's a good number.
if (!m_activeGesture && (std::abs(e.delta.x) < 5 && std::abs(e.delta.y) < 5)) { if (!m_activeGesture && (std::abs(m_currentTotalDelta.x) < 5 && std::abs(m_currentTotalDelta.y) < 5)) {
Debug::log(TRACE, "CTrackpadGestures::gestureUpdate (swipe): gesture delta too small to start considering, waiting"); Debug::log(TRACE, "CTrackpadGestures::gestureUpdate (swipe): gesture delta too small to start considering, waiting");
return; return;
} }
@ -126,12 +129,12 @@ void CTrackpadGestures::gestureUpdate(const IPointer::SSwipeUpdateEvent& e) {
// try to find a gesture that matches our current state // try to find a gesture that matches our current state
auto direction = TRACKPAD_GESTURE_DIR_NONE; auto direction = TRACKPAD_GESTURE_DIR_NONE;
auto axis = std::abs(e.delta.x) > std::abs(e.delta.y) ? TRACKPAD_GESTURE_DIR_HORIZONTAL : TRACKPAD_GESTURE_DIR_VERTICAL; auto axis = std::abs(m_currentTotalDelta.x) > std::abs(m_currentTotalDelta.y) ? TRACKPAD_GESTURE_DIR_HORIZONTAL : TRACKPAD_GESTURE_DIR_VERTICAL;
if (axis == TRACKPAD_GESTURE_DIR_HORIZONTAL) if (axis == TRACKPAD_GESTURE_DIR_HORIZONTAL)
direction = e.delta.x < 0 ? TRACKPAD_GESTURE_DIR_LEFT : TRACKPAD_GESTURE_DIR_RIGHT; direction = m_currentTotalDelta.x < 0 ? TRACKPAD_GESTURE_DIR_LEFT : TRACKPAD_GESTURE_DIR_RIGHT;
else else
direction = e.delta.y < 0 ? TRACKPAD_GESTURE_DIR_UP : TRACKPAD_GESTURE_DIR_DOWN; direction = m_currentTotalDelta.y < 0 ? TRACKPAD_GESTURE_DIR_UP : TRACKPAD_GESTURE_DIR_DOWN;
const auto MODS = g_pInputManager->getModsFromAllKBs(); const auto MODS = g_pInputManager->getModsFromAllKBs();

View file

@ -37,6 +37,7 @@ class CTrackpadGestures {
std::vector<SP<SGestureData>> m_gestures; std::vector<SP<SGestureData>> m_gestures;
Vector2D m_currentTotalDelta = {};
SP<SGestureData> m_activeGesture = nullptr; SP<SGestureData> m_activeGesture = nullptr;
bool m_gestureFindFailed = false; bool m_gestureFindFailed = false;
}; };