From 17495dd6aedd27fb8a083fc841a7f297e6a8da8f Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Sat, 5 May 2018 18:56:35 +0200 Subject: nxagent: simplify nxagentWaitEvents() no more need to pass down a struct, we now only pass the milliseconds and let the function do the rest. --- nx-X11/programs/Xserver/hw/nxagent/Client.c | 2 +- nx-X11/programs/Xserver/hw/nxagent/Events.c | 43 ++++++++++++++------------- nx-X11/programs/Xserver/hw/nxagent/Events.h | 2 +- nx-X11/programs/Xserver/hw/nxagent/Handlers.c | 2 +- nx-X11/programs/Xserver/hw/nxagent/Screen.c | 6 +--- nx-X11/programs/Xserver/hw/nxagent/Split.c | 2 +- nx-X11/programs/Xserver/hw/nxagent/Window.c | 6 +--- nxcomp/src/Loop.cpp | 4 +++ 8 files changed, 32 insertions(+), 35 deletions(-) diff --git a/nx-X11/programs/Xserver/hw/nxagent/Client.c b/nx-X11/programs/Xserver/hw/nxagent/Client.c index 206b6d8e3..6ea0c4fcf 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Client.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Client.c @@ -400,7 +400,7 @@ void nxagentWaitWakeupBySplit(ClientPtr client) fprintf(stderr, "++++++nxagentWaitWakeupBySplit: Yielding control to the NX transport.\n"); #endif - nxagentWaitEvents(nxagentDisplay, NULL); + nxagentWaitEvents(nxagentDisplay, 0); } } diff --git a/nx-X11/programs/Xserver/hw/nxagent/Events.c b/nx-X11/programs/Xserver/hw/nxagent/Events.c index 89030b1b0..0223667c4 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Events.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Events.c @@ -3303,7 +3303,6 @@ int nxagentHandleConfigureNotify(XEvent* X) ScreenPtr pScreen = nxagentScreen(X -> xconfigure.window); Bool doRandR = False; - struct timeval timeout; if (X -> xconfigure.window == nxagentDefaultWindows[pScreen -> myNum]) { @@ -3339,10 +3338,7 @@ int nxagentHandleConfigureNotify(XEvent* X) { newEvents = False; - timeout.tv_sec = 0; - timeout.tv_usec = 500 * 1000; - - nxagentWaitEvents(nxagentDisplay, &timeout); + nxagentWaitEvents(nxagentDisplay, 500); /* * This should also flush the NX link for us. @@ -3809,7 +3805,7 @@ int nxagentWaitForResource(GetResourceFuncPtr pGetResource, PredicateFuncPtr pPr while ((resource = (*pGetResource)(nxagentDisplay)) == -1) { - if (nxagentWaitEvents(nxagentDisplay, NULL) == -1) + if (nxagentWaitEvents(nxagentDisplay, 0) == -1) { return -1; } @@ -4490,14 +4486,11 @@ int nxagentPendingEvents(Display *dpy) } /* - * Blocks until an event becomes - * available. + * Blocks until an event becomes available. */ -int nxagentWaitEvents(Display *dpy, struct timeval *tm) +int nxagentWaitEvents(Display *dpy, useconds_t msec) { - XEvent ev; - #ifdef DEBUG fprintf(stderr, "nxagentWaitEvents called.\n"); #endif @@ -4505,33 +4498,41 @@ int nxagentWaitEvents(Display *dpy, struct timeval *tm) NXFlushDisplay(dpy, NXFlushLink); /* - * If the transport is not running we - * have to rely on Xlib to wait for an - * event. In this case the timeout is - * ignored. + * If the transport is not running we have to rely on Xlib to wait + * for an event. In this case the timeout is ignored. */ if (NXTransRunning(NX_FD_ANY) == 1) { - NXTransContinue(tm); + if (msec > 0) + { + struct timeval tm = { + .tv_sec = 0, + .tv_usec = msec * 1000 + }; + NXTransContinue(&tm); + } + else + { + NXTransContinue(NULL); + } } else { + XEvent ev; XPeekEvent(dpy, &ev); } /* - * Check if we encountered a display - * error. If we did, wait for the + * Check if we encountered a display error. If we did, wait for the * time requested by the caller. */ if (NXDisplayError(dpy) == 1) { - if (tm != NULL) + if (msec > 0) { - usleep(tm -> tv_sec * 1000 * 1000 + - tm -> tv_usec); + usleep(msec * 1000); } return -1; diff --git a/nx-X11/programs/Xserver/hw/nxagent/Events.h b/nx-X11/programs/Xserver/hw/nxagent/Events.h index 5df0e1f05..8bc798945 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Events.h +++ b/nx-X11/programs/Xserver/hw/nxagent/Events.h @@ -232,6 +232,6 @@ Bool nxagentPendingEvents(Display *dpy); #define nxagentCheckEvents(display, event, predicate, argument) \ XCheckIfEventNoFlush((display), (event), (predicate), (argument)) -int nxagentWaitEvents(Display *, struct timeval *); +int nxagentWaitEvents(Display *, useconds_t msec); #endif /* __Events_H__ */ diff --git a/nx-X11/programs/Xserver/hw/nxagent/Handlers.c b/nx-X11/programs/Xserver/hw/nxagent/Handlers.c index c9aea9cdd..7311889b7 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Handlers.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Handlers.c @@ -1255,7 +1255,7 @@ void nxagentDispatchHandler(ClientPtr client, int in, int out) while (nxagentTokens.pending == TOKENS_PENDING_LIMIT) { - if (nxagentWaitEvents(nxagentDisplay, NULL) == -1) + if (nxagentWaitEvents(nxagentDisplay, 0) == -1) { nxagentTokens.pending = 0; diff --git a/nx-X11/programs/Xserver/hw/nxagent/Screen.c b/nx-X11/programs/Xserver/hw/nxagent/Screen.c index 62634de60..8d578c084 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Screen.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Screen.c @@ -364,7 +364,6 @@ FIXME: We'll check for ReparentNotify and LeaveNotify events after for (int i = 0; i < 100 && nxagentWMIsRunning; i++) { - struct timeval timeout; XEvent e; #ifdef TEST @@ -378,10 +377,7 @@ FIXME: We'll check for ReparentNotify and LeaveNotify events after XSync(nxagentDisplay, 0); - timeout.tv_sec = 0; - timeout.tv_usec = 50 * 1000; - - nxagentWaitEvents(nxagentDisplay, &timeout); + nxagentWaitEvents(nxagentDisplay, 50); } } else diff --git a/nx-X11/programs/Xserver/hw/nxagent/Split.c b/nx-X11/programs/Xserver/hw/nxagent/Split.c index 11221ea99..d58d70bfd 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Split.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Split.c @@ -804,7 +804,7 @@ void nxagentWaitDrawable(DrawablePtr pDrawable) fprintf(stderr, "nxagentWaitDrawable: Yielding control to the NX transport.\n"); #endif - nxagentWaitEvents(nxagentDisplay, NULL); + nxagentWaitEvents(nxagentDisplay, 0); } } diff --git a/nx-X11/programs/Xserver/hw/nxagent/Window.c b/nx-X11/programs/Xserver/hw/nxagent/Window.c index 357c6efbd..fc59973bd 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Window.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Window.c @@ -850,7 +850,6 @@ void nxagentSwitchAllScreens(ScreenPtr pScreen, Bool switchOn) * Change to fullscreen mode. */ - struct timeval timeout; int i; XEvent e; @@ -875,10 +874,7 @@ void nxagentSwitchAllScreens(ScreenPtr pScreen, Bool switchOn) XSync(nxagentDisplay, 0); - timeout.tv_sec = 0; - timeout.tv_usec = 50 * 1000; - - nxagentWaitEvents(nxagentDisplay, &timeout); + nxagentWaitEvents(nxagentDisplay, 50); } if (i < 100) diff --git a/nxcomp/src/Loop.cpp b/nxcomp/src/Loop.cpp index ddffcd1ca..bb8a89d64 100644 --- a/nxcomp/src/Loop.cpp +++ b/nxcomp/src/Loop.cpp @@ -1565,6 +1565,10 @@ int NXTransRunning(int fd) return (control != NULL); } +// +// FIXME: why timeval? Passing milliseconds would be more convenient, +// the timeval struct/T_timestamp could be built on demand. +// int NXTransContinue(struct timeval *selectTs) { if (control != NULL) -- cgit v1.2.3