From 79857511c5655ddfe74c0b2d6ad7d742d9ec1fdd Mon Sep 17 00:00:00 2001 From: "Alexey I. Froloff" Date: Wed, 22 Aug 2012 20:40:31 +0400 Subject: [PATCH] wmpager: use select(2) instead of usleep(3), increase sleep time to 0.5 sec --- wmpager/src/wmpager.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/wmpager/src/wmpager.c b/wmpager/src/wmpager.c index 8d74e7f..7080b63 100644 --- a/wmpager/src/wmpager.c +++ b/wmpager/src/wmpager.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -278,6 +279,7 @@ void initApplicationName (char* szApplicationName) { */ static Display* _display; +static int _xfd; Display* getDisplay () { return _display; @@ -308,6 +310,7 @@ void initDisplay (char* szDisplay) { ); exit(-1); } + _xfd= XConnectionNumber(_display); } /* @@ -697,6 +700,8 @@ void loop () { Display* display= getDisplay(); XEvent event; char* atom_name; + struct timeval tv; + fd_set fds; if (isVerbose()) { fprintf(stdout, "[%8ld] starting event loop\n", currentTimeMillis()); @@ -749,7 +754,12 @@ void loop () { break; } } - usleep(50000); + + tv.tv_sec = 0; + tv.tv_usec = 500000UL; + FD_ZERO(&fds); + FD_SET(_xfd, &fds); + select(_xfd + 1, &fds, NULL, NULL, &tv); } } -- 2.11.4.GIT