Skip to content

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

Merged
aslan2142 merged 3 commits into
mainfrom
feat/gdk-lifecycle-window-hook
Nov 25, 2026
Merged

aslan2142 merged 3 commits into
mainfrom
feat/gdk-lifecycle-window-hook

Conversation

@Andretuta

Copy link
Copy Markdown
Collaborator

Claimed in the coordination issue as: RT-GDK-SPEECH-DISPLAY-LIFECYCLE (#14 (comment)). 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 xgameruntime_offline: one silent speech voice with WAVE streams, display power requests for timeout deferrals (RT-GDK-SPEECH-DISPLAY-LIFECYCLE) #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 a02134a) on current main, plus the ANSI window set.

Tested

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

… (split from #401)

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 (a02134a), as the maintainer asked for one topic per pull request.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@aslan2142

Copy link
Copy Markdown
Collaborator

@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?

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

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

@piyonchu

Copy link
Copy Markdown
Contributor

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

Andretuta and others added 2 commits November 25, 2026 00:58
…ow-hook

# 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 <noreply@anthropic.com>
@aslan2142
aslan2142 merged commit 604ddff into main Nov 25, 2026
2 of 5 checks passed
@aslan2142

Copy link
Copy Markdown
Collaborator

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

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

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

Labels

needs rebase Conflicts with the base branch: rebase it on main

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants