From 2eb1eac6a6d6025203313dfea945097b3257622a Mon Sep 17 00:00:00 2001 From: Seunghun Lee Date: Thu, 11 Aug 2022 17:44:59 +0900 Subject: [PATCH] data_device: Add dnd implementation to ds_data_source_client Change-Id: I2c08a3a803419e079bf0607dbfd2bae699732fc7 --- src/data_device/data_source_client.c | 79 +++++++++++++++++++++++++++++++++++- 1 file changed, 78 insertions(+), 1 deletion(-) diff --git a/src/data_device/data_source_client.c b/src/data_device/data_source_client.c index 11501f8..3fa1225 100644 --- a/src/data_device/data_source_client.c +++ b/src/data_device/data_source_client.c @@ -13,6 +13,13 @@ static void data_source_client_iface_accept(struct ds_data_source *source, static void data_handle_client_iface_send(struct ds_data_source *source, const char *mime_type, int32_t fd); static void data_source_client_iface_destroy(struct ds_data_source *source); +static void data_source_client_iface_dnd_drop( + struct ds_data_source *ds_source); +static void data_source_client_iface_dnd_finish( + struct ds_data_source *ds_source); +static void data_source_client_iface_dnd_action( + struct ds_data_source *ds_source, + enum wl_data_device_manager_dnd_action action); struct ds_data_source_client * create_data_source_client(struct wl_client *client, uint32_t version, @@ -39,6 +46,21 @@ create_data_source_client(struct wl_client *client, uint32_t version, source->iface.send = data_handle_client_iface_send; source->iface.destroy = data_source_client_iface_destroy; + if (wl_resource_get_version(source->resource) >= + WL_DATA_SOURCE_DND_DROP_PERFORMED_SINCE_VERSION) { + source->iface.dnd_drop = data_source_client_iface_dnd_drop; + } + + if (wl_resource_get_version(source->resource) >= + WL_DATA_SOURCE_DND_FINISHED_SINCE_VERSION) { + source->iface.dnd_finish = data_source_client_iface_dnd_finish; + } + + if (wl_resource_get_version(source->resource) >= + WL_DATA_SOURCE_ACTION_SINCE_VERSION) { + source->iface.dnd_action = data_source_client_iface_dnd_action; + } + ds_data_source_init(&source->base, &source->iface); return source; @@ -114,7 +136,28 @@ data_source_client_handle_set_actions(struct wl_client *client, if (!source) return; - // TODO + if (source->base.actions >= 0) { + wl_resource_post_error(source->resource, + WL_DATA_SOURCE_ERROR_INVALID_ACTION_MASK, + "cannot set actions more than once"); + return; + } + + if (dnd_actions & ~DATA_DEVICE_ALL_ACTIONS) { + wl_resource_post_error(source->resource, + WL_DATA_SOURCE_ERROR_INVALID_ACTION_MASK, + "invalid action mask %x", dnd_actions); + return; + } + + if (source->finalized) { + wl_resource_post_error(source->resource, + WL_DATA_SOURCE_ERROR_INVALID_ACTION_MASK, + "invalid action change after wl_data_device.start_drag"); + return; + } + + source->base.actions = dnd_actions; } static const struct wl_data_source_interface wl_data_source_iface = { @@ -161,3 +204,37 @@ data_source_client_iface_destroy(struct ds_data_source *ds_source) wl_resource_set_user_data(source->resource, NULL); free(source); } + +static void +data_source_client_iface_dnd_drop(struct ds_data_source *ds_source) +{ + struct ds_data_source_client *source; + + source = data_source_client_from_data_source(ds_source); + assert(wl_resource_get_version(source->resource) >= + WL_DATA_SOURCE_DND_DROP_PERFORMED_SINCE_VERSION); + wl_data_source_send_dnd_drop_performed(source->resource); +} + +static void +data_source_client_iface_dnd_finish(struct ds_data_source *ds_source) +{ + struct ds_data_source_client *source; + + source = data_source_client_from_data_source(ds_source); + assert(wl_resource_get_version(source->resource) >= + WL_DATA_SOURCE_DND_FINISHED_SINCE_VERSION); + wl_data_source_send_dnd_finished(source->resource); +} + +static void +data_source_client_iface_dnd_action(struct ds_data_source *ds_source, + enum wl_data_device_manager_dnd_action action) +{ + struct ds_data_source_client *source; + + source = data_source_client_from_data_source(ds_source); + assert(wl_resource_get_version(source->resource) >= + WL_DATA_SOURCE_ACTION_SINCE_VERSION); + wl_data_source_send_dnd_finished(source->resource); +} -- 2.7.4