From 729f11ecbe527ee613c7b728930238b451ea9c6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 24 Jun 2026 22:55:34 +0200 Subject: [PATCH] Simplify away some nonsense --- Common/UI/Screen.cpp | 8 +++----- Common/UI/Screen.h | 4 ++-- Common/UI/UIScreen.cpp | 37 +------------------------------------ Common/UI/UIScreen.h | 2 +- UI/NativeApp.cpp | 32 +++++++++++++++++++++++++++++++- 5 files changed, 38 insertions(+), 45 deletions(-) diff --git a/Common/UI/Screen.cpp b/Common/UI/Screen.cpp index 586bf147ae..48a664fea9 100644 --- a/Common/UI/Screen.cpp +++ b/Common/UI/Screen.cpp @@ -183,18 +183,16 @@ void ScreenManager::touch(const TouchInput &touch) { } } -bool ScreenManager::key(const KeyInput &key) { +void ScreenManager::key(const KeyInput &key) { std::lock_guard guard(inputLock_); - bool result = false; // Send key up to every screen layer, to avoid stuck keys. if (key.flags & KeyInputFlags::UP) { for (auto &layer : stack_) { - result = layer.screen->UnsyncKey(key); + layer.screen->UnsyncKey(key); } } else if (!stack_.empty()) { - result = stack_.back().screen->UnsyncKey(key); + stack_.back().screen->UnsyncKey(key); } - return result; } void ScreenManager::axis(const AxisInput *axes, size_t count) { diff --git a/Common/UI/Screen.h b/Common/UI/Screen.h index 0c696d892e..046da7b498 100644 --- a/Common/UI/Screen.h +++ b/Common/UI/Screen.h @@ -106,7 +106,7 @@ public: // Return value of UnsyncTouch is only used to let the overlay screen block touches. virtual bool UnsyncTouch(const TouchInput &touch) = 0; // Return value of UnsyncKey is used to not block certain system keys like volume when unhandled, on Android. - virtual bool UnsyncKey(const KeyInput &touch) = 0; + virtual void UnsyncKey(const KeyInput &touch) = 0; virtual void UnsyncAxis(const AxisInput *axes, size_t count) = 0; virtual void RecreateViews() {} @@ -186,7 +186,7 @@ public: // Instant touch, separate from the update() mechanism. void touch(const TouchInput &touch); - bool key(const KeyInput &key); + void key(const KeyInput &key); void axis(const AxisInput *axes, size_t count); void sendMessage(UIMessage message, const char *value); diff --git a/Common/UI/UIScreen.cpp b/Common/UI/UIScreen.cpp index 55188b2bfb..f6289ece88 100644 --- a/Common/UI/UIScreen.cpp +++ b/Common/UI/UIScreen.cpp @@ -114,47 +114,12 @@ void UIScreen::UnsyncAxis(const AxisInput *axes, size_t count) { } } -bool UIScreen::UnsyncKey(const KeyInput &key) { - bool retval = false; - using namespace UI; - - // Ignore volume keys and stuff here. Not elegant but need to propagate bools through the view hierarchy as well... - switch (key.keyCode) { - case NKCODE_VOLUME_DOWN: - case NKCODE_VOLUME_UP: - case NKCODE_VOLUME_MUTE: - return false; - default: - break; - } - - if (root_) { - KeyEventResult kev = KeyEventToFocusMoves(key); - if (!(key.flags & KeyInputFlags::IS_REPEAT)) { - // If a repeat, we follow what KeyEventToFocusMoves set it to. - // Otherwise we signal that we used the key, always. - kev = KeyEventResult::ACCEPT; - } - - switch (kev) { - case UI::KeyEventResult::ACCEPT: - retval = true; - break; - case UI::KeyEventResult::PASS_THROUGH: - retval = false; - break; - case UI::KeyEventResult::IGNORE_KEY: - return false; - } - } - +void UIScreen::UnsyncKey(const KeyInput &key) { QueuedEvent ev{}; ev.type = QueuedEventType::KEY; ev.key = key; - std::lock_guard guard(eventQueueLock_); eventQueue_.push_back(ev); - return retval; } void UIScreen::update() { diff --git a/Common/UI/UIScreen.h b/Common/UI/UIScreen.h index 946cb75901..f6124ccfe8 100644 --- a/Common/UI/UIScreen.h +++ b/Common/UI/UIScreen.h @@ -47,7 +47,7 @@ public: virtual void axis(const AxisInput &axis); bool UnsyncTouch(const TouchInput &touch) override; - bool UnsyncKey(const KeyInput &key) override; + void UnsyncKey(const KeyInput &key) override; void UnsyncAxis(const AxisInput *axes, size_t count) override; TouchInput transformTouch(const TouchInput &touch) override; diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index b1fc21c5b5..eac30899f0 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -1526,8 +1526,38 @@ bool NativeKey(const KeyInput &key) { KeyInput modKey = key; modKey.flags |= modifierFlags; + // Ignore volume keys and stuff here. Not elegant but need to propagate bools through the view hierarchy as well... + switch (key.keyCode) { + case NKCODE_VOLUME_DOWN: + case NKCODE_VOLUME_UP: + case NKCODE_VOLUME_MUTE: + return false; + default: + break; + } + + bool retval = false; + + UI::KeyEventResult kev = UI::KeyEventToFocusMoves(key); + if (!(key.flags & KeyInputFlags::IS_REPEAT)) { + // If a repeat, we follow what KeyEventToFocusMoves set it to. + // Otherwise we signal that we used the key, always. + kev = UI::KeyEventResult::ACCEPT; + } + + switch (kev) { + case UI::KeyEventResult::ACCEPT: + retval = true; + break; + case UI::KeyEventResult::PASS_THROUGH: + retval = false; + break; + case UI::KeyEventResult::IGNORE_KEY: + return false; + } + // Dispatch the key event. - bool retval = g_screenManager->key(modKey); + g_screenManager->key(modKey); // The Mode key can have weird consequences on some devices, see #17245. if (key.keyCode == NKCODE_BUTTON_MODE) {