home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / lib / X / XMaskEvent.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-20  |  2.2 KB  |  73 lines

  1. /* $XConsortium: XMaskEvent.c,v 11.22 91/02/20 18:48:54 rws Exp $ */
  2. /* Copyright    Massachusetts Institute of Technology    1986    */
  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. #if __STDC__
  20. #define Const const
  21. #else
  22. #define Const /**/
  23. #endif
  24.  
  25. extern _XQEvent *_qfree;
  26. extern long Const _Xevent_to_mask[];
  27. #define AllPointers (PointerMotionMask|PointerMotionHintMask|ButtonMotionMask)
  28. #define AllButtons (Button1MotionMask|Button2MotionMask|Button3MotionMask|\
  29.             Button4MotionMask|Button5MotionMask)
  30.  
  31. /* 
  32.  * return the next event in the queue matching one of the events in the mask.
  33.  * If no event, flush output, and wait until match succeeds.
  34.  * Events earlier in the queue are not discarded.
  35.  */
  36.  
  37. XMaskEvent (dpy, mask, event)
  38.     register Display *dpy;
  39.     long mask;        /* Selected event mask. */
  40.     register XEvent *event;    /* XEvent to be filled in. */
  41. {
  42.     register _XQEvent *prev, *qelt;
  43.  
  44.         LockDisplay(dpy);
  45.     prev = NULL;
  46.     while (1) {
  47.         for (qelt = prev ? prev->next : dpy->head;
  48.          qelt;
  49.          prev = qelt, qelt = qelt->next) {
  50.         if ((qelt->event.type < LASTEvent) &&
  51.             (_Xevent_to_mask[qelt->event.type] & mask) &&
  52.             ((qelt->event.type != MotionNotify) ||
  53.              (mask & AllPointers) ||
  54.              (mask & AllButtons & qelt->event.xmotion.state))) {
  55.             *event = qelt->event;
  56.             if (prev) {
  57.             if ((prev->next = qelt->next) == NULL)
  58.                 dpy->tail = prev;
  59.             } else {
  60.             if ((dpy->head = qelt->next) == NULL)
  61.             dpy->tail = NULL;
  62.             }
  63.             qelt->next = _qfree;
  64.             _qfree = qelt;
  65.             dpy->qlen--;
  66.             UnlockDisplay(dpy);
  67.             return;
  68.         }
  69.         }
  70.         _XReadEvents(dpy);
  71.     }
  72. }
  73.