jlevy@arisia.Xerox.COM (Jacob Levy) (02/16/89)
Suppose I wanted to write an application that sat in an infinite loop and only every so often checked for input from X. It is simple to do this with Xlib, but seems a lot hairier with Xt. What's involved is at the very least doing your own dispatching and event processing. I know that this is possible using the low-level Xt intrinsics, but I want to save myself some pain in learning how to do it - is there someone out there in Netland who has done this before? Could someone help me out on this with example or skeleton code, or at least with ideas and suggestions based on their own experience? Thanks, --Jacob
swick@ATHENA.MIT.EDU (Ralph R Swick) (02/16/89)
> Suppose I wanted to write an application that sat in an infinite > loop and only every so often checked for input from X. The basic technique is to use XtAppPending() to poll the various sources of input known to Xt. You could look at the implementation of XtAppMainLoop() to see how to write your own, but it should be pretty clear from the documentation. An alternative method is to have Xt call your infinite loop as a "work procedure". You merely need to return from your loop every so often to have Xt do it's thing. The more often you return, the better X response you'll get. Which you choose may be more a matter of style than anything else, but there's a subtle difference in the implicit priority of your compute loop and the X events in the two cases.
klee@daisy.UUCP (Ken Lee) (02/17/89)
In article <626@arisia.Xerox.COM> jlevy.pa@xerox.com (Jacob Levy) writes: >Suppose I wanted to write an application that sat in an infinite >loop and only every so often checked for input from X. It is >simple to do this with Xlib, but seems a lot hairier with Xt. XtAppMainLoop is just an infinite loop calling XtAppNextEvent() and XtDispatchEvent(). If you want, you can do anything else and call these 2 routines when you feel like it. If you're expecting both widget and non-widget events, you can add the non-widget events to the dispatch table or process them separately with your own dispatch routine. Ken Lee -- klee@daisy.uucp Daisy Systems Corp., Interactive Graphics Tools Dept.
jim@athsys.uucp (Jim Becker) (02/18/89)
From article <2696@daisy.UUCP>, by klee@daisy.UUCP (Ken Lee): > In article <626@arisia.Xerox.COM> jlevy.pa@xerox.com (Jacob Levy) writes: >>Suppose I wanted to write an application that sat in an infinite >>loop and only every so often checked for input from X. It is >>simple to do this with Xlib, but seems a lot hairier with Xt. > This is a somewhat related question and possible solution. I have a couple of programs that give visual update status on the screen. Most of the time they are snoozing away, waking up every five seconds or so. Currently I am doing a sleep() call, then a call to XPending() to check for recent events. This works, but sometimes there is a lag of up to five seconds when I just miss Expose or other events. After playing in the X server code, it appears to me that the application should be able to do a select() call with the desired timeout value set and the appropriate bit set for the display->fd socket connection. Then the select() call would sleep until either the timeout occurred or there was activity from the X server connection. This is speculation, as I haven't had a chance to try this myself. (It also only works on select() oriented systems..) Does this sound like it would work correctly? Seems like you could also use a SIGIO handler and a global flag to indicate the presence of XEvents to be processed. -Jim Becker ...!sun!athsys!jim