Skip to content

Commit

Permalink
data-control: Don't send offers to the clients that sent them
Browse files Browse the repository at this point in the history
If a client is listening for offers and sends an offer, it will block forever
when it attempts to receive the offer and read from the file descriptor. This
is because the offer is sent back to the client that sent it. Since the writing
and reading ends are in the same client, it never has a chance to write,
barring methods to work around this problem.

Here we fix the problem by not making offers back to the client that sent them.
Closes swaywm#2406.
  • Loading branch information
soreau committed Sep 21, 2020
1 parent 87836dc commit c13a935
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions types/wlr_data_control_v1.c
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,17 @@ static void control_send_selection(struct wlr_data_control_device_v1 *device) {
}

device->selection_offer_resource = NULL;

struct client_data_source *client_source =
wl_container_of(source, client_source, source);
if (client_source && device->resource) {
struct wl_resource *source_resource = client_source->resource;
// Don't send the offer back to the client that sent it
if (source_resource && wl_resource_get_client(source_resource) ==
wl_resource_get_client(device->resource))
return;
}

if (source != NULL) {
device->selection_offer_resource =
create_offer(device, &source->mime_types, false);
Expand Down Expand Up @@ -488,6 +499,17 @@ static void control_send_primary_selection(
}

device->primary_selection_offer_resource = NULL;

struct client_primary_selection_source *client_source =
wl_container_of(source, client_source, source);
if (client_source && device->resource) {
struct wl_resource *source_resource = client_source->resource;
// Don't send the offer back to the client that sent it
if (source_resource && wl_resource_get_client(source_resource) ==
wl_resource_get_client(device->resource))
return;
}

if (source != NULL) {
device->primary_selection_offer_resource =
create_offer(device, &source->mime_types, true);
Expand Down

0 comments on commit c13a935

Please sign in to comment.