Skip to content

Raise the window more reliably #274

@guijan

Description

@guijan

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

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()

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions