Tue, 29 Oct 2024 11:52:01 +0100
improve window close handling
ui/gtk/list.c | file | annotate | diff | comparison | revisions | |
ui/gtk/window.c | file | annotate | diff | comparison | revisions |
--- a/ui/gtk/list.c Tue Oct 29 11:29:18 2024 +0100 +++ b/ui/gtk/list.c Tue Oct 29 11:52:01 2024 +0100 @@ -187,6 +187,7 @@ UiList *list = var ? var->value : NULL; GtkListStore *listmodel = create_list_store(list, model); gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(listmodel)); + g_object_unref(listmodel); UiListView *listview = malloc(sizeof(UiListView)); listview->obj = obj; @@ -340,6 +341,7 @@ UiList *list = var ? var->value : NULL; GtkListStore *listmodel = create_list_store(list, model); gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(listmodel)); + g_object_unref(listmodel); //g_signal_connect(view, "drag-begin", G_CALLBACK(drag_begin), NULL); //g_signal_connect(view, "drag-end", G_CALLBACK(drag_end), NULL); @@ -498,7 +500,6 @@ GtkListStore *store = create_list_store(list, view->model); gtk_tree_view_set_model(GTK_TREE_VIEW(view->widget), GTK_TREE_MODEL(store)); g_object_unref(G_OBJECT(store)); - // TODO: free old model } UiListSelection ui_listview_getselection(UiList *list) { @@ -518,16 +519,13 @@ } void ui_listview_destroy(GtkWidget *w, UiListView *v) { - gtk_tree_view_set_model(GTK_TREE_VIEW(w), NULL); + //gtk_tree_view_set_model(GTK_TREE_VIEW(w), NULL); ui_destroy_boundvar(v->obj->ctx, v->var); - // TODO: destroy model? free(v); } void ui_combobox_destroy(GtkWidget *w, UiListView *v) { - gtk_combo_box_set_model(GTK_COMBO_BOX(w), NULL); ui_destroy_boundvar(v->obj->ctx, v->var); - // TODO: destroy model? free(v); } @@ -636,6 +634,7 @@ if(listmodel) { gtk_combo_box_set_model(GTK_COMBO_BOX(combobox), GTK_TREE_MODEL(listmodel)); + g_object_unref(listmodel); } uicbox->var = var; @@ -698,6 +697,7 @@ UiListView *view = list->obj; GtkListStore *store = create_list_store(view->var->value, view->model); gtk_combo_box_set_model(GTK_COMBO_BOX(view->widget), GTK_TREE_MODEL(store)); + g_object_unref(store); } UiListSelection ui_combobox_getselection(UiList *list) {
--- a/ui/gtk/window.c Tue Oct 29 11:29:18 2024 +0100 +++ b/ui/gtk/window.c Tue Oct 29 11:52:01 2024 +0100 @@ -49,7 +49,7 @@ static int window_default_width = 650; static int window_default_height = 550; -void ui_exit_event(GtkWidget *widget, gpointer data) { +static gboolean ui_window_destroy(void *data) { UiObject *obj = data; UiEvent ev; ev.window = obj->window; @@ -61,7 +61,8 @@ if(obj->ctx->close_callback) { obj->ctx->close_callback(&ev, obj->ctx->close_data); } - // TODO: free UiObject + + cxMempoolDestroy(obj->ctx->mp); nwindows--; #ifdef UI_GTK2 @@ -69,6 +70,14 @@ gtk_main_quit(); } #endif + + return FALSE; +} + +void ui_exit_event(GtkWidget *widget, gpointer data) { + // delay exit handler + UiObject *obj = data; + g_idle_add(ui_window_destroy, data); } #if GTK_MAJOR_VERSION >= 4