The gamepad pauses while the window has no focus in a game Steam started, so Steam's overlay and menus get its presses alone (#1462)

Since #971, SDL passes gamepad events to the game while its window has no focus (SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS). On Linux the window is SDL's, and under Steam the focus goes to Steam's overlay and menus while they are open (the Quick Access menu in SteamOS's Game Mode): the game took the presses meant for them too, which 0.4.1 did not.

The new setting pad_background (auto, 1, 0; read at start) decides the hint. auto, the default, keeps it on unless Steam started the game (SteamGameId or SteamOverlayGameId in the environment, set for Steam games and non-Steam shortcuts alike); 1 keeps the gamepad playing behind other windows under Steam too, 0 pauses it everywhere. input_map.c input_pad_background_pick holds the decision and cfg_probe checks it. On Windows the game window is not SDL's, and nothing changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ShannoonRuaaaandClaude Opus 5.5 committed 2026-11-24 19:08:22 -08:00
1 parent 6205940caf
commit 58fd4f6f68
7 files changed
+44 -5

No files matched your search

+7
View File
@@ -324,6 +324,13 @@ gyro all the time. Pick an activation the game does not need (a back button), or
of the game's own motion. Under Steam the Steam Controller's gyro arrives already corrected, so it keeps a bias of its
own (`gyro_bias_pad` ends in "(under Steam)").
On Linux the gamepad keeps playing while the game window has no focus (#971), except in a game Steam started: the
Steam overlay and Steam's menus (the Quick Access menu and the Steam menu in SteamOS's Game Mode) take the focus while
they are open, and the presses meant for them must not reach the game too (#1462). Steam sets `SteamGameId` for its
own games and for non-Steam shortcuts; the log then says `input: the gamepad pauses while the window has no focus`.
`pad_background = 1` keeps the gamepad playing behind other windows under Steam too, `0` pauses it everywhere
(`runtime/input.c`, `start`; read at start). On Windows the game window is not SDL's, and the gamepad always plays.
## Scripted input
`TOTK_INPUT_SCRIPT=<file>` replays presses. It is ORed with real input and still applies under `TOTK_INPUT=none`. One event per line, `#` starts a comment:
+3 -2
View File
@@ -57,7 +57,7 @@ static const char *const known[] = {
"MEM_RESERVE_MIB", "MENU_CURSOR", "MENU_CURSOR_LOG", "MENU_TEST_DIR", "MENU_TEST_SET", "MINIMAL_LAYOUT", "MIRROR_GAP", "MODS_DIR", "MODS_DISABLED", "MODS_NO_CODE", "MODS_ORDER", "MODS_REBUILD", "MODS_WITHOUT_CODE", "MOTION", "MOUSE_AIM_SCALE", "MOUSE_MODE", "MOUSE_DIRECT_PATCH", "MOUSE_SENS", "MOVIE_ASPECT", "MOVIE_HOST", "MOVIE_PACE",
"MVOBJ_ALL", "MVOBJ_BANKS", "MVOBJ_EQUAL", "MVOBJ_EXACT", "MVOBJ_EXEC", "MVOBJ_NOC4", "MVOBJ_ONLY", "MVOBJ_TIMES", "MVPREV_CHECK", "MVPREV_GROW", "MVPREV_SKIP", "MVPREV_TRUST", "MV_CHECK",
"MV_SURVEY", "NULL_ATTACH",
"ONE_PER_CORE", "OPERATION_MODE", "OPTREF_GUARD", "OUTPUT_RES", "PAD_LAYOUT", "PASS_CRUMBS", "PATCH_OUTPUT", "PATCH_SCENE", "PCORE", "PCSS", "PCSS_K", "PERF_CENSUS", "PERF_OVERLAY", "PERF_SLOW_MS", "PIPELINE_CACHE", "PIPE_MEMO", "PIPE_PREBUILD", "PIPE_SKIP", "PIPE_SYNC", "PIPE_WAIT", "PLUGIN_TICK_OFFSET", "PLUGIN_TRACE", "POINTER_IMAGE",
"ONE_PER_CORE", "OPERATION_MODE", "OPTREF_GUARD", "OUTPUT_RES", "PAD_BACKGROUND", "PAD_LAYOUT", "PASS_CRUMBS", "PATCH_OUTPUT", "PATCH_SCENE", "PCORE", "PCSS", "PCSS_K", "PERF_CENSUS", "PERF_OVERLAY", "PERF_SLOW_MS", "PIPELINE_CACHE", "PIPE_MEMO", "PIPE_PREBUILD", "PIPE_SKIP", "PIPE_SYNC", "PIPE_WAIT", "PLUGIN_TICK_OFFSET", "PLUGIN_TRACE", "POINTER_IMAGE",
"PREWARM_XLATE", "PROBE_MOVIE", "PROBE_MOVIE_BENCH", "PROBE_MOVIE_SHOT", "PROFILE", "PROFILE_CHAINS", "PROFILE_DIR", "PROFILE_FRAMES",
"PROFILE_MAIN", "PROFILE_RENDER", "PROMPTS", "PUSH_SKIP", "PUSH_STAGE", "QUICKLOAD_KEY", "QUICKSAVE", "QUICKSAVE_KEY", "RDOC", "RDOC_DIR", "RDOC_DLL", "REALTIME", "REC_ASYNC", "REC_END", "REC_SPIN_US", "REEXEC", "REFLEX",
"RENDER_SCALE", "REPLAY_ASYNC", "REPLAY_CHUNKS", "REPLAY_CHUNK_DRAWS", "REPLAY_SKEW_US", "REPLAY_STATE_CHECK", "REPLAY_WORKERS",
@@ -98,7 +98,7 @@ static const struct { const char *key, *section; } sections[] = {
{"AUDIO_DEVICE", "audio"},
{"MOTION", "input"}, {"GYRO_CALIBRATION", "input"}, {"GYRO_AUTO_BIAS", "input"}, {"RUMBLE_STRENGTH", "input"}, {"RUMBLE_CURVE", "input"}, {"RUMBLE_TRIGGERS", "input"},
{"GYRO_BIAS_X", "input"}, {"GYRO_BIAS_Y", "input"}, {"GYRO_BIAS_Z", "input"}, {"GYRO_BIAS_PAD", "input"},
{"PAD_LAYOUT", "input"}, {"PROMPTS", "input"}, {"STICK_DEADZONE", "input"}, {"LSTICK_DEADZONE", "input"}, {"RSTICK_DEADZONE", "input"},
{"PAD_BACKGROUND", "input"}, {"PAD_LAYOUT", "input"}, {"PROMPTS", "input"}, {"STICK_DEADZONE", "input"}, {"LSTICK_DEADZONE", "input"}, {"RSTICK_DEADZONE", "input"},
{"STICK_SENS", "input"},
{"MENU_CURSOR", "input"}, {"MAP_CLICK", "input"}, {"DIALOGUE_CLICK", "input"}, {"POINTER_IMAGE", "input"}, {"QUICKSAVE", "input"}, {"QUICKSAVE_KEY", "input"}, {"QUICKLOAD_KEY", "input"}, {"MOUSE_MODE", "input"}, {"MOUSE_SENS", "input"}, {"MOUSE_AIM_SCALE", "input"}, {"WALK_KEY", "input"}, {"WALK_SCALE", "input"}, {"FREECAM_PATCH", "input"}, {"FREECAM_PAD", "input"}, {"FREECAM_KEY", "input"}, {"INPUT_RECORD", "input"},
{"BIND_A", "input"}, {"BIND_B", "input"}, {"BIND_X", "input"}, {"BIND_Y", "input"}, {"BIND_LCLICK", "input"},
@@ -183,6 +183,7 @@ static const CfgMeta metas[] = {
{"GYRO_BIAS_X", "", NULL, RESTART}, {"GYRO_BIAS_Y", "", NULL, RESTART}, {"GYRO_BIAS_Z", "", NULL, RESTART},
{"GYRO_BIAS_PAD", "", NULL, RESTART},
{"RUMBLE_TRIGGERS", "0", "0|1", LIVE}, {"PAD_LAYOUT", "auto", "auto|nintendo|xbox", LIVE},
{"PAD_BACKGROUND", "auto", "auto|0|1", RESTART}, // input.c start: SDL's background joystick events (#971, #1462)
{"PROMPTS", "nintendo", "nintendo|xbox|playstation|pc", RESTART},
{"STICK_DEADZONE", "8", "0..50", LIVE}, {"STICK_SENS", "1", "0.1..3", RESTART},
{"LSTICK_DEADZONE", "", "0..50", LIVE}, {"RSTICK_DEADZONE", "", "0..50", LIVE},
+6
View File
@@ -315,6 +315,12 @@ int probe_cfg(void) {
CHECK(input_pad_layout_pick("xbox_prompts", 0) == PAD_LAYOUT_NINTENDO &&
input_pad_layout_pick("Xbox_Prompts", 1) == PAD_LAYOUT_NINTENDO,
"pad layout: 0.1.9's xbox_prompts keeps the Nintendo positions (only the prompts change, romfs.c overlay_init)");
// Gamepad events behind other windows (input_map.c, input.c start)
CHECK(input_pad_background_pick("auto", 0) && !input_pad_background_pick("auto", 1) &&
input_pad_background_pick(NULL, 0) && !input_pad_background_pick(NULL, 1),
"pad background: automatic is on, off when Steam started the game (its overlay takes the gamepad, #1462)");
CHECK(input_pad_background_pick("1", 1) && !input_pad_background_pick("0", 0),
"pad background: 1 and 0 win over the Steam check");
// Button prompts (input_map.c)
CHECK(input_prompts_pick(NULL, "auto") == PROMPTS_NINTENDO && input_prompts_pick("", "xbox") == PROMPTS_NINTENDO &&
input_prompts_pick("Xbox", "nintendo") == PROMPTS_XBOX && input_prompts_pick("nintendo", "xbox") == PROMPTS_NINTENDO,
+12 -3
View File
@@ -671,9 +671,18 @@ static void start(void) {
// window lacks keyboard focus (SDL_PrivateJoystickShouldIgnoreEvent in SDL_joystick.c; centring and releases
// pass). That applies where the window is SDL's (Linux); the Win32 window on Windows is not an SDL window. The
// game keeps running out of focus by default (TOTK_ASSUME_FOCUS, ov_system.c oe_set_focus), so the gamepad has to
// keep working there. With the setting off the game's main thread waits while unfocused and reads no input, so
// the hint can stay on for the whole run.
SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1");
// keep working there (#971). With the setting off the game's main thread waits while unfocused and reads no input,
// so the hint can stay on for the whole run. A game Steam started is the exception (input_pad_background_pick):
// Steam's overlay and menus take the focus while they are open, and the presses meant for them reached the game
// too (#1462). Steam sets SteamGameId for its own games and for non-Steam shortcuts, SteamOverlayGameId with the
// overlay. TOTK_PAD_BACKGROUND = 1 or 0 decides it either way.
const char *gid = getenv("SteamGameId"), *ogid = getenv("SteamOverlayGameId");
int under_steam = (gid && *gid) || (ogid && *ogid);
const char *bg = cfg_value("TOTK_PAD_BACKGROUND");
if (input_pad_background_pick(bg, under_steam)) SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1");
else
rt_log("input: the gamepad pauses while the window has no focus (%s)",
strcmp(bg, "0") ? "Steam started the game; pad_background = 1 keeps it" : "pad_background = 0");
if (!SDL_Init(SDL_INIT_GAMEPAD)) { state = -1; rt_log("input: SDL gamepad init failed (%s), keyboard only", SDL_GetError()); }
else state = 1;
if (state == 1) test_pad_attach();
+6
View File
@@ -305,6 +305,12 @@ int input_pad_layout_pick(const char *setting, int east_labelled_a) {
return east_labelled_a ? PAD_LAYOUT_NINTENDO : PAD_LAYOUT_XBOX;
}
int input_pad_background_pick(const char *setting, int under_steam) {
if (setting && !strcmp(setting, "1")) return 1;
if (setting && !strcmp(setting, "0")) return 0;
return !under_steam;
}
int input_prompts_pick(const char *prompts, const char *pad_layout) {
if (prompts && *prompts)
return !strcasecmp(prompts, "xbox") ? PROMPTS_XBOX
+6
View File
@@ -91,6 +91,12 @@ void input_map_configure(void);
// pad's east button is labelled A (a Switch Pro Controller, a GuliKit) and Xbox otherwise.
int input_pad_layout_pick(const char *setting, int east_labelled_a);
// Whether SDL passes gamepad presses and stick movements to the game while its window has no focus (TOTK_PAD_BACKGROUND,
// input.c start): "1" on, "0" off. Anything else ("auto", NULL) is on unless Steam started the game: then the focus
// goes to Steam's overlay and menus (the Quick Access menu in SteamOS's Game Mode), whose gamepad it is while they are
// open (#1462); elsewhere the gamepad keeps playing while another window has the focus (#971).
int input_pad_background_pick(const char *setting, int under_steam);
// Button prompts (TOTK_PROMPTS): the controller whose buttons the game's prompts show. Nintendo: the game's own. Xbox:
// LB RB LT RT, Menu, View and a d-pad cross for the other buttons, and the face buttons named by the label of the
// button the pad layout presses (runtime/romfs.c overlay_init, tools/make_romfs_patches.py --prompts). PlayStation: the
+4
View File
@@ -454,6 +454,10 @@
# labels, xbox for the others). The bind_ lines below apply on top. Changes while the game runs take effect at once.
# 0.1.9's xbox_prompts is read as nintendo with prompts = xbox.
# pad_layout = auto
# The gamepad while the game window has no focus (Linux; on Windows it always plays): 1 keeps it playing behind other
# windows, 0 pauses it, auto pauses it only when Steam started the game, so the Steam overlay and Steam's menus
# (the Quick Access menu in SteamOS's Game Mode) get the gamepad while they are open. Read at start.
# pad_background = auto
# The buttons the game's prompts show: nintendo (the game's own), xbox (LB RB LT RT, Menu, View and a d-pad cross,
# and A B X Y as labelled on the button pad_layout presses: with nintendo, A shows as B and X as Y), playstation
# (○ × △ □, L1 R1 L2 R2, Options and Share, on the button pad_layout presses: with nintendo, A shows as ○), or pc