Add baseline implementation of Automatic Termination #5430
+15
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Explanation of Automatic Termination in case you’re not familiar with the concept – skip to below the divider if you already know what it is :)
Traditionally, open apps have a process associated with them and closed apps don’t have one. Automatic Termination brings an iOS-like process model to the Mac:
While Automatic Termination is enabled, the system can at any time ask an app to quit through the usual
NSApp.terminate()
.If the app is performing work which cannot be paused when it’s quit and then resumed once it’s launched again, then it should temporarily disable Automatic Termination until that work is complete. (Note that enabling and disabling Automatic Termination works in a manner similar to reference counting, so you can call the enable or disable methods as many times as you like as long as the calls are balanced.)
This PR adds Automatic Termination to Ghostty in a very limited form.
Ideally Ghostty would have scrollback restoration: if this were the case, we’d leave Automatic Termination enabled all the time except for when a shell is running commands, enabling it again once it’s back at the prompt. If a surface is at the prompt, then that means it can be closed and later restored with full fidelity, and the user would be none the wiser.
Unfortunately Ghostty doesn’t have scrollback restoration, meaning Automatic Termination needs to be disabled as long as a surface is open. Open surfaces have scrollback which can’t be restored should the OS decide to terminate us, so we need to disable Automatic Termination while there are open surfaces.
Although this may make supporting Automatic Termination seem pointless, it does gain us two nice features: instant reopen, and automatic close when no windows are open. You can observe this behavior in TextEdit, Preview, QuickTime Player, Pages, Keynote, etc. Here’s a small demonstration:
Untitled.mp4
And here’s a demonstration of how this PR interacts with the quick terminal:
Screen.Recording.2025-01-30.at.11.47.37.PM.mp4
Note that I never actually invoked Quit in either of these videos.
I’m not sure whether it’s necessary to implement a setting to disable Automatic Termination in Ghostty, since it’s standard behavior on macOS across a wide range of apps and there’s a built-in way to turn it off (
defaults write -g NSDisableAutomaticTermination -bool YES
). In case you think there should be a dedicated setting for this in Ghostty, the setting should be distinct fromquit-after-last-window-closed
, since Automatic Termination is wider in scope than just making the app appear to close once its last window is gone.Let me know if you have any thoughts or questions :D