Allow specifying window logos in the launch command

This commit is contained in:
Kovid Goyal 2021-12-04 12:35:27 +05:30
parent 3035ba08c3
commit 254ba401d4
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
5 changed files with 24 additions and 4 deletions

View File

@ -172,6 +172,21 @@ Set the title for the newly created OS window. This title will override any
titles set by programs running in kitty.
--logo
Path to a PNG image to use as the logo for the newly created window. See :opt:`window_logo_path`.
--logo-position
The position for the window logo. Only takes effect if :option:`--logo` is specified. See :opt:`window_logo_position`.
--logo-alpha
type=float
default=-1
The amount the window logo should be faded into the background.
Only takes effect if :option:`--logo` is specified. See :opt:`window_logo_position`.
--color
type=list
Change colors in the newly launched window. You can either specify a path to a .conf
@ -399,5 +414,7 @@ def launch(
apply_colors(new_window, opts.color)
if opts.keep_focus and active:
boss.set_active_window(active, switch_os_window_if_needed=True)
if opts.logo:
new_window.set_logo(opts.logo, opts.logo_position or '', opts.logo_alpha)
return new_window
return None

View File

@ -649,11 +649,11 @@ def active_tab_title_template(x: str) -> Optional[str]:
return None if x == 'none' else x
def config_or_absolute_path(x: str) -> Optional[str]:
def config_or_absolute_path(x: str, env: Optional[Dict[str, str]] = None) -> Optional[str]:
if x.lower() == 'none':
return None
x = os.path.expanduser(x)
x = os.path.expandvars(x)
x = expandvars(x, env or {})
if not os.path.isabs(x):
x = os.path.join(config_dir, x)
return x

View File

@ -40,6 +40,9 @@ class Launch(RemoteCommand):
stdin_add_line_wrap_markers: Boolean indicating whether to add line wrap markers to stdin
no_response: Boolean indicating whether to send back the window id
marker: Specification for marker for new window, for example: "text 1 ERROR"
logo: Path to window logo
logo_position: Window logo position as string or empty string to use default
logo_alpha: Window logo alpha or -1 to use default
self: Boolean, if True use tab the command was run in
'''

View File

@ -1166,7 +1166,7 @@ PYWRAP1(set_window_logo) {
PA("KKKsUf", &os_window_id, &tab_id, &window_id, &path, &position, &alpha);
bool ok = false;
WITH_WINDOW(os_window_id, tab_id, window_id);
ok = set_window_logo(window, path, bganchor(position), alpha, false);
ok = set_window_logo(window, path, PyObject_IsTrue(position) ? bganchor(position) : OPT(window_logo_position), (0 <= alpha && alpha <= 1) ? alpha : OPT(window_logo_alpha), false);
END_WITH_WINDOW;
if (ok) Py_RETURN_TRUE;
Py_RETURN_FALSE;

View File

@ -1092,7 +1092,7 @@ class Window:
def set_logo(self, path: str, position: str = 'bottom-right', alpha: float = 0.5) -> None:
from .options.utils import config_or_absolute_path
path = config_or_absolute_path(path) or path
path = config_or_absolute_path(path, get_options().env) or path
set_window_logo(self.os_window_id, self.tab_id, self.id, path, position, alpha)
# actions {{{