mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2025-10-31 22:25:21 -04:00
data-device: make sources inert, rename cancel to destroy
This commit is contained in:
parent
4cb0697e57
commit
1150ff13ce
6 changed files with 45 additions and 38 deletions
|
|
@ -155,7 +155,7 @@ void wlr_seat_set_selection(struct wlr_seat *seat,
|
|||
struct wlr_data_source *source, uint32_t serial) {
|
||||
if (seat->selection_source) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,20 +40,6 @@ void wlr_data_source_init(struct wlr_data_source *source,
|
|||
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,
|
||||
int32_t 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) {
|
||||
if (source->impl->cancel) {
|
||||
source->impl->cancel(source);
|
||||
void wlr_data_source_destroy(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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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 =
|
||||
client_data_source_from_wlr_data_source(wlr_source);
|
||||
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) {
|
||||
|
|
@ -167,6 +169,9 @@ static void data_source_set_actions(struct wl_client *client,
|
|||
struct wl_resource *resource, uint32_t dnd_actions) {
|
||||
struct wlr_client_data_source *source =
|
||||
client_data_source_from_resource(resource);
|
||||
if (source == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (source->source.actions >= 0) {
|
||||
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 wlr_client_data_source *source =
|
||||
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));
|
||||
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 = {
|
||||
.offer = data_source_offer,
|
||||
.destroy = data_source_destroy,
|
||||
.offer = data_source_offer,
|
||||
.set_actions = data_source_set_actions,
|
||||
};
|
||||
|
||||
static void data_source_handle_resource_destroy(struct wl_resource *resource) {
|
||||
struct wlr_client_data_source *source =
|
||||
client_data_source_from_resource(resource);
|
||||
wlr_data_source_finish(&source->source);
|
||||
wl_list_remove(wl_resource_get_link(source->resource));
|
||||
free(source);
|
||||
if (source != NULL) {
|
||||
wlr_data_source_destroy(&source->source);
|
||||
}
|
||||
wl_list_remove(wl_resource_get_link(resource));
|
||||
}
|
||||
|
||||
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.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) >=
|
||||
WL_DATA_SOURCE_DND_DROP_PERFORMED_SINCE_VERSION) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
} else if (drag->source->impl->dnd_finish) {
|
||||
wlr_data_source_cancel(drag->source);
|
||||
wlr_data_source_destroy(drag->source);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -159,7 +159,7 @@ void wlr_seat_destroy(struct wlr_seat *seat) {
|
|||
|
||||
if (seat->selection_source) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue