1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-21 05:18:06 +01:00

- simpler and more straightforward event handling for timer, idle, input

and X events (also fixed some problems the old handling logic had)
This commit is contained in:
dan
2001-03-21 01:29:22 +00:00
parent f5dcab0663
commit bc3b44acaa
7 changed files with 35 additions and 49 deletions

View File

@@ -7,6 +7,10 @@ Changes since wmaker 0.64.0:
- added WMAddPersistentTimerHandler() - added WMAddPersistentTimerHandler()
- Moved all internal handlers (timer, idle and input) to handlers.c - Moved all internal handlers (timer, idle and input) to handlers.c
- simplified wevent.c and wutil.c. - simplified wevent.c and wutil.c.
- fixed handling of input with poll (was broken)
- fixed mem leak that occured when input handling was done with poll
- simpler and more straightforward event handling for timer, idle, input
and X events (also fixed some problems the old handling logic had)
changes since wmaker 0.63.1: changes since wmaker 0.63.1:
............................ ............................

View File

@@ -542,8 +542,6 @@ Bool W_CheckIdleHandlers(void);
void W_CheckTimerHandlers(void); void W_CheckTimerHandlers(void);
Bool W_HaveInputHandlers(void);
Bool W_HandleInputEvents(Bool waitForInput, int inputfd); Bool W_HandleInputEvents(Bool waitForInput, int inputfd);
#ifdef __cplusplus #ifdef __cplusplus

View File

@@ -279,7 +279,7 @@ int wsprintesc(char *buffer, int length, char *format, WMSEscapes **escapes,
/*......................................................................*/ /*......................................................................*/
/* This function is used _only_ if you create a NON-GUI program. /* This function is used _only_ if you create a non-GUI program.
* For GUI based programs use WMNextEvent()/WMHandleEvent() instead. * For GUI based programs use WMNextEvent()/WMHandleEvent() instead.
* This function will handle all input/timer/idle events, then return. * This function will handle all input/timer/idle events, then return.
*/ */

View File

@@ -389,13 +389,6 @@ W_CheckTimerHandlers(void)
} }
Bool
W_HaveInputHandlers(void)
{
return (inputHandler && WMGetBagItemCount(inputHandler)>0);
}
/* /*
* This functions will handle input events on all registered file descriptors. * This functions will handle input events on all registered file descriptors.
* Input: * Input:
@@ -423,10 +416,10 @@ W_HaveInputHandlers(void)
* *
* Parametersshould be passed like this: * Parametersshould be passed like this:
* - from wevent.c: * - from wevent.c:
* waitForInput = True * waitForInput - apropriate value passed by the function who called us
* inputfd = ConnectionNumber(dpy) * inputfd = ConnectionNumber(dpy)
* - from wutil.c: * - from wutil.c:
* waitForInput - value passed from the function who calls this function * waitForInput - apropriate value passed by the function who called us
* inputfd = -1 * inputfd = -1
* *
*/ */
@@ -436,7 +429,7 @@ W_HandleInputEvents(Bool waitForInput, int inputfd)
#if defined(HAVE_POLL) && defined(HAVE_POLL_H) && !defined(HAVE_SELECT) #if defined(HAVE_POLL) && defined(HAVE_POLL_H) && !defined(HAVE_SELECT)
struct poll fd *fds; struct poll fd *fds;
InputHandler *handler; InputHandler *handler;
int count, timeout, nfds, i, extrafd, retval; int count, timeout, nfds, i, extrafd;
extrafd = (inputfd < 0) ? 0 : 1; extrafd = (inputfd < 0) ? 0 : 1;
@@ -526,17 +519,14 @@ W_HandleInputEvents(Bool waitForInput, int inputfd)
WMFreeBag(handlerCopy); WMFreeBag(handlerCopy);
} }
/* we may only return count>0, because the returned value is not checked /* --oldway-- retval = ((inputfd < 0) ? (count > 0) :
* anywhere anyway. -Dan fds[nfds].revents & (POLLIN|POLLRDNORM|POLLRDBAND|POLLPRI));*/
*/
retval = ((inputfd < 0) ? (count > 0) :
fds[nfds].revents & (POLLIN|POLLRDNORM|POLLRDBAND|POLLPRI));
wfree(fds); wfree(fds);
W_FlushASAPNotificationQueue(); W_FlushASAPNotificationQueue();
return retval; return (count > 0);
#else #else
#ifdef HAVE_SELECT #ifdef HAVE_SELECT
struct timeval timeout; struct timeval timeout;
@@ -634,7 +624,8 @@ W_HandleInputEvents(Bool waitForInput, int inputfd)
W_FlushASAPNotificationQueue(); W_FlushASAPNotificationQueue();
return ((inputfd < 0) ? (count > 0) : FD_ISSET(inputfd, &rset)); /* --oldway-- return ((inputfd < 0) ? (count > 0) : FD_ISSET(inputfd, &rset));*/
return (count > 0);
#else /* not HAVE_SELECT, not HAVE_POLL */ #else /* not HAVE_SELECT, not HAVE_POLL */
Neither select nor poll. You lose. Neither select nor poll. You lose.
#endif /* HAVE_SELECT */ #endif /* HAVE_SELECT */

View File

@@ -381,8 +381,13 @@ WMIsDoubleClick(XEvent *event)
} }
Bool /*
W_WaitForEvent(Display *dpy, unsigned long xeventmask) * If waitForInput is False, it will just peek to see if input is available
* then return without processing input but the return value will show
* if input is available or not.
*/
static Bool
waitForEvent(Display *dpy, unsigned long xeventmask, Bool waitForInput)
{ {
XSync(dpy, False); XSync(dpy, False);
if (xeventmask==0) { if (xeventmask==0) {
@@ -396,7 +401,7 @@ W_WaitForEvent(Display *dpy, unsigned long xeventmask)
} }
} }
return W_HandleInputEvents(True, ConnectionNumber(dpy)); return W_HandleInputEvents(waitForInput, ConnectionNumber(dpy));
} }
@@ -407,9 +412,8 @@ WMNextEvent(Display *dpy, XEvent *event)
W_CheckTimerHandlers(); W_CheckTimerHandlers();
while (XPending(dpy) == 0) { while (XPending(dpy) == 0) {
/* Do idle stuff */
/* Do idle and timer stuff while there are no timer or X events */ /* Do idle and timer stuff while there are no timer or X events */
while (XPending(dpy) == 0 && W_CheckIdleHandlers()) { while (!waitForEvent(dpy, 0, False) && W_CheckIdleHandlers()) {
/* dispatch timer events */ /* dispatch timer events */
W_CheckTimerHandlers(); W_CheckTimerHandlers();
} }
@@ -420,8 +424,8 @@ WMNextEvent(Display *dpy, XEvent *event)
* an event that already arrived. * an event that already arrived.
*/ */
/* wait for something to happen or a timer to expire */ /* wait for something to happen or a timer to expire */
W_WaitForEvent(dpy, 0); waitForEvent(dpy, 0, True);
/* Check any expired timers */ /* Check any expired timers */
W_CheckTimerHandlers(); W_CheckTimerHandlers();
} }
@@ -429,8 +433,9 @@ WMNextEvent(Display *dpy, XEvent *event)
XNextEvent(dpy, event); XNextEvent(dpy, event);
} }
/* /*
* Cant use this because XPending() will make W_WaitForEvent * Cant use this because XPending() will make waitForEvent
* return even if the event in the queue is not what we want, * return even if the event in the queue is not what we want,
* and if we block until some new event arrives from the * and if we block until some new event arrives from the
* server, other events already in the queue (like Expose) * server, other events already in the queue (like Expose)
@@ -438,7 +443,7 @@ WMNextEvent(Display *dpy, XEvent *event)
*/ */
void void
WMMaskEvent(Display *dpy, long mask, XEvent *event) WMMaskEvent(Display *dpy, long mask, XEvent *event)
{ {
while (!XCheckMaskEvent(dpy, mask, event)) { while (!XCheckMaskEvent(dpy, mask, event)) {
/* Do idle stuff while there are no timer or X events */ /* Do idle stuff while there are no timer or X events */
while (W_CheckIdleHandlers()) { while (W_CheckIdleHandlers()) {
@@ -446,15 +451,16 @@ WMMaskEvent(Display *dpy, long mask, XEvent *event)
return; return;
} }
/* Wait for input on the X connection socket */ /* Wait for input on the X connection socket or another input handler */
W_WaitForEvent(dpy, mask); waitForEvent(dpy, mask, True);
/* Check any expired timers */ /* Check any expired timers */
W_CheckTimerHandlers(); W_CheckTimerHandlers();
} }
} }
Bool
Bool
WMScreenPending(WMScreen *scr) WMScreenPending(WMScreen *scr)
{ {
if (XPending(scr->display)) if (XPending(scr->display))

View File

@@ -7,28 +7,15 @@
#include "WINGsP.h" #include "WINGsP.h"
void void
WHandleEvents() WHandleEvents()
{ {
/* Check any expired timers */ /* Check any expired timers */
W_CheckTimerHandlers(); W_CheckTimerHandlers();
/* We need to make sure that we have some input handler before calling /* Do idle and timer stuff while there are no input events */
* W_CheckIdleHandlers() in a while loop, because else the while loop /* Do not wait for input here. just peek to se if input is available */
* can run forever (if some idle handler reinitiates itself). while (!W_HandleInputEvents(False, -1) && W_CheckIdleHandlers()) {
*/
if (W_HaveInputHandlers()) {
/* Do idle and timer stuff while there are no input events */
/* Check again if there are still input handlers, because some idle
* handler could have removed them */
while (W_CheckIdleHandlers() && W_HaveInputHandlers() &&
!W_HandleInputEvents(False, -1)) {
/* dispatch timer events */
W_CheckTimerHandlers();
}
} else {
W_CheckIdleHandlers();
/* dispatch timer events */ /* dispatch timer events */
W_CheckTimerHandlers(); W_CheckTimerHandlers();
} }

View File

@@ -335,7 +335,7 @@ handleSig(int sig)
wfatal(_("crashed while trying to do some post-crash cleanup. Aborting immediatelly.")); wfatal(_("crashed while trying to do some post-crash cleanup. Aborting immediatelly."));
signal(sig, SIG_DFL); signal(sig, SIG_DFL);
kill(getpid(), sig); kill(getpid(), sig);
exit(1); return;
} }
already_crashed = 1; already_crashed = 1;