diff --git a/kitty/child-monitor.c b/kitty/child-monitor.c index c8b201d9c..56f34ea48 100644 --- a/kitty/child-monitor.c +++ b/kitty/child-monitor.c @@ -487,6 +487,7 @@ static inline bool update_window_title(Window *w, OSWindow *os_window) { if (w->title && w->title != os_window->window_title) { os_window->window_title = w->title; + Py_INCREF(os_window->window_title); set_os_window_title(os_window, PyUnicode_AsUTF8(w->title)); #ifdef __APPLE__ if (os_window == global_state.focused_os_window) cocoa_update_title(w->title); @@ -661,6 +662,7 @@ main_loop(ChildMonitor *self) { for (size_t w = global_state.num_os_windows; w > 0; w--) { OSWindow *os_window = global_state.os_windows + w - 1; if (should_os_window_close(os_window)) { + destroy_os_window(os_window); call_boss(on_os_window_closed, "Kii", os_window->id, os_window->viewport_width, os_window->viewport_width); for (size_t t=0; t < os_window->num_tabs; t++) { Tab *tab = os_window->tabs + t; diff --git a/kitty/glfw.c b/kitty/glfw.c index de29ed3d7..446d1c810 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -275,6 +275,12 @@ create_os_window(PyObject UNUSED *self, PyObject *args) { return PyLong_FromUnsignedLongLong(w->id); } +void +destroy_os_window(OSWindow *w) { + if (w->handle) glfwDestroyWindow(w->handle); + w->handle = NULL; +} + // Global functions {{{ static void error_callback(int error, const char* description) { diff --git a/kitty/state.c b/kitty/state.c index 9cfee1d09..44093110d 100644 --- a/kitty/state.c +++ b/kitty/state.c @@ -164,7 +164,7 @@ remove_tab(id_type os_window_id, id_type id) { } static inline void -destroy_os_window(OSWindow *w) { +destroy_os_window_item(OSWindow *w) { for (size_t t = w->num_tabs; t > 0; t--) { Tab *tab = w->tabs + t - 1; remove_tab_inner(w, tab->id); @@ -183,7 +183,7 @@ remove_os_window(id_type os_window_id) { END_WITH_OS_WINDOW if (found) { WITH_OS_WINDOW_REFS - REMOVER(global_state.os_windows, os_window_id, global_state.num_os_windows, OSWindow, destroy_os_window, global_state.capacity); + REMOVER(global_state.os_windows, os_window_id, global_state.num_os_windows, OSWindow, destroy_os_window_item, global_state.capacity); END_WITH_OS_WINDOW_REFS } return found; diff --git a/kitty/state.h b/kitty/state.h index 9b6bcb57f..7a8aefedb 100644 --- a/kitty/state.h +++ b/kitty/state.h @@ -143,6 +143,7 @@ void event_loop_wait(double timeout); void swap_window_buffers(OSWindow *w); void make_window_context_current(OSWindow *w); void hide_mouse(OSWindow *w); +void destroy_os_window(OSWindow *w); void set_os_window_title(OSWindow *w, const char *title); OSWindow* os_window_for_kitty_window(id_type); OSWindow* add_os_window();