Sun, 23 Nov 2025 11:21:17 +0100
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"); } }