xlibmotif

libXm get display number from widget


I'm using libXm4.0.3. I want to get the display number that the widget is being displayed on from the widget.

Going directly to xlib causes a segfault. Xt seems to also segfault.

I started using some of the XmGetXmDisplay or XmGetXmScreen functions, but I'm seeing "Could not find per display information" and I don't know how to overcome this.

How can I get the current display number from a libXm widget?

This is my current code:

int get_disp_num_from_widget(Widget w) {
    Screen* xs = w->core.screen; //Xlib screen
    if (xs) {
        Display* xd = w->core.screen->display; //Xlib display
        if (xd) {
            XmDisplay d = XmGetXmDisplay(xd); // causes "Couldn't find per display information"
            if (d) {
                char* string = d->display.bindingsString;
                if (string) {
                    printf("Display binding string: %s", string);
                }
            }
        }
    }
    return -1;
}

Solution

  • You can get the Display * of any widget using the XtDisplay(Widget *) function.