aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/wlr/types/wlr_data_device.h11
-rw-r--r--types/data_device/wlr_data_device.c2
-rw-r--r--types/data_device/wlr_data_source.c59
-rw-r--r--types/data_device/wlr_drag.c2
-rw-r--r--types/seat/wlr_seat.c2
-rw-r--r--xwayland/selection/incoming.c7
6 files changed, 45 insertions, 38 deletions
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);
@@ -187,11 +187,6 @@ 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
diff --git a/types/data_device/wlr_data_device.c b/types/data_device/wlr_data_device.c
index 30f7d035..f2bcb806 100644
--- a/types/data_device/wlr_data_device.c
+++ b/types/data_device/wlr_data_device.c
@@ -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;
}
diff --git a/types/data_device/wlr_data_source.c b/types/data_device/wlr_data_source.c
index 413f461a..a2878aed 100644
--- a/types/data_device/wlr_data_source.c
+++ b/types/data_device/wlr_data_source.c
@@ -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) {
diff --git a/types/data_device/wlr_drag.c b/types/data_device/wlr_drag.c
index 8e737597..8b4048c8 100644
--- a/types/data_device/wlr_drag.c
+++ b/types/data_device/wlr_drag.c
@@ -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);
}
}
diff --git a/types/seat/wlr_seat.c b/types/seat/wlr_seat.c
index c2503658..bc092fc6 100644
--- a/types/seat/wlr_seat.c
+++ b/types/seat/wlr_seat.c
@@ -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;
}
diff --git a/xwayland/selection/incoming.c b/xwayland/selection/incoming.c
index e3f68ea7..290af0bf 100644
--- a/xwayland/selection/incoming.c
+++ b/xwayland/selection/incoming.c
@@ -203,17 +203,16 @@ static void data_source_send(struct wlr_data_source *wlr_source,
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 =
data_source_from_wlr_data_source(wlr_source);
- wlr_data_source_finish(&source->base);
wl_array_release(&source->mime_types_atoms);
free(source);
}
static const struct wlr_data_source_impl data_source_impl = {
.send = data_source_send,
- .cancel = data_source_cancel,
+ .destroy = data_source_destroy,
};
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,
wl_display_next_serial(xwm->xwayland->wl_display));
} else {
- wlr_data_source_cancel(&source->base);
+ wlr_data_source_destroy(&source->base);
}
} else if (selection == &xwm->primary_selection) {
struct x11_primary_selection_source *source =