0

I'm writing an application using X11, Xt, and Motif directly with C. I want to have the ability to list all the children widgets from a parent Window. Is there a way to do this?

I found the following snippet to recursively parse a Motif widget tree here, but I only have an Xlib Window struct, so I want to be able get the children Widgets of that Window, then pass that Widget to something akin to that recursive tree parser.

My current code looks something like this:

int main() {
    Display* display;
    int screen_num = 0;
    display = XOpenDisplay(NULL);
    Window window = XRootWindow(display, screen_num);
    dumpWidgetTree((Widget)window);
    return 0;
}

I tried simply casting Window to Widget, but that just caused a segfault, as expected.

seanr8
  • 411
  • 1
  • 5
  • 15
  • X11 does not have notion of "widgets", you can only get list of all child windows using XQueryTree - see https://tronche.com/gui/x/xlib/window-information/XQueryTree.html – Andrey Sidorov Jan 09 '19 at 23:24
  • @AndreySidorov, that makes sense, thanks. Given that I specifically want to try to pull as much information as I can about a widget on the screen (things like: is this a button or a text area?), is there any way that I can approach this from the Motif or Xt level and get this information? – seanr8 Jan 10 '19 at 16:04
  • don't know much about Motif, your question if very specific to toolkit in question. If they use some of the X transports to track internal state ( Atoms, properties, selections ) then maybe but you'll need to go through motif codebase to know that – Andrey Sidorov Jan 10 '19 at 23:05
  • Interactively, you can do that with Editres. I'm not sure if that would be a solution. – Quasímodo Nov 12 '20 at 14:06

1 Answers1

0

You can get most of the widgets from the window tree. You can use the 'XtWindowToWidget' to translate windowID to widget. This approach will work for the widget in the current app, and will not be able to access windowless widgets (a.k.a. Gadgets).

dash-o
  • 13,723
  • 1
  • 10
  • 37