From 2d48afb052ad14f96ac354152376962979efbb3c Mon Sep 17 00:00:00 2001 From: chrg6 Date: Wed, 11 Nov 2026 07:47:08 -0500 Subject: [PATCH] Open the menu when the gamepad in use goes away and no other is connected. The game is always told one controller is connected, so a disconnect read as nothing pressed and play went on without the player noticing; the console would stop and ask for a controller. Audit finding F-8-04. Co-Authored-By: Claude Opus 5.5 --- runtime/input.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/runtime/input.c b/runtime/input.c index 02f062a3..bda39037 100644 --- a/runtime/input.c +++ b/runtime/input.c @@ -538,7 +538,11 @@ static void pad_primary(SDL_Gamepad *p, const char *why) { // Under lock: closes the gamepads that went away and opens the ones that came; the primary falls back to the first // open one when it left. Logs each change. +// The game is always told one controller is connected, so a disconnect read as nothing pressed and play went on +// uncontrolled (the console would stop and ask for a controller). When the primary goes and no other gamepad takes +// its place, the menu opens: the player sees it, and it takes the keyboard and mouse until it is closed. static void scan_pads(void) { + int had = pad != NULL; for (int i = 0; i < npads;) { if (SDL_GamepadConnected(pads[i])) { i++; continue; } rt_log("input: gamepad \"%s\" disconnected", SDL_GetGamepadName(pads[i]) ? SDL_GetGamepadName(pads[i]) : "?"); @@ -563,6 +567,10 @@ static void scan_pads(void) { } SDL_free(ids); if (!pad && npads) pad_primary(pads[0], "in use"); + if (had && !pad && !menu_is_open()) { + rt_log("input: the gamepad in use went away and no other is connected: the menu opens"); + menu_toggle(); + } } // Under lock: 1 when p has a button down, a trigger pulled or a stick past half way (a drifting stick does not count).