[comp.windows.open-look] looking ahead in X event queue

wolinsky%isys@uunet.UU.NET (Jeff Wolinsky) (01/22/91)

It would be VERY useful if I could look ahead in my event queue with
the following conditions:

	(1) If the specific event isn't found, it shouldn't wait.

	(2) If the event is found, it should be left in its postion
	    in the queue.

I know that XCheckIfEvent() satisfies condition 1 but not 2, whereas
XPeekIfEvent() satisfies 2 but not 1.  Other than pulling every event
off the queue and XPutBackEvent() when I'm done, any suggestions?

---

Jeffrey Wolinsky - Manager, Software Systems - Isys Controls, Inc.

wolinsky@isys.com  or  uunet!isys!wolinsky

jcb@frisbee.Eng.Sun.COM (Jim Becker) (01/23/91)

wolinsky%isys@uunet.UU.NET (Jeff Wolinsky) writes:

    It would be VERY useful if I could look ahead in my event queue with
    the following conditions:

    	(1) If the specific event isn't found, it shouldn't wait.

    	(2) If the event is found, it should be left in its postion
    	    in the queue.

    I know that XCheckIfEvent() satisfies condition 1 but not 2, whereas
    XPeekIfEvent() satisfies 2 but not 1.  Other than pulling every event
    off the queue and XPutBackEvent() when I'm done, any suggestions?


You can look into  the  queue  yourself,  but  this  isn't  supported,
advised or approved by official channels. If you want to look into the
queue  for events, here is an example of how it can be done. Note that
there  are also things one can do to force flushing and such, but this
is the basic example of how to get in there.

This looks for expose events, and returns boolean.

/*
 *	poke down the queue to see if there are more expose events 
 * 	this looks down the display event queue to see if there is 
 *	another event that is of the exposure type. the content of
 *	the queue is not disturbed. somewhat questionable, but there
 *	is no mechanism that doesn't disturb the queue in Xlib.
 */
no_more_expose( display, window )
Display		*display;
Window		window;
{
struct	_XSQEvent	*qevent;
        Window		ewin;
        int		etype;
	short		found	= FALSE;

        for( qevent  = display->head;
	     qevent != NULL && !found;
	     qevent  = qevent->next ) {

		etype	= qevent->event.xany.type;
		ewin	= qevent->event.xany.window;

		found	= ((etype == Expose) ||
			   (etype == GraphicsExpose)) &&
			   (ewin  == window);
	}

        return !found;
}


-Jim
--
--    
	 Jim Becker / jcb%frisbee@sun.com  / Sun Microsystems

desai@progress.COM (Jatin Desai) (01/24/91)

I think the trick is to use XCheckIfEvent with a predicate function which
always returns False, but stores the real return status which gets checked
after XCheckIfEvent returns.

Jatin Desai
Progress Software
desai@progress.com

jcb@frisbee.Eng.Sun.COM (Jim Becker) (01/24/91)

desai@progress.COM (Jatin Desai) writes:

    I  think  the  trick  is  to  use  XCheckIfEvent  with a predicate
    function which always returns False, but stores  the  real  return
    status which gets checked after XCheckIfEvent returns.

    Jatin Desai
    Progress Software
    desai@progress.com


The  only  downside to this `trick' is you have to traverse the entire
event queue every time you want to look for something.  But  it  is  a
legal way to do what is desired.

-Jim

--
--    
	 Jim Becker / jcb%frisbee@sun.com  / Sun Microsystems