From 2b99dabdac823fee3ea843a9ded8bbe7718c3b44 Mon Sep 17 00:00:00 2001 From: grorp Date: Fri, 26 Jan 2024 23:19:06 +0100 Subject: [PATCH] Touchscreen: Abort ongoing short taps if touch interaction mode changes (#14305) --- src/gui/touchscreengui.cpp | 9 +++++++++ src/gui/touchscreengui.h | 1 + 2 files changed, 10 insertions(+) diff --git a/src/gui/touchscreengui.cpp b/src/gui/touchscreengui.cpp index c9fe5569e..d8ac39c31 100644 --- a/src/gui/touchscreengui.cpp +++ b/src/gui/touchscreengui.cpp @@ -1091,6 +1091,15 @@ void TouchScreenGUI::applyContextControls(const TouchInteractionMode &mode) u64 now = porting::getTimeMs(); + // If the meanings of short and long taps have been swapped, abort any ongoing + // short taps because they would do something else than the player expected. + // Long taps don't need this, they're adjusted to the swapped meanings instead. + if (mode != m_last_mode) { + m_dig_pressed_until = 0; + m_place_pressed_until = 0; + } + m_last_mode = mode; + switch (m_tap_state) { case TapState::ShortTap: if (mode == SHORT_DIG_LONG_PLACE) { diff --git a/src/gui/touchscreengui.h b/src/gui/touchscreengui.h index 2e48a71cf..661f70f10 100644 --- a/src/gui/touchscreengui.h +++ b/src/gui/touchscreengui.h @@ -314,6 +314,7 @@ private: v2s32 getPointerPos(); void emitMouseEvent(EMOUSE_INPUT_EVENT type); + TouchInteractionMode m_last_mode = TouchInteractionMode_END; TapState m_tap_state = TapState::None; bool m_dig_pressed = false;