Allow setting OS window size in session files

This commit is contained in:
Kovid Goyal 2019-04-02 20:20:39 +05:30
parent 4baf7b5bba
commit 96f5c66755
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 16 additions and 2 deletions

View File

@ -26,6 +26,8 @@ To update |kitty|, :doc:`follow the instructions <binary>`.
- Allow creating new OS windows in session files (:iss:`1514`)
- Allow setting OS window size in session files
- Allow specifying a value of ``none`` for the :opt:`selection_foreground`
which will cause kitty to not change text color in selections (:iss:`1358`)

View File

@ -345,6 +345,8 @@ For example:
# Create a new OS window
new_os_window
# set new window size to 80x25 cells
os_window_size 80c 25c
launch sh
# Make the current window the active (focused) window
focus

View File

@ -146,7 +146,7 @@ class Boss:
def add_os_window(self, startup_session, os_window_id=None, wclass=None, wname=None, opts_for_size=None, startup_id=None):
if os_window_id is None:
opts_for_size = opts_for_size or self.opts
opts_for_size = opts_for_size or startup_session.os_window_size or self.opts
cls = wclass or self.args.cls or appname
with startup_notification_handler(do_notify=startup_id is not None, startup_id=startup_id) as pre_show_callback:
os_window_id = create_os_window(

View File

@ -3,6 +3,7 @@
# License: GPL v3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
import shlex
from collections import namedtuple
from .config_data import to_layout_names
from .constants import shell_path, kitty_exe
@ -10,6 +11,10 @@ from .layout import all_layouts
from .utils import log_error
WindowSizeOpts = namedtuple(
'WindowSizeOpts', 'initial_window_width initial_window_height window_margin_width window_padding_width remember_window_size')
class Tab:
def __init__(self, opts, name):
@ -28,6 +33,7 @@ class Session:
self.tabs = []
self.active_tab_idx = 0
self.default_title = default_title
self.os_window_size = None
def add_tab(self, opts, name=''):
if self.tabs and not self.tabs[-1].windows:
@ -90,7 +96,7 @@ def parse_session(raw, opts, default_title=None):
for line in raw.splitlines():
line = line.strip()
if line and not line.startswith('#'):
cmd, rest = line.partition(' ')[::2]
cmd, rest = line.split(maxsplit=1)
cmd, rest = cmd.strip(), rest.strip()
if cmd == 'new_tab':
ans.add_tab(opts, rest)
@ -110,6 +116,10 @@ def parse_session(raw, opts, default_title=None):
ans.set_cwd(rest)
elif cmd == 'title':
ans.set_next_title(rest)
elif cmd == 'os_window_size':
from kitty.config_data import window_size
w, h = map(window_size, rest.split(maxsplit=1))
ans.os_window_size = WindowSizeOpts(w, h, opts.window_margin_width, opts.window_padding_width, False)
else:
raise ValueError('Unknown command in session file: {}'.format(cmd))
yield finalize_session(ans)