--- a/ui/gtk/window.c Thu Nov 14 17:26:16 2024 +0100 +++ b/ui/gtk/window.c Fri Nov 15 21:16:18 2024 +0100 @@ -51,18 +51,7 @@ static gboolean ui_window_destroy(void *data) { UiObject *obj = data; - UiEvent ev; - ev.window = obj->window; - ev.document = obj->ctx->document; - ev.obj = obj; - ev.eventdata = NULL; - ev.intval = 0; - - if(obj->ctx->close_callback) { - obj->ctx->close_callback(&ev, obj->ctx->close_data); - } - - cxMempoolDestroy(obj->ctx->mp); + uic_object_destroy(obj); nwindows--; #ifdef UI_GTK2 @@ -74,27 +63,44 @@ return FALSE; } +void ui_window_widget_destroy(UiObject *obj) { +#if GTK_MAJOR_VERSION >= 4 + gtk_window_destroy(GTK_WINDOW(obj->widget)); +#else + gtk_widget_destroy(obj->widget); +#endif +} + void ui_exit_event(GtkWidget *widget, gpointer data) { // delay exit handler - UiObject *obj = data; g_idle_add(ui_window_destroy, data); } +static gboolean ui_window_close_request(UiObject *obj) { + uic_context_prepare_close(obj->ctx); + obj->ref--; + if(obj->ref > 0) { + gtk_widget_hide(obj->widget); + return TRUE; + } else { + return FALSE; + } +} + #if GTK_MAJOR_VERSION >= 4 -static gboolean close_request(GtkWindow* self, UiContext *ctx) { - uic_context_prepare_close(ctx); - return FALSE; +static gboolean close_request(GtkWindow* self, UiObject *obj) { + return ui_window_close_request(obj); } #else -static gboolean close_request(GtkWidget* self, GdkEvent* event, UiContext *ctx) { - uic_context_prepare_close(ctx); - return FALSE; +static gboolean close_request(GtkWidget* self, GdkEvent* event, UiObject *obj) { + return ui_window_close_request(obj); } #endif static UiObject* create_window(const char *title, void *window_data, UiBool simple) { CxMempool *mp = cxBasicMempoolCreate(256); - UiObject *obj = cxCalloc(mp->allocator, 1, sizeof(UiObject)); + UiObject *obj = cxCalloc(mp->allocator, 1, sizeof(UiObject)); + obj->ref = 1; #ifdef UI_LIBADWAITA obj->widget = adw_application_window_new(ui_get_application()); @@ -130,6 +136,7 @@ window_default_height); } + obj->destroy = ui_window_widget_destroy; g_signal_connect( obj->widget, "destroy", @@ -140,13 +147,13 @@ obj->widget, "close-request", G_CALLBACK(close_request), - obj->ctx); + obj); #else g_signal_connect( obj->widget, "delete-event", G_CALLBACK(close_request), - obj->ctx); + obj); #endif GtkWidget *vbox = ui_gtk_vbox_new(0);