Skip to content

Commit

Permalink
retry a couple times when grabbing pointer
Browse files Browse the repository at this point in the history
similar to keyboard grab logic
  • Loading branch information
N-R-K committed Nov 11, 2024
1 parent cdb85fc commit 558d6aa
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/scrot_selection.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,16 @@ static void scrotSelectionCreate(void)

unsigned int const EVENT_MASK = ButtonMotionMask | ButtonPressMask | ButtonReleaseMask;

if ((XGrabPointer(disp, root, False, EVENT_MASK, GrabModeAsync,
GrabModeAsync, root, sel->curCross, CurrentTime)
!= GrabSuccess)) {
int ret;
struct timespec t = clockNow();
for (int attempts = 0; attempts < 20; ++attempts) {
ret = XGrabPointer(disp, root, False, EVENT_MASK, GrabModeAsync,
GrabModeAsync, root, sel->curCross, CurrentTime);
if (ret != AlreadyGrabbed)
break;
t = scrotSleepFor(t, 50);
}
if (ret != GrabSuccess) {
scrotSelectionDestroy();
errx(EXIT_FAILURE, "couldn't grab pointer");
}
Expand Down

0 comments on commit 558d6aa

Please sign in to comment.