Latch the Minus+Plus combo until both are released, serialise menu open and close, pack the cursor release flags into one word, and drop menu_available

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Valiantsin DzerakhandClaude Opus 5.5 committed 2026-10-26 09:51:56 +03:00
1 parent 0cfc489bbf
commit 4d4b0efeb8
6 files changed
+64 -25

No files matched your search

+19 -7
View File
@@ -38,13 +38,26 @@ static const unsigned char roboto_ttf[] = {
static std::atomic<int> g_open; // the menu is open
static std::atomic<int> g_reset; // opened or closed since the last laid-out frame: drop stale input
static void set_open(int open) {
if (g_open.exchange(open) == open) return;
g_reset.store(1);
input_menu(open);
rt_log("menu: %s", open ? "open" : "closed");
// g_open, the input block and the log line change together under open_lock, so they cannot disagree when the window thread
// (F1, Esc), the polling thread (combo) and the present path (Continue, B) race.
static PlatMutex open_lock = PLAT_MUTEX_INIT;
// want 0 or 1 sets the state; -1 flips it. Returns the new state.
static int change_open(int want) {
plat_mutex_lock(&open_lock);
int open = want < 0 ? !g_open.load() : want;
if (g_open.load() != open) {
g_open.store(open);
g_reset.store(1);
input_menu(open);
rt_log("menu: %s", open ? "open" : "closed");
}
plat_mutex_unlock(&open_lock);
return open;
}
static void set_open(int open) { change_open(open); }
// TOTK_MENU_TEST=<frame>[:<frames per page>]: the presented frame the menu opens at for the shot hook; 0 when unset
static uint64_t test_frame(void) {
static std::atomic<long long> f{-1};
@@ -59,10 +72,9 @@ static uint64_t test_frame(void) {
}
static int g_failed_flag();
extern "C" int menu_available(void) { return 1; }
extern "C" int menu_is_open(void) { return g_open.load(std::memory_order_relaxed); }
extern "C" void menu_toggle(void) {
if (!g_failed_flag()) set_open(!g_open.load());
if (!g_failed_flag()) change_open(-1);
}
// ---- events from the window adapter, queued while the menu is open; the present path hands them to ImGui
-1
View File
@@ -20,7 +20,6 @@ extern "C" {
#endif
// ---- state, any thread
int menu_available(void); // always 1: the menu opens on every platform
int menu_is_open(void);
void menu_toggle(void); // F1 / Esc on the keyboard, Minus+Plus on the pad
+1
View File
@@ -44,6 +44,7 @@ extern "C" int menu_window_msg(HWND h, UINT m, WPARAM w, LPARAM l, LRESULT *res)
case WM_KEYDOWN:
case WM_SYSKEYDOWN:
// bit 30: auto-repeat
// Esc with the menu open (opened by F1 too) is not a toggle here: it goes to the menu, which closes itself
if (!(l & (1 << 30)) && (w == VK_F1 || (w == VK_ESCAPE && !menu_is_open()))) {
menu_toggle();
*res = 0;