use ui_object_set/get to store UiMotifAppWindow (Motif)

Sun, 23 Nov 2025 11:21:17 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 23 Nov 2025 11:21:17 +0100
changeset 933
70e14fa98ab4
parent 932
28fc967f74ef
child 934
89118a9350da

use ui_object_set/get to store UiMotifAppWindow (Motif)

ui/motif/window.c file | annotate | diff | comparison | revisions
ui/motif/window.h file | annotate | diff | comparison | revisions
--- a/ui/motif/window.c	Sun Nov 23 11:16:13 2025 +0100
+++ b/ui/motif/window.c	Sun Nov 23 11:21:17 2025 +0100
@@ -88,11 +88,7 @@
     }
     
     UiMotifAppWindow *appwindow = cxZalloc(a, sizeof(UiMotifAppWindow));
-    // Because we store appwindow as userdata in the widget, we use this
-    // magic field to check, if the pointer is actually the correct type.
-    // This is a dubious technique, but this is only the last defense
-    // mechanism against someone using the API wrong.
-    appwindow->magic = UI_MOTIF_APP_WINDOW;
+    ui_object_set(obj, "ui_motif_app_window", appwindow);
     
     Arg args[16];
     int n = 0;
@@ -101,7 +97,6 @@
     XtSetArg(args[n], XmNminHeight, 50); n++;
     XtSetArg(args[n], XmNwidth, window_width); n++;
     XtSetArg(args[n], XmNheight, window_height); n++;
-    XtSetArg(args[n], XmNuserData, appwindow); n++;
     
     Widget toplevel = XtAppCreateShell(
             ui_appname(),
@@ -174,16 +169,13 @@
 }
 
 void ui_window_menubar_set_visible(UiObject *obj, UiBool visible) {
-    UiMotifAppWindow *window = NULL;
-    XtVaGetValues(obj->widget, XmNuserData, &window, NULL);
+    UiMotifAppWindow *window = ui_object_get(obj, "ui_motif_app_window");
     if(window) {
-        if(window->magic != UI_MOTIF_APP_WINDOW) {
-            fprintf(stderr, "Error: obj is not an app window\n");
-            return;
-        }
         if(window->menubar) {
             ui_set_visible(window->menubar, visible);
         }
+    } else {
+        fprintf(stderr, "Error: obj is not an application window\n");
     }
 }
 
--- a/ui/motif/window.h	Sun Nov 23 11:16:13 2025 +0100
+++ b/ui/motif/window.h	Sun Nov 23 11:21:17 2025 +0100
@@ -39,7 +39,6 @@
 #define UI_MOTIF_APP_WINDOW 0xabcd
 
 typedef struct UiMotifAppWindow {
-    int magic;
     Widget menubar;
 } UiMotifAppWindow;
 

mercurial