[comp.windows.x] XtMainLoop and events

Lionel.Duchamp@CAD.CS.CMU.EDU (10/10/89)

How is it possible to take care of an application's events handling while
taking care ( thru XtMainLoop ?) of the callbacks handling of the widgets this
application is using ?  I guess there are some standard methods to deal with 
this standard problem. Any code or litterature on this matter ?

Thanks in advance

Lionel Duchamp
CadLab - Dept of Architecture
CMU

swick@ATHENA.MIT.EDU (Ralph R. Swick) (10/12/89)

> How is it possible to take care of an application's events handling while
> taking care ( thru XtMainLoop ?) of the callbacks handling of the widgets this
> application is using ?

If I interpret your question correctly, you have a mixed application;
some parts of it use widgets and attach callbacks to those widgets
while other parts create windows directly and expect to be able
to read events from those windows.

There are several approaches to accomplishing this.  Of course, I
have to say that the ideal approach is to convert the rest of
the application into a (set of) application-specific widgets.
The application code that handles each event type becomes either
event handlers registered on the appropriate private widgets
(frequently the quickest approach when transforming existing
code) or action procedures driven through a translation table.

An intermediate approach is to replace the application's
XCreateWindow calls with XtCreateWidget(,widgetClass,,,) calls;
i.e. use the Core widget merely as a wrapper around your windows
and register event handlers as above.

The minimalist approach is to write your own MainLoop consisting
of the two calls:

   for (;;) {
	XtAppNextEvent(...);
	XtDispatchEvent(...);
   }

and examine the window id of each event to see if it's one of
your windows.  There's no harm in dispatching all events to Xt,
even if some of them are for non-widget windows.  The spec says
that XtDispatchEvent is supposed to tell you whether or not it
actually found a widget to handle the event, but this wasn't
implemented in R3, so you'll have to keep track of your own window
ids and compare against every event.