From 59ded41f7a502f50be85ceff27eb302119e17e3b Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 5 Nov 2022 11:34:10 +0530 Subject: [PATCH] When no OS Window is focused the active_* should return those belonging to the last focused OS Window --- kitty/boss.py | 13 +++++++++---- kitty/tabs.py | 8 +++++--- kitty/window.py | 15 ++++++++------- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/kitty/boss.py b/kitty/boss.py index a3aa1438c..cb28f7f62 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -343,7 +343,6 @@ class Boss: def list_os_windows(self, self_window: Optional[Window] = None) -> Iterator[OSWindowDict]: with cached_process_data(): - active_tab, active_window = self.active_tab, self.active_window active_tab_manager = self.active_tab_manager for os_window_id, tm in self.os_window_map.items(): yield { @@ -352,7 +351,7 @@ class Boss: 'is_active': tm is active_tab_manager, 'is_focused': current_focused_os_window_id() == os_window_id, 'last_focused': os_window_id == last_focused_os_window_id(), - 'tabs': list(tm.list_tabs(active_tab, active_window, self_window)), + 'tabs': list(tm.list_tabs(self_window)), 'wm_class': tm.wm_class, 'wm_name': tm.wm_name } @@ -1090,8 +1089,14 @@ class Boss: @property def active_tab_manager(self) -> Optional[TabManager]: - os_window_id = current_os_window() - return None if os_window_id is None else self.os_window_map.get(os_window_id) + os_window_id = current_focused_os_window_id() + if os_window_id <= 0: + os_window_id = last_focused_os_window_id() + if os_window_id <= 0: + q = current_os_window() + if q is not None: + os_window_id = q + return self.os_window_map.get(os_window_id) @property def active_tab(self) -> Optional[Tab]: diff --git a/kitty/tabs.py b/kitty/tabs.py index e6c101edb..aa93b7210 100644 --- a/kitty/tabs.py +++ b/kitty/tabs.py @@ -699,7 +699,8 @@ class Tab: # {{{ def move_window_backward(self) -> None: self.move_window(-1) - def list_windows(self, active_window: Optional[Window], self_window: Optional[Window] = None) -> Generator[WindowDict, None, None]: + def list_windows(self, self_window: Optional[Window] = None) -> Generator[WindowDict, None, None]: + active_window = self.active_window for w in self: yield w.as_dict( is_active_window=w is active_window, @@ -939,7 +940,8 @@ class TabManager: # {{{ def __len__(self) -> int: return len(self.tabs) - def list_tabs(self, active_tab: Optional[Tab], active_window: Optional[Window], self_window: Optional[Window] = None) -> Generator[TabDict, None, None]: + def list_tabs(self, self_window: Optional[Window] = None) -> Generator[TabDict, None, None]: + active_tab = self.active_tab for tab in self: yield { 'id': tab.id, @@ -950,7 +952,7 @@ class TabManager: # {{{ 'layout_state': tab.current_layout.layout_state(), 'layout_opts': tab.current_layout.layout_opts.serialized(), 'enabled_layouts': tab.enabled_layouts, - 'windows': list(tab.list_windows(active_window, self_window)), + 'windows': list(tab.list_windows(self_window)), 'active_window_history': list(tab.windows.active_window_history), } diff --git a/kitty/window.py b/kitty/window.py index fcbe1f03b..1532a09dc 100644 --- a/kitty/window.py +++ b/kitty/window.py @@ -36,11 +36,12 @@ from .fast_data_types import ( NUM_UNDERLINE_STYLES, OSC, REVERSE, SCROLL_FULL, SCROLL_LINE, SCROLL_PAGE, 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, 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, + current_focused_os_window_id, encode_key_for_tty, get_boss, get_click_interval, + get_options, init_cell_program, last_focused_os_window_id, mark_os_window_dirty, + mouse_selection, 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, ) from .keys import keyboard_mode_name, mod_mask from .notify import ( @@ -926,7 +927,7 @@ class Window: tab = self.tabref() if tab is not None: tab.relayout_borders() - elif self.os_window_id == current_os_window(): + elif self.os_window_id == current_focused_os_window_id(): # Cancel IME composition after loses focus update_ime_position_for_window(self.id, False, -1) @@ -1361,7 +1362,7 @@ class Window: self.destroyed = True del self.kitten_result_processors if hasattr(self, 'screen'): - if self.is_active and self.os_window_id == current_os_window(): + if self.is_active and self.os_window_id == current_focused_os_window_id(): # Cancel IME composition when window is destroyed update_ime_position_for_window(self.id, False, -1) # Remove cycles so that screen is de-allocated immediately