Path: utzoo!utgpu!watserv1!watmath!att!rutgers!cs.utexas.edu!mayoff From: mayoff@cs.utexas.edu (Robert Mayoff) Newsgroups: comp.windows.x Subject: Re: Waiting for Xlib events Keywords: asynchronous, select Message-ID: <974@earth.cs.utexas.edu> Date: 24 Oct 90 01:35:36 GMT References: <3540@idunno.Princeton.EDU> Organization: Dept of Computer Sciences, UTexas, Austin Lines: 33 In article <3540@idunno.Princeton.EDU> rhl@grendel.Princeton.EDU (Robert Lupton (the Good)) writes: >I have a number of programmes that spend most of their time doing other >things, but also wish to keep an X-window up-to-date. In other words, >the XEvent loop is not the main control loop. >I am currently doing this by select()ing on input from the keyboard, It is interesting that you are (apparently) taking input from stdin, not from the X window itself... >timing out, and going off to look for XEvents with XCheckMaskEvent(); >if there are none pending it's back to select(). >It'd like to get a signal of some sort when an event is ready so as not >to use up cycles continually (modulo the select() timeout) polling for >input, but none seems to be mensioned in the Xlib manuals (specifically >the O'Reilly ones). >I am not looking for a server-specific hack, so maybe this isn't possible? This should be easy for you to accomplish, since you are already selecting on the keyboard. Get the X socket file descriptor by using the ConnectionNumber macro on your Dislay pointer, and add it to your select file-descriptor mask. Before your select call, call XFlush. Then, select with no timeout (i.e., select should block). When it returns, check to see if the X socket file descriptor is set in the returned mask. If so, call your X event handler. If your other file descriptor is set in the mask, call your keyboard handler. Check both each time, because it is possible for both file descriptors to be set (if input comes in on both channels before you are up for execution again). I have used this technique several times on Suns and IBM RTs. -- /_ rob /_ Fun things to do with UNIX (#34 in a series): / while(!fork()) kill(getppid(), 9);