Skip to content

runtime: LEONIDA_WINDOW_MONITOR / LEONIDA_WINDOW_NO_ACTIVATE keep a run's windows on one monitor without taking the focus - #9129

Closed
thedarkcr0w wants to merge 1 commit into
ProjectLeonida:mainfrom
thedarkcr0w:window-placement
Closed

thedarkcr0w wants to merge 1 commit into
ProjectLeonida:mainfrom
thedarkcr0w:window-placement

Conversation

@thedarkcr0w

Copy link
Copy Markdown

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, EnumDisplayMonitors order) or on a named device (DISPLAY2 or \\.\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 call place() and show_command().
  • runtime/shims/window_placement_shims.cpp: the title's CreateWindowExA, CreateWindowExW and ShowWindow imports. 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 under user32.dll. A top-level window created WS_VISIBLE is created hidden, placed, then shown, because CreateWindowEx itself would activate it before it could be moved. Child windows and windows with a parent pass through unchanged. ShowWindow maps 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.
  • The environment is read on each call, not cached in a function-local static: these run on the title's thread, where a static's thread-safe-init guard would read TLS the title owns (as in runtime/shims: remove function-local static guards in gameinput, dxgi_com and xmem #7359).

Tested

Windows 11, MSVC 2022 Build Tools RelWithDebInfo, NVIDIA GeForce RTX 4090 (driver 32.0.16.1062), two 2560x1440 monitors.

  • New window_placement_test (CTest window_placement), 19 checks, all pass. They cover the registry entries for both API sets and user32, 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 a WS_VISIBLE window and a ShowWindow(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.
  • Retail dry-run (own 1.0.2.1 copy): the executable's CreateWindowExA and ShowWindow bind 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 on main already because shims/xg_xs.cpp is missing from that list. That's unrelated, and I left it as it is.
  • scripts/check_no_game_data.py is clean on the new files.

AI-assisted (Claude Code).

…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 abnalstlll-byte left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) and LEONIDA_WINDOW_NO_ACTIVATE (forces SW_SHOWNOACTIVATE / SW_SHOWNA / SW_SHOWMINNOACTIVE).
    • Intercepts CreateWindowExA/W and ShowWindow for retail executable API sets and user32.dll.
    • Avoids function-local static guards to prevent TLS contention with title threads.
  • 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.

@smowlyy

smowlyy commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Verified head 99a038672 merged onto main (867d922f0) on native Windows 11 (10.0.26300.9974, MSVC 19.44, RelWithDebInfo):

  • python -I scripts/check_no_game_data.py on all 6 changed files: clean (exit 0)
  • cmake --build runtime/build --target window_placement_test --parallel: built cleanly
  • ctest --test-dir runtime/build -R window_placement --output-on-failure -V: 1/1 passed (window_placement_test: OK (0 failures); single-monitor setup skipped second-monitor placement as expected)

AI-assisted.

@GeremC

GeremC commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

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 ctest through Wine 9.0; CPU only, no game files (a single-monitor X11 desktop).

  • ctest -R window_placement: passed. The test builds and runs from the cross-build, and Wine's user32 answers what it needs.
  • No negative control: the shim files are new in this PR.

AI-assisted (Claude Code).

@Krashgamer

Copy link
Copy Markdown
Contributor

Tested 99a038672 on the retail boot: pass. Windows 11, Intel i7-10700K, NVIDIA RTX 3080 (610.88), MSVC 14.51 RelWithDebInfo, own 1.0.2.1 copy, LEONIDA_D3D12=vulkan with a make_game.py shader work folder. Two displays of different sizes: a 2560x1440 primary and a 1920x1080 second.

Base: ASTROWwwW:ladder-frame @ a1751a9f0 + #7604 + #8591 (with present_state_for presenting into find_title_window, done locally), then this PR merged locally (only runtime/CMakeLists.txt and the build_runtime.ps1 file list conflicted; I kept both sides).

  • Without the switch, the title's window comes up larger than the primary display and spans both monitors.
  • With LEONIDA_WINDOW_MONITOR=1, the window opens centred on the primary display and fits inside its work area (checked by eye). The boot runs as before: 64,267 D3D12 calls in 240 s, no fault, stopped at the time limit.
  • ctest: window_placement and title_window pass. 290/294 overall; the 4 failures (d3d12_vulkan_device, d3d12_depth_resolve, d3d12_indirect_rt, d3d12_bindless_churn) fail on this machine without these changes too.
  • Not tested: LEONIDA_WINDOW_NO_ACTIVATE.

Counts and API names only, no game data. AI-assisted (Claude Code).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants