implement window reference counting (Motif)

2 weeks ago

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 26 Feb 2025 18:59:21 +0100 (2 weeks ago)
changeset 479
d9b58dd1c30b
parent 478
6292f93c2213
child 480
7dfd5e546b99

implement window reference counting (Motif)

ui/motif/toolkit.c file | annotate | diff | comparison | revisions
ui/motif/window.c file | annotate | diff | comparison | revisions
--- a/ui/motif/toolkit.c	Wed Feb 26 18:21:04 2025 +0100
+++ b/ui/motif/toolkit.c	Wed Feb 26 18:59:21 2025 +0100
@@ -164,7 +164,10 @@
 
 void ui_show(UiObject *obj) {
     uic_check_group_widgets(obj->ctx);
-    XtRealizeWidget(obj->widget);
+    if(!XtIsRealized(obj->widget)) {
+        XtRealizeWidget(obj->widget);
+        obj->ref++;
+    }
 }
 
 void ui_close(UiObject *obj) {
--- a/ui/motif/window.c	Wed Feb 26 18:21:04 2025 +0100
+++ b/ui/motif/window.c	Wed Feb 26 18:59:21 2025 +0100
@@ -45,16 +45,27 @@
 static int window_default_width = 600;
 static int window_default_height = 500;
 
-static void window_close_handler(Widget window, void *udata, void *cdata) {
-    UiObject *obj = udata;
+void ui_window_widget_destroy(UiObject *obj) {
+    XtDestroyWidget(obj->widget);
     uic_object_destroy(obj);
-    
     nwindows--;
     if(nwindows == 0) {
         ui_exit_mainloop();
     }
 }
 
+static void window_close_handler(Widget window, void *udata, void *cdata) {
+    UiObject *obj = udata;
+     
+    uic_context_prepare_close(obj->ctx);
+    obj->ref--;
+    if(obj->ref > 0) {
+        XtUnmapWidget(obj->widget);
+    } else {
+        ui_window_widget_destroy(obj);
+    }
+}
+
 
 static UiObject* create_window(const char *title, void *window_data, Boolean simple) {
     CxMempool *mp = cxMempoolCreateSimple(256);
@@ -62,6 +73,7 @@
     UiObject *obj = cxCalloc(a, 1, sizeof(UiObject));
     obj->ctx = uic_context(obj, mp);
     obj->window = window_data;
+    obj->destroy = ui_window_widget_destroy;
     
     Arg args[16];
     int n = 0;

mercurial