|
|
1.1 root 1: #include <X/mit-copyright.h>
2:
3: /* $Header: XNextEvent.c,v 10.4 86/02/01 15:37:26 tony Rel $ */
4: /* Copyright Massachusetts Institute of Technology 1985 */
5:
6: #include "XlibInternal.h"
7:
8: extern _QEvent *_qfree;
9:
10: /* Flush output and (wait for and) return the next event in the queue.
11: */
12:
13: XNextEvent (event)
14: register XEvent *event;
15: {
16: register _QEvent *qelt;
17: register Display *dpy = _XlibCurrentDisplay;
18:
19: _XFlush (dpy);
20:
21: /* if the queue is empty, read as many events as possible
22: and enqueue them */
23: while (dpy->head == NULL) {
24: char buf[BUFSIZE];
25: int pend_not_register; /* because can't "&" a register variable */
26: register int pend;
27: register XRep *rep;
28:
29: /* find out how much data can be read */
30: if (ioctl(dpy->fd, FIONREAD, &pend_not_register) < 0)
31: _XIOError(dpy);
32: pend = pend_not_register;
33:
34: /* must read at least one XRep; if none is pending, then
35: we'll just block waiting for it */
36: if (pend < sizeof(XRep))
37: pend = sizeof (XRep);
38:
39: /* but we won't read more than the max buffer size */
40: if (pend > BUFSIZE)
41: pend = BUFSIZE;
42:
43: /* round down to an integral number of XReps */
44: pend = (pend / sizeof (XRep)) * sizeof (XRep);
45:
46: _XRead (dpy, buf, pend);
47: for (rep = (XRep *) buf; pend > 0; rep++, pend -= sizeof(XRep))
48: if (rep->code == X_Error)
49: _XError (dpy, (XErrorEvent *) rep);
50: else /* it's an event packet; enqueue it */
51: _XEnq (dpy, (XEvent *) rep);
52: }
53:
54: *event = (qelt = dpy->head)->event;
55:
56: /* move the head of the queue to the free list */
57: if ((dpy->head = qelt->next) == NULL)
58: dpy->tail = NULL;
59: qelt->next = _qfree;
60: _qfree = qelt;
61: dpy->qlen--;
62: }
63:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.