Allow copying current window/tab/os window titles when creating new ones via the launch command. Fixes #4933
This commit is contained in:
parent
4c77b0c562
commit
f4d44f30b4
@ -1361,6 +1361,10 @@ def set_os_window_title(os_window_id: int, title: str) -> None:
|
|||||||
pass
|
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:
|
def update_ime_position_for_window(window_id: int, force: bool = False, update_focus: int = 0) -> bool:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@ -9,7 +9,9 @@ from .child import Child
|
|||||||
from .cli import parse_args
|
from .cli import parse_args
|
||||||
from .cli_stub import LaunchCLIOptions
|
from .cli_stub import LaunchCLIOptions
|
||||||
from .constants import kitty_exe, shell_path
|
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 .options.utils import env as parse_env
|
||||||
from .tabs import Tab, TabManager
|
from .tabs import Tab, TabManager
|
||||||
from .types import run_once
|
from .types import run_once
|
||||||
@ -32,12 +34,14 @@ def options_spec() -> str:
|
|||||||
return '''
|
return '''
|
||||||
--window-title --title
|
--window-title --title
|
||||||
The title to set for the new window. By default, title is controlled by the
|
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
|
--tab-title
|
||||||
The title for the new tab if launching in a new tab. By default, the 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
|
--type
|
||||||
@ -175,7 +179,8 @@ Set the WM_NAME property on X11 for the newly created OS Window when using
|
|||||||
|
|
||||||
--os-window-title
|
--os-window-title
|
||||||
Set the title for the newly created OS window. This title will override any
|
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
|
--logo
|
||||||
@ -344,6 +349,14 @@ def launch(
|
|||||||
active_child = active.child
|
active_child = active.child
|
||||||
else:
|
else:
|
||||||
active_child = None
|
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)
|
env = get_env(opts, active_child)
|
||||||
kw: LaunchKwds = {
|
kw: LaunchKwds = {
|
||||||
'allow_remote_control': opts.allow_remote_control,
|
'allow_remote_control': opts.allow_remote_control,
|
||||||
|
|||||||
@ -927,12 +927,15 @@ PYWRAP1(sync_os_window_title) {
|
|||||||
|
|
||||||
PYWRAP1(set_os_window_title) {
|
PYWRAP1(set_os_window_title) {
|
||||||
id_type os_window_id;
|
id_type os_window_id;
|
||||||
const char *title;
|
PyObject *title;
|
||||||
PA("Ks", &os_window_id, &title);
|
PA("KU", &os_window_id, &title);
|
||||||
WITH_OS_WINDOW(os_window_id)
|
WITH_OS_WINDOW(os_window_id)
|
||||||
if (strlen(title)) {
|
if (PyUnicode_GetLength(title)) {
|
||||||
os_window->title_is_overriden = true;
|
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 {
|
} else {
|
||||||
os_window->title_is_overriden = false;
|
os_window->title_is_overriden = false;
|
||||||
if (os_window->window_title) set_os_window_title(os_window, PyUnicode_AsUTF8(os_window->window_title));
|
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;
|
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) {
|
PYWRAP1(pt_to_px) {
|
||||||
@ -1280,6 +1292,7 @@ static PyMethodDef module_methods[] = {
|
|||||||
MW(background_opacity_of, METH_O),
|
MW(background_opacity_of, METH_O),
|
||||||
MW(update_window_visibility, METH_VARARGS),
|
MW(update_window_visibility, METH_VARARGS),
|
||||||
MW(sync_os_window_title, METH_VARARGS),
|
MW(sync_os_window_title, METH_VARARGS),
|
||||||
|
MW(get_os_window_title, METH_VARARGS),
|
||||||
MW(set_os_window_title, METH_VARARGS),
|
MW(set_os_window_title, METH_VARARGS),
|
||||||
MW(global_font_size, METH_VARARGS),
|
MW(global_font_size, METH_VARARGS),
|
||||||
MW(set_background_image, METH_VARARGS),
|
MW(set_background_image, METH_VARARGS),
|
||||||
|
|||||||
@ -564,7 +564,7 @@ class Window:
|
|||||||
return dict(
|
return dict(
|
||||||
id=self.id,
|
id=self.id,
|
||||||
is_focused=is_focused,
|
is_focused=is_focused,
|
||||||
title=self.override_title or self.title,
|
title=self.title,
|
||||||
pid=self.child.pid,
|
pid=self.child.pid,
|
||||||
cwd=self.child.current_cwd or self.child.cwd,
|
cwd=self.child.current_cwd or self.child.cwd,
|
||||||
cmdline=self.child.cmdline,
|
cmdline=self.child.cmdline,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user