# HG changeset patch # User Olaf Wintermann # Date 1763893277 -3600 # Node ID 70e14fa98ab4b2b3b0db9ca9efcd246cf50532f9 # Parent 28fc967f74ef6ede70e087a6066d51383874b904 use ui_object_set/get to store UiMotifAppWindow (Motif) diff -r 28fc967f74ef -r 70e14fa98ab4 ui/motif/window.c --- 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"); } } diff -r 28fc967f74ef -r 70e14fa98ab4 ui/motif/window.h --- 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;