home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / lib / X / XChkIfEv.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-01-29  |  2.1 KB  |  76 lines

  1. /* $XConsortium: XChkIfEv.c,v 11.11 91/01/06 11:44:28 rws Exp $ */
  2. /* Copyright    Massachusetts Institute of Technology    1985, 1987    */
  3.  
  4. /*
  5. Permission to use, copy, modify, distribute, and sell this software and its
  6. documentation for any purpose is hereby granted without fee, provided that
  7. the above copyright notice appear in all copies and that both that
  8. copyright notice and this permission notice appear in supporting
  9. documentation, and that the name of M.I.T. not be used in advertising or
  10. publicity pertaining to distribution of the software without specific,
  11. written prior permission.  M.I.T. makes no representations about the
  12. suitability of this software for any purpose.  It is provided "as is"
  13. without express or implied warranty.
  14. */
  15.  
  16. #define NEED_EVENTS
  17. #include "Xlibint.h"
  18.  
  19. extern _XQEvent *_qfree;
  20.  
  21. /* 
  22.  * Check existing events in queue to find if any match.  If so, return.
  23.  * If not, flush buffer and see if any more events are readable. If one
  24.  * matches, return.  If all else fails, tell the user no events found.
  25.  */
  26.  
  27. Bool XCheckIfEvent (dpy, event, predicate, arg)
  28.         register Display *dpy;
  29.     Bool (*predicate)(
  30. #if NeedNestedPrototypes
  31.               Display*            /* display */,
  32.               XEvent*            /* event */,
  33.               char*                /* arg */
  34. #endif
  35.               );        /* function to call */
  36.     register XEvent *event;        /* XEvent to be filled in. */
  37.     char *arg;
  38. {
  39.     register _XQEvent *prev, *qelt;
  40.     int n;            /* time through count */
  41.  
  42.         LockDisplay(dpy);
  43.     prev = NULL;
  44.     for (n = 3; --n >= 0;) {
  45.         for (qelt = prev ? prev->next : dpy->head;
  46.          qelt;
  47.          prev = qelt, qelt = qelt->next) {
  48.         if ((*predicate)(dpy, &qelt->event, arg)) {
  49.             *event = qelt->event;
  50.             if (prev) {
  51.             if ((prev->next = qelt->next) == NULL)
  52.                 dpy->tail = prev;
  53.             } else {
  54.             if ((dpy->head = qelt->next) == NULL)
  55.             dpy->tail = NULL;
  56.             }
  57.             qelt->next = _qfree;
  58.             _qfree = qelt;
  59.             dpy->qlen--;
  60.             UnlockDisplay(dpy);
  61.             return True;
  62.         }
  63.         }
  64.         switch (n) {
  65.           case 2:
  66.         _XEventsQueued(dpy, QueuedAfterReading);
  67.         break;
  68.           case 1:
  69.         _XFlush(dpy);
  70.         break;
  71.         }
  72.     }
  73.     UnlockDisplay(dpy);
  74.     return False;
  75. }
  76.