From a8eacd500cfe0eb75ed54ee18e625f3ef9e99cb6 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 12 Aug 2025 13:44:15 +0530 Subject: [PATCH] Finish serialization to session file --- kitty/boss.py | 10 ++++++++++ kitty/tabs.py | 16 ++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/kitty/boss.py b/kitty/boss.py index 9d168a6ef..26ec4e6c8 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -501,6 +501,16 @@ class Boss: 'background_opacity': bo, } + def serialize_state_as_session(self) -> Iterator[str]: + s = {current_focused_os_window_id(): 2, last_focused_os_window_id(): 1} + + def skey(os_window_id: int) -> int: + return s.get(os_window_id, 0) + + for os_window_id in sorted(self.os_window_map, key=skey): + tm = self.os_window_map[os_window_id] + yield from tm.serialize_state_as_session() + @property def all_tab_managers(self) -> Iterator[TabManager]: yield from self.os_window_map.values() diff --git a/kitty/tabs.py b/kitty/tabs.py index fd187383e..49ef66f79 100644 --- a/kitty/tabs.py +++ b/kitty/tabs.py @@ -1186,6 +1186,22 @@ class TabManager: # {{{ 'active_tab_idx': self.active_tab_idx, } + def serialize_state_as_session(self) -> list[str]: + tmap = {tab.id: tab for tab in self} + ans = [] + for tab_id in self.active_tab_history: + tab = tmap.get(tab_id) + if tab is not None: + ans.extend(tab.serialize_state_as_session()) + if ans: + prefix = ['new_os_window'] + if self.wm_class: + prefix.append(f'os_window_class {self.wm_class}') + if self.wm_name: + prefix.append(f'os_window_name {self.wm_name}') + ans = prefix + ans + return ans + @property def active_tab(self) -> Tab | None: try: