Instead of polling for the event (with drift from calling nanosleep() in a loop...), this code:
|
struct timespec delay = {0, 10000000L}; // 10ms |
|
|
|
for (short i = 0; i < 30; ++i) { |
|
if (XCheckIfEvent(disp, &(XEvent){0}, &scrotXEventVisibility, (XPointer)&target)) |
|
break; |
|
nanosleep(&delay, NULL); |
|
} |
Should use
select() or
poll() to wait for the fd used to communicate with the X server to have some data, then use
XCheckIfEvent() to check if the data is what we're watching for.
Edit: Is 300ms enough of a delay? 10ms is often the precision OSes offer to the userland when it comes to timers, there's probably significant drift in polling every 10ms, fixing this might expose an issue with the delay being too short, but I find it unlikely for local X servers.
Edit 2: fixed incorrect statement about poll()
Instead of polling for the event (with drift from calling
nanosleep()in a loop...), this code:scrot/src/scrot.c
Lines 373 to 379 in dc65e96
Should use
select()orpoll()to wait for the fd used to communicate with the X server to have some data, then useXCheckIfEvent()to check if the data is what we're watching for.Edit: Is 300ms enough of a delay? 10ms is often the precision OSes offer to the userland when it comes to timers, there's probably significant drift in polling every 10ms, fixing this might expose an issue with the delay being too short, but I find it unlikely for local X servers.
Edit 2: fixed incorrect statement about
poll()