Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macOS: Remember last focused window location for next startup #4233

Open
mitchellh opened this issue Dec 31, 2024 · 9 comments · May be fixed by #5529
Open

macOS: Remember last focused window location for next startup #4233

mitchellh opened this issue Dec 31, 2024 · 9 comments · May be fixed by #5529
Labels
gui GUI or app issue regardless of platform (i.e. Swift, GTK) os/macos

Comments

@mitchellh
Copy link
Contributor

mitchellh commented Dec 31, 2024

Discussed in #4204

Originally posted by evertonstz December 31, 2024
I'm one of those guys that keeps closing and reopening their terminal during the day and that's one of the first things I noticed when using Ghostty: it doesn't remembers the size and position of the last closed window like most other MacOS apps.
It's been a long time since I used Linux with modern gnome, but I think that's also the expected behavior for apps there, right?

Research on Other Behavior

Terminal.app and iTerm both remember the position of the last focused window (not last created window) and restore it when restarting the app. Only the position is remembered, not the size.

Note this is different from window-save-state. This isn't restoring any window. This is just remembering the position.

This behavior isn't typical with Gnome applications, so this is tagged macOS only.

Implementation

Given this is a macOS only behavior, I'm inclined to leverage macOS APIs for this and put this information into defaults. I suspect that's where these programs are also doing it but verification required.

I think we should solve this completely in the Swift code.

There are no configs currently to specify an initial window position, but in the future if/when we have those, those should always override this.

@mitchellh mitchellh added os/macos gui GUI or app issue regardless of platform (i.e. Swift, GTK) labels Dec 31, 2024
@huhu415
Copy link

huhu415 commented Jan 8, 2025

My config file: window-save-state = always and quit-after-last-window-closed=true
I also found that if you use comand + q to exit ghostty, the next time you start it, the position and size will be remembered.

But if I use comand + w to exit ghostty, even if I set quit-after-last-window-closed=true, even though it has already exited, the next time I open it, I still won't remember the setting and size

@jsumners
Copy link

I look forward to this being implemented. I tend to keep my terminal in the lower left corner of my workspace. I also utilize multiple "Spaces," usually one per project. So I end up creating multiple terminal windows, at least one per Space, and, while not a deal breaker, it gets tiresome having to manually move the new window to the location I typically keep it.

@karlhorky
Copy link

karlhorky commented Jan 13, 2025

@jsumners does the window-save-state config setting work for you?

window-save-state = always

window-save-state

Whether to enable saving and restoring window state. Window state includes their position, size, tabs, splits, etc.

  • always will always save window state whenever Ghostty is exited.

This works for me so far.

@mitchellh
Copy link
Contributor Author

Note this issue is different from window-save-state. That remembers windows that were open. The behavior being described in this issue is that macOS apps appear to remember the last location (not size) of windows that were focused or closed in order to open the first window on the next app startup.

@jsumners
Copy link

Note this issue is different from window-save-state. That remembers windows that were open. The behavior being described in this issue is that macOS apps appear to remember the last location (not size) of windows that were focused or closed in order to open the first window on the next app startup.

Right. And I'm adding more information that the last focused window should also inform the position of the next new window created from the Dock icon's context menu.

@pluiedev
Copy link
Contributor

pluiedev commented Jan 13, 2025

Note that on a technical level we cannot make this work on Linux, at least not just for Ghostty. GTK and Wayland explicitly do not allow windows to move themselves, because in Wayland the placement of each window is solely the responsibility of the compositor/window manager, and this functionality can only be implemented there.

@rizalstrato
Copy link

shell-integration = zsh
window-save-state = always
quit-after-last-window-closed=true

i used these three on config file. (i used zsh)
Worked everytime

@markwyner
Copy link

Thanks for this information, @mitchellh. Do you know where this fits for release on your roadmap? It's one of only two things about Ghostty that are really bothering me. It's an otherwise amazing terminal. Excellent work overall.

@jsumners
Copy link

jsumners commented Feb 1, 2025

Nothing can be released if no one PRs a fix. I do not see any PRs associated with this issue. I'm sure they'd welcome your contribution.

@liby liby linked a pull request Feb 2, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gui GUI or app issue regardless of platform (i.e. Swift, GTK) os/macos
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants