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

Manually merged
github merged 3 commits from gh-pr/769/head into gh-pr/769/base 2026-11-26 09:20:26 +00:00
Owner

@⁠Andretuta on GitHub · 2026-11-24 13:35 UTC · original
ubiquitarianism:feat/gdk-lifecycle-window-hook → main · +484 −2 · 6 files · 3 commits · merged 2026-11-25 08:50 UTC

Claimed in the coordination issue as: RT-GDK-SPEECH-DISPLAY-LIFECYCLE (#14). 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

**@⁠Andretuta** on GitHub · 2026-11-24 13:35 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/769) `ubiquitarianism:feat/gdk-lifecycle-window-hook` → `main` · +484 −2 · 6 files · 3 commits · merged 2026-11-25 08:50 UTC Claimed in the coordination issue as: `RT-GDK-SPEECH-DISPLAY-LIFECYCLE` (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14). 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)
RegisterAppStateChangeNotification / UnregisterAppStateChangeNotification under
api-ms-win-core-psm-appnotify-l1-1-0/-l1-1-1 and kernelbase.dll, and CreateWindowExW/A under
user32.dll and ext-ms-win-rtcore-ntuser-window-l1-1-0/-l1-1-1, plus CreateWindowExA under
ext-ms-win-rtcore-ntuser-window-ansi-l1-1-0, the set the title's import table names. The title's
first top-level window is fitted to the work area and hooked: SC_CLOSE runs the suspend callbacks
(quiesced TRUE) and ends the run through the title's ExitProcess, with a 1 s deadline.

Split from #401 (a02134a9c), as the maintainer asked for one topic per pull request.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	scripts/build_runtime.ps1
scripts/build_runtime.ps1 conflicted in the $files list of the build
without CMake: main added shims\silent_audio.cpp there (#1598) after this
branch had merged main, and this branch adds shims\lifecycle.cpp. Both
entries are kept, lifecycle.cpp where this branch had it. The branch's
other change in that file (user32.lib on the link line) merged cleanly.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:20:25 +00:00
github manually merged commit 8b771908c3 into gh-pr/769/base 2026-11-26 09:20:26 +00:00
Author
Owner

@⁠aslan2142 on GitHub · 2026-11-25 01:51 UTC · original

@⁠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).

**@⁠aslan2142** on GitHub · 2026-11-25 01:51 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/769#issuecomment-7150048070) @⁠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).
Author
Owner

@⁠piyonchu on GitHub · 2026-11-25 02:08 UTC · original

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
**@⁠piyonchu** on GitHub · 2026-11-25 02:08 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/769#issuecomment-7150361977) 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
Author
Owner

@⁠aslan2142 on GitHub · 2026-11-25 08:50 UTC · original

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).

**@⁠aslan2142** on GitHub · 2026-11-25 08:50 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/769#issuecomment-7157546134) 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).
This discussion has been locked. Commenting is limited to contributors.
No description provided.