lifecycle: suspend callbacks on window close and fit the title window (RT-GDK-SPEECH-DISPLAY-LIFECYCLE, split from #401) #769

Merged
Andretuta merged 3 commits from upstream-pr/769 into main 2026-11-25 08:50:49 +00:00
Andretuta commented 2026-11-24 13:35:43 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Andretuta on 2026-11-24T13:35:43Z.


Claimed in the coordination issue as: RT-GDK-SPEECH-DISPLAY-LIFECYCLE (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7121796272). Split from #401 at the maintainer's request (one topic per pull request).

What and why

Console titles never get a desktop WM_CLOSE: quitting suspends the title (its RegisterAppStateChangeNotification callbacks run with quiesced TRUE so it can flush saves) and then ends the process. They also size their window for a 4K render target, which overflows smaller desktops.

  • runtime/shims/lifecycle.{h,cpp}: RegisterAppStateChangeNotification / UnregisterAppStateChangeNotification under api-ms-win-core-psm-appnotify-l1-1-0.dll, api-ms-win-core-psm-appnotify-l1-1-1.dll and kernelbase.dll.
  • CreateWindowExW / CreateWindowExA under user32.dll and ext-ms-win-rtcore-ntuser-window-l1-1-0/-l1-1-1.dll, and CreateWindowExA under ext-ms-win-rtcore-ntuser-window-ansi-l1-1-0.dll. The title's import table names CreateWindowExA from that ANSI set and RegisterAppStateChangeNotification from api-ms-win-core-psm-appnotify-l1-1-0 (tools/pe_inspect.py). The version in #401 missed the ANSI set, so the game's window would never have been hooked. Only the title's first top-level window (no parent, not WS_CHILD, not WS_EX_TOOLWINDOW) is fitted to the primary monitor's work area and hooked.
  • Its SC_CLOSE runs the registered suspend callbacks under the registration lock, off the window thread, then ends the run through the title's own ExitProcess shim (process.cpp), so the host finishes its cleanup. The deadline is 1 s: if the callbacks have not returned by then, the run ends the same way.
  • A callback may unregister itself; a registration removed by UnregisterAppStateChangeNotification is never called after it returned.
  • lifecycle_test in runtime/CMakeLists.txt; scripts/build_runtime.ps1 adds shims\lifecycle.cpp and user32.lib to the cl fallback; one paragraph in docs/runtime_imports.md.

The code is #401's lifecycle part (as of a02134a9c) on current main, plus the ANSI window set.

Tested

  • MSVC 14.44 / Windows SDK 10.0.26100: lifecycle_test 30 checks, 0 failures, under CTest (new: CreateWindowExA binds through the ANSI set to the same shim).
  • Build-script, docs and test_gdk_runtime_calls pytest: 82 passed.
  • Merges cleanly with #401 and #537 (git merge-tree).
  • Not run with the title itself.

GPUs tested: n/a (CPU-only Win32 tests)

AI-assisted: yes

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. (n/a — runtime shims only)

🤖 Generated with Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5473177940 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/769). Originally posted by [Andretuta](https://github.com/Andretuta) on 2026-11-24T13:35:43Z. --- Claimed in the coordination issue as: `RT-GDK-SPEECH-DISPLAY-LIFECYCLE` (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7121796272). Split from #401 at the maintainer's request (one topic per pull request). ### What and why Console titles never get a desktop `WM_CLOSE`: quitting suspends the title (its `RegisterAppStateChangeNotification` callbacks run with `quiesced` TRUE so it can flush saves) and then ends the process. They also size their window for a 4K render target, which overflows smaller desktops. - **`runtime/shims/lifecycle.{h,cpp}`:** `RegisterAppStateChangeNotification` / `UnregisterAppStateChangeNotification` under `api-ms-win-core-psm-appnotify-l1-1-0.dll`, `api-ms-win-core-psm-appnotify-l1-1-1.dll` and `kernelbase.dll`. - `CreateWindowExW` / `CreateWindowExA` under `user32.dll` and `ext-ms-win-rtcore-ntuser-window-l1-1-0/-l1-1-1.dll`, and `CreateWindowExA` under `ext-ms-win-rtcore-ntuser-window-ansi-l1-1-0.dll`. The title's import table names `CreateWindowExA` from that ANSI set and `RegisterAppStateChangeNotification` from `api-ms-win-core-psm-appnotify-l1-1-0` (`tools/pe_inspect.py`). The version in #401 missed the ANSI set, so the game's window would never have been hooked. Only the title's first top-level window (no parent, not `WS_CHILD`, not `WS_EX_TOOLWINDOW`) is fitted to the primary monitor's work area and hooked. - Its `SC_CLOSE` runs the registered suspend callbacks under the registration lock, off the window thread, then ends the run through the title's own `ExitProcess` shim (`process.cpp`), so the host finishes its cleanup. **The deadline is 1 s:** if the callbacks have not returned by then, the run ends the same way. - A callback may unregister itself; a registration removed by `UnregisterAppStateChangeNotification` is never called after it returned. - `lifecycle_test` in `runtime/CMakeLists.txt`; `scripts/build_runtime.ps1` adds `shims\lifecycle.cpp` and `user32.lib` to the `cl` fallback; one paragraph in `docs/runtime_imports.md`. The code is #401's lifecycle part (as of a02134a9c) on current `main`, plus the ANSI window set. ### Tested - MSVC 14.44 / Windows SDK 10.0.26100: `lifecycle_test` 30 checks, 0 failures, under CTest (new: `CreateWindowExA` binds through the ANSI set to the same shim). - Build-script, docs and `test_gdk_runtime_calls` pytest: 82 passed. - Merges cleanly with #401 and #537 (`git merge-tree`). - Not run with the title itself. GPUs tested: n/a (CPU-only Win32 tests) AI-assisted: yes ### 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. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a — runtime shims only) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
aslan2142 commented 2026-11-25 01:51:56 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-11-25T01:51:56Z.


@Andretuta this is reviewed and ready to merge; one small conflict stands in the way, and I can't resolve it myself because maintainer edits are off on this branch. Could you merge current main into it and push?

  • The conflict is only in scripts/build_runtime.ps1, in the cl fallback: keep main's side, then add "shims\lifecycle.cpp" after process.cpp in the source list, and user32.lib to the link line. Nothing else conflicts, now that #984 and #968 are in main.
  • Checked: the claim RT-GDK-SPEECH-DISPLAY-LIFECYCLE is valid and this is the split the owner asked for on #401. Neither #984 nor #939 has a lifecycle shim or fits the window when it is created, so this is not covered elsewhere.
  • Tested on a local merge with #984: under Wine (clang-cl build, llvmpipe and an RDNA2 iGPU) lifecycle passes on both devices and none of the selected tests changed (lifecycle, xgameruntime*, run_tiny*, xbox_present, dxgi*); the docs tests, test_ci_registration and test_build_runtime_fallback pass.
  • An optional follow-up, not needed for this PR: for a window created with CreateWindowExA, subclassing with SetWindowLongPtrA and CallWindowProcA would keep it an ANSI window; SetWindowLongPtrW turns it into a Unicode one. It works either way.
  • #1240 also binds RegisterAppStateChangeNotification and UnregisterAppStateChangeNotification on the same two appnotify API sets. I've asked there for that pair to be dropped, since yours was claimed first and calls the callbacks.

Once it's pushed and merges cleanly, I'll merge it.

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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7150048070 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/769#issuecomment-7150048070). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-11-25T01:51:56Z. --- @Andretuta this is reviewed and ready to merge; one small conflict stands in the way, and I can't resolve it myself because maintainer edits are off on this branch. Could you merge current `main` into it and push? - **The conflict** is only in `scripts/build_runtime.ps1`, in the `cl` fallback: keep `main`'s side, then add `"shims\lifecycle.cpp"` after `process.cpp` in the source list, and `user32.lib` to the link line. Nothing else conflicts, now that #984 and #968 are in `main`. - **Checked:** the claim `RT-GDK-SPEECH-DISPLAY-LIFECYCLE` is valid and this is the split the owner asked for on #401. Neither #984 nor #939 has a lifecycle shim or fits the window when it is created, so this is not covered elsewhere. - **Tested** on a local merge with #984: under Wine (clang-cl build, llvmpipe and an RDNA2 iGPU) `lifecycle` passes on both devices and none of the selected tests changed (`lifecycle`, `xgameruntime*`, `run_tiny*`, `xbox_present`, `dxgi*`); the docs tests, `test_ci_registration` and `test_build_runtime_fallback` pass. - **An optional follow-up, not needed for this PR:** for a window created with `CreateWindowExA`, subclassing with `SetWindowLongPtrA` and `CallWindowProcA` would keep it an ANSI window; `SetWindowLongPtrW` turns it into a Unicode one. It works either way. - **#1240** also binds `RegisterAppStateChangeNotification` and `UnregisterAppStateChangeNotification` on the same two `appnotify` API sets. I've asked there for that pair to be dropped, since yours was claimed first and calls the callbacks. Once it's pushed and merges cleanly, I'll merge it. AI-assisted (Claude Code, Claude Opus 5.5).
piyonchu commented 2026-11-25 02:08:19 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by piyonchu on 2026-11-25T02:08:19Z.


Note from #1240 (RT-PSM-APPNOTIFY-WER): dropped RegisterAppStateChangeNotification / UnregisterAppStateChangeNotification from #1240 so #769 remains the sole shim registration for those two APIs.

In case it is helpful for #769's lifecycle_test, here are the edge cases we had been covering on RegisterAppStateChangeNotification / UnregisterAppStateChangeNotification:

  • RegisterAppStateChangeNotification(..., nullptr) returning ERROR_INVALID_PARAMETER
  • RegisterAppStateChangeNotification(nullptr, ..., &out) returning ERROR_INVALID_PARAMETER and zeroing *Registration
  • UnregisterAppStateChangeNotification(nullptr) and foreign/double-unregister pointers not faulting
<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7150361977 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/769#issuecomment-7150361977). Originally posted by [piyonchu](https://github.com/piyonchu) on 2026-11-25T02:08:19Z. --- Note from `#1240` (`RT-PSM-APPNOTIFY-WER`): dropped `RegisterAppStateChangeNotification` / `UnregisterAppStateChangeNotification` from `#1240` so `#769` remains the sole shim registration for those two APIs. In case it is helpful for `#769`'s `lifecycle_test`, here are the edge cases we had been covering on `RegisterAppStateChangeNotification` / `UnregisterAppStateChangeNotification`: - `RegisterAppStateChangeNotification(..., nullptr)` returning `ERROR_INVALID_PARAMETER` - `RegisterAppStateChangeNotification(nullptr, ..., &out)` returning `ERROR_INVALID_PARAMETER` and zeroing `*Registration` - `UnregisterAppStateChangeNotification(nullptr)` and foreign/double-unregister pointers not faulting
aslan2142 commented 2026-11-25 08:50:52 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-11-25T08:50:52Z.


Merged. Thank you, @Andretuta, for splitting this out of #401 and for bringing it up to date.

  • Claim: RT-GDK-SPEECH-DISPLAY-LIFECYCLE was posted at 04:11 UTC on 2026-11-24, before this PR, and is unedited; this is the split the owner asked for on #401.
  • What it adds, and nothing else had it: on a close of the title's window, the suspend callbacks the title registered run (with quiesced = TRUE, on a new thread, with a 1 s deadline) before the run ends; and the title's first top-level window is fitted to the desktop's work area with its aspect kept. Neither #984 nor #939 carries a lifecycle shim or fits the window when it is created.
  • The update: your merge of main was clean when you pushed it; the conflict came back when #1598 (the silent audio endpoint, merged after it) added shims\silent_audio.cpp to the same $files line of scripts/build_runtime.ps1 that this PR extends. A maintainer merge of main (8b771908c, no force-push) keeps both entries, lifecycle.cpp where you had it; your user32.lib change on the link line merged cleanly. Sorry for the extra round.
  • Windows suite under Wine on main + this branch (llvmpipe and an RDNA2 iGPU): lifecycle passes on both; nothing goes from pass to fail. d3d12_pipeline_library failed once on the iGPU in the full run and passes alone 3 of 3 times on both devices (load, not this change).
  • Checked on main 237deb64c + 8b771908c: it merges cleanly; the semantic suite passes (487 files, 6,279 tests, 0 files failed); the 14 docs and writer tests pass; check_no_game_data.py is clean on the 6 changed files.
  • An optional follow-up: for a window created with CreateWindowExA, subclassing with SetWindowLongPtrA and CallWindowProcA would keep it an ANSI window; SetWindowLongPtrW turns it into a Unicode one. It works either way.
  • #1240 also binds RegisterAppStateChangeNotification and UnregisterAppStateChangeNotification on the same two appnotify API sets; it has been asked to drop that pair.

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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7157546134 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/769#issuecomment-7157546134). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-11-25T08:50:52Z. --- Merged. Thank you, @Andretuta, for splitting this out of #401 and for bringing it up to date. - **Claim:** `RT-GDK-SPEECH-DISPLAY-LIFECYCLE` was posted at 04:11 UTC on 2026-11-24, before this PR, and is unedited; this is the split the owner asked for on #401. - **What it adds, and nothing else had it:** on a close of the title's window, the suspend callbacks the title registered run (with `quiesced = TRUE`, on a new thread, with a 1 s deadline) before the run ends; and the title's first top-level window is fitted to the desktop's work area with its aspect kept. Neither #984 nor #939 carries a lifecycle shim or fits the window when it is created. - **The update:** your merge of `main` was clean when you pushed it; the conflict came back when #1598 (the silent audio endpoint, merged after it) added `shims\silent_audio.cpp` to the same `$files` line of `scripts/build_runtime.ps1` that this PR extends. A maintainer merge of `main` (`8b771908c`, no force-push) keeps both entries, `lifecycle.cpp` where you had it; your `user32.lib` change on the link line merged cleanly. Sorry for the extra round. - **Windows suite under Wine on `main` + this branch (llvmpipe and an RDNA2 iGPU):** `lifecycle` passes on both; nothing goes from pass to fail. `d3d12_pipeline_library` failed once on the iGPU in the full run and passes alone 3 of 3 times on both devices (load, not this change). - **Checked** on `main` `237deb64c` + `8b771908c`: it merges cleanly; the semantic suite passes (487 files, 6,279 tests, 0 files failed); the 14 docs and writer tests pass; `check_no_game_data.py` is clean on the 6 changed files. - **An optional follow-up:** for a window created with `CreateWindowExA`, subclassing with `SetWindowLongPtrA` and `CallWindowProcA` would keep it an ANSI window; `SetWindowLongPtrW` turns it into a Unicode one. It works either way. - **#1240** also binds `RegisterAppStateChangeNotification` and `UnregisterAppStateChangeNotification` on the same two `appnotify` API sets; it has been asked to drop that pair. AI-assisted (Claude Code, Claude Opus 5.5).
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!769
No description provided.