Tue, 29 Oct 2024 10:37:14 +0100
clear context states before closing a window
ui/common/context.c | file | annotate | diff | comparison | revisions | |
ui/common/context.h | 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/context.c Tue Oct 29 10:28:52 2024 +0100 +++ b/ui/common/context.c Tue Oct 29 10:37:14 2024 +0100 @@ -81,6 +81,11 @@ return ctx->parent ? uic_root_context(ctx->parent) : ctx; } +void uic_context_prepare_close(UiContext *ctx) { + cxListClear(ctx->groups); + cxListClear(ctx->group_widgets); +} + void uic_context_attach_document(UiContext *ctx, void *document) { cxListAdd(ctx->documents, document); ctx->document = document;
--- a/ui/common/context.h Tue Oct 29 10:28:52 2024 +0100 +++ b/ui/common/context.h Tue Oct 29 10:37:14 2024 +0100 @@ -115,6 +115,8 @@ void uic_context_set_document(UiContext *ctx, void *document); // deprecated void uic_context_detach_document(UiContext *ctx); // deprecated +void uic_context_prepare_close(UiContext *ctx); + void uic_context_attach_document(UiContext *ctx, void *document); void uic_context_detach_document2(UiContext *ctx, void *document); void uic_context_detach_all(UiContext *ctx);
--- a/ui/gtk/toolkit.c Tue Oct 29 10:28:52 2024 +0100 +++ b/ui/gtk/toolkit.c Tue Oct 29 10:37:14 2024 +0100 @@ -166,6 +166,7 @@ } void ui_close(UiObject *obj) { + uic_context_prepare_close(obj->ctx); #if GTK_CHECK_VERSION(4, 0, 0) gtk_window_close(GTK_WINDOW(obj->widget)); #else
--- a/ui/gtk/window.c Tue Oct 29 10:28:52 2024 +0100 +++ b/ui/gtk/window.c Tue Oct 29 10:37:14 2024 +0100 @@ -71,6 +71,11 @@ #endif } +static gboolean close_request(GtkWindow* self, UiContext *ctx) { + uic_context_prepare_close(ctx); + return FALSE; +} + static UiObject* create_window(const char *title, void *window_data, UiBool simple) { CxMempool *mp = cxBasicMempoolCreate(256); UiObject *obj = cxCalloc(mp->allocator, 1, sizeof(UiObject)); @@ -114,6 +119,11 @@ "destroy", G_CALLBACK(ui_exit_event), obj); + g_signal_connect( + obj->widget, + "close-request", + G_CALLBACK(close_request), + obj->ctx); GtkWidget *vbox = ui_gtk_vbox_new(0); #ifdef UI_LIBADWAITA