From 2c72c56e220beee3bf584a3066e931f654281bd6 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 12 Apr 2022 20:35:31 +0530 Subject: [PATCH] Add a couple more states to match against So we can now select windows/tabs that are not active/focused but are in the active/focused tab/os window. --- kitty/rc/base.py | 6 ++++-- kitty/tabs.py | 4 ++++ kitty/window.py | 4 ++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/kitty/rc/base.py b/kitty/rc/base.py index 6c73c7158..d8f772a27 100644 --- a/kitty/rc/base.py +++ b/kitty/rc/base.py @@ -90,7 +90,8 @@ active windows in the currently active tab, with zero being the currently active window and so on. When using the :italic:`env` field to match on environment variables you can specify only the environment variable name or a name and value, for example, :italic:`env:MY_ENV_VAR=2`. The field :code:`state` matches -on the state of the window. Supported states are: :code:`active`, :code:`focused` and :code:`needs_attention`. +on the state of the window. Supported states are: +:code:`active`, :code:`focused`, :code:`needs_attention`, :code:`parent_active` and :code:`parent_focused`. Active windows are windows that are the active window in their parent tab. There is only one focused window and it is the window to which keyboard events are delivered. ''' @@ -110,7 +111,8 @@ the tab that contains the window with the specified id or title. The :code:`inde is used to match the nth tab in the currently active OS window. The :code:`recent` number matches recently active tabs in the currently active OS window, with zero being the currently active tab, one the previously active tab and so on. The field :code:`state` matches -on the state of the tab. Supported states are: :code:`active`, :code:`focused` and :code:`needs_attention`. +on the state of the tab. Supported states are: +:code:`active`, :code:`focused`, :code:`needs_attention`, :code:`parent_active` and :code:`parent_focused`. Active tabs are tabs that are the active tab in their parent OS Window. There is only one focused tab and it is the tab to which keyboard events are delivered. ''' diff --git a/kitty/tabs.py b/kitty/tabs.py index 09dfa0833..07883dd87 100644 --- a/kitty/tabs.py +++ b/kitty/tabs.py @@ -717,6 +717,10 @@ class Tab: # {{{ for w in self: if w.needs_attention: return True + if query == 'parent_active': + return active_tab_manager is not None and self.tab_manager_ref() is active_tab_manager + if query == 'parent_focused': + return active_tab_manager is not None and self.tab_manager_ref() is active_tab_manager and self.os_window_id == current_os_window() return False return False diff --git a/kitty/window.py b/kitty/window.py index 48ab8edd2..6283b8002 100644 --- a/kitty/window.py +++ b/kitty/window.py @@ -668,6 +668,10 @@ class Window: return active_tab is not None and self is active_tab.active_window and current_os_window() == self.os_window_id if query == 'needs_attention': return self.needs_attention + if query == 'parent_active': + return active_tab is not None and self.tabref() is active_tab + if query == 'parent_focused': + return active_tab is not None and self.tabref() is active_tab and current_os_window() == self.os_window_id return False pat = compile_match_query(query, field != 'env') return self.matches(field, pat)