diff --git a/kitty/boss.py b/kitty/boss.py index 77f515b04..414056559 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -2431,7 +2431,8 @@ class Boss: remote.close() if is_wayland(): - run_with_activation_token(doit) + if not run_with_activation_token(doit): + doit() else: doit() diff --git a/kitty/fast_data_types.pyi b/kitty/fast_data_types.pyi index e664e1e83..b38e2120d 100644 --- a/kitty/fast_data_types.pyi +++ b/kitty/fast_data_types.pyi @@ -1559,7 +1559,7 @@ def get_docs_ref_map() -> bytes: ... def clearenv() -> None: ... def set_clipboard_data_types(ct: int, mime_types: Tuple[str, ...]) -> None: ... def get_clipboard_mime(ct: int, mime: Optional[str], callback: Callable[[bytes], None]) -> None: ... -def run_with_activation_token(func: Callable[[str], None]) -> None: ... +def run_with_activation_token(func: Callable[[str], None]) -> bool: ... def make_x11_window_a_dock_window(x11_window_id: int, strut: Tuple[int, int, int, int, int, int, int, int, int, int, int, int]) -> None: ... def unicode_database_version() -> Tuple[int, int, int]: ... def wrapped_kitten_names() -> List[str]: ... diff --git a/kitty/state.c b/kitty/state.c index c375491d3..2890bb3c9 100644 --- a/kitty/state.c +++ b/kitty/state.c @@ -871,10 +871,22 @@ PYWRAP1(run_with_activation_token) { OSWindow *os_window = global_state.os_windows + o; if (os_window->is_focused) { run_with_activation_token_in_os_window(os_window, args); - break; + Py_RETURN_TRUE; } } - Py_RETURN_NONE; + id_type os_window_id = last_focused_os_window_id(); + if (!os_window_id) { + if (!global_state.num_os_windows) Py_RETURN_FALSE; + os_window_id = global_state.os_windows[0].id; + } + for (size_t o = 0; o < global_state.num_os_windows; o++) { + OSWindow *os_window = global_state.os_windows + o; + if (os_window->id == os_window_id) { + run_with_activation_token_in_os_window(os_window, args); + Py_RETURN_TRUE; + } + } + Py_RETURN_FALSE; } PYWRAP1(set_os_window_chrome) {