data-device: send offer on get_data_device

This commit is contained in:
emersion 2018-12-09 13:22:09 +01:00
parent 84f278eca1
commit 1a2727cc38
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
1 changed files with 28 additions and 13 deletions

View File

@ -93,6 +93,26 @@ static void data_device_handle_resource_destroy(struct wl_resource *resource) {
} }
static void device_resource_send_selection(struct wl_resource *device_resource) {
struct wlr_seat_client *seat_client =
seat_client_from_data_device_resource(device_resource);
assert(seat_client != NULL);
struct wlr_data_source *source = seat_client->seat->selection_source;
if (source != NULL) {
struct wlr_data_offer *offer =
data_offer_create(device_resource, source);
if (offer == NULL) {
wl_client_post_no_memory(seat_client->client);
return;
}
wl_data_device_send_selection(device_resource, offer->resource);
} else {
wl_data_device_send_selection(device_resource, NULL);
}
}
void wlr_seat_client_send_selection(struct wlr_seat_client *seat_client) { void wlr_seat_client_send_selection(struct wlr_seat_client *seat_client) {
struct wlr_data_source *source = seat_client->seat->selection_source; struct wlr_data_source *source = seat_client->seat->selection_source;
if (source != NULL) { if (source != NULL) {
@ -101,18 +121,7 @@ void wlr_seat_client_send_selection(struct wlr_seat_client *seat_client) {
struct wl_resource *device_resource; struct wl_resource *device_resource;
wl_resource_for_each(device_resource, &seat_client->data_devices) { wl_resource_for_each(device_resource, &seat_client->data_devices) {
if (source != NULL) { device_resource_send_selection(device_resource);
struct wlr_data_offer *offer =
data_offer_create(device_resource, source);
if (offer == NULL) {
wl_client_post_no_memory(seat_client->client);
return;
}
wl_data_device_send_selection(device_resource, offer->resource);
} else {
wl_data_device_send_selection(device_resource, NULL);
}
} }
} }
@ -202,8 +211,14 @@ static void data_device_manager_get_data_device(struct wl_client *client,
return; return;
} }
wl_resource_set_implementation(resource, &data_device_impl, seat_client, wl_resource_set_implementation(resource, &data_device_impl, seat_client,
&data_device_handle_resource_destroy); data_device_handle_resource_destroy);
wl_list_insert(&seat_client->data_devices, wl_resource_get_link(resource)); wl_list_insert(&seat_client->data_devices, wl_resource_get_link(resource));
struct wlr_seat_client *focused_client =
seat_client->seat->keyboard_state.focused_client;
if (focused_client == seat_client) {
device_resource_send_selection(resource);
}
} }
static void data_device_manager_create_data_source(struct wl_client *client, static void data_device_manager_create_data_source(struct wl_client *client,