Remote control: When matching window by state:focused match the window belonging to the OS window that was last focused

Fixes #5602
This commit is contained in:
Kovid Goyal 2022-11-03 21:52:20 +05:30
parent f5de08d5fa
commit 935c4ded6b
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 28 additions and 3 deletions

View File

@ -54,6 +54,8 @@ Detailed list of changes
- Wayland: Fix high CPU usage when using some input methods (:pull:`5369`)
- Remote control: When matching window by `state:focused` match the window belonging to the OS window that was last focused (:iss:`5602`)
0.26.4 [2022-10-17]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -786,6 +786,10 @@ def current_os_window() -> Optional[int]:
pass
def last_focused_os_window_id() -> int:
pass
def cocoa_set_menubar_title(title: str) -> None:
pass

View File

@ -96,7 +96,7 @@ pt_to_px(double pt, id_type os_window_id) {
OSWindow*
current_os_window() {
current_os_window(void) {
if (global_state.callback_os_window) return global_state.callback_os_window;
for (size_t i = 0; i < global_state.num_os_windows; i++) {
if (global_state.os_windows[i].is_focused) return global_state.os_windows + i;
@ -104,6 +104,19 @@ current_os_window() {
return global_state.os_windows;
}
static id_type
last_focused_os_window_id(void) {
id_type ans = 0, max_fc_count = 0;
for (size_t i = 0; i < global_state.num_os_windows; i++) {
OSWindow *w = &global_state.os_windows[i];
if (w->last_focused_counter > max_fc_count) {
ans = w->id; max_fc_count = w->last_focused_counter;
}
}
return ans;
}
OSWindow*
os_window_for_kitty_window(id_type kitty_window_id) {
for (size_t i = 0; i < global_state.num_os_windows; i++) {
@ -665,6 +678,11 @@ PYWRAP0(next_window_id) {
return PyLong_FromUnsignedLongLong(global_state.window_id_counter + 1);
}
PYWRAP0(last_focused_os_window_id) {
return PyLong_FromUnsignedLongLong(last_focused_os_window_id());
}
PYWRAP1(handle_for_window_id) {
id_type os_window_id;
PA("K", &os_window_id);
@ -1266,6 +1284,7 @@ KK5I(add_borders_rect)
static PyMethodDef module_methods[] = {
MW(current_os_window, METH_NOARGS),
MW(next_window_id, METH_NOARGS),
MW(last_focused_os_window_id, METH_NOARGS),
MW(set_options, METH_VARARGS),
MW(get_options, METH_NOARGS),
MW(click_mouse_url, METH_VARARGS),

View File

@ -37,7 +37,7 @@ from .fast_data_types import (
STRIKETHROUGH, TINT_PROGRAM, Color, KeyEvent, Screen, add_timer, add_window,
cell_size_for_window, click_mouse_cmd_output, click_mouse_url, compile_program,
current_os_window, encode_key_for_tty, get_boss, get_click_interval, get_options,
init_cell_program, mark_os_window_dirty, mouse_selection,
init_cell_program, mark_os_window_dirty, mouse_selection, last_focused_os_window_id,
move_cursor_to_mouse_if_in_prompt, pt_to_px, set_titlebar_color, set_window_logo,
set_window_padding, set_window_render_data, update_ime_position_for_window,
update_window_title, update_window_visibility, wakeup_main_loop,
@ -707,7 +707,7 @@ class Window:
if query == 'active':
return active_tab is not None and self is active_tab.active_window
if query == 'focused':
return active_tab is not None and self is active_tab.active_window and current_os_window() == self.os_window_id
return active_tab is not None and self is active_tab.active_window and last_focused_os_window_id() == self.os_window_id
if query == 'needs_attention':
return self.needs_attention
if query == 'parent_active':