lifecycle: suspend callbacks on window close and fit the title window (RT-GDK-SPEECH-DISPLAY-LIFECYCLE, split from #401) #769
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs rebase
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!769
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/769/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@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 UTCClaimed 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 (itsRegisterAppStateChangeNotificationcallbacks run withquiescedTRUE 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/UnregisterAppStateChangeNotificationunderapi-ms-win-core-psm-appnotify-l1-1-0.dll,api-ms-win-core-psm-appnotify-l1-1-1.dllandkernelbase.dll.CreateWindowExW/CreateWindowExAunderuser32.dllandext-ms-win-rtcore-ntuser-window-l1-1-0/-l1-1-1.dll, andCreateWindowExAunderext-ms-win-rtcore-ntuser-window-ansi-l1-1-0.dll. The title's import table namesCreateWindowExAfrom that ANSI set andRegisterAppStateChangeNotificationfromapi-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, notWS_CHILD, notWS_EX_TOOLWINDOW) is fitted to the primary monitor's work area and hooked.SC_CLOSEruns the registered suspend callbacks under the registration lock, off the window thread, then ends the run through the title's ownExitProcessshim (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.UnregisterAppStateChangeNotificationis never called after it returned.lifecycle_testinruntime/CMakeLists.txt;scripts/build_runtime.ps1addsshims\lifecycle.cppanduser32.libto theclfallback; one paragraph indocs/runtime_imports.md.The code is #401's lifecycle part (as of
a02134a9c) on currentmain, plus the ANSI window set.Tested
lifecycle_test30 checks, 0 failures, under CTest (new:CreateWindowExAbinds through the ANSI set to the same shim).test_gdk_runtime_callspytest: 82 passed.git merge-tree).GPUs tested: n/a (CPU-only Win32 tests)
AI-assisted: yes
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a — runtime shims only)🤖 Generated with Claude Code
@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
maininto it and push?scripts/build_runtime.ps1, in theclfallback: keepmain's side, then add"shims\lifecycle.cpp"afterprocess.cppin the source list, anduser32.libto the link line. Nothing else conflicts, now that #984 and #968 are inmain.RT-GDK-SPEECH-DISPLAY-LIFECYCLEis 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.lifecyclepasses on both devices and none of the selected tests changed (lifecycle,xgameruntime*,run_tiny*,xbox_present,dxgi*); the docs tests,test_ci_registrationandtest_build_runtime_fallbackpass.CreateWindowExA, subclassing withSetWindowLongPtrAandCallWindowProcAwould keep it an ANSI window;SetWindowLongPtrWturns it into a Unicode one. It works either way.RegisterAppStateChangeNotificationandUnregisterAppStateChangeNotificationon the same twoappnotifyAPI 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 on GitHub · 2026-11-25 02:08 UTC · original
Note from
#1240(RT-PSM-APPNOTIFY-WER): droppedRegisterAppStateChangeNotification/UnregisterAppStateChangeNotificationfrom#1240so#769remains the sole shim registration for those two APIs.In case it is helpful for
#769'slifecycle_test, here are the edge cases we had been covering onRegisterAppStateChangeNotification/UnregisterAppStateChangeNotification:RegisterAppStateChangeNotification(..., nullptr)returningERROR_INVALID_PARAMETERRegisterAppStateChangeNotification(nullptr, ..., &out)returningERROR_INVALID_PARAMETERand zeroing*RegistrationUnregisterAppStateChangeNotification(nullptr)and foreign/double-unregister pointers not faulting@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.
RT-GDK-SPEECH-DISPLAY-LIFECYCLEwas 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.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.mainwas clean when you pushed it; the conflict came back when #1598 (the silent audio endpoint, merged after it) addedshims\silent_audio.cppto the same$filesline ofscripts/build_runtime.ps1that this PR extends. A maintainer merge ofmain(8b771908c, no force-push) keeps both entries,lifecycle.cppwhere you had it; youruser32.libchange on the link line merged cleanly. Sorry for the extra round.main+ this branch (llvmpipe and an RDNA2 iGPU):lifecyclepasses on both; nothing goes from pass to fail.d3d12_pipeline_libraryfailed once on the iGPU in the full run and passes alone 3 of 3 times on both devices (load, not this change).main237deb64c+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.pyis clean on the 6 changed files.CreateWindowExA, subclassing withSetWindowLongPtrAandCallWindowProcAwould keep it an ANSI window;SetWindowLongPtrWturns it into a Unicode one. It works either way.RegisterAppStateChangeNotificationandUnregisterAppStateChangeNotificationon the same twoappnotifyAPI sets; it has been asked to drop that pair.AI-assisted (Claude Code, Claude Opus 5.5).