selection: allows using a wrapper source to filter data

1. Added support for intercepting clipboard selection operations.
2. Wraps data sources to control data provision based on client PID.
3. Added wlr_data_receiver to data source's send to identify the
recipient.
4. Includes new example "clipboard-control.c" to illustrate clipboard
permission management.
5. Added PID and client members to data source and receiver for access
control.
This commit is contained in:
JiDe Zhang 2025-09-19 15:58:58 +08:00
parent 1f0fb95e3b
commit 6745b7bd49
18 changed files with 2723 additions and 108 deletions

View file

@ -37,6 +37,7 @@ static void data_device_set_selection(struct wl_client *client,
if (source != NULL) {
source->finalized = true;
assert(client == source->source.client);
}
struct wlr_data_source *wlr_source =

View file

@ -6,10 +6,21 @@
#include <unistd.h>
#include <wayland-server-core.h>
#include <wlr/types/wlr_data_device.h>
#include <wlr/types/wlr_data_receiver.h>
#include <wlr/types/wlr_seat.h>
#include <wlr/util/log.h>
#include "types/wlr_data_device.h"
// Empty destroy function for simple data receiver implementation
static void handle_data_receiver_simple_destroy(struct wlr_data_receiver *receiver) {
// No-op: receiver is embedded in another structure and will be freed with it
}
// Simple data receiver implementation with no callbacks
static const struct wlr_data_receiver_impl wlr_data_receiver_simple_impl = {
.destroy = handle_data_receiver_simple_destroy,
};
static const struct wl_data_offer_interface data_offer_impl;
static struct wlr_data_offer *data_offer_from_resource(
@ -88,7 +99,7 @@ static void data_offer_handle_accept(struct wl_client *client,
return;
}
wlr_data_source_accept(offer->source, serial, mime_type);
wlr_data_source_accept(offer->source, serial, mime_type, &offer->receiver);
}
static void data_offer_handle_receive(struct wl_client *client,
@ -99,7 +110,11 @@ static void data_offer_handle_receive(struct wl_client *client,
return;
}
wlr_data_source_send(offer->source, mime_type, fd);
// Set receiver fd for this transfer
offer->receiver.fd = fd;
assert(client == offer->receiver.client);
wlr_data_source_send(offer->source, mime_type, &offer->receiver);
}
static void data_offer_source_dnd_finish(struct wlr_data_offer *offer) {
@ -208,6 +223,8 @@ void data_offer_destroy(struct wlr_data_offer *offer) {
}
}
wlr_data_receiver_destroy(&offer->receiver);
// Make the resource inert
wl_resource_set_user_data(offer->resource, NULL);
@ -261,6 +278,10 @@ struct wlr_data_offer *data_offer_create(struct wl_resource *device_resource,
wl_resource_set_implementation(offer->resource, &data_offer_impl, offer,
data_offer_handle_resource_destroy);
wlr_data_receiver_init(&offer->receiver, &wlr_data_receiver_simple_impl);
offer->receiver.client = client;
wl_client_get_credentials(client, &offer->receiver.pid, NULL, NULL);
switch (type) {
case WLR_DATA_OFFER_SELECTION:
wl_list_insert(&seat_client->seat->selection_offers, &offer->link);

View file

@ -5,6 +5,7 @@
#include <unistd.h>
#include <wayland-server-core.h>
#include <wlr/types/wlr_data_device.h>
#include <wlr/types/wlr_data_receiver.h>
#include <wlr/types/wlr_seat.h>
#include <wlr/util/log.h>
#include "types/wlr_data_device.h"
@ -16,21 +17,28 @@ void wlr_data_source_init(struct wlr_data_source *source,
*source = (struct wlr_data_source){
.impl = impl,
.actions = -1,
.pid = 0,
};
wl_array_init(&source->mime_types);
wl_signal_init(&source->events.destroy);
}
void wlr_data_source_send(struct wlr_data_source *source, const char *mime_type,
int32_t fd) {
source->impl->send(source, mime_type, fd);
void wlr_data_source_send(struct wlr_data_source *source,
const char *mime_type, struct wlr_data_receiver *receiver) {
source->impl->send(source, mime_type, receiver);
}
void wlr_data_source_accept(struct wlr_data_source *source, uint32_t serial,
const char *mime_type) {
void wlr_data_source_accept(struct wlr_data_source *source,
uint32_t serial, const char *mime_type, struct wlr_data_receiver *receiver) {
source->accepted = (mime_type != NULL);
if (source->impl->accept) {
source->impl->accept(source, serial, mime_type);
source->impl->accept(source, serial, mime_type, receiver);
}
}
void wlr_data_source_cancelled(struct wlr_data_source *source) {
if (source->impl->cancelled) {
source->impl->cancelled(source);
}
}
@ -76,6 +84,61 @@ void wlr_data_source_dnd_action(struct wlr_data_source *source,
}
}
void wlr_data_source_copy(struct wlr_data_source *dest, struct wlr_data_source *src) {
if (dest == NULL || src == NULL) {
return;
}
// Copy basic metadata
dest->client = src->client;
dest->pid = src->pid;
dest->accepted = src->accepted;
dest->actions = src->actions;
dest->current_dnd_action = src->current_dnd_action;
dest->compositor_action = src->compositor_action;
/* Clear any existing mime types before copying */
if (dest->mime_types.size > 0) {
char **p;
wl_array_for_each(p, &dest->mime_types) {
free(*p);
}
wl_array_release(&dest->mime_types);
wl_array_init(&dest->mime_types);
}
// Copy MIME types from source
char **p;
wl_array_for_each(p, &src->mime_types) {
char **dest_p = wl_array_add(&dest->mime_types, sizeof(*dest_p));
if (dest_p == NULL) {
wlr_log(WLR_ERROR, "Failed to add MIME type to destination");
continue;
}
char *mime_type_copy = strdup(*p);
if (mime_type_copy == NULL) {
wlr_log(WLR_ERROR, "Failed to copy MIME type");
continue;
}
*dest_p = mime_type_copy;
}
}
struct wlr_data_source *wlr_data_source_get_original(
struct wlr_data_source *source) {
if (!source) {
return NULL;
}
if (source->impl && source->impl->get_original) {
return source->impl->get_original(source);
}
return source;
}
static const struct wl_data_source_interface data_source_impl;
@ -87,7 +150,7 @@ struct wlr_client_data_source *client_data_source_from_resource(
}
static void client_data_source_accept(struct wlr_data_source *wlr_source,
uint32_t serial, const char *mime_type);
uint32_t serial, const char *mime_type, struct wlr_data_receiver *receiver);
static struct wlr_client_data_source *client_data_source_from_wlr_data_source(
struct wlr_data_source *wlr_source) {
@ -97,18 +160,26 @@ static struct wlr_client_data_source *client_data_source_from_wlr_data_source(
}
static void client_data_source_accept(struct wlr_data_source *wlr_source,
uint32_t serial, const char *mime_type) {
uint32_t serial, const char *mime_type, struct wlr_data_receiver *receiver) {
struct wlr_client_data_source *source =
client_data_source_from_wlr_data_source(wlr_source);
wl_data_source_send_target(source->resource, mime_type);
}
static void client_data_source_send(struct wlr_data_source *wlr_source,
const char *mime_type, int32_t fd) {
const char *mime_type, struct wlr_data_receiver *receiver) {
struct wlr_client_data_source *source =
client_data_source_from_wlr_data_source(wlr_source);
wl_data_source_send_send(source->resource, mime_type, fd);
close(fd);
wl_data_source_send_send(source->resource, mime_type, receiver->fd);
close(receiver->fd);
receiver->fd = -1;
}
static void client_data_source_cancelled(struct wlr_data_source *wlr_source) {
struct wlr_client_data_source *source =
client_data_source_from_wlr_data_source(wlr_source);
wl_data_source_send_cancelled(source->resource);
}
static void client_data_source_destroy(struct wlr_data_source *wlr_source) {
@ -254,6 +325,7 @@ struct wlr_client_data_source *client_data_source_create(
source->impl.accept = client_data_source_accept;
source->impl.send = client_data_source_send;
source->impl.cancelled = client_data_source_cancelled;
source->impl.destroy = client_data_source_destroy;
if (wl_resource_get_version(source->resource) >=
@ -270,5 +342,8 @@ struct wlr_client_data_source *client_data_source_create(
}
wlr_data_source_init(&source->source, &source->impl);
source->source.client = client;
wl_client_get_credentials(client, &source->source.pid, NULL, NULL);
return source;
}

View file

@ -3,6 +3,7 @@ wlr_files += files(
'data_device/wlr_data_offer.c',
'data_device/wlr_data_source.c',
'data_device/wlr_drag.c',
'wlr_data_receiver.c',
'ext_image_capture_source_v1/base.c',
'ext_image_capture_source_v1/output.c',
'ext_image_capture_source_v1/foreign_toplevel.c',

View file

@ -4,12 +4,23 @@
#include <unistd.h>
#include <wlr/types/wlr_data_control_v1.h>
#include <wlr/types/wlr_data_device.h>
#include <wlr/types/wlr_data_receiver.h>
#include <wlr/types/wlr_primary_selection.h>
#include <wlr/util/log.h>
#include "wlr-data-control-unstable-v1-protocol.h"
#define DATA_CONTROL_MANAGER_VERSION 2
// Empty destroy function for simple data receiver implementation
static void handle_data_receiver_simple_destroy(struct wlr_data_receiver *receiver) {
// No-op: receiver is embedded in another structure and will be freed with it
}
// Simple data receiver implementation with no callbacks
static const struct wlr_data_receiver_impl wlr_data_receiver_simple_impl = {
.destroy = handle_data_receiver_simple_destroy,
};
struct data_control_source {
struct wl_resource *resource;
struct wl_array mime_types;
@ -124,11 +135,13 @@ static struct client_data_source *
}
static void client_source_send(struct wlr_data_source *wlr_source,
const char *mime_type, int fd) {
const char *mime_type, struct wlr_data_receiver *receiver) {
struct client_data_source *source =
client_data_source_from_source(wlr_source);
zwlr_data_control_source_v1_send_send(source->resource, mime_type, fd);
close(fd);
zwlr_data_control_source_v1_send_send(source->resource, mime_type, receiver->fd);
close(receiver->fd);
receiver->fd = -1;
}
static void client_source_destroy(struct wlr_data_source *wlr_source) {
@ -172,11 +185,13 @@ static struct client_primary_selection_source *
static void client_primary_selection_source_send(
struct wlr_primary_selection_source *wlr_source,
const char *mime_type, int fd) {
const char *mime_type, struct wlr_data_receiver *receiver) {
struct client_primary_selection_source *source =
client_primary_selection_source_from_source(wlr_source);
zwlr_data_control_source_v1_send_send(source->resource, mime_type, fd);
close(fd);
zwlr_data_control_source_v1_send_send(source->resource, mime_type, receiver->fd);
close(receiver->fd);
receiver->fd = -1;
}
static void client_primary_selection_source_destroy(
@ -208,6 +223,9 @@ struct data_offer {
struct wl_resource *resource;
struct wlr_data_control_device_v1 *device;
bool is_primary;
// Data receiver for this offer
struct wlr_data_receiver receiver;
};
static void data_offer_destroy(struct data_offer *offer) {
@ -225,6 +243,8 @@ static void data_offer_destroy(struct data_offer *offer) {
}
wl_resource_set_user_data(offer->resource, NULL);
wlr_data_receiver_destroy(&offer->receiver);
free(offer);
}
@ -251,20 +271,27 @@ static void offer_handle_receive(struct wl_client *client,
return;
}
// Set receiver fd for this transfer
offer->receiver.fd = fd;
assert(offer->receiver.client == client);
if (offer->is_primary) {
if (device->seat->primary_selection_source == NULL) {
close(fd);
return;
}
wlr_primary_selection_source_send(
device->seat->primary_selection_source,
mime_type, fd);
mime_type, &offer->receiver);
} else {
if (device->seat->selection_source == NULL) {
close(fd);
return;
}
wlr_data_source_send(device->seat->selection_source, mime_type, fd);
wlr_data_source_send(device->seat->selection_source,
mime_type, &offer->receiver);
}
}
@ -306,6 +333,10 @@ static struct wl_resource *create_offer(struct wlr_data_control_device_v1 *devic
offer->resource = resource;
wlr_data_receiver_init(&offer->receiver, &wlr_data_receiver_simple_impl);
offer->receiver.client = client;
wl_client_get_credentials(client, &offer->receiver.pid, NULL, NULL);
wl_resource_set_implementation(resource, &offer_impl, offer,
offer_handle_resource_destroy);
@ -369,6 +400,8 @@ static void control_handle_set_selection(struct wl_client *client,
struct wlr_data_source *wlr_source = &client_source->source;
wlr_data_source_init(wlr_source, &client_source_impl);
wlr_source->client = client;
wl_client_get_credentials(client, &wlr_source->pid, NULL, NULL);
source->active_source = wlr_source;
wl_array_release(&wlr_source->mime_types);
@ -421,6 +454,8 @@ static void control_handle_set_primary_selection(struct wl_client *client,
struct wlr_primary_selection_source *wlr_source = &client_source->source;
wlr_primary_selection_source_init(wlr_source, &client_primary_selection_source_impl);
wlr_source->client = client;
wl_client_get_credentials(client, &wlr_source->pid, NULL, NULL);
source->active_primary_source = wlr_source;
wl_array_release(&wlr_source->mime_types);

55
types/wlr_data_receiver.c Normal file
View file

@ -0,0 +1,55 @@
#include <assert.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <wlr/types/wlr_data_receiver.h>
#include <wlr/util/log.h>
void wlr_data_receiver_init(struct wlr_data_receiver *receiver,
const struct wlr_data_receiver_impl *impl) {
assert(receiver && impl);
*receiver = (struct wlr_data_receiver){
.impl = impl,
.fd = -1,
.pid = 0,
.client = NULL,
};
wl_signal_init(&receiver->events.destroy);
}
void wlr_data_receiver_destroy(struct wlr_data_receiver *receiver) {
if (!receiver) {
return;
}
wl_signal_emit_mutable(&receiver->events.destroy, receiver);
assert(wl_list_empty(&receiver->events.destroy.listener_list));
int fd = receiver->fd;
if (receiver->impl && receiver->impl->destroy) {
receiver->impl->destroy(receiver);
} else {
free(receiver);
}
if (fd >= 0 && fcntl(fd, F_GETFD) != -1) {
close(fd);
}
}
void wlr_data_receiver_cancelled(struct wlr_data_receiver *receiver) {
if (!receiver) {
return;
}
if (receiver->impl && receiver->impl->cancelled) {
receiver->impl->cancelled(receiver);
}
// Close fd if still valid
if (receiver->fd >= 0 && fcntl(receiver->fd, F_GETFD) != -1) {
close(receiver->fd);
receiver->fd = -1;
}
}

View file

@ -4,12 +4,23 @@
#include <unistd.h>
#include <wlr/types/wlr_ext_data_control_v1.h>
#include <wlr/types/wlr_data_device.h>
#include <wlr/types/wlr_data_receiver.h>
#include <wlr/types/wlr_primary_selection.h>
#include <wlr/util/log.h>
#include "ext-data-control-v1-protocol.h"
#define EXT_DATA_CONTROL_MANAGER_VERSION 1
// Empty destroy function for simple data receiver implementation
static void handle_data_receiver_simple_destroy(struct wlr_data_receiver *receiver) {
// No-op: receiver is embedded in another structure and will be freed with it
}
// Simple data receiver implementation with no callbacks
static const struct wlr_data_receiver_impl wlr_data_receiver_simple_impl = {
.destroy = handle_data_receiver_simple_destroy,
};
struct data_control_source {
struct wl_resource *resource;
struct wl_array mime_types;
@ -124,11 +135,11 @@ static struct client_data_source *
}
static void client_source_send(struct wlr_data_source *wlr_source,
const char *mime_type, int fd) {
const char *mime_type, struct wlr_data_receiver *receiver) {
struct client_data_source *source =
client_data_source_from_source(wlr_source);
ext_data_control_source_v1_send_send(source->resource, mime_type, fd);
close(fd);
ext_data_control_source_v1_send_send(source->resource, mime_type, receiver->fd);
close(receiver->fd);
}
static void client_source_destroy(struct wlr_data_source *wlr_source) {
@ -172,11 +183,11 @@ static struct client_primary_selection_source *
static void client_primary_selection_source_send(
struct wlr_primary_selection_source *wlr_source,
const char *mime_type, int fd) {
const char *mime_type, struct wlr_data_receiver *receiver) {
struct client_primary_selection_source *source =
client_primary_selection_source_from_source(wlr_source);
ext_data_control_source_v1_send_send(source->resource, mime_type, fd);
close(fd);
ext_data_control_source_v1_send_send(source->resource, mime_type, receiver->fd);
close(receiver->fd);
}
static void client_primary_selection_source_destroy(
@ -208,6 +219,9 @@ struct data_offer {
struct wl_resource *resource;
struct wlr_ext_data_control_device_v1 *device;
bool is_primary;
// Data receiver for this offer
struct wlr_data_receiver receiver;
};
static void data_offer_destroy(struct data_offer *offer) {
@ -225,6 +239,8 @@ static void data_offer_destroy(struct data_offer *offer) {
}
wl_resource_set_user_data(offer->resource, NULL);
wlr_data_receiver_destroy(&offer->receiver);
free(offer);
}
@ -251,6 +267,9 @@ static void offer_handle_receive(struct wl_client *client,
return;
}
offer->receiver.fd = fd;
assert(offer->receiver.client == client);
if (offer->is_primary) {
if (device->seat->primary_selection_source == NULL) {
close(fd);
@ -258,13 +277,14 @@ static void offer_handle_receive(struct wl_client *client,
}
wlr_primary_selection_source_send(
device->seat->primary_selection_source,
mime_type, fd);
mime_type, &offer->receiver);
} else {
if (device->seat->selection_source == NULL) {
close(fd);
return;
}
wlr_data_source_send(device->seat->selection_source, mime_type, fd);
wlr_data_source_send(device->seat->selection_source,
mime_type, &offer->receiver);
}
}
@ -305,6 +325,9 @@ static struct wl_resource *create_offer(struct wlr_ext_data_control_device_v1 *d
}
offer->resource = resource;
wlr_data_receiver_init(&offer->receiver, &wlr_data_receiver_simple_impl);
offer->receiver.client = client;
wl_client_get_credentials(client, &offer->receiver.pid, NULL, NULL);
wl_resource_set_implementation(resource, &offer_impl, offer,
offer_handle_resource_destroy);
@ -369,6 +392,8 @@ static void control_handle_set_selection(struct wl_client *client,
struct wlr_data_source *wlr_source = &client_source->source;
wlr_data_source_init(wlr_source, &client_source_impl);
wlr_source->client = client;
wl_client_get_credentials(client, &wlr_source->pid, NULL, NULL);
source->active_source = wlr_source;
wl_array_release(&wlr_source->mime_types);
@ -421,6 +446,8 @@ static void control_handle_set_primary_selection(struct wl_client *client,
struct wlr_primary_selection_source *wlr_source = &client_source->source;
wlr_primary_selection_source_init(wlr_source, &client_primary_selection_source_impl);
wlr_source->client = client;
wl_client_get_credentials(client, &wlr_source->pid, NULL, NULL);
source->active_primary_source = wlr_source;
wl_array_release(&wlr_source->mime_types);

View file

@ -39,11 +39,61 @@ void wlr_primary_selection_source_destroy(
}
void wlr_primary_selection_source_send(
struct wlr_primary_selection_source *source, const char *mime_type,
int32_t fd) {
source->impl->send(source, mime_type, fd);
struct wlr_primary_selection_source *source,
const char *mime_type, struct wlr_data_receiver *receiver) {
source->impl->send(source, mime_type, receiver);
}
void wlr_primary_selection_source_copy(struct wlr_primary_selection_source *dest,
struct wlr_primary_selection_source *src) {
if (dest == NULL || src == NULL) {
return;
}
dest->client = src->client;
dest->pid = src->pid;
/* Clear any existing mime types before copying */
if (dest->mime_types.size > 0) {
char **p;
wl_array_for_each(p, &dest->mime_types) {
free(*p);
}
wl_array_release(&dest->mime_types);
wl_array_init(&dest->mime_types);
}
// Copy MIME types from source
char **p;
wl_array_for_each(p, &src->mime_types) {
char **dest_p = wl_array_add(&dest->mime_types, sizeof(*dest_p));
if (dest_p == NULL) {
wlr_log(WLR_ERROR, "Failed to add MIME type to destination");
continue;
}
char *mime_type_copy = strdup(*p);
if (mime_type_copy == NULL) {
wlr_log(WLR_ERROR, "Failed to copy MIME type");
continue;
}
*dest_p = mime_type_copy;
}
}
struct wlr_primary_selection_source *wlr_primary_selection_source_get_original(
struct wlr_primary_selection_source *source) {
if (!source) {
return NULL;
}
if (source->impl && source->impl->get_original) {
return source->impl->get_original(source);
}
return source;
}
void wlr_seat_request_set_primary_selection(struct wlr_seat *seat,
struct wlr_seat_client *client,

View file

@ -5,15 +5,33 @@
#include <unistd.h>
#include <wlr/types/wlr_primary_selection_v1.h>
#include <wlr/types/wlr_primary_selection.h>
#include <wlr/types/wlr_data_receiver.h>
#include <wlr/types/wlr_seat.h>
#include <wlr/util/log.h>
#include "primary-selection-unstable-v1-protocol.h"
#define DEVICE_MANAGER_VERSION 1
// Primary selection offer structure
struct primary_selection_offer {
struct wlr_primary_selection_v1_device *device;
// Data receiver for this offer
struct wlr_data_receiver receiver;
};
// Primary selection receiver implementation
static void handle_primary_selection_receiver_destroy(struct wlr_data_receiver *receiver) {
// The receiver is embedded in primary_selection_offer, so don't free it
}
static const struct wlr_data_receiver_impl primary_selection_receiver_impl = {
.destroy = handle_primary_selection_receiver_destroy,
};
static const struct zwp_primary_selection_offer_v1_interface offer_impl;
static struct wlr_primary_selection_v1_device *device_from_offer_resource(
static struct primary_selection_offer *offer_from_resource(
struct wl_resource *resource) {
assert(wl_resource_instance_of(resource,
&zwp_primary_selection_offer_v1_interface, &offer_impl));
@ -22,15 +40,19 @@ static struct wlr_primary_selection_v1_device *device_from_offer_resource(
static void offer_handle_receive(struct wl_client *client,
struct wl_resource *resource, const char *mime_type, int32_t fd) {
struct wlr_primary_selection_v1_device *device =
device_from_offer_resource(resource);
if (device == NULL || device->seat->primary_selection_source == NULL) {
struct primary_selection_offer *offer = offer_from_resource(resource);
if (offer == NULL || offer->device == NULL ||
offer->device->seat->primary_selection_source == NULL) {
close(fd);
return;
}
wlr_primary_selection_source_send(device->seat->primary_selection_source,
mime_type, fd);
// Set receiver fd for this transfer
offer->receiver.fd = fd;
assert(offer->receiver.client == client);
wlr_primary_selection_source_send(offer->device->seat->primary_selection_source,
mime_type, &offer->receiver);
}
static void offer_handle_destroy(struct wl_client *client,
@ -45,6 +67,11 @@ static const struct zwp_primary_selection_offer_v1_interface offer_impl = {
static void offer_handle_resource_destroy(struct wl_resource *resource) {
wl_list_remove(wl_resource_get_link(resource));
struct primary_selection_offer *offer = offer_from_resource(resource);
if (offer) {
wlr_data_receiver_destroy(&offer->receiver);
free(offer);
}
}
static struct wlr_primary_selection_v1_device *device_from_resource(
@ -64,7 +91,22 @@ static void create_offer(struct wl_resource *device_resource,
wl_resource_post_no_memory(device_resource);
return;
}
wl_resource_set_implementation(resource, &offer_impl, device,
// Create the offer structure with embedded receiver
struct primary_selection_offer *offer = calloc(1, sizeof(*offer));
if (offer == NULL) {
wl_resource_destroy(resource);
wl_resource_post_no_memory(device_resource);
return;
}
offer->device = device;
wlr_data_receiver_init(&offer->receiver, &primary_selection_receiver_impl);
offer->receiver.client = client;
wl_client_get_credentials(client, &offer->receiver.pid, NULL, NULL);
wl_resource_set_implementation(resource, &offer_impl, offer,
offer_handle_resource_destroy);
wl_list_insert(&device->offers, wl_resource_get_link(resource));
@ -80,7 +122,8 @@ static void create_offer(struct wl_resource *device_resource,
}
static void destroy_offer(struct wl_resource *resource) {
if (device_from_offer_resource(resource) == NULL) {
struct primary_selection_offer *offer = offer_from_resource(resource);
if (offer == NULL) {
return;
}
@ -101,10 +144,12 @@ struct client_data_source {
static void client_source_send(
struct wlr_primary_selection_source *wlr_source,
const char *mime_type, int fd) {
const char *mime_type, struct wlr_data_receiver *receiver) {
struct client_data_source *source = wl_container_of(wlr_source, source, source);
zwp_primary_selection_source_v1_send_send(source->resource, mime_type, fd);
close(fd);
zwp_primary_selection_source_v1_send_send(source->resource, mime_type, receiver->fd);
close(receiver->fd);
receiver->fd = -1;
}
static void client_source_destroy(
@ -374,6 +419,8 @@ static void device_manager_handle_create_source(struct wl_client *client,
return;
}
wlr_primary_selection_source_init(&source->source, &client_source_impl);
source->source.client = client;
wl_client_get_credentials(client, &source->source.pid, NULL, NULL);
uint32_t version = wl_resource_get_version(manager_resource);
source->resource = wl_resource_create(client,