data-device: make sources inert, rename cancel to destroy

This commit is contained in:
emersion 2018-12-09 11:50:28 +01:00
parent 4cb0697e57
commit 1150ff13ce
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48
6 changed files with 45 additions and 38 deletions

View file

@ -55,7 +55,7 @@ struct wlr_data_source_impl {
int32_t fd); int32_t fd);
void (*accept)(struct wlr_data_source *source, uint32_t serial, void (*accept)(struct wlr_data_source *source, uint32_t serial,
const char *mime_type); 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_drop)(struct wlr_data_source *source);
void (*dnd_finish)(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, void wlr_data_source_init(struct wlr_data_source *source,
const struct wlr_data_source_impl *impl); 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, * Sends the data as the specified MIME type over the passed file descriptor,
* then close it. * 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 * 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 * Notifies the data source that the drop operation was performed. This does not

View file

@ -155,7 +155,7 @@ void wlr_seat_set_selection(struct wlr_seat *seat,
struct wlr_data_source *source, uint32_t serial) { struct wlr_data_source *source, uint32_t serial) {
if (seat->selection_source) { if (seat->selection_source) {
wl_list_remove(&seat->selection_source_destroy.link); wl_list_remove(&seat->selection_source_destroy.link);
wlr_data_source_cancel(seat->selection_source); wlr_data_source_destroy(seat->selection_source);
seat->selection_source = NULL; seat->selection_source = NULL;
} }

View file

@ -40,20 +40,6 @@ void wlr_data_source_init(struct wlr_data_source *source,
source->actions = -1; source->actions = -1;
} }
void wlr_data_source_finish(struct wlr_data_source *source) {
if (source == NULL) {
return;
}
wlr_signal_emit_safe(&source->events.destroy, source);
char **p;
wl_array_for_each(p, &source->mime_types) {
free(*p);
}
wl_array_release(&source->mime_types);
}
void wlr_data_source_send(struct wlr_data_source *source, const char *mime_type, void wlr_data_source_send(struct wlr_data_source *source, const char *mime_type,
int32_t fd) { int32_t fd) {
source->impl->send(source, mime_type, fd); source->impl->send(source, mime_type, fd);
@ -67,9 +53,23 @@ void wlr_data_source_accept(struct wlr_data_source *source, uint32_t serial,
} }
} }
void wlr_data_source_cancel(struct wlr_data_source *source) { void wlr_data_source_destroy(struct wlr_data_source *source) {
if (source->impl->cancel) { if (source == NULL) {
source->impl->cancel(source); return;
}
wlr_signal_emit_safe(&source->events.destroy, source);
char **p;
wl_array_for_each(p, &source->mime_types) {
free(*p);
}
wl_array_release(&source->mime_types);
if (source->impl->destroy) {
source->impl->destroy(source);
} else {
free(source);
} }
} }
@ -127,10 +127,12 @@ static void client_data_source_send(struct wlr_data_source *wlr_source,
close(fd); close(fd);
} }
static void client_data_source_cancel(struct wlr_data_source *wlr_source) { static void client_data_source_destroy(struct wlr_data_source *wlr_source) {
struct wlr_client_data_source *source = struct wlr_client_data_source *source =
client_data_source_from_wlr_data_source(wlr_source); client_data_source_from_wlr_data_source(wlr_source);
wl_data_source_send_cancelled(source->resource); wl_data_source_send_cancelled(source->resource);
wl_resource_set_user_data(source->resource, NULL);
free(source);
} }
static void client_data_source_dnd_drop(struct wlr_data_source *wlr_source) { static void client_data_source_dnd_drop(struct wlr_data_source *wlr_source) {
@ -167,6 +169,9 @@ static void data_source_set_actions(struct wl_client *client,
struct wl_resource *resource, uint32_t dnd_actions) { struct wl_resource *resource, uint32_t dnd_actions) {
struct wlr_client_data_source *source = struct wlr_client_data_source *source =
client_data_source_from_resource(resource); client_data_source_from_resource(resource);
if (source == NULL) {
return;
}
if (source->source.actions >= 0) { if (source->source.actions >= 0) {
wl_resource_post_error(source->resource, wl_resource_post_error(source->resource,
@ -196,6 +201,13 @@ static void data_source_offer(struct wl_client *client,
struct wl_resource *resource, const char *mime_type) { struct wl_resource *resource, const char *mime_type) {
struct wlr_client_data_source *source = struct wlr_client_data_source *source =
client_data_source_from_resource(resource); client_data_source_from_resource(resource);
if (source == NULL) {
return;
}
if (source->finalized) {
wlr_log(WLR_DEBUG, "offering additional MIME type after "
"wl_data_device.set_selection");
}
char **p = wl_array_add(&source->source.mime_types, sizeof(*p)); char **p = wl_array_add(&source->source.mime_types, sizeof(*p));
if (p) { if (p) {
@ -210,17 +222,18 @@ static void data_source_offer(struct wl_client *client,
} }
static const struct wl_data_source_interface data_source_impl = { static const struct wl_data_source_interface data_source_impl = {
.offer = data_source_offer,
.destroy = data_source_destroy, .destroy = data_source_destroy,
.offer = data_source_offer,
.set_actions = data_source_set_actions, .set_actions = data_source_set_actions,
}; };
static void data_source_handle_resource_destroy(struct wl_resource *resource) { static void data_source_handle_resource_destroy(struct wl_resource *resource) {
struct wlr_client_data_source *source = struct wlr_client_data_source *source =
client_data_source_from_resource(resource); client_data_source_from_resource(resource);
wlr_data_source_finish(&source->source); if (source != NULL) {
wl_list_remove(wl_resource_get_link(source->resource)); wlr_data_source_destroy(&source->source);
free(source); }
wl_list_remove(wl_resource_get_link(resource));
} }
struct wlr_client_data_source *client_data_source_create( struct wlr_client_data_source *client_data_source_create(
@ -245,7 +258,7 @@ struct wlr_client_data_source *client_data_source_create(
source->impl.accept = client_data_source_accept; source->impl.accept = client_data_source_accept;
source->impl.send = client_data_source_send; source->impl.send = client_data_source_send;
source->impl.cancel = client_data_source_cancel; source->impl.destroy = client_data_source_destroy;
if (wl_resource_get_version(source->resource) >= if (wl_resource_get_version(source->resource) >=
WL_DATA_SOURCE_DND_DROP_PERFORMED_SINCE_VERSION) { WL_DATA_SOURCE_DND_DROP_PERFORMED_SINCE_VERSION) {

View file

@ -174,7 +174,7 @@ static uint32_t drag_handle_pointer_button(struct wlr_seat_pointer_grab *grab,
}; };
wlr_signal_emit_safe(&drag->events.drop, &event); wlr_signal_emit_safe(&drag->events.drop, &event);
} else if (drag->source->impl->dnd_finish) { } else if (drag->source->impl->dnd_finish) {
wlr_data_source_cancel(drag->source); wlr_data_source_destroy(drag->source);
} }
} }

View file

@ -159,7 +159,7 @@ void wlr_seat_destroy(struct wlr_seat *seat) {
if (seat->selection_source) { if (seat->selection_source) {
wl_list_remove(&seat->selection_source_destroy.link); wl_list_remove(&seat->selection_source_destroy.link);
wlr_data_source_cancel(seat->selection_source); wlr_data_source_destroy(seat->selection_source);
seat->selection_source = NULL; seat->selection_source = NULL;
} }

View file

@ -203,17 +203,16 @@ static void data_source_send(struct wlr_data_source *wlr_source,
mime_type, fd); mime_type, fd);
} }
static void data_source_cancel(struct wlr_data_source *wlr_source) { static void data_source_destroy(struct wlr_data_source *wlr_source) {
struct x11_data_source *source = struct x11_data_source *source =
data_source_from_wlr_data_source(wlr_source); data_source_from_wlr_data_source(wlr_source);
wlr_data_source_finish(&source->base);
wl_array_release(&source->mime_types_atoms); wl_array_release(&source->mime_types_atoms);
free(source); free(source);
} }
static const struct wlr_data_source_impl data_source_impl = { static const struct wlr_data_source_impl data_source_impl = {
.send = data_source_send, .send = data_source_send,
.cancel = data_source_cancel, .destroy = data_source_destroy,
}; };
struct x11_primary_selection_source { struct x11_primary_selection_source {
@ -353,7 +352,7 @@ static void xwm_selection_get_targets(struct wlr_xwm_selection *selection) {
wlr_seat_request_set_selection(xwm->seat, &source->base, wlr_seat_request_set_selection(xwm->seat, &source->base,
wl_display_next_serial(xwm->xwayland->wl_display)); wl_display_next_serial(xwm->xwayland->wl_display));
} else { } else {
wlr_data_source_cancel(&source->base); wlr_data_source_destroy(&source->base);
} }
} else if (selection == &xwm->primary_selection) { } else if (selection == &xwm->primary_selection) {
struct x11_primary_selection_source *source = struct x11_primary_selection_source *source =