diff --git a/kitty/boss.py b/kitty/boss.py index 87fe7d272..758ca6410 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -1817,13 +1817,15 @@ class Boss: def on_os_window_closed(self, os_window_id: int, viewport_width: int, viewport_height: int) -> None: self.cached_values['window-size'] = viewport_width, viewport_height + windows_in_os_window = {w.id: w for w in self.window_id_map.values() if w.os_window_id == os_window_id} tm = self.os_window_map.pop(os_window_id, None) if tm is not None: - tm.destroy() - for window_id in tuple(w.id for w in self.window_id_map.values() if w.os_window_id == os_window_id): + tm.destroy() # this will call destroy on all windows + for window_id, w in windows_in_os_window.items(): self.child_monitor.mark_for_close(window_id) self.window_id_map.pop(window_id, None) self.window_floats_map.pop(window_id, None) + w.destroy() # in case tm was None if not self.os_window_map and is_macos: cocoa_set_menubar_title('') action = self.os_window_death_actions.pop(os_window_id, None) diff --git a/kitty/window.py b/kitty/window.py index fc03f9e1e..29ffae3c8 100644 --- a/kitty/window.py +++ b/kitty/window.py @@ -1743,10 +1743,12 @@ class Window: traceback.print_exc() def destroy(self) -> None: + if self.destroyed: + return + self.destroyed = True for cw in self.floats: cw.destroy() self.call_watchers(self.watchers.on_close, {}) - self.destroyed = True self.clipboard_request_manager.close() del self.kitten_result_processors if hasattr(self, 'screen'):