From 1150ff13ceeeb76ce17c8b7a8ca199230d7b87f9 Mon Sep 17 00:00:00 2001 From: emersion Date: Sun, 9 Dec 2018 11:50:28 +0100 Subject: data-device: make sources inert, rename cancel to destroy --- include/wlr/types/wlr_data_device.h | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'include/wlr') diff --git a/include/wlr/types/wlr_data_device.h b/include/wlr/types/wlr_data_device.h index 4ab181db..1d2451b9 100644 --- a/include/wlr/types/wlr_data_device.h +++ b/include/wlr/types/wlr_data_device.h @@ -55,7 +55,7 @@ struct wlr_data_source_impl { int32_t fd); void (*accept)(struct wlr_data_source *source, uint32_t serial, const char *mime_type); - void (*cancel)(struct wlr_data_source *source); + void (*destroy)(struct wlr_data_source *source); void (*dnd_drop)(struct wlr_data_source *source); void (*dnd_finish)(struct wlr_data_source *source); @@ -186,11 +186,6 @@ void wlr_seat_set_selection(struct wlr_seat *seat, void wlr_data_source_init(struct wlr_data_source *source, const struct wlr_data_source_impl *impl); -/** - * Finishes the data source. - */ -void wlr_data_source_finish(struct wlr_data_source *source); - /** * Sends the data as the specified MIME type over the passed file descriptor, * then close it. @@ -207,9 +202,9 @@ void wlr_data_source_accept(struct wlr_data_source *source, uint32_t serial, /** * Notifies the data source it is no longer valid and should be destroyed. That - * potentially destroys immediately the data source. + * destroys immediately the data source. */ -void wlr_data_source_cancel(struct wlr_data_source *source); +void wlr_data_source_destroy(struct wlr_data_source *source); /** * Notifies the data source that the drop operation was performed. This does not -- cgit v1.2.3 From 0040f7089f3d12cc8457790a9bd24a556a6f5a75 Mon Sep 17 00:00:00 2001 From: emersion Date: Sun, 9 Dec 2018 16:36:36 +0100 Subject: data-device: unexport wlr_seat_client_send_selection --- include/types/wlr_data_device.h | 8 ++++++++ include/wlr/types/wlr_data_device.h | 9 --------- types/data_device/wlr_data_device.c | 4 ++-- types/seat/wlr_seat_keyboard.c | 11 ++++++----- 4 files changed, 16 insertions(+), 16 deletions(-) (limited to 'include/wlr') diff --git a/include/types/wlr_data_device.h b/include/types/wlr_data_device.h index d2bdcc38..0f58cc29 100644 --- a/include/types/wlr_data_device.h +++ b/include/types/wlr_data_device.h @@ -33,5 +33,13 @@ struct wlr_seat_client *seat_client_from_data_device_resource( bool seat_client_start_drag(struct wlr_seat_client *client, struct wlr_data_source *source, struct wlr_surface *icon_surface, struct wlr_surface *origin, uint32_t serial); +/** + * Creates a new wl_data_offer if there is a wl_data_source currently set as + * the seat selection and sends it to the seat client, followed by the + * wl_data_device.selection() event. If there is no current selection, the + * wl_data_device.selection() event will carry a NULL wl_data_offer. If the + * client does not have a wl_data_device for the seat nothing will be done. + */ +void seat_client_send_selection(struct wlr_seat_client *seat_client); #endif diff --git a/include/wlr/types/wlr_data_device.h b/include/wlr/types/wlr_data_device.h index 1d2451b9..5bf52599 100644 --- a/include/wlr/types/wlr_data_device.h +++ b/include/wlr/types/wlr_data_device.h @@ -156,15 +156,6 @@ struct wlr_data_device_manager *wlr_data_device_manager_create( */ void wlr_data_device_manager_destroy(struct wlr_data_device_manager *manager); -/** - * Creates a new wl_data_offer if there is a wl_data_source currently set as - * the seat selection and sends it to the seat client, followed by the - * wl_data_device.selection() event. If there is no current selection, the - * wl_data_device.selection() event will carry a NULL wl_data_offer. If the - * client does not have a wl_data_device for the seat nothing * will be done. - */ -void wlr_seat_client_send_selection(struct wlr_seat_client *seat_client); - /** * Requests a selection to be set for the seat. */ diff --git a/types/data_device/wlr_data_device.c b/types/data_device/wlr_data_device.c index d3c0ed06..208d2f3e 100644 --- a/types/data_device/wlr_data_device.c +++ b/types/data_device/wlr_data_device.c @@ -113,7 +113,7 @@ static void device_resource_send_selection(struct wl_resource *device_resource) } } -void wlr_seat_client_send_selection(struct wlr_seat_client *seat_client) { +void seat_client_send_selection(struct wlr_seat_client *seat_client) { struct wlr_data_source *source = seat_client->seat->selection_source; if (source != NULL) { source->accepted = false; @@ -174,7 +174,7 @@ void wlr_seat_set_selection(struct wlr_seat *seat, struct wlr_seat_client *focused_client = seat->keyboard_state.focused_client; if (focused_client) { - wlr_seat_client_send_selection(focused_client); + seat_client_send_selection(focused_client); } if (source) { diff --git a/types/seat/wlr_seat_keyboard.c b/types/seat/wlr_seat_keyboard.c index 96176b6d..c92103eb 100644 --- a/types/seat/wlr_seat_keyboard.c +++ b/types/seat/wlr_seat_keyboard.c @@ -2,17 +2,18 @@ #include #include #include -#include #include +#include #include #include #include -#include #include +#include #include +#include "types/wlr_data_device.h" #include "types/wlr_seat.h" -#include "util/signal.h" #include "util/shm.h" +#include "util/signal.h" static void default_keyboard_enter(struct wlr_seat_keyboard_grab *grab, struct wlr_surface *surface, uint32_t keycodes[], size_t num_keycodes, @@ -271,8 +272,6 @@ void wlr_seat_keyboard_enter(struct wlr_seat *seat, wl_keyboard_send_enter(resource, serial, surface->resource, &keys); } wl_array_release(&keys); - - wlr_seat_client_send_selection(client); } // reinitialize the focus destroy events @@ -292,6 +291,8 @@ void wlr_seat_keyboard_enter(struct wlr_seat *seat, // tell new client about any modifier change last, // as it targets seat->keyboard_state.focused_client wlr_seat_keyboard_send_modifiers(seat, modifiers); + + seat_client_send_selection(client); } struct wlr_seat_keyboard_focus_change_event event = { -- cgit v1.2.3 From 909b3b16f3b7634dff02030123637ae94a012850 Mon Sep 17 00:00:00 2001 From: emersion Date: Sun, 9 Dec 2018 17:27:37 +0100 Subject: data-device: add wlr_data_offer.type --- include/types/wlr_data_device.h | 2 +- include/wlr/types/wlr_data_device.h | 6 ++++++ types/data_device/wlr_data_device.c | 4 ++-- types/data_device/wlr_data_offer.c | 12 +++++++++++- types/data_device/wlr_data_source.c | 2 +- types/data_device/wlr_drag.c | 4 ++-- 6 files changed, 23 insertions(+), 7 deletions(-) (limited to 'include/wlr') diff --git a/include/types/wlr_data_device.h b/include/types/wlr_data_device.h index 0f58cc29..28073880 100644 --- a/include/types/wlr_data_device.h +++ b/include/types/wlr_data_device.h @@ -17,7 +17,7 @@ struct wlr_client_data_source { extern const struct wlr_surface_role drag_icon_surface_role; struct wlr_data_offer *data_offer_create(struct wl_resource *device_resource, - struct wlr_data_source *source); + struct wlr_data_source *source, enum wlr_data_offer_type type); void data_offer_update_action(struct wlr_data_offer *offer); void data_offer_destroy(struct wlr_data_offer *offer); diff --git a/include/wlr/types/wlr_data_device.h b/include/wlr/types/wlr_data_device.h index 5bf52599..e82dfa60 100644 --- a/include/wlr/types/wlr_data_device.h +++ b/include/wlr/types/wlr_data_device.h @@ -35,9 +35,15 @@ struct wlr_data_device_manager { void *data; }; +enum wlr_data_offer_type { + WLR_DATA_OFFER_SELECTION, + WLR_DATA_OFFER_DRAG, +}; + struct wlr_data_offer { struct wl_resource *resource; struct wlr_data_source *source; + enum wlr_data_offer_type type; uint32_t actions; enum wl_data_device_manager_dnd_action preferred_action; diff --git a/types/data_device/wlr_data_device.c b/types/data_device/wlr_data_device.c index e4e56d4a..ad5bed36 100644 --- a/types/data_device/wlr_data_device.c +++ b/types/data_device/wlr_data_device.c @@ -107,8 +107,8 @@ static void device_resource_send_selection(struct wl_resource *device_resource) struct wlr_data_source *source = seat_client->seat->selection_source; if (source != NULL) { - struct wlr_data_offer *offer = - data_offer_create(device_resource, source); + struct wlr_data_offer *offer = data_offer_create(device_resource, + source, WLR_DATA_OFFER_SELECTION); if (offer == NULL) { wl_client_post_no_memory(seat_client->client); return; diff --git a/types/data_device/wlr_data_offer.c b/types/data_device/wlr_data_offer.c index 07ce18c4..b610e4ac 100644 --- a/types/data_device/wlr_data_offer.c +++ b/types/data_device/wlr_data_offer.c @@ -55,6 +55,8 @@ static uint32_t data_offer_choose_action(struct wlr_data_offer *offer) { } void data_offer_update_action(struct wlr_data_offer *offer) { + assert(offer->type == WLR_DATA_OFFER_DRAG); + uint32_t action = data_offer_choose_action(offer); if (offer->source->current_dnd_action == action) { return; @@ -160,6 +162,13 @@ static void data_offer_handle_set_actions(struct wl_client *client, return; } + if (offer->type != WLR_DATA_OFFER_DRAG) { + wl_resource_post_error(offer->resource, + WL_DATA_OFFER_ERROR_INVALID_OFFER, + "set_action can only be sent to drag-and-drop offers"); + return; + } + offer->actions = actions; offer->preferred_action = preferred_action; @@ -199,7 +208,7 @@ static void data_offer_handle_source_destroy(struct wl_listener *listener, } struct wlr_data_offer *data_offer_create(struct wl_resource *device_resource, - struct wlr_data_source *source) { + struct wlr_data_source *source, enum wlr_data_offer_type type) { struct wlr_seat_client *seat_client = seat_client_from_data_device_resource(device_resource); assert(seat_client != NULL); @@ -210,6 +219,7 @@ struct wlr_data_offer *data_offer_create(struct wl_resource *device_resource, return NULL; } offer->source = source; + offer->type = type; struct wl_client *client = wl_resource_get_client(device_resource); uint32_t version = wl_resource_get_version(device_resource); diff --git a/types/data_device/wlr_data_source.c b/types/data_device/wlr_data_source.c index d4265132..ed794454 100644 --- a/types/data_device/wlr_data_source.c +++ b/types/data_device/wlr_data_source.c @@ -186,7 +186,7 @@ static void data_source_offer(struct wl_client *client, return; } if (source->finalized) { - wlr_log(WLR_DEBUG, "offering additional MIME type after " + wlr_log(WLR_DEBUG, "Offering additional MIME type after " "wl_data_device.set_selection"); } diff --git a/types/data_device/wlr_drag.c b/types/data_device/wlr_drag.c index ba5e384c..d6e93cb2 100644 --- a/types/data_device/wlr_drag.c +++ b/types/data_device/wlr_drag.c @@ -61,8 +61,8 @@ static void drag_set_focus(struct wlr_drag *drag, struct wl_resource *device_resource; wl_resource_for_each(device_resource, &focus_client->data_devices) { - struct wlr_data_offer *offer = - data_offer_create(device_resource, drag->source); + struct wlr_data_offer *offer = data_offer_create(device_resource, + drag->source, WLR_DATA_OFFER_DRAG); if (offer == NULL) { wl_resource_post_no_memory(device_resource); return; -- cgit v1.2.3 From a1f9d7ad9efbd248ceb85307a51e6dcf27f6bb25 Mon Sep 17 00:00:00 2001 From: emersion Date: Sun, 9 Dec 2018 17:35:11 +0100 Subject: data-device: keep track of wlr_data_offer in wlr_seat lists --- include/wlr/types/wlr_data_device.h | 1 + include/wlr/types/wlr_seat.h | 2 ++ types/data_device/wlr_data_offer.c | 11 +++++++++++ types/seat/wlr_seat.c | 2 ++ 4 files changed, 16 insertions(+) (limited to 'include/wlr') diff --git a/include/wlr/types/wlr_data_device.h b/include/wlr/types/wlr_data_device.h index e82dfa60..59aa718f 100644 --- a/include/wlr/types/wlr_data_device.h +++ b/include/wlr/types/wlr_data_device.h @@ -44,6 +44,7 @@ struct wlr_data_offer { struct wl_resource *resource; struct wlr_data_source *source; enum wlr_data_offer_type type; + struct wl_list link; // wlr_seat::{selection_offers,drag_offers} uint32_t actions; enum wl_data_device_manager_dnd_action preferred_action; diff --git a/include/wlr/types/wlr_seat.h b/include/wlr/types/wlr_seat.h index 6bc4af1a..f6df7413 100644 --- a/include/wlr/types/wlr_seat.h +++ b/include/wlr/types/wlr_seat.h @@ -197,6 +197,7 @@ struct wlr_seat { struct wlr_data_source *selection_source; uint32_t selection_serial; + struct wl_list selection_offers; // wlr_data_offer::link struct wlr_primary_selection_source *primary_selection_source; uint32_t primary_selection_serial; @@ -205,6 +206,7 @@ struct wlr_seat { struct wlr_drag *drag; struct wlr_data_source *drag_source; uint32_t drag_serial; + struct wl_list drag_offers; // wlr_data_offer::link struct wlr_seat_pointer_state pointer_state; struct wlr_seat_keyboard_state keyboard_state; diff --git a/types/data_device/wlr_data_offer.c b/types/data_device/wlr_data_offer.c index b610e4ac..0b0332b1 100644 --- a/types/data_device/wlr_data_offer.c +++ b/types/data_device/wlr_data_offer.c @@ -181,9 +181,11 @@ void data_offer_destroy(struct wlr_data_offer *offer) { } wl_list_remove(&offer->source_destroy.link); + wl_list_remove(&offer->link); // Make the resource inert wl_resource_set_user_data(offer->resource, NULL); + free(offer); } @@ -232,6 +234,15 @@ 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); + switch (type) { + case WLR_DATA_OFFER_SELECTION: + wl_list_insert(&seat_client->seat->selection_offers, &offer->link); + break; + case WLR_DATA_OFFER_DRAG: + wl_list_insert(&seat_client->seat->drag_offers, &offer->link); + break; + } + offer->source_destroy.notify = data_offer_handle_source_destroy; wl_signal_add(&source->events.destroy, &offer->source_destroy); diff --git a/types/seat/wlr_seat.c b/types/seat/wlr_seat.c index eba204dd..3595be15 100644 --- a/types/seat/wlr_seat.c +++ b/types/seat/wlr_seat.c @@ -267,6 +267,8 @@ struct wlr_seat *wlr_seat_create(struct wl_display *display, const char *name) { seat->name = strdup(name); wl_list_init(&seat->clients); wl_list_init(&seat->drag_icons); + wl_list_init(&seat->selection_offers); + wl_list_init(&seat->drag_offers); wl_signal_init(&seat->events.start_drag); wl_signal_init(&seat->events.new_drag_icon); -- cgit v1.2.3