Tue, 29 Oct 2024 10:44:28 +0100
add toolkit window close fix
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:27:16 2024 +0100 +++ b/ui/common/context.c Tue Oct 29 10:44:28 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:27:16 2024 +0100 +++ b/ui/common/context.h Tue Oct 29 10:44:28 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:27:16 2024 +0100 +++ b/ui/gtk/toolkit.c Tue Oct 29 10:44:28 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:27:16 2024 +0100 +++ b/ui/gtk/window.c Tue Oct 29 10:44:28 2024 +0100 @@ -71,6 +71,18 @@ #endif } +#if GTK_MAJOR_VERSION >= 4 +static gboolean close_request(GtkWindow* self, UiContext *ctx) { + uic_context_prepare_close(ctx); + return FALSE; +} +#else +static gboolean close_request(GtkWidget* self, GdkEvent* event, UiContext *ctx) { + uic_context_prepare_close(ctx); + return FALSE; +} +#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)); @@ -114,6 +126,19 @@ "destroy", G_CALLBACK(ui_exit_event), obj); +#if GTK_MAJOR_VERSION >= 4 + g_signal_connect( + obj->widget, + "close-request", + G_CALLBACK(close_request), + obj->ctx); +#else + g_signal_connect( + obj->widget, + "delete-event", + G_CALLBACK(close_request), + obj->ctx); +#endif GtkWidget *vbox = ui_gtk_vbox_new(0); #ifdef UI_LIBADWAITA