Commit graph

6 commits

Author SHA1 Message Date
Kovid Goyal
24201d3080
Implement session saving on Logout for Linux as well 2026-10-19 10:49:22 +05:30
Kovid Goyal
7c35cc6429
Remove orphaned keychain keys of sessions saved at logout
Keys whose snapshot no longer exists, for example because it was deleted
by a cache cleaner or because the keychain was locked when deleting it,
are deleted when saving at logout, when claiming snapshots at startup and
when removing all snapshots. This is done with the snapshot lock held, so
snapshots being saved or restored are never affected. Only keys with the
format of the ids kitty creates are deleted.
2026-10-16 12:02:20 +05:30
Kovid Goyal
8f0b7eff31
Encrypt sessions saved at logout with a key in the macOS Keychain
Every snapshot is encrypted with AES-256-GCM using a random key, stored
in the login keychain under a random id. The name of every file is
authenticated, so files cannot be swapped. The key is deleted before the
snapshot whenever it is removed, so copies of the snapshot left on disk
or in backups cannot be read.

The keychain is never allowed to show any UI. If storing the key fails
nothing is saved, if reading it fails the snapshot is deleted, with the
error logged in both cases.

The key is generated, stored and read only in C, in mlocked memory that
is cleared when freed, via a new random_secret() and the Keychain
functions in cocoa_window.m.
2026-10-16 11:57:31 +05:30
Kovid Goyal
76a00e5142
macOS: Optionally restore kitty, including scrollback, after logging out
A new option restore_session_after_logout. When macOS asks kitty to quit
because the user is logging out, restarting or shutting down, every kitty
instance saves a snapshot: its session, including OS Window geometry, the
scrollback of every window and the command line, working directory and
environment of the instance.

The next kitty started without a session or command to run claims all
snapshots, restores the one saved by an instance with the same command
line itself and starts a separate kitty instance for each of the others,
so every instance keeps its own command line arguments and environment.
Snapshots are deleted only after their windows have been created. A
snapshot that fails to restore twice, for example because kitty crashed,
is deleted. Snapshots from an earlier logout that were never restored are
deleted when saving, using the wall clock start time of the process.

Restored scrollback is parsed before the child is allowed to run, after
the window has its final size. Only the scrollback and screen are saved,
not the scrollback pager history. Before parsing, everything except SGR,
OSC 8 and OSC 66 is removed, so a modified snapshot cannot run escape
codes such as OSC 52, and the restored output has no shell integration
marks. Programs other than the shell are not started again.

A quit is treated as being for a logout only if it is confirmed within
LOGOUT_CONFIRMATION_TIMEOUT of the logout request, and not if the quit
was cancelled in between.

Fixes #1197
2026-10-16 11:41:27 +05:30
Kovid Goyal
d4eb2b34e6
Sessions: Add os_window_position and save_as_session --os-window-geometry
The geometry of fullscreen OS Windows is the one from before they were made
fullscreen. On macOS this is now also recorded when using native fullscreen
via the window buttons/menu.
2026-10-16 11:29:28 +05:30
Kovid Goyal
6a3cfbcb10
Sessions: Fix os_window_size being ignored when remember_window_size is enabled
A size specified in the session now takes precedence over both the
remembered size and the remembered maximized state.
2026-10-16 11:26:53 +05:30