Repository navigation
runtime: LEONIDA_WINDOW_MONITOR / LEONIDA_WINDOW_NO_ACTIVATE keep a run's windows on one monitor without taking the focus - #9129
thedarkcr0w wants to merge 1 commit into
Conversation
…a run's windows on one monitor without taking the focus The title's CreateWindowExA/W and ShowWindow imports (the ext-ms-win-rtcore-ntuser-window API sets the retail executable uses, and user32) go through new shims. LEONIDA_WINDOW_MONITOR=<n> or a device name (DISPLAY2) moves a top-level window into that monitor's work area, centred and fitted; LEONIDA_WINDOW_NO_ACTIVATE=1 shows windows without activating them, so a test run never takes the keyboard focus (and with it the input) from the person at the PC. Unset, nothing changes. window_placement_test covers both, the device-name forms, child windows and the show-command mapping.
abnalstlll-byte
left a comment
There was a problem hiding this comment.
Independent Windows review (commit 99a038672e981ca7243079a82294f659eb9af5fd)
What changed:
runtime/shims/window_placement.{h,cpp}&runtime/shims/window_placement_shims.cpp:- Implements
LEONIDA_WINDOW_MONITOR(routes and fits top-level window to specific 1-based display index or device name) andLEONIDA_WINDOW_NO_ACTIVATE(forcesSW_SHOWNOACTIVATE/SW_SHOWNA/SW_SHOWMINNOACTIVE). - Intercepts
CreateWindowExA/WandShowWindowfor retail executable API sets anduser32.dll. - Avoids function-local static guards to prevent TLS contention with title threads.
- Implements
runtime/test/window_placement_test.cpp:- 19 test checks covering multi-monitor routing, oversize fitting, non-activating show command mapping, and foreground focus retention.
Verification on Windows 11 host:
- Built and verified with MSVC: window placement calculations and focus-retention logic pass cleanly.
- Clean diff: no game files or retail traces.
LGTM! Highly valuable quality-of-life feature for local testing.
|
Verified head
AI-assisted. |
|
Tested 99a0386 (already contains main 867d922) under Wine: pass On: Linux, Ubuntu 24.04, cross-built with clang-cl 19.1.1 + xwin SDK (RelWithDebInfo), run by
AI-assisted (Claude Code). |
|
Tested Base:
Counts and API names only, no game data. AI-assisted (Claude Code). |
Claimed in #9065: #9065 (comment)
What and why
The retail title shows its own window with
ShowWindow, which activates it. So a boot run on a desktop someone is using takes their keyboard focus, and with it their keyboard and mouse input, on whatever monitor Windows picks. Two switches let a tester keep runs on a spare monitor and keep working:LEONIDA_WINDOW_MONITOR=<n>: a top-level window opens on monitor n (1-based,EnumDisplayMonitorsorder) or on a named device (DISPLAY2or\\.\DISPLAY2), centred in its work area and shrunk to fit. A number or name no monitor has changes nothing.LEONIDA_WINDOW_NO_ACTIVATE=1: windows are shown without being activated, so the run never takes the focus.Unset, nothing changes.
Design
runtime/shims/window_placement.{h,cpp}: the helpers (target_work_area,no_activate,place,show_command), with no shim table, so any target can link them. The runtime's own windows (for example a PresentX window) can callplace()andshow_command().runtime/shims/window_placement_shims.cpp: the title'sCreateWindowExA,CreateWindowExWandShowWindowimports. They are registered under the API sets the retail executable imports them from (ext-ms-win-rtcore-ntuser-window-ansi-l1-1-0.dll,ext-ms-win-rtcore-ntuser-window-l1-1-0.dll) and underuser32.dll. A top-level window createdWS_VISIBLEis created hidden, placed, then shown, becauseCreateWindowExitself would activate it before it could be moved. Child windows and windows with a parent pass through unchanged.ShowWindowmaps every showing command to its non-activating form (SW_SHOWNORMAL/SW_SHOWDEFAULT/SW_RESTORE->SW_SHOWNOACTIVATE,SW_SHOW->SW_SHOWNA,SW_SHOWMINIMIZED->SW_SHOWMINNOACTIVE). A "maximized" window is sized to the target's work area instead.Tested
Windows 11, MSVC 2022 Build Tools RelWithDebInfo, NVIDIA GeForce RTX 4090 (driver 32.0.16.1062), two 2560x1440 monitors.
window_placement_test(CTestwindow_placement), 19 checks, all pass. They cover the registry entries for both API sets anduser32, placement by number and by device name with and without the prefix, unknown monitors, fitting an oversized window, child windows, the show-command mapping, and aWS_VISIBLEwindow and aShowWindow(SW_SHOWNORMAL)both being shown without becoming the foreground window. On a one-monitor machine it uses monitor 1 and prints a SKIP line for the second-monitor case.CreateWindowExAandShowWindowbind to these shims; 0 unimplemented imports. Boot runs with both switches set keep the title's window on the second monitor without taking the focus.scripts/build_runtime.ps1: both files added to the cl.exe fallback.tests/test_build_runtime_fallback.py's launcher check fails onmainalready becauseshims/xg_xs.cppis missing from that list. That's unrelated, and I left it as it is.scripts/check_no_game_data.pyis clean on the new files.AI-assisted (Claude Code).