mirror of
https://github.com/hyprwm/Hyprland
synced 2025-12-20 15:30:03 +01:00
gestures: fix gesture direction detection (#11852)
This commit is contained in:
parent
f854b5bffb
commit
43fb4753fc
2 changed files with 8 additions and 4 deletions
|
|
@ -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();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue