gtk-primary-selection: remove offer struct

We don't need it, we can use the device instead.
master
emersion 6 years ago
parent f001f98cef
commit cbe42d1006
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48

@ -36,7 +36,7 @@ struct wlr_gtk_primary_selection_device {
struct wl_list resources; // wl_resource_get_link struct wl_list resources; // wl_resource_get_link
struct wlr_gtk_primary_selection_source *source; struct wlr_gtk_primary_selection_source *source;
struct wl_list offers; // wlr_gtk_primary_selection_offer::link struct wl_list offers; // wl_resource_get_link
struct wl_listener seat_destroy; struct wl_listener seat_destroy;
struct wl_listener seat_focus_change; struct wl_listener seat_focus_change;
@ -64,21 +64,6 @@ struct wlr_gtk_primary_selection_source {
void *data; void *data;
}; };
/**
* An offer is the receiving side of a selection. When the selection is set,
* offers are created for the currently focused client and can be used to
* initiate the data transfer.
*/
struct wlr_gtk_primary_selection_offer {
struct wl_resource *resource;
struct wlr_gtk_primary_selection_source *source;
struct wl_list link; // wlr_gtk_primary_selection_device::offers
struct wl_listener source_destroy;
void *data;
};
struct wlr_gtk_primary_selection_device_manager * struct wlr_gtk_primary_selection_device_manager *
wlr_gtk_primary_selection_device_manager_create(struct wl_display *display); wlr_gtk_primary_selection_device_manager_create(struct wl_display *display);
void wlr_gtk_primary_selection_device_manager_destroy( void wlr_gtk_primary_selection_device_manager_destroy(

@ -199,7 +199,6 @@ struct wlr_seat {
// not owned by the seat // not owned by the seat
struct wlr_gtk_primary_selection_source *primary_selection_source; struct wlr_gtk_primary_selection_source *primary_selection_source;
uint32_t primary_selection_serial;
// `drag` goes away before `drag_source`, when the implicit grab ends // `drag` goes away before `drag_source`, when the implicit grab ends
struct wlr_drag *drag; struct wlr_drag *drag;

@ -13,7 +13,7 @@
static const struct gtk_primary_selection_offer_interface offer_impl; static const struct gtk_primary_selection_offer_interface offer_impl;
static struct wlr_gtk_primary_selection_offer *offer_from_resource( static struct wlr_gtk_primary_selection_device *device_from_offer_resource(
struct wl_resource *resource) { struct wl_resource *resource) {
assert(wl_resource_instance_of(resource, assert(wl_resource_instance_of(resource,
&gtk_primary_selection_offer_interface, &offer_impl)); &gtk_primary_selection_offer_interface, &offer_impl));
@ -22,14 +22,14 @@ static struct wlr_gtk_primary_selection_offer *offer_from_resource(
static void offer_handle_receive(struct wl_client *client, static void offer_handle_receive(struct wl_client *client,
struct wl_resource *resource, const char *mime_type, int32_t fd) { struct wl_resource *resource, const char *mime_type, int32_t fd) {
struct wlr_gtk_primary_selection_offer *offer = struct wlr_gtk_primary_selection_device *device =
offer_from_resource(resource); device_from_offer_resource(resource);
if (offer == NULL) { if (device == NULL || device->source == NULL) {
close(fd); close(fd);
return; return;
} }
offer->source->send(offer->source, mime_type, fd); device->source->send(device->source, mime_type, fd);
} }
static void offer_handle_destroy(struct wl_client *client, static void offer_handle_destroy(struct wl_client *client,
@ -42,65 +42,53 @@ static const struct gtk_primary_selection_offer_interface offer_impl = {
.destroy = offer_handle_destroy, .destroy = offer_handle_destroy,
}; };
static void offer_destroy(struct wlr_gtk_primary_selection_offer *offer) {
if (offer == NULL) {
return;
}
// Make resource inert
wl_resource_set_user_data(offer->resource, NULL);
wl_list_remove(&offer->source_destroy.link);
free(offer);
}
static void offer_handle_resource_destroy(struct wl_resource *resource) { static void offer_handle_resource_destroy(struct wl_resource *resource) {
struct wlr_gtk_primary_selection_offer *offer = wl_list_remove(wl_resource_get_link(resource));
offer_from_resource(resource);
offer_destroy(offer);
} }
static void offer_handle_source_destroy(struct wl_listener *listener, static struct wlr_gtk_primary_selection_device *device_from_resource(
void *data) { struct wl_resource *resource);
struct wlr_gtk_primary_selection_offer *offer =
wl_container_of(listener, offer, source_destroy);
offer_destroy(offer);
}
static void offer_create(struct wl_resource *device_resource, static void create_offer(struct wl_resource *device_resource,
struct wlr_gtk_primary_selection_source *source) { struct wlr_gtk_primary_selection_source *source) {
struct wlr_gtk_primary_selection_offer *offer = struct wlr_gtk_primary_selection_device *device =
calloc(1, sizeof(struct wlr_gtk_primary_selection_offer)); device_from_resource(device_resource);
if (offer == NULL) { assert(device != NULL);
wl_resource_post_no_memory(device_resource);
return;
}
struct wl_client *client = wl_resource_get_client(device_resource); struct wl_client *client = wl_resource_get_client(device_resource);
uint32_t version = wl_resource_get_version(device_resource); uint32_t version = wl_resource_get_version(device_resource);
offer->resource = wl_resource_create(client, struct wl_resource *resource = wl_resource_create(client,
&gtk_primary_selection_offer_interface, version, 0); &gtk_primary_selection_offer_interface, version, 0);
if (offer->resource == NULL) { if (resource == NULL) {
free(offer);
wl_resource_post_no_memory(device_resource); wl_resource_post_no_memory(device_resource);
return; return;
} }
wl_resource_set_implementation(offer->resource, &offer_impl, offer, wl_resource_set_implementation(resource, &offer_impl, device,
offer_handle_resource_destroy); offer_handle_resource_destroy);
offer->source = source; wl_list_insert(&device->offers, wl_resource_get_link(resource));
offer->source_destroy.notify = offer_handle_source_destroy; gtk_primary_selection_device_send_data_offer(device_resource, resource);
wl_signal_add(&source->events.destroy, &offer->source_destroy);
gtk_primary_selection_device_send_data_offer(device_resource,
offer->resource);
char **p; char **p;
wl_array_for_each(p, &source->mime_types) { wl_array_for_each(p, &source->mime_types) {
gtk_primary_selection_offer_send_offer(offer->resource, *p); gtk_primary_selection_offer_send_offer(resource, *p);
} }
gtk_primary_selection_device_send_selection(device_resource, gtk_primary_selection_device_send_selection(device_resource, resource);
offer->resource); }
static void destroy_offer(struct wl_resource *resource) {
if (device_from_offer_resource(resource) == NULL) {
return;
}
// Make the offer inert
wl_resource_set_user_data(resource, NULL);
struct wl_list *link = wl_resource_get_link(resource);
wl_list_remove(link);
wl_list_init(link);
} }
@ -193,12 +181,6 @@ static void device_handle_set_selection(struct wl_client *client,
// TODO: improve serial checking // TODO: improve serial checking
struct wlr_seat *seat = device->seat; struct wlr_seat *seat = device->seat;
if (seat->primary_selection_serial > 0 &&
seat->primary_selection_serial - serial < UINT32_MAX / 2) {
return;
}
seat->primary_selection_serial = serial;
wlr_gtk_primary_selection_device_manager_set_selection(device->manager, wlr_gtk_primary_selection_device_manager_set_selection(device->manager,
seat, &source->source); seat, &source->source);
} }
@ -223,7 +205,7 @@ static void device_resource_send_selection(struct wl_resource *resource,
assert(device_from_resource(resource) != NULL); assert(device_from_resource(resource) != NULL);
if (source != NULL) { if (source != NULL) {
offer_create(resource, source); create_offer(resource, source);
} else { } else {
gtk_primary_selection_device_send_selection(resource, NULL); gtk_primary_selection_device_send_selection(resource, NULL);
} }
@ -259,9 +241,9 @@ static void device_set_selection(
device->source = NULL; device->source = NULL;
} }
struct wlr_gtk_primary_selection_offer *offer, *tmp; struct wl_resource *resource, *tmp;
wl_list_for_each_safe(offer, tmp, &device->offers, link) { wl_resource_for_each_safe(resource, tmp, &device->offers) {
offer_destroy(offer); destroy_offer(resource);
} }
device->source = source; device->source = source;
@ -291,6 +273,8 @@ static void device_handle_seat_focus_change(struct wl_listener *listener,
void *data) { void *data) {
struct wlr_gtk_primary_selection_device *device = struct wlr_gtk_primary_selection_device *device =
wl_container_of(listener, device, seat_focus_change); wl_container_of(listener, device, seat_focus_change);
// TODO: maybe make previous offers inert, or set a NULL selection for
// previous client?
device_send_selection(device); device_send_selection(device);
} }
@ -342,11 +326,14 @@ static void device_destroy(struct wlr_gtk_primary_selection_device *device) {
wl_list_remove(&device->link); wl_list_remove(&device->link);
wl_list_remove(&device->seat_destroy.link); wl_list_remove(&device->seat_destroy.link);
wl_list_remove(&device->seat_focus_change.link); wl_list_remove(&device->seat_focus_change.link);
struct wlr_gtk_primary_selection_offer *offer, *offer_tmp; if (device->source != NULL) {
wl_list_for_each_safe(offer, offer_tmp, &device->offers, link) { wl_list_remove(&device->source_destroy.link);
offer_destroy(offer); device->source->cancel(device->source);
} }
struct wl_resource *resource, *resource_tmp; struct wl_resource *resource, *resource_tmp;
wl_resource_for_each_safe(resource, resource_tmp, &device->offers) {
destroy_offer(resource);
}
wl_resource_for_each_safe(resource, resource_tmp, &device->resources) { wl_resource_for_each_safe(resource, resource_tmp, &device->resources) {
// Make the resource inert // Make the resource inert
wl_resource_set_user_data(resource, NULL); wl_resource_set_user_data(resource, NULL);

Loading…
Cancel
Save