Skip to content

Commit

Permalink
clipserve: Retry GetSelectionOwner check when acquiring selection
Browse files Browse the repository at this point in the history
This hasn't come up, but better to avoid using expect() if possible.
  • Loading branch information
cdown committed Nov 10, 2024
1 parent d034810 commit b4ccc8a
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/clipserve.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,21 @@ static void _nonnull_ serve_clipboard(uint64_t hash,

selections[1] = XInternAtom(dpy, "CLIPBOARD", False);
for (size_t i = 0; i < arrlen(selections); i++) {
XSetSelectionOwner(dpy, selections[i], win, CurrentTime);
expect(XGetSelectionOwner(dpy, selections[i]) == win); // ICCCM 2.1
bool success = false;
for (int attempts = 0; attempts < 5; attempts++) {
XSetSelectionOwner(dpy, selections[i], win, CurrentTime);

// According to ICCCM 2.1, a client acquiring a selection should
// confirm success by verifying with GetSelectionOwner.
if (XGetSelectionOwner(dpy, selections[i]) == win) {
success = true;
break;
}
}
if (!success) {
die("Failed to set selection for %s\n",
XGetAtomName(dpy, selections[i]));
}
}
remaining_selections = arrlen(selections);

Expand Down

0 comments on commit b4ccc8a

Please sign in to comment.