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()
- Moved all internal handlers (timer, idle and input) to handlers.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:
............................

View File

@@ -542,8 +542,6 @@ Bool W_CheckIdleHandlers(void);
void W_CheckTimerHandlers(void);
Bool W_HaveInputHandlers(void);
Bool W_HandleInputEvents(Bool waitForInput, int inputfd);
#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.
* 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.
* Input:
@@ -423,10 +416,10 @@ W_HaveInputHandlers(void)
*
* Parametersshould be passed like this:
* - from wevent.c:
* waitForInput = True
* waitForInput - apropriate value passed by the function who called us
* inputfd = ConnectionNumber(dpy)
* - 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
*
*/
@@ -436,7 +429,7 @@ W_HandleInputEvents(Bool waitForInput, int inputfd)
#if defined(HAVE_POLL) && defined(HAVE_POLL_H) && !defined(HAVE_SELECT)
struct poll fd *fds;
InputHandler *handler;
int count, timeout, nfds, i, extrafd, retval;
int count, timeout, nfds, i, extrafd;
extrafd = (inputfd < 0) ? 0 : 1;
@@ -526,17 +519,14 @@ W_HandleInputEvents(Bool waitForInput, int inputfd)
WMFreeBag(handlerCopy);
}
/* we may only return count>0, because the returned value is not checked
* anywhere anyway. -Dan
*/
retval = ((inputfd < 0) ? (count > 0) :
fds[nfds].revents & (POLLIN|POLLRDNORM|POLLRDBAND|POLLPRI));
/* --oldway-- retval = ((inputfd < 0) ? (count > 0) :
fds[nfds].revents & (POLLIN|POLLRDNORM|POLLRDBAND|POLLPRI));*/
wfree(fds);
W_FlushASAPNotificationQueue();
return retval;
return (count > 0);
#else
#ifdef HAVE_SELECT
struct timeval timeout;
@@ -634,7 +624,8 @@ W_HandleInputEvents(Bool waitForInput, int inputfd)
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 */
Neither select nor poll. You lose.
#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);
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();
while (XPending(dpy) == 0) {
/* Do idle stuff */
/* 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 */
W_CheckTimerHandlers();
}
@@ -420,8 +424,8 @@ WMNextEvent(Display *dpy, XEvent *event)
* an event that already arrived.
*/
/* wait for something to happen or a timer to expire */
W_WaitForEvent(dpy, 0);
waitForEvent(dpy, 0, True);
/* Check any expired timers */
W_CheckTimerHandlers();
}
@@ -429,8 +433,9 @@ WMNextEvent(Display *dpy, XEvent *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,
* and if we block until some new event arrives from the
* server, other events already in the queue (like Expose)
@@ -438,7 +443,7 @@ WMNextEvent(Display *dpy, XEvent *event)
*/
void
WMMaskEvent(Display *dpy, long mask, XEvent *event)
{
{
while (!XCheckMaskEvent(dpy, mask, event)) {
/* Do idle stuff while there are no timer or X events */
while (W_CheckIdleHandlers()) {
@@ -446,15 +451,16 @@ WMMaskEvent(Display *dpy, long mask, XEvent *event)
return;
}
/* Wait for input on the X connection socket */
W_WaitForEvent(dpy, mask);
/* Wait for input on the X connection socket or another input handler */
waitForEvent(dpy, mask, True);
/* Check any expired timers */
W_CheckTimerHandlers();
}
}
Bool
Bool
WMScreenPending(WMScreen *scr)
{
if (XPending(scr->display))

View File

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

View File

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