kitty icon indicating copy to clipboard operation
kitty copied to clipboard

Mac OS: kitty doesn't restore

Open toonn opened this issue 5 years ago • 15 comments

Mac OS offers the option to resume all your open apps after a shutdown, Apple's version of hibernate, I guess. Terminal.app actually restores the ouput/history in the windows that were open when you shut the system down.

While that's nice, just restoring windows to the positions and sizes they had when shutting down would be plenty for me. Previous versions of kitty restored the positions, not the size. The current version (0.12.3) doesn't for me.

Note that I don't like the remember_window_size setting, I want new terminals to open at 80x24, it's just some long running terminals I'd like to restore to whatever size I made them.

On a similar note, I've been unable to change kitty windows's sizes using applescript, this was a nice QoL improvement with Terminal.app because the Mac OS window manager is so impotent.

toonn avatar Dec 02 '18 22:12 toonn

kitty has no code to restore window positions, so I am surprised it would ever have happened. As I recall, cocoa has some special APIs for saving/restoring application state. These are not wrapped by glfw (the toolkit kitty uses) so they would need to be implement in kitty/cocoa_window.m instead. This is too much effort for me personally, but patches are welcome.

kovidgoyal avatar Dec 03 '18 08:12 kovidgoyal

I assume this holds for applescript control as well? How about simply opening at startup if it was open at shutdown? Does that also require implementation?

How hard/easy would it be to build kitty? Maybe I can git bisect to find where the behavior was lost?

toonn avatar Dec 03 '18 10:12 toonn

No idea about aplescript control. Isn't applescript going to be retired by apple? opening at startup is the same thing as far as i know. see https://sw.kovidgoyal.net/kitty/build.html for how to build from source

kovidgoyal avatar Dec 03 '18 10:12 kovidgoyal

It would be very nice to have this feature. :)

pencilcheck avatar Apr 10 '19 07:04 pencilcheck

After looking into this a little, I think this is the necessary related documentation.

setFrameAutosaveName might also work to solve it too, apparently.

Here is the related StackOverflow where I found them. It took a while to figure out the right thing to search for.

zoidyzoidzoid avatar Apr 17 '19 08:04 zoidyzoidzoid

This is the only missing feature blocked me using kitty in Mac, after reboot the workspace will be gone.

JunfengJia avatar Apr 04 '20 22:04 JunfengJia

@kovidgoyal my preferred way for you to implement something like this, if you ever did, would be to have the opposite of ls so that the output of kitty @ ls can be re-used. I'd be pretty happy with something like:

kitty @ ls > savestate
kitty @ fromjson < savestate

In an ideal world, kitty ls would support --match and so it would also be trivial to save a subset of the window state.

A less good implementation could be some sort of kitty @ save-session feature that would dump a session file that approximated the current setup. I think that'll be worse by definition as session files don't have all the information that is already in ls and it's surely less work to add the right info into the ls JSON structure and rehydrate from there.

anicolao avatar Aug 11 '20 11:08 anicolao

While I'm not usually intentionally restoring, the restore feature comes in very handy when the OS crashes (which does happen...). Even if the windows aren't resized/placed correctly, at least having them all pop up again with the previous scrollback content is really, really useful.

I also wish there were a CMD+SHIFT+T "restore closed tab" feature for when I fat finger CMD+W.

Restoring working directories probably requires something like #3091.

lloeki avatar Nov 12 '20 11:11 lloeki

To be clear, my original issue report is just about restoring window size and location. You should probably open a new issue to talk about restoring terminal state like Terminal.app does.

toonn avatar Nov 12 '20 21:11 toonn

If anyone is interested, I wrote a script which converts the output of kitty @ ls into a kitty session file, so that you can do:

# Dump the current kitty session:
$ kitty @ ls > kitty-dump.json
# Convert this JSON file into a kitty session file:
$ cat kitty-dump.json | python3 ./kitty-convert-dump.py > kitty-session.kitty
# Start kitty from that session file:
$ kitty --session kitty-session.kitty

It's here if anyone wants to use it: https://github.com/dflock/kitty-save-session

dflock avatar Feb 24 '21 22:02 dflock

While I'm not usually intentionally restoring, the restore feature comes in very handy when the OS crashes (which does happen...). Even if the windows aren't resized/placed correctly, at least having them all pop up again with the previous scrollback content is really, really useful.

I also wish there were a CMD+SHIFT+T "restore closed tab" feature for when I fat finger CMD+W.

This is essentially the same as opening a new tab, because when you close the tab, the shell in there is killed, the terminal could show the scroll back buffer, and reopen trhe shell in the old directory, but it is not the same. After a restart, I think there is no way to get back shell state, though scroll back can be dumped then restored. It would have to handle the case of running something like vim or less.

sharpenedblade avatar Oct 20 '21 04:10 sharpenedblade

@kovidgoyal do we have any updates on this? I would have loved if kitty could restore directories at least automatically if someone quits and reopens it.

ShivamJoker avatar Mar 30 '22 17:03 ShivamJoker

I'm having this issue when my Mac wakes up from sleep. Kitty has stopped rendering and displays a still image, however the application has not stopped responding to the OS. Killing and restarting Kitty shows that TMUX has been receiving the keystrokes and the state has updated accordingly, it was only the rendering that was frozen.

mkylmamaa avatar May 27 '22 06:05 mkylmamaa

For anyone that might tackle the window position restore issue, GLFW seems to have support for it on macOS with the window hint GLFW_COCOA_FRAME_NAME while running glfwCreateWindow. I tried to tackle it myself in glfw.c, but had no success.

This also might be a clue in glfw's source for cocoa_window.m

lkhrs avatar Jul 08 '22 16:07 lkhrs

Lack of restoration is the biggest issue I have had with Kitty so far. The standard Terminal.app behavior is to restore terminal locations and sizes, background color and other attributes set per window. Within each, it restores terminal history along with a marker telling the date when the history was restored ( [Restored 21. Feb 2023 at 15.47.28]), and tries to restore the CWD of the shell. The lack of this feature makes one postpone necessary computer restarts as well as delay updates of Kitty itself. image

jammi avatar Feb 21 '23 13:02 jammi