diff --git a/kitty/fast_data_types.pyi b/kitty/fast_data_types.pyi index 24a174359..871ce4c31 100644 --- a/kitty/fast_data_types.pyi +++ b/kitty/fast_data_types.pyi @@ -1361,6 +1361,10 @@ def set_os_window_title(os_window_id: int, title: str) -> None: pass +def get_os_window_title(os_window_id: int) -> Optional[str]: + pass + + def update_ime_position_for_window(window_id: int, force: bool = False, update_focus: int = 0) -> bool: pass diff --git a/kitty/launch.py b/kitty/launch.py index 7f34a6b20..7a35bb786 100644 --- a/kitty/launch.py +++ b/kitty/launch.py @@ -9,7 +9,9 @@ from .child import Child from .cli import parse_args from .cli_stub import LaunchCLIOptions from .constants import kitty_exe, shell_path -from .fast_data_types import patch_color_profiles, set_clipboard_string +from .fast_data_types import ( + get_os_window_title, patch_color_profiles, set_clipboard_string +) from .options.utils import env as parse_env from .tabs import Tab, TabManager from .types import run_once @@ -32,12 +34,14 @@ def options_spec() -> str: return ''' --window-title --title The title to set for the new window. By default, title is controlled by the -child process. +child process. The special value :code:`current` will copy the title from the currently +active window. --tab-title The title for the new tab if launching in a new tab. By default, the title -of the active window in the tab is used as the tab title. +of the active window in the tab is used as the tab title. The special value +:code:`current` will copy the title form the title of the currently active tab. --type @@ -175,7 +179,8 @@ Set the WM_NAME property on X11 for the newly created OS Window when using --os-window-title Set the title for the newly created OS window. This title will override any -titles set by programs running in kitty. +titles set by programs running in kitty. The special value :code:`current` +will use the title of the current OS Window, if any. --logo @@ -344,6 +349,14 @@ def launch( active_child = active.child else: active_child = None + if opts.window_title == 'current': + opts.window_title = active.title if active else None + if opts.tab_title == 'current': + atab = boss.active_tab + opts.tab_title = atab.title if atab else None + if opts.os_window_title == 'current': + tm = boss.active_tab_manager + opts.os_window_title = get_os_window_title(tm.os_window_id) if tm else None env = get_env(opts, active_child) kw: LaunchKwds = { 'allow_remote_control': opts.allow_remote_control, diff --git a/kitty/state.c b/kitty/state.c index 6de00cf5e..93c5a5a36 100644 --- a/kitty/state.c +++ b/kitty/state.c @@ -927,12 +927,15 @@ PYWRAP1(sync_os_window_title) { PYWRAP1(set_os_window_title) { id_type os_window_id; - const char *title; - PA("Ks", &os_window_id, &title); + PyObject *title; + PA("KU", &os_window_id, &title); WITH_OS_WINDOW(os_window_id) - if (strlen(title)) { + if (PyUnicode_GetLength(title)) { os_window->title_is_overriden = true; - set_os_window_title(os_window, title); + Py_XDECREF(os_window->window_title); + os_window->window_title = title; + Py_INCREF(title); + set_os_window_title(os_window, PyUnicode_AsUTF8(title)); } else { os_window->title_is_overriden = false; if (os_window->window_title) set_os_window_title(os_window, PyUnicode_AsUTF8(os_window->window_title)); @@ -942,6 +945,15 @@ PYWRAP1(set_os_window_title) { Py_RETURN_NONE; } +PYWRAP1(get_os_window_title) { + id_type os_window_id; + PA("K", &os_window_id); + WITH_OS_WINDOW(os_window_id) + if (os_window->window_title) return Py_BuildValue("O", os_window->window_title); + END_WITH_OS_WINDOW + Py_RETURN_NONE; +} + PYWRAP1(pt_to_px) { @@ -1280,6 +1292,7 @@ static PyMethodDef module_methods[] = { MW(background_opacity_of, METH_O), MW(update_window_visibility, METH_VARARGS), MW(sync_os_window_title, METH_VARARGS), + MW(get_os_window_title, METH_VARARGS), MW(set_os_window_title, METH_VARARGS), MW(global_font_size, METH_VARARGS), MW(set_background_image, METH_VARARGS), diff --git a/kitty/window.py b/kitty/window.py index 5ecefb2a5..44dfaf1c9 100644 --- a/kitty/window.py +++ b/kitty/window.py @@ -564,7 +564,7 @@ class Window: return dict( id=self.id, is_focused=is_focused, - title=self.override_title or self.title, + title=self.title, pid=self.child.pid, cwd=self.child.current_cwd or self.child.cwd, cmdline=self.child.cmdline,