|
|
Question : Is there any non-blocking equivalent to XNextEvent?
|
|
Hi!
I've just started working with xlib. Can anyone tell me if there's any nonblocking equivalent to XNextEvent() ? XCheckWindowEvent() and others are not what i really want. I'm writing a programme which draws to a window, after every time interval 't'. But i also want to receive user input events. If i use XNextEvent(), it blocks until there's some input, so it'll not allow me to draw to screen continously. On the other hand, if i use XCheckWindowEvent() in a loop like:
while(1) { if(time interval 't' has elapsed) draw something
if(XCheckWindowEvent()) { handle input event } }
this eats up cpu time like anything.
So what i really require is a function, which blocks for a period of time 't', or until an input event is received from XServer, whichever is earlier. Thus, when it doesn't need to do anything, the programme will simply block, rather than keep on looping!
I might be able to use select() system call to block for time 't', but then it'll block even if an event is received, which will make the user wait, making the programme less responsive. Not something desirable.
Is there any way out?
Please help. Regards, logicTRANCE
|
Answer : Is there any non-blocking equivalent to XNextEvent?
|
|
I think what you're seeing as the delay and what is occuring are two different things. Keep in mind that stdout is line buffered, therefore nothing hits standard out until a newline is encountered. Since you place your newlines BEFORE outputing the information line, you don't actually see the output hit the screen until the next printf statement is executed.
fflush(stdout);
or rearranging the newlines will cure this unsightlyness.
|
|
|
|
|