Fri, 15 Nov 2024 21:23:16 +0100
start UiObject ref with 0 and increases ref with ui_show
ui/common/object.c | file | annotate | diff | comparison | revisions | |
ui/gtk/toolkit.c | file | annotate | diff | comparison | revisions | |
ui/gtk/window.c | file | annotate | diff | comparison | revisions |
--- a/ui/common/object.c Fri Nov 15 21:16:18 2024 +0100 +++ b/ui/common/object.c Fri Nov 15 21:23:16 2024 +0100 @@ -54,7 +54,9 @@ } void ui_object_unref(UiObject *obj) { - if(--obj->ref == 0) { + // it is possible to have 0 references, in case + // a window was created but ui_show was never called + if(obj->ref == 0 || --obj->ref == 0) { if(obj->destroy) { obj->destroy(obj); } else {
--- a/ui/gtk/toolkit.c Fri Nov 15 21:16:18 2024 +0100 +++ b/ui/gtk/toolkit.c Fri Nov 15 21:23:16 2024 +0100 @@ -163,6 +163,7 @@ #elif GTK_MAJOR_VERSION <= 3 gtk_widget_show_all(obj->widget); #endif + obj->ref++; } void ui_close(UiObject *obj) {
--- a/ui/gtk/window.c Fri Nov 15 21:16:18 2024 +0100 +++ b/ui/gtk/window.c Fri Nov 15 21:23:16 2024 +0100 @@ -80,7 +80,11 @@ uic_context_prepare_close(obj->ctx); obj->ref--; if(obj->ref > 0) { +#if GTK_CHECK_VERSION(2, 18, 0) + gtk_widget_set_visible(obj->widget, FALSE); +#else gtk_widget_hide(obj->widget); +#endif return TRUE; } else { return FALSE; @@ -100,7 +104,7 @@ static UiObject* create_window(const char *title, void *window_data, UiBool simple) { CxMempool *mp = cxBasicMempoolCreate(256); UiObject *obj = cxCalloc(mp->allocator, 1, sizeof(UiObject)); - obj->ref = 1; + obj->ref = 0; #ifdef UI_LIBADWAITA obj->widget = adw_application_window_new(ui_get_application());