Widgets with Xlib/Xt/Motif, raw Xlib, or OpenGL widgets?

I am having a terrible time finding information, and in
particular examples, of widgets used in an application
that has its own event handling, etc. To make this a
bit more clear, all of the examples of Motif/Lesstif
widgets I have seen are built on an infrastructure that
makes use of the event handling that cames along with
the toolbox of which the widgets are part.

I would like to use Motif/Lesstif widgets in my code
but maintain low-level control over the event handling
and the behaviour of the application.

I have come up with two solutions:

  1. build primitive widgets with Xlib and trap button
    presses (build a box and handle clicks of the mouse), and
  2. build primitive widgets with the GL and trap
    mouse presses with the GL feedback.

Both of these approaches would work for simple
“button-like” widgets, but would be terrible for
text inputs, etc.

What do you recommend? Can anyone point me to any
examples or alternatives? (I know my questions is very
loosly related to the GL)

i’m not quite sure that i got the question right…if the following doesn’t help you, you should give more information about your app.

usually you create your widgets, add callback functions to the widgets and start the application loop with XtAppMainLoop.

every widget type (XmPushbutton, XmLabel) has its own list of callback types which can be added to the widget’s callback list- like you can add a callback as type XmNactivateCallback to a pushbutton. you cannot add an XmNactivateCallback to an XmLabel widget, which means that a label does not do anything when you click on it.

but there is an XtAddEventHandler function in Intrinsic.h, which allows you to add a callback function of any type to any widget.

if you want a label to call a particular function on mouseclick, you just call

XtAddEventHandler(my_label, ButtonPressMask, false, (XtEventHandler*)click_func, NULL);

instead of ButtonPressMask you can use any of the event masks defined in X.h

Thanks for the response. In fact, what I do NOT want to
do is use the toolkit’s (Xt) event handling with the
XAppMainLoop! I am not exactly sure on how the event
handling is done and if polling or select() is used
within the toolbox, but I strictly want to use my own
handlers.

Here is what I have in mind. I have a simulation (of
several objects in 3D) running and interacting with
certain threads that do AI, etc. Occasionally, I want
to interact with the simulation by setting certain
parameters, reseting parameters, and so on. I would
be perfectly happy if a window could be "Map"ed
with the widgets in it, and I would interact with
that window instead of the display with the GL context.

Maybe I am failing to see the grand scheme of things
when putting together the toolkit’s event handling
and my app’s event loops.

replace XtAppMainLoop with the following:

while(true) {
        XEvent  xev;
        XSendEvent(XtDisplay(toplevel_shell), XtWindow(toplevel_shell), true, ExposureMask, &xev);
        XtAppNextEvent(ctx, &xev);
        XtDispatchEvent(&xev); } 

usually XtAppNextEvent waits until an event is generated. i guess you don’t want that, so you should send an exposure (or any other event)
to the toplevel shell using XSendEvent.

I have been away from this forum this couple of days.
Thanks for your responses.

I think you have, pretty much, answered my question,
and I will look into it some more, test a few things
and I will revive this thread to share my experiences.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.