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