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.
This commit is contained in:
Kovid Goyal
2022-04-12 20:35:31 +05:30
parent f15ce21da1
commit 2c72c56e22
3 changed files with 12 additions and 2 deletions

View File

@@ -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.
'''

View File

@@ -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

View File

@@ -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)