Fix is_self

This commit is contained in:
Kovid Goyal 2021-04-13 08:54:45 +05:30
parent 958d4d8a6a
commit 8d743e9511
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 12 additions and 21 deletions

View File

@ -214,7 +214,7 @@ class Boss:
self.os_window_map[os_window_id] = tm
return os_window_id
def list_os_windows(self) -> Generator[OSWindowDict, None, None]:
def list_os_windows(self, self_window: Optional[Window] = None) -> Generator[OSWindowDict, None, None]:
with cached_process_data():
active_tab, active_window = self.active_tab, self.active_window
active_tab_manager = self.active_tab_manager
@ -223,7 +223,7 @@ class Boss:
'id': os_window_id,
'platform_window_id': platform_window_id(os_window_id),
'is_focused': tm is active_tab_manager,
'tabs': list(tm.list_tabs(active_tab, active_window)),
'tabs': list(tm.list_tabs(active_tab, active_window, self_window)),
'wm_class': tm.wm_class,
'wm_name': tm.wm_name
}

View File

@ -45,14 +45,7 @@ Show all environment variables in output not just differing ones.
result['is_self'] = True
return result
if window is not None:
orig_callback = window.serialize_callback
window.serialize_callback = serialize_callback
try:
data = list(boss.list_os_windows())
finally:
if window is not None:
window.serialize_callback = orig_callback
data = list(boss.list_os_windows(window))
if not payload_get('all_env_vars'):
all_env_blocks: List[Dict[str, str]] = []
common_env_vars: Set[Tuple[str, str]] = set()

View File

@ -491,9 +491,9 @@ class Tab: # {{{
def move_window_backward(self) -> None:
self.move_window(-1)
def list_windows(self, active_window: Optional[Window]) -> Generator[WindowDict, None, None]:
def list_windows(self, active_window: Optional[Window], self_window: Optional[Window] = None) -> Generator[WindowDict, None, None]:
for w in self:
yield w.as_dict(is_focused=w is active_window)
yield w.as_dict(is_focused=w is active_window, is_self=w is self_window)
def matches(self, field: str, pat: Pattern) -> bool:
if field == 'id':
@ -664,14 +664,14 @@ class TabManager: # {{{
def __len__(self) -> int:
return len(self.tabs)
def list_tabs(self, active_tab: Optional[Tab], active_window: Optional[Window]) -> Generator[TabDict, None, None]:
def list_tabs(self, active_tab: Optional[Tab], active_window: Optional[Window], self_window: Optional[Window] = None) -> Generator[TabDict, None, None]:
for tab in self:
yield {
'id': tab.id,
'is_focused': tab is active_tab,
'title': tab.name or tab.title,
'layout': str(tab.current_layout.name),
'windows': list(tab.list_windows(active_window)),
'windows': list(tab.list_windows(active_window, self_window)),
'active_window_history': list(tab.windows.active_window_history),
}

View File

@ -56,6 +56,7 @@ class WindowDict(TypedDict):
cmdline: List[str]
env: Dict[str, str]
foreground_processes: List[ProcessDesc]
is_self: bool
class PipeData(TypedDict):
@ -308,7 +309,6 @@ class Window:
self.id: int = add_window(tab.os_window_id, tab.id, self.title)
self.margin = EdgeWidths()
self.padding = EdgeWidths()
self.serialize_callback: Optional[Callable[[Window, Dict[str, Any]], Dict[str, Any]]] = None
if not self.id:
raise Exception('No tab with id: {} in OS Window: {} was found, or the window counter wrapped'.format(tab.id, tab.os_window_id))
self.tab_id = tab.id
@ -381,7 +381,7 @@ class Window:
return 'Window(title={}, id={})'.format(
self.title, self.id)
def as_dict(self, is_focused: bool = False) -> WindowDict:
def as_dict(self, is_focused: bool = False, is_self: bool = False) -> WindowDict:
return dict(
id=self.id,
is_focused=is_focused,
@ -390,11 +390,12 @@ class Window:
cwd=self.child.current_cwd or self.child.cwd,
cmdline=self.child.cmdline,
env=self.child.environ,
foreground_processes=self.child.foreground_processes
foreground_processes=self.child.foreground_processes,
is_self=is_self
)
def serialize_state(self) -> Dict[str, Any]:
ans = {
return {
'version': 1,
'id': self.id,
'child_title': self.child_title,
@ -408,9 +409,6 @@ class Window:
'margin': self.margin.serialize(),
'padding': self.padding.serialize(),
}
if self.serialize_callback is not None:
ans = self.serialize_callback(self, ans)
return ans
@property
def current_colors(self) -> Dict: