Skip to content

Remembers window position after quit#8601

Closed
dgshanee wants to merge 9 commits into
kovidgoyal:masterfrom
dgshanee:master
Closed

Remembers window position after quit#8601
dgshanee wants to merge 9 commits into
kovidgoyal:masterfrom
dgshanee:master

Conversation

@dgshanee

@dgshanee dgshanee commented May 4, 2025

Copy link
Copy Markdown
Contributor

Adds a cache partition to remember the window position after quitting. Solves #1119

@kovidgoyal

Copy link
Copy Markdown
Owner

It's not that simple, this can for example lead to the window being
positioned off screen if the screen resolution has changed. And it wont
work on tiling window managers, and Wayland and so on.

It definitely needs to be behind a default off option and if we are
implementing this then implement a --position command line flag for
kitty as well.

@dgshanee

dgshanee commented May 4, 2025

Copy link
Copy Markdown
Contributor Author

@kovidgoyal it works for Rectangle for macos but I don't know about Wayland. Perhaps I could make the x and y values offsets of the screen resolution?

@dgshanee

dgshanee commented May 4, 2025

Copy link
Copy Markdown
Contributor Author

@kovidgoyal I just tested it with different resolutions on macos and nothing appears off-screen. I think glfw accounts for off-screen positioning when making windows. Let me know.

@kovidgoyal

Copy link
Copy Markdown
Owner

You need to store the monitor geometry and the window position. On Cocoa
and X11 the window co-ordinates are in the same co-ordinate space as the
monitor co-ordinates. Then the restoring position code needs to handle
the case when the current monitor layout has changed, glfw absolutely
does not do that, see the _glfwplatformcreatewindow function in
cocoa_window.m

This behavior needs to be made optional, defaulting to off, the default
may be changed in the future if it works well.

There needs to be a --position CLI flag added to kitty and all this
needs to be documented, noting that on Wayland it doesn't work at all
since applications are not allowed to set window positions.

@dgshanee

dgshanee commented May 5, 2025

Copy link
Copy Markdown
Contributor Author

@kovidgoyal I just pushed a working version of what you described. Thanks!

@kovidgoyal

Copy link
Copy Markdown
Owner

OK I'll review when I have a moment

@kovidgoyal

Copy link
Copy Markdown
Owner

You need to store all available monitor geometries not just the primary one (the os window being closed could be on any monitor not necessarily the primary one), and then in the restore code check that the geometries are unchanged and only then restore, otherwise let the window manager decide where to place the window. Use glfwGetMonitors, glfwGetMonitorPos and glfwGetMonitorWorkarea and glfwgetmonitorphysicalsize. Store all that data in the cache and when restoring use it to decide whether to restore or abort or move and restore.

@dgshanee

dgshanee commented May 5, 2025

Copy link
Copy Markdown
Contributor Author

Got it, thanks.

@dgshanee

Copy link
Copy Markdown
Contributor Author

@kovidgoyal It now only restores if the monitor workarea is the exact same. Also, <pyerrors.h> was throwing undefined function errors, so I fixed it by importing <Python.h> in glfw.c. Let me know!

@dgshanee

Copy link
Copy Markdown
Contributor Author

@kovidgoyal It seems my pull request changed some of the formatting of the code. I'll fix that right now

@dgshanee

Copy link
Copy Markdown
Contributor Author

@kovidgoyal Working version is here. Sorry about the confusion.

@kovidgoyal

Copy link
Copy Markdown
Owner

Please fix the CI failures

@dgshanee

Copy link
Copy Markdown
Contributor Author

I think it was because of including Python.h in kitty/glfw.c

@dgshanee

Copy link
Copy Markdown
Contributor Author

@kovidgoyal should be working now

zchee pushed a commit to zchee/kitty that referenced this pull request Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants