Syncing some files updated after running configure
[wmaker-crm.git] / WINGs / wevent.c
blobe38cf55133f673a2796bbaa80804e3ad80155e16
3 /*
4 * This event handling stuff was based on Tk.
5 */
7 #include "WINGsP.h"
9 #include "../src/config.h"
11 #include <sys/types.h>
12 #include <unistd.h>
14 #ifdef HAVE_POLL_H
15 #include <poll.h>
16 #endif
19 #include <X11/Xos.h>
21 #ifdef HAVE_SYS_SELECT_H
22 # include <sys/select.h>
23 #endif
25 #include <time.h>
27 #ifndef X_GETTIMEOFDAY
28 #define X_GETTIMEOFDAY(t) gettimeofday(t, (struct timezone*)0)
29 #endif
33 extern _WINGsConfiguration WINGsConfiguration;
37 typedef struct TimerHandler {
38 WMCallback *callback; /* procedure to call */
39 struct timeval when; /* when to call the callback */
40 void *clientData;
41 struct TimerHandler *next;
42 } TimerHandler;
45 typedef struct IdleHandler {
46 WMCallback *callback;
47 void *clientData;
48 struct IdleHandler *next;
49 } IdleHandler;
52 typedef struct InputHandler {
53 WMInputProc *callback;
54 void *clientData;
55 int fd;
56 int mask;
57 struct InputHandler *next;
58 } InputHandler;
61 /* table to map event types to event masks */
62 static unsigned long eventMasks[] = {
65 KeyPressMask, /* KeyPress */
66 KeyReleaseMask, /* KeyRelease */
67 ButtonPressMask, /* ButtonPress */
68 ButtonReleaseMask, /* ButtonRelease */
69 PointerMotionMask|PointerMotionHintMask|ButtonMotionMask
70 |Button1MotionMask|Button2MotionMask|Button3MotionMask
71 |Button4MotionMask|Button5MotionMask,
72 /* MotionNotify */
73 EnterWindowMask, /* EnterNotify */
74 LeaveWindowMask, /* LeaveNotify */
75 FocusChangeMask, /* FocusIn */
76 FocusChangeMask, /* FocusOut */
77 KeymapStateMask, /* KeymapNotify */
78 ExposureMask, /* Expose */
79 ExposureMask, /* GraphicsExpose */
80 ExposureMask, /* NoExpose */
81 VisibilityChangeMask, /* VisibilityNotify */
82 SubstructureNotifyMask, /* CreateNotify */
83 StructureNotifyMask, /* DestroyNotify */
84 StructureNotifyMask, /* UnmapNotify */
85 StructureNotifyMask, /* MapNotify */
86 SubstructureRedirectMask, /* MapRequest */
87 StructureNotifyMask, /* ReparentNotify */
88 StructureNotifyMask, /* ConfigureNotify */
89 SubstructureRedirectMask, /* ConfigureRequest */
90 StructureNotifyMask, /* GravityNotify */
91 ResizeRedirectMask, /* ResizeRequest */
92 StructureNotifyMask, /* CirculateNotify */
93 SubstructureRedirectMask, /* CirculateRequest */
94 PropertyChangeMask, /* PropertyNotify */
95 0, /* SelectionClear */
96 0, /* SelectionRequest */
97 0, /* SelectionNotify */
98 ColormapChangeMask, /* ColormapNotify */
99 ClientMessageMask, /* ClientMessage */
100 0, /* Mapping Notify */
105 /* queue of timer event handlers */
106 static TimerHandler *timerHandler=NULL;
108 static IdleHandler *idleHandler=NULL;
110 static InputHandler *inputHandler=NULL;
112 /* hook for other toolkits or wmaker process their events */
113 static WMEventHook *extraEventHandler=NULL;
117 #define timerPending() (timerHandler)
119 #define idlePending() (idleHandler)
122 static void
123 rightNow(struct timeval *tv) {
124 X_GETTIMEOFDAY(tv);
127 /* is t1 after t2 ? */
128 #define IS_AFTER(t1, t2) (((t1).tv_sec > (t2).tv_sec) || \
129 (((t1).tv_sec == (t2).tv_sec) \
130 && ((t1).tv_usec > (t2).tv_usec)))
133 static void
134 addmillisecs(struct timeval *tv, int milliseconds)
136 tv->tv_usec += milliseconds*1000;
138 tv->tv_sec += tv->tv_usec/1000000;
139 tv->tv_usec = tv->tv_usec%1000000;
143 WMHandlerID
144 WMAddTimerHandler(int milliseconds, WMCallback *callback, void *cdata)
146 TimerHandler *handler, *tmp;
148 handler = malloc(sizeof(TimerHandler));
149 if (!handler)
150 return NULL;
152 rightNow(&handler->when);
153 addmillisecs(&handler->when, milliseconds);
154 handler->callback = callback;
155 handler->clientData = cdata;
156 /* insert callback in queue, sorted by time left */
157 if (!timerHandler || !IS_AFTER(handler->when, timerHandler->when)) {
158 /* first in the queue */
159 handler->next = timerHandler;
160 timerHandler = handler;
161 } else {
162 tmp = timerHandler;
163 while (tmp->next && IS_AFTER(handler->when, tmp->next->when)) {
164 tmp = tmp->next;
166 handler->next = tmp->next;
167 tmp->next = handler;
169 return handler;
174 void
175 WMDeleteTimerWithClientData(void *cdata)
177 TimerHandler *handler, *tmp;
179 if (!cdata || !timerHandler)
180 return;
182 tmp = timerHandler;
183 if (tmp->clientData==cdata) {
184 timerHandler = tmp->next;
185 free(tmp);
186 } else {
187 while (tmp->next) {
188 if (tmp->next->clientData==cdata) {
189 handler = tmp->next;
190 tmp->next = handler->next;
191 free(handler);
192 break;
194 tmp = tmp->next;
201 void
202 WMDeleteTimerHandler(WMHandlerID handlerID)
204 TimerHandler *tmp, *handler=(TimerHandler*)handlerID;
206 if (!handler || !timerHandler)
207 return;
209 tmp = timerHandler;
210 if (tmp==handler) {
211 timerHandler = handler->next;
212 free(handler);
213 } else {
214 while (tmp->next) {
215 if (tmp->next==handler) {
216 tmp->next=handler->next;
217 free(handler);
218 break;
220 tmp = tmp->next;
227 WMHandlerID
228 WMAddIdleHandler(WMCallback *callback, void *cdata)
230 IdleHandler *handler, *tmp;
232 handler = malloc(sizeof(IdleHandler));
233 if (!handler)
234 return NULL;
236 handler->callback = callback;
237 handler->clientData = cdata;
238 handler->next = NULL;
239 /* add callback at end of queue */
240 if (!idleHandler) {
241 idleHandler = handler;
242 } else {
243 tmp = idleHandler;
244 while (tmp->next) {
245 tmp = tmp->next;
247 tmp->next = handler;
250 return handler;
255 void
256 WMDeleteIdleHandler(WMHandlerID handlerID)
258 IdleHandler *tmp, *handler = (IdleHandler*)handlerID;
260 if (!handler || !idleHandler)
261 return;
263 tmp = idleHandler;
264 if (tmp == handler) {
265 idleHandler = handler->next;
266 free(handler);
267 } else {
268 while (tmp->next) {
269 if (tmp->next == handler) {
270 tmp->next = handler->next;
271 free(handler);
272 break;
274 tmp = tmp->next;
281 WMHandlerID
282 WMAddInputHandler(int fd, int condition, WMInputProc *proc, void *clientData)
284 InputHandler *handler;
286 handler = wmalloc(sizeof(InputHandler));
288 handler->fd = fd;
289 handler->mask = condition;
290 handler->callback = proc;
291 handler->clientData = clientData;
293 handler->next = inputHandler;
295 inputHandler = handler;
297 return handler;
301 void
302 WMDeleteInputHandler(WMHandlerID handlerID)
304 InputHandler *tmp, *handler = (InputHandler*)handlerID;
306 if (!handler || !inputHandler)
307 return;
309 tmp = inputHandler;
310 if (tmp == handler) {
311 inputHandler = handler->next;
312 free(handler);
313 } else {
314 while (tmp->next) {
315 if (tmp->next == handler) {
316 tmp->next = handler->next;
317 free(handler);
318 break;
320 tmp = tmp->next;
326 static void
327 checkIdleHandlers()
329 IdleHandler *handler, *tmp;
331 if (!idleHandler) {
332 W_FlushIdleNotificationQueue();
333 return;
336 handler = idleHandler;
338 /* we will process all idleHandlers so, empty the handler list */
339 idleHandler = NULL;
341 while (handler) {
342 tmp = handler->next;
343 (*handler->callback)(handler->clientData);
344 /* remove the handler */
345 free(handler);
347 handler = tmp;
349 W_FlushIdleNotificationQueue();
354 static void
355 checkTimerHandlers()
357 TimerHandler *handler;
358 struct timeval now;
360 rightNow(&now);
362 while (timerHandler && IS_AFTER(now, timerHandler->when)) {
363 handler = timerHandler;
364 timerHandler = timerHandler->next;
365 handler->next = NULL;
366 (*handler->callback)(handler->clientData);
367 free(handler);
370 W_FlushASAPNotificationQueue();
375 static void
376 delayUntilNextTimerEvent(struct timeval *delay)
378 struct timeval now;
380 if (!timerHandler) {
381 /* The return value of this function is only valid if there _are_
382 timers active. */
383 delay->tv_sec = 0;
384 delay->tv_usec = 0;
385 return;
388 rightNow(&now);
389 if (IS_AFTER(now, timerHandler->when)) {
390 delay->tv_sec = 0;
391 delay->tv_usec = 0;
392 } else {
393 delay->tv_sec = timerHandler->when.tv_sec - now.tv_sec;
394 delay->tv_usec = timerHandler->when.tv_usec - now.tv_usec;
395 if (delay->tv_usec < 0) {
396 delay->tv_usec += 1000000;
397 delay->tv_sec--;
406 * WMCreateEventHandler--
407 * Create an event handler and put it in the event handler list for the
408 * view. If the same callback and clientdata are already used in another
409 * handler, the masks are swapped.
412 void
413 WMCreateEventHandler(WMView *view, unsigned long mask, WMEventProc *eventProc,
414 void *clientData)
416 W_EventHandler *handler;
417 W_EventHandler *ptr = view->handlerList;
418 unsigned long eventMask;
420 if (ptr==NULL) {
421 handler = wmalloc(sizeof(W_EventHandler));
423 handler->nextHandler = NULL;
425 view->handlerList = handler;
427 eventMask = mask;
428 } else {
429 handler = NULL;
430 eventMask = mask;
431 while (ptr != NULL) {
432 if (ptr->clientData == clientData && ptr->proc == eventProc) {
433 handler = ptr;
435 eventMask |= ptr->eventMask;
437 ptr = ptr->nextHandler;
439 if (!handler) {
440 handler = wmalloc(sizeof(W_EventHandler));
441 handler->nextHandler = view->handlerList;
442 view->handlerList = handler;
446 /* select events for window */
447 handler->eventMask = mask;
448 handler->proc = eventProc;
449 handler->clientData = clientData;
454 * WMDeleteEventHandler--
455 * Delete event handler matching arguments from windows
456 * event handler list.
459 void
460 WMDeleteEventHandler(WMView *view, unsigned long mask, WMEventProc *eventProc,
461 void *clientData)
463 W_EventHandler *handler, *ptr, *pptr;
465 ptr = view->handlerList;
467 handler = NULL;
468 pptr = NULL;
470 while (ptr!=NULL) {
471 if (ptr->eventMask == mask && ptr->proc == eventProc
472 && ptr->clientData == clientData) {
473 handler = ptr;
474 break;
476 pptr = ptr;
477 ptr = ptr->nextHandler;
480 if (!handler)
481 return;
483 if (!pptr) {
484 view->handlerList = handler->nextHandler;
485 } else {
486 pptr->nextHandler = handler->nextHandler;
488 free(handler);
493 void
494 W_CleanUpEvents(WMView *view)
496 W_EventHandler *ptr, *nptr;
498 ptr = view->handlerList;
500 while (ptr!=NULL) {
501 nptr = ptr->nextHandler;
502 free(ptr);
503 ptr = nptr;
509 static Time
510 getEventTime(WMScreen *screen, XEvent *event)
512 switch (event->type) {
513 case ButtonPress:
514 case ButtonRelease:
515 return event->xbutton.time;
516 case KeyPress:
517 case KeyRelease:
518 return event->xkey.time;
519 case MotionNotify:
520 return event->xmotion.time;
521 case EnterNotify:
522 case LeaveNotify:
523 return event->xcrossing.time;
524 case PropertyNotify:
525 return event->xproperty.time;
526 case SelectionClear:
527 return event->xselectionclear.time;
528 case SelectionRequest:
529 return event->xselectionrequest.time;
530 case SelectionNotify:
531 return event->xselection.time;
532 default:
533 return screen->lastEventTime;
538 void
539 W_CallDestroyHandlers(W_View *view)
541 XEvent event;
542 W_EventHandler *hPtr;
544 event.type = DestroyNotify;
545 event.xdestroywindow.window = view->window;
546 event.xdestroywindow.event = view->window;
547 hPtr = view->handlerList;
548 while (hPtr!=NULL) {
549 if (hPtr->eventMask & StructureNotifyMask) {
550 (*hPtr->proc)(&event, hPtr->clientData);
553 hPtr = hPtr->nextHandler;
559 WMHandleEvent(XEvent *event)
561 W_EventHandler *hPtr;
562 W_View *view, *vPtr, *toplevel;
563 unsigned long mask;
564 Window window;
566 if (event->type == MappingNotify) {
567 XRefreshKeyboardMapping(&event->xmapping);
568 return True;
571 mask = eventMasks[event->xany.type];
573 window = event->xany.window;
575 /* diferentiate SubstructureNotify with StructureNotify */
576 if (mask == StructureNotifyMask) {
577 if (event->xmap.event != event->xmap.window) {
578 mask = SubstructureNotifyMask;
579 window = event->xmap.event;
582 view = W_GetViewForXWindow(event->xany.display, window);
583 if (!view) {
584 if (extraEventHandler)
585 (extraEventHandler)(event);
587 return False;
590 view->screen->lastEventTime = getEventTime(view->screen, event);
592 toplevel = W_TopLevelOfView(view);
594 if (event->type == SelectionNotify || event->type == SelectionClear
595 || event->type == SelectionRequest) {
596 /* handle selection related events */
597 W_HandleSelectionEvent(event);
600 /* if it's a key event, redispatch it to the focused control */
601 if (mask & (KeyPressMask|KeyReleaseMask)) {
602 W_View *focused = W_FocusedViewOfToplevel(toplevel);
604 if (focused) {
605 view = focused;
609 /* compress Motion events */
610 if (event->type == MotionNotify && !view->flags.dontCompressMotion) {
611 while (XPending(event->xmotion.display)) {
612 XEvent ev;
613 XPeekEvent(event->xmotion.display, &ev);
614 if (ev.type == MotionNotify
615 && event->xmotion.window == ev.xmotion.window
616 && event->xmotion.subwindow == ev.xmotion.subwindow) {
617 /* replace events */
618 XNextEvent(event->xmotion.display, event);
619 } else break;
623 /* compress expose events */
624 if (event->type == Expose && !view->flags.dontCompressExpose) {
625 while (XCheckTypedWindowEvent(event->xexpose.display, view->window,
626 Expose, event));
630 if (view->screen->modal && toplevel!=view->screen->modalView
631 && !toplevel->flags.worksWhenModal) {
632 if (event->type == KeyPress || event->type == KeyRelease
633 || event->type == MotionNotify || event->type == ButtonPress
634 || event->type == ButtonRelease
635 || event->type == FocusIn || event->type == FocusOut) {
636 return True;
640 /* This is a hack. It will make the panel be secure while
641 * the event handlers are handled, as some event handler
642 * might destroy the widget. */
643 W_RetainView(toplevel);
645 hPtr = view->handlerList;
647 while (hPtr!=NULL) {
648 W_EventHandler *tmp;
650 tmp = hPtr->nextHandler;
652 if ((hPtr->eventMask & mask)) {
653 (*hPtr->proc)(event, hPtr->clientData);
656 hPtr = tmp;
659 /* pass the event to the top level window of the widget */
660 if (view->parent!=NULL) {
661 vPtr = view;
662 while (vPtr->parent!=NULL)
663 vPtr = vPtr->parent;
665 hPtr = vPtr->handlerList;
667 while (hPtr!=NULL) {
669 if (hPtr->eventMask & mask) {
670 (*hPtr->proc)(event, hPtr->clientData);
672 hPtr = hPtr->nextHandler;
676 /* save button click info to track double-clicks */
677 if (view->screen->ignoreNextDoubleClick) {
678 view->screen->ignoreNextDoubleClick = 0;
679 } else {
680 if (event->type == ButtonPress) {
681 view->screen->lastClickWindow = event->xbutton.window;
682 view->screen->lastClickTime = event->xbutton.time;
686 W_ReleaseView(toplevel);
688 return True;
693 WMIsDoubleClick(XEvent *event)
695 W_View *view;
697 if (event->type != ButtonPress)
698 return False;
700 view = W_GetViewForXWindow(event->xany.display, event->xbutton.window);
702 if (!view)
703 return False;
705 if (view->screen->lastClickWindow != event->xbutton.window)
706 return False;
708 if (event->xbutton.time - view->screen->lastClickTime
709 < WINGsConfiguration.doubleClickDelay) {
710 view->screen->lastClickTime = 0;
711 view->screen->lastClickWindow = None;
712 view->screen->ignoreNextDoubleClick = 1;
713 return True;
714 } else
715 return False;
719 Bool
720 W_WaitForEvent(Display *dpy, unsigned long xeventmask)
722 #if defined(HAVE_POLL) && defined(HAVE_POLL_H) && !defined(HAVE_SELECT)
723 struct pollfd *fds;
724 InputHandler *handler;
725 int count, timeout, nfds, k, retval;
727 for (nfds = 1, handler = inputHandler;
728 handler != 0; handler = handler->next) nfds++;
730 fds = wmalloc(nfds * sizeof(struct pollfd));
731 fds[0].fd = ConnectionNumber(dpy);
732 fds[0].events = POLLIN;
734 for (k = 1, handler = inputHandler;
735 handler;
736 handler = handler->next, k++) {
737 fds[k].fd = handler->fd;
738 fds[k].events = 0;
739 if (handler->mask & WIReadMask)
740 fds[k].events |= POLLIN;
742 if (handler->mask & WIWriteMask)
743 fds[k].events |= POLLOUT;
745 #if 0 /* FIXME */
746 if (handler->mask & WIExceptMask)
747 FD_SET(handler->fd, &eset);
748 #endif
752 * Setup the select() timeout to the estimated time until the
753 * next timer expires.
755 if (timerPending()) {
756 struct timeval tv;
757 delayUntilNextTimerEvent(&tv);
758 timeout = tv.tv_sec * 1000 + tv.tv_usec / 1000;
759 } else {
760 timeout = -1;
763 if (xeventmask==0) {
764 if (XPending(dpy))
765 return True;
766 } else {
767 XEvent ev;
768 if (XCheckMaskEvent(dpy, xeventmask, &ev)) {
769 XPutBackEvent(dpy, &ev);
770 return True;
774 count = poll(fds, nfds, timeout);
776 if (count > 0) {
777 handler = inputHandler;
778 k = 1;
779 while (handler) {
780 int mask;
782 mask = 0;
784 if (fds[k].revents & (POLLIN|POLLRDNORM|POLLRDBAND|POLLPRI))
785 mask |= WIReadMask;
787 if (fds[k].revents & (POLLOUT | POLLWRBAND))
788 mask |= WIWriteMask;
790 if (fds[k].revents & (POLLHUP | POLLNVAL | POLLERR))
791 mask |= WIExceptMask;
793 if (mask!=0 && handler->callback) {
794 (*handler->callback)(handler->fd, mask,
795 handler->clientData);
798 handler = handler->next;
799 k++;
803 retval = fds[0].revents & (POLLIN|POLLRDNORM|POLLRDBAND|POLLPRI);
804 free(fds);
806 W_FlushASAPNotificationQueue();
808 return retval;
809 #else /* not HAVE_POLL */
810 #ifdef HAVE_SELECT
811 struct timeval timeout;
812 struct timeval *timeoutPtr;
813 fd_set rset, wset, eset;
814 int maxfd;
815 int count;
816 InputHandler *handler = inputHandler;
818 FD_ZERO(&rset);
819 FD_ZERO(&wset);
820 FD_ZERO(&eset);
822 FD_SET(ConnectionNumber(dpy), &rset);
823 maxfd = ConnectionNumber(dpy);
825 while (handler) {
826 if (handler->mask & WIReadMask)
827 FD_SET(handler->fd, &rset);
829 if (handler->mask & WIWriteMask)
830 FD_SET(handler->fd, &wset);
832 if (handler->mask & WIExceptMask)
833 FD_SET(handler->fd, &eset);
835 if (maxfd < handler->fd)
836 maxfd = handler->fd;
838 handler = handler->next;
843 * Setup the select() timeout to the estimated time until the
844 * next timer expires.
846 if (timerPending()) {
847 delayUntilNextTimerEvent(&timeout);
848 timeoutPtr = &timeout;
849 } else {
850 timeoutPtr = (struct timeval*)0;
853 XSync(dpy, False);
854 if (xeventmask==0) {
855 if (XPending(dpy))
856 return True;
857 } else {
858 XEvent ev;
859 if (XCheckMaskEvent(dpy, xeventmask, &ev)) {
860 XPutBackEvent(dpy, &ev);
861 return True;
865 count = select(1 + maxfd, &rset, &wset, &eset, timeoutPtr);
867 if (count > 0) {
868 handler = inputHandler;
870 while (handler) {
871 int mask;
873 mask = 0;
875 if (FD_ISSET(handler->fd, &rset))
876 mask |= WIReadMask;
878 if (FD_ISSET(handler->fd, &wset))
879 mask |= WIWriteMask;
881 if (FD_ISSET(handler->fd, &eset))
882 mask |= WIExceptMask;
884 if (mask!=0 && handler->callback) {
885 (*handler->callback)(handler->fd, mask,
886 handler->clientData);
889 handler = handler->next;
893 W_FlushASAPNotificationQueue();
895 return FD_ISSET(ConnectionNumber(dpy), &rset);
896 #else /* not HAVE_SELECT, not HAVE_POLL */
897 Neither select nor poll. You lose.
898 #endif /* HAVE_SELECT */
899 #endif /* HAVE_POLL */
903 void
904 WMNextEvent(Display *dpy, XEvent *event)
906 /* Check any expired timers */
907 if (timerPending()) {
908 checkTimerHandlers();
911 while (XPending(dpy) == 0) {
912 /* Do idle stuff */
913 /* Do idle and timer stuff while there are no timer or X events */
914 while (!XPending(dpy) && idlePending()) {
915 if (idlePending())
916 checkIdleHandlers();
917 /* dispatch timer events */
918 if (timerPending())
919 checkTimerHandlers();
923 * Make sure that new events did not arrive while we were doing
924 * timer/idle stuff. Or we might block forever waiting for
925 * an event that already arrived.
927 /* wait to something happen */
928 W_WaitForEvent(dpy, 0);
930 /* Check any expired timers */
931 if (timerPending()) {
932 checkTimerHandlers();
936 XNextEvent(dpy, event);
939 #if 0
940 void
941 WMMaskEvent(Display *dpy, long mask, XEvent *event)
943 unsigned long milliseconds;
944 struct timeval timeout;
945 struct timeval *timeoutOrInfty;
946 fd_set readset;
948 while (!XCheckMaskEvent(dpy, mask, event)) {
949 /* Do idle stuff while there are no timer or X events */
950 while (idlePending()) {
951 checkIdleHandlers();
952 if (XCheckMaskEvent(dpy, mask, event))
953 return;
957 * Setup the select() timeout to the estimated time until the
958 * next timer expires.
960 if (timerPending()) {
961 delayUntilNextTimerEvent(&timeout);
962 timeoutOrInfty = &timeout;
963 } else {
964 timeoutOrInfty = (struct timeval*)0;
967 if (XCheckMaskEvent(dpy, mask, event))
968 return;
970 /* Wait for input on the X connection socket */
971 FD_ZERO(&readset);
972 FD_SET(ConnectionNumber(dpy), &readset);
973 select(1 + ConnectionNumber(dpy), &readset, (fd_set*)0, (fd_set*)0,
974 timeoutOrInfty);
976 /* Check any expired timers */
977 if (timerPending()) {
978 checkTimerHandlers();
982 #endif
983 #if 1
985 * Cant use this because XPending() will make W_WaitForEvent
986 * return even if the event in the queue is not what we want,
987 * and if we block until some new event arrives from the
988 * server, other events already in the queue (like Expose)
989 * will be deferred.
991 void
992 WMMaskEvent(Display *dpy, long mask, XEvent *event)
994 while (!XCheckMaskEvent(dpy, mask, event)) {
995 /* Do idle stuff while there are no timer or X events */
996 while (idlePending()) {
997 checkIdleHandlers();
998 if (XCheckMaskEvent(dpy, mask, event))
999 return;
1002 /* Wait for input on the X connection socket */
1003 W_WaitForEvent(dpy, mask);
1005 /* Check any expired timers */
1006 if (timerPending()) {
1007 checkTimerHandlers();
1011 #endif
1013 Bool
1014 WMScreenPending(WMScreen *scr)
1016 if (XPending(scr->display))
1017 return True;
1018 else
1019 return False;
1023 WMEventHook*
1024 WMHookEventHandler(WMEventHook *handler)
1026 WMEventHook *oldHandler = extraEventHandler;
1028 extraEventHandler = handler;
1030 return oldHandler;