Keep the game in focus by default, so switching windows during a load no longer stops it for good.

The game sets focus handling mode 2: on a Switch the system then suspends the whole process while it is out of focus.
Here only its main thread stopped, in PopNotificationMessage, while the loader threads, audio and clocks ran on, and a
tester on Hyprland with 1.4.3 saw a load never finish after the window lost and regained the focus; TOTK_ASSUME_FOCUS=1
avoided it. That is now the default (assume_focus in totk.ini, as MacNativeGames always reports in focus); 0 restores
the pause. Each focus change is logged, so a report shows whether the window saw it.
This commit is contained in:
Wellington Dias committed 2026-10-30 14:56:13 -03:00
1 parent ba4eae2123
commit 021413740d
6 files changed
+17 -11

No files matched your search

+1 -1
View File
@@ -103,7 +103,7 @@ From the repository root, in PowerShell. Every step that depends on the game ver
The AMD driver keeps its pipeline cache per exe path and holds a limited amount: preparing another build folder can
evict this one's. `totk.exe --warm-shaders` rebuilds it from the shader cache.
7. Run. Keep the window in the foreground; an unfocused window stalls the game.
7. Run. The game keeps running when its window loses the focus (`assume_focus` in `totk.ini`).
```powershell
build\<ver>\totk.exe
+1 -1
View File
@@ -38,7 +38,7 @@ build\<ver>\totk.exe
`TOTK_VK_VALIDATION=1` turns on the Vulkan validation layer (it comes with the Vulkan SDK). It makes the game slower;
do one run with it and one without (`set TOTK_VK_VALIDATION=`).
Keep the window in the foreground: an unfocused window stalls the game. Shaders the preparation did not cover compile on first use, so
The game keeps running behind other windows (`assume_focus = 0` in `totk.ini` pauses it instead). Shaders the preparation did not cover compile on first use, so
the first minutes of play can stutter.
Play into the open field (load a save, walk around for a minute, fight something if you can), then close the window.
+2 -2
View File
@@ -60,7 +60,7 @@ static const struct { const char *key, *section; } sections[] = {
{"FULLSCREEN", "display"}, {"WINDOW_SIZE", "display"}, {"PERF_OVERLAY", "display"}, {"VK_PRESENT", "display"},
{"GPU_INDEX", "display"}, {"OUTPUT_RES", "display"}, {"RENDER_SCALE", "display"}, {"UPSCALER", "display"},
{"SHARPNESS", "display"}, {"PICTURE_FIT", "display"},
{"DEVICE_PROFILE", "display"},
{"DEVICE_PROFILE", "display"}, {"ASSUME_FOCUS", "display"},
{"MENU_LANG", "language"}, {"LANG", "language"}, {"OPERATION_MODE", "language"},
{"VOLUME", "audio"},
{"MOTION", "input"}, {"RUMBLE_STRENGTH", "input"}, {"RUMBLE_CURVE", "input"}, {"RUMBLE_TRIGGERS", "input"},
@@ -95,7 +95,7 @@ static const CfgMeta metas[] = {
{"OUTPUT_RES", "1920x1080", NULL, RESTART}, {"RENDER_SCALE", "game", "game|50|67|75|100|125|150|200", RESTART},
{"UPSCALER", "fsr", "fsr|bilinear", LIVE}, {"SHARPNESS", "80", "0..100", LIVE},
{"PICTURE_FIT", "keep", "keep|stretch", LIVE},
{"DEVICE_PROFILE", "auto", "auto|desktop|deck", RESTART},
{"DEVICE_PROFILE", "auto", "auto|desktop|deck", RESTART}, {"ASSUME_FOCUS", "1", "0|1", RESTART},
// Game
{"FPS_LIMIT", "60", "30|40|45|60|90|120|144|display", LIVE}, {"FPS60", "1", "0|1", LIVE},
{"REALTIME", "1", "0|1", RESTART}, {"CLOTH_REALTIME", "1", "0|1", RESTART},
+1
View File
@@ -53,6 +53,7 @@ void gfx_window_focus_changed(int in) {
oe_set_focus(in); // pinned to 1 by TOTK_ASSUME_FOCUS inside
oe_push_message(OE_MSG_FOCUS_STATE_CHANGED);
plat_inc32(&g_focus_msgs);
rt_log("gfx: window %s the focus", in ? "gained" : "lost");
}
// The window was closed: the process ends with it, as in MNG, once a save Commit still running in the background is
+9 -7
View File
@@ -9,8 +9,8 @@
// TOTK_LOCALE=<BCP 47 tag> else the language for this locale ("pt-BR"), else the Windows user locale;
// a language the game does not ship becomes en-US
// TOTK_OPERATION_MODE=docked|handheld operation and performance mode reported to the game (default docked)
// TOTK_ASSUME_FOCUS=1 GetCurrentFocusState always reports in focus, whatever the window says; the
// window opens without taking focus (gfx_window_win.c), for scripted runs
// TOTK_ASSUME_FOCUS=1|0 1 (default): GetCurrentFocusState always reports in focus, whatever the
// window says; 0: out of focus while the window is, as on a Switch (see below)
// TOTK_SHARED_FONTS=<dir> nn::pl shared fonts (tools/extract_fonts.py output), default
// <romfs>/../../firmware/shared-fonts
#include <ctype.h>
@@ -147,16 +147,18 @@ static void ov_focus_mode(Cpu *c) {
}
}
// FocusState GetCurrentFocusState(): 1 in focus, 2 out of focus (nn::oe::FocusState). In focus until the window
// reports otherwise through oe_set_focus; TOTK_ASSUME_FOCUS=1 (unattended runs) pins it to 1. The caller of
// oe_set_focus also pushes OE_MSG_FOCUS_STATE_CHANGED.
// FocusState GetCurrentFocusState(): 1 in focus, 2 out of focus (nn::oe::FocusState). The game sets focus handling
// mode 2: on a Switch the system then suspends the whole process while it is out of focus and sends Resume when it
// returns. Here only the game's main thread stops (it waits in PopNotificationMessage for the next message) while its
// loader threads, audio and clocks run on, and a load interrupted that way was seen to never finish (Linux, 1.4.3).
// So TOTK_ASSUME_FOCUS=1, the default, keeps it at 1, as MacNativeGames does; with 0 it follows the window through
// oe_set_focus. The caller of oe_set_focus also pushes OE_MSG_FOCUS_STATE_CHANGED.
static volatile int32_t focus_state = 1;
static int assume_focus(void) {
static volatile int32_t v = -1;
int32_t a = v;
if (a < 0) {
const char *e = cfg_get("TOTK_ASSUME_FOCUS");
a = e && atoi(e) ? 1 : 0;
a = atoi(cfg_value("TOTK_ASSUME_FOCUS")) ? 1 : 0;
plat_xchg32(&v, a);
}
return (int)a;
+3
View File
@@ -124,6 +124,9 @@
# Picture shape when the window's differs from the game resolution's (a 16:9 game on a 16:10 screen): keep (its
# proportions, with black bars) or stretch (over the whole window). Changes take effect at once.
# picture_fit = keep
# 1: the game always counts itself in focus and keeps running behind other windows. 0: it pauses while the window
# lacks the focus, as a Switch does with the HOME menu; a load interrupted that way can stop for good. Read at start.
# assume_focus = 1
[language]
# Language: a Windows locale such as de-DE, or a Switch code (en-US, ja, zh-Hant, ...). Default: the Windows locale.