From 8cebf6e31931bb904eb5e429c7a0de053f4a9b55 Mon Sep 17 00:00:00 2001 From: jpirnay Date: Sat, 2 May 2026 23:38:19 +0200 Subject: [PATCH] Fix button race --- src/activities/browser/OpdsBookBrowserActivity.cpp | 11 +++++++---- src/activities/home/GlobalBookmarksActivity.cpp | 10 ++++++---- src/activities/home/RecentBooksActivity.cpp | 12 ++++++++---- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/activities/browser/OpdsBookBrowserActivity.cpp b/src/activities/browser/OpdsBookBrowserActivity.cpp index 2035217c..98ad8053 100644 --- a/src/activities/browser/OpdsBookBrowserActivity.cpp +++ b/src/activities/browser/OpdsBookBrowserActivity.cpp @@ -164,19 +164,22 @@ void OpdsBookBrowserActivity::loop() { } if (!entries.empty()) { - buttonNavigator.onNextRelease([this] { + // Navigator is restricted to Up/Down so a Left release used to launch + // search (line above) cannot also be consumed here as a previous-item + // step on the same tick. + buttonNavigator.onRelease({MappedInputManager::Button::Down}, [this] { selectorIndex = ButtonNavigator::nextIndex(selectorIndex, entries.size()); requestUpdate(); }); - buttonNavigator.onPreviousRelease([this] { + buttonNavigator.onRelease({MappedInputManager::Button::Up}, [this] { selectorIndex = ButtonNavigator::previousIndex(selectorIndex, entries.size()); requestUpdate(); }); - buttonNavigator.onNextContinuous([this] { + buttonNavigator.onContinuous({MappedInputManager::Button::Down}, [this] { selectorIndex = ButtonNavigator::nextPageIndex(selectorIndex, entries.size(), PAGE_ITEMS); requestUpdate(); }); - buttonNavigator.onPreviousContinuous([this] { + buttonNavigator.onContinuous({MappedInputManager::Button::Up}, [this] { selectorIndex = ButtonNavigator::previousPageIndex(selectorIndex, entries.size(), PAGE_ITEMS); requestUpdate(); }); diff --git a/src/activities/home/GlobalBookmarksActivity.cpp b/src/activities/home/GlobalBookmarksActivity.cpp index 5e50c6c9..8295fb6c 100644 --- a/src/activities/home/GlobalBookmarksActivity.cpp +++ b/src/activities/home/GlobalBookmarksActivity.cpp @@ -252,17 +252,19 @@ void GlobalBookmarksActivity::loop() { const int pageItems = UITheme::getInstance().getNumberOfItemsPerPage(renderer, true, false, true, false); - buttonNavigator.onNextRelease([this] { + // Navigator is restricted to Up/Down so the Left (rename) and Right (delete) + // handlers above cannot race default cursor movement on the same release tick. + buttonNavigator.onRelease({MappedInputManager::Button::Down}, [this] { selectorIndex = buttonNavigator.nextIndex(selectorIndex); requestUpdate(); }); - buttonNavigator.onPreviousRelease([this] { + buttonNavigator.onRelease({MappedInputManager::Button::Up}, [this] { selectorIndex = buttonNavigator.previousIndex(selectorIndex); requestUpdate(); }); - buttonNavigator.onNextContinuous([this, total, pageItems] { + buttonNavigator.onContinuous({MappedInputManager::Button::Down}, [this, total, pageItems] { int next = ButtonNavigator::nextPageIndex(selectorIndex, total, pageItems); if (isSeparatorRow(next)) { const int adj = ButtonNavigator::nextIndex(next, total, [this](int i) { return !isSeparatorRow(i); }); @@ -272,7 +274,7 @@ void GlobalBookmarksActivity::loop() { requestUpdate(); }); - buttonNavigator.onPreviousContinuous([this, total, pageItems] { + buttonNavigator.onContinuous({MappedInputManager::Button::Up}, [this, total, pageItems] { int prev = ButtonNavigator::previousPageIndex(selectorIndex, total, pageItems); if (isSeparatorRow(prev)) { const int adj = ButtonNavigator::previousIndex(prev, total, [this](int i) { return !isSeparatorRow(i); }); diff --git a/src/activities/home/RecentBooksActivity.cpp b/src/activities/home/RecentBooksActivity.cpp index 1102ec5a..fe09fff3 100644 --- a/src/activities/home/RecentBooksActivity.cpp +++ b/src/activities/home/RecentBooksActivity.cpp @@ -125,22 +125,26 @@ void RecentBooksActivity::loop() { int listSize = static_cast(recentBooks.size()); - buttonNavigator.onNextRelease([this, listSize] { + // Navigator is restricted to Up/Down so it cannot race the Left/Right Short + // handlers above: with a double-click action configured, Short events are + // deferred 300ms while wasReleased() is immediate, which would otherwise let + // the cursor move before the custom action runs on the wrong entry. + buttonNavigator.onRelease({MappedInputManager::Button::Down}, [this, listSize] { selectorIndex = ButtonNavigator::nextIndex(static_cast(selectorIndex), listSize); requestUpdate(); }); - buttonNavigator.onPreviousRelease([this, listSize] { + buttonNavigator.onRelease({MappedInputManager::Button::Up}, [this, listSize] { selectorIndex = ButtonNavigator::previousIndex(static_cast(selectorIndex), listSize); requestUpdate(); }); - buttonNavigator.onNextContinuous([this, listSize, pageItems] { + buttonNavigator.onContinuous({MappedInputManager::Button::Down}, [this, listSize, pageItems] { selectorIndex = ButtonNavigator::nextPageIndex(static_cast(selectorIndex), listSize, pageItems); requestUpdate(); }); - buttonNavigator.onPreviousContinuous([this, listSize, pageItems] { + buttonNavigator.onContinuous({MappedInputManager::Button::Up}, [this, listSize, pageItems] { selectorIndex = ButtonNavigator::previousPageIndex(static_cast(selectorIndex), listSize, pageItems); requestUpdate(); });