d3d12: Alt+Enter switches to borderless fullscreen instead of freezing the picture (D3D12-BORDERLESS-FULLSCREEN) #2752

Merged
leonida/mandy
alpfilho merged 2 commits from d3d12/borderless-fullscreen into main 2026-11-30 23:53:55 +00:00

Pull request successfully merged and closed

alpfilho commented 2026-11-30 15:31:30 +00:00

Claimed in the coordination issue as: D3D12-BORDERLESS-FULLSCREEN (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7258292257)

What and why

In d3d12/, Alt+Enter went to DXGI's own exclusive fullscreen. Nothing in the runtime makes the buffers again for it, so the picture froze and nothing more was shown.

  • leonida-gpu/src/host.rs: after the swap chain is made, MakeWindowAssociation(hwnd, DXGI_MWA_NO_ALT_ENTER) is called on the swap chain's own factory (GetParent), so DXGI leaves Alt+Enter alone.
  • leonida-hle/src/modules/lifecycle.rs, the title window's procedure:
    • Alt+Enter takes the window out of its frame, over the whole of its monitor (MonitorFromWindow / rcMonitor).
    • The next Alt+Enter gives back its frame and its place.
    • The key, the repeats of a held key and its character (a beep) do not reach the title; the repeats do not switch the window either.
    • Going back gives back only the frame and edge styles, not the whole old style. A window made borderless before it was first shown therefore stays shown.
    • Each window keeps its own saved frame and place, forgotten at WM_NCDESTROY.
    • A child window (WS_CHILD) is left as it was, and Alt+Enter goes on to it.
  • LEONIDA_FULLSCREEN=1 (-Fullscreen in both launchers, or FULLSCREEN (NO BORDER) in the F1 menu) makes the window borderless from the start.
  • The swap chain is not made again: its picture is scaled to the window as before (LEONIDA_PRESENT_SCALE).

VIctory has a borderless fullscreen, which gave the idea; this code is written for leonida-hle. RT-WINDOW-MODES (#14) is about runtime/'s windows and has no pull request; this changes d3d12/ only.

Tested

  • In game (with the FSR 3 frame generation of #2615, now in main):
    • The first build brought back the window's whole style from before it was shown, which hid the window on the first Alt+Enter. That is fixed here: only the frame bits come back.
    • With the fix, and with -Fullscreen and FSR 3 frame generation on, the window started borderless over the 1920x1080 monitor.
    • Alt+Enter switched it to a framed window and back ten times in a row, with the picture shown each time.
    • It played on for about 4 minutes, and the session ended by closing the window.
  • Review fixes (the second commit, from the review below): the three cases merzleckeier found under Wine (a second window overwriting the first one's saved place, a child window made monitor-sized, a held key's repeats reaching the title's procedure) each have a test now. The in-game run above was before these fixes; they change nothing for the title's one top-level window and a single press.
  • Unit tests: cargo test -p leonida-hle --lib lifecycle, 15 passed, with five new tests that send the keys to windows of their own and run one at a time:
    • Alt+Enter goes borderless at the monitor's size and back to the same frame and rect; a repeat and a plain Enter do not switch it.
    • A window made borderless before it was shown stays visible when Alt+Enter gives its frame back.
    • Two windows switched A, B, B, A each come back to their own frame and place.
    • A child window keeps its place and style.
    • Neither Alt+Enter nor three repeats of it reach the title's procedure, another Alt key still does, and the window is forgotten when it is destroyed.
  • Lint and build: cargo clippy reports nothing in lifecycle.rs, scripts\build-nvidia.ps1 builds and both launchers parse, on the branch rebased onto 08e42a516.

GPUs tested: NVIDIA GeForce RTX 3060 12 GB, driver 621.40, Windows 11 Pro (build 26300)

AI-assisted: yes (Claude Code, Claude Opus 5.5)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (No translator change.)

🤖 Generated with Claude Code

Claimed in the coordination issue as: D3D12-BORDERLESS-FULLSCREEN (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7258292257) ### What and why In `d3d12/`, Alt+Enter went to DXGI's own exclusive fullscreen. Nothing in the runtime makes the buffers again for it, so the picture froze and nothing more was shown. - `leonida-gpu/src/host.rs`: after the swap chain is made, `MakeWindowAssociation(hwnd, DXGI_MWA_NO_ALT_ENTER)` is called on the swap chain's own factory (`GetParent`), so DXGI leaves Alt+Enter alone. - `leonida-hle/src/modules/lifecycle.rs`, the title window's procedure: - Alt+Enter takes the window out of its frame, over the whole of its monitor (`MonitorFromWindow` / `rcMonitor`). - The next Alt+Enter gives back its frame and its place. - The key, the repeats of a held key and its character (a beep) do not reach the title; the repeats do not switch the window either. - Going back gives back only the frame and edge styles, not the whole old style. A window made borderless before it was first shown therefore stays shown. - Each window keeps its own saved frame and place, forgotten at `WM_NCDESTROY`. - A child window (`WS_CHILD`) is left as it was, and Alt+Enter goes on to it. - `LEONIDA_FULLSCREEN=1` (`-Fullscreen` in both launchers, or **FULLSCREEN (NO BORDER)** in the F1 menu) makes the window borderless from the start. - The swap chain is not made again: its picture is scaled to the window as before (`LEONIDA_PRESENT_SCALE`). VIctory has a borderless fullscreen, which gave the idea; this code is written for `leonida-hle`. RT-WINDOW-MODES (#14) is about `runtime/`'s windows and has no pull request; this changes `d3d12/` only. ### Tested - **In game (with the FSR 3 frame generation of #2615, now in `main`):** - The first build brought back the window's whole style from before it was shown, which hid the window on the first Alt+Enter. That is fixed here: only the frame bits come back. - With the fix, and with `-Fullscreen` and FSR 3 frame generation on, the window started borderless over the 1920x1080 monitor. - Alt+Enter switched it to a framed window and back ten times in a row, with the picture shown each time. - It played on for about 4 minutes, and the session ended by closing the window. - **Review fixes** (the second commit, from the review below): the three cases merzleckeier found under Wine (a second window overwriting the first one's saved place, a child window made monitor-sized, a held key's repeats reaching the title's procedure) each have a test now. The in-game run above was before these fixes; they change nothing for the title's one top-level window and a single press. - **Unit tests:** `cargo test -p leonida-hle --lib lifecycle`, 15 passed, with five new tests that send the keys to windows of their own and run one at a time: - Alt+Enter goes borderless at the monitor's size and back to the same frame and rect; a repeat and a plain Enter do not switch it. - A window made borderless before it was shown stays visible when Alt+Enter gives its frame back. - Two windows switched A, B, B, A each come back to their own frame and place. - A child window keeps its place and style. - Neither Alt+Enter nor three repeats of it reach the title's procedure, another Alt key still does, and the window is forgotten when it is destroyed. - **Lint and build:** `cargo clippy` reports nothing in `lifecycle.rs`, `scripts\build-nvidia.ps1` builds and both launchers parse, on the branch rebased onto `08e42a516`. GPUs tested: NVIDIA GeForce RTX 3060 12 GB, driver 621.40, Windows 11 Pro (build 26300) AI-assisted: yes (Claude Code, Claude Opus 5.5) ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (No translator change.) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
merzleckeier commented 2026-11-30 15:40:32 +00:00

Independent Wine check of Alt+Enter with multiple windows

MEASURED. I cross-built the unchanged lifecycle.rs from 85f4ca8b against the Windows SDK with Rust 1.98.1 and ran it on Wine 11.22 with a private 1024×768 Xvfb display. A small harness stubbed unrelated GPU and loader interfaces and drove the hooked windows with synthetic SendMessageW calls. The 12 stock lifecycle tests passed, including the two new fullscreen tests.

  1. A second top-level window overwrites the first window's saved state. Start with two framed windows and send Alt+Enter in the order A, B, B, A. B restores its frame. A stays unframed at [0, 0, 1024, 768] instead of restoring [30, 40, 350, 240]. The assignment to the single WINDOWED slot saves B over A.
  2. The hotkey makes a child window monitor-sized. Sending the same message to a hooked WS_CHILD | WS_BORDER window changed its bounds from [49, 110, 369, 310] to [29, 70, 1053, 838] and its style from 0x40800000 to 0xc0000000. The same case on main be769080 left the child unchanged. The startup path already checks WS_CHILD. The hotkey path reaches set_borderless for this child.
  3. A held key reaches the previous window procedure. The initial Alt+Enter and the Enter WM_SYSCHAR were consumed. The synthetic previous procedure received one WM_SYSKEYDOWN with lParam=0x60000000 for the held key. The frame stayed borderless during the repeat, which is what the stock test checks.

Each failure reproduced in isolation. In a local test-only control I stored the saved state per HWND, excluded WS_CHILD from the hotkey and consumed repeats without toggling. All 15 tests then passed. A second agent independently reran the cases using a separate Wine prefix and Xvfb. This checks Win32 message handling and window state under Wine. Native Windows input and DXGI presentation were outside the test. AI-assisted with OpenAI Codex.

# Independent Wine check of Alt+Enter with multiple windows **MEASURED.** I cross-built the unchanged `lifecycle.rs` from `85f4ca8b` against the Windows SDK with Rust 1.98.1 and ran it on Wine 11.22 with a private 1024×768 Xvfb display. A small harness stubbed unrelated GPU and loader interfaces and drove the hooked windows with synthetic `SendMessageW` calls. The 12 stock lifecycle tests passed, including the two new fullscreen tests. 1. **A second top-level window overwrites the first window's saved state.** Start with two framed windows and send Alt+Enter in the order A, B, B, A. B restores its frame. A stays unframed at `[0, 0, 1024, 768]` instead of restoring `[30, 40, 350, 240]`. The assignment to the single `WINDOWED` slot saves B over A. 2. **The hotkey makes a child window monitor-sized.** Sending the same message to a hooked `WS_CHILD | WS_BORDER` window changed its bounds from `[49, 110, 369, 310]` to `[29, 70, 1053, 838]` and its style from `0x40800000` to `0xc0000000`. The same case on `main` `be769080` left the child unchanged. The startup path already checks `WS_CHILD`. The hotkey path reaches `set_borderless` for this child. 3. **A held key reaches the previous window procedure.** The initial Alt+Enter and the Enter `WM_SYSCHAR` were consumed. The synthetic previous procedure received one `WM_SYSKEYDOWN` with `lParam=0x60000000` for the held key. The frame stayed borderless during the repeat, which is what the stock test checks. Each failure reproduced in isolation. In a local test-only control I stored the saved state per HWND, excluded `WS_CHILD` from the hotkey and consumed repeats without toggling. All 15 tests then passed. A second agent independently reran the cases using a separate Wine prefix and Xvfb. This checks Win32 message handling and window state under Wine. Native Windows input and DXGI presentation were outside the test. AI-assisted with OpenAI Codex.
alpfilho commented 2026-11-30 16:46:07 +00:00

@merzleckeier thanks for the Wine check. I confirmed all three findings in the code, and they are fixed in 6bc847d0b, with one test each:

  1. One saved slot for every window. WINDOWED is now one entry per window (Vec<Windowed> keyed by HWND), so A, B, B, A brings each window back to its own frame and place. An entry is also dropped at WM_NCDESTROY, because a later window can get the same handle. Test: two_windows_keep_their_own_places.
  2. Child windows. The hotkey path now leaves a WS_CHILD window alone. Its Alt+Enter and Enter WM_SYSCHAR go on to it as on main, and set_borderless itself refuses to make a child borderless. Test: a_child_window_is_left_alone, which checks that the window keeps its rect and style.
  3. Held key. alt_enter now tells a press from a repeat (bit 30), and window_proc consumes both. A repeat neither switches the window nor reaches the previous procedure. Test: a_held_alt_enter_does_not_reach_the_title. It swaps a counting procedure in for the title's, then sends one Alt+Enter and three repeats, and counts zero WM_SYSKEYDOWN. Another Alt key still gets through.

The branch is also rebased onto 08e42a516, which resolves the needs rebase conflicts in host.rs (next to the new shown::install) and in the play-nvidia.ps1 switch list (now with MotionBlur).

Re-run on native Windows 11 (RTX 3060, driver 621.40):

  • cargo test -p leonida-hle --lib lifecycle gives 15 passed, including your three cases.
  • cargo clippy reports nothing in lifecycle.rs.
  • scripts\build-nvidia.ps1 builds, and both launchers parse.

The in-game run in the description was made before these fixes. They change nothing for the title's one top-level window or a single press.

AI-assisted (Claude Code, Claude Opus 5.5).

@merzleckeier thanks for the Wine check. I confirmed all three findings in the code, and they are fixed in `6bc847d0b`, with one test each: 1. **One saved slot for every window.** `WINDOWED` is now one entry per window (`Vec<Windowed>` keyed by HWND), so A, B, B, A brings each window back to its own frame and place. An entry is also dropped at `WM_NCDESTROY`, because a later window can get the same handle. Test: `two_windows_keep_their_own_places`. 2. **Child windows.** The hotkey path now leaves a `WS_CHILD` window alone. Its Alt+Enter and Enter `WM_SYSCHAR` go on to it as on `main`, and `set_borderless` itself refuses to make a child borderless. Test: `a_child_window_is_left_alone`, which checks that the window keeps its rect and style. 3. **Held key.** `alt_enter` now tells a press from a repeat (bit 30), and window_proc consumes both. A repeat neither switches the window nor reaches the previous procedure. Test: `a_held_alt_enter_does_not_reach_the_title`. It swaps a counting procedure in for the title's, then sends one Alt+Enter and three repeats, and counts zero `WM_SYSKEYDOWN`. Another Alt key still gets through. The branch is also rebased onto `08e42a516`, which resolves the `needs rebase` conflicts in `host.rs` (next to the new `shown::install`) and in the `play-nvidia.ps1` switch list (now with `MotionBlur`). Re-run on native Windows 11 (RTX 3060, driver 621.40): - `cargo test -p leonida-hle --lib lifecycle` gives 15 passed, including your three cases. - `cargo clippy` reports nothing in `lifecycle.rs`. - `scripts\build-nvidia.ps1` builds, and both launchers parse. The in-game run in the description was made before these fixes. They change nothing for the title's one top-level window or a single press. AI-assisted (Claude Code, Claude Opus 5.5).
Sign in to join this conversation.
No description provided.