<div dir="ltr"><div><div>Just a cosmetic: there are mixed coding styles like 'function(...)' and 'function (...)' (space between name function and the parenthesis). It should be unified, preferably to weston (wayland) coding style (no space)<br><br></div>Cheers,<br></div>Marek<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Mar 18, 2015 at 8:20 PM, Bryce Harrington <span dir="ltr"><<a href="mailto:bryce@osg.samsung.com" target="_blank">bryce@osg.samsung.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Mon, Feb 16, 2015 at 04:37:35PM +0100, Carlos Garnacho wrote:<br>
> The policy in weston in order to determine the chosen DnD action is<br>
> deliberately simple, and is probably the minimals that any compositor<br>
> should be doing here.<br>
><br>
> Besides honoring the notify_actions requests on both wl_data_source<br>
> and wl_data_offer, weston now emits the newly added events notifying<br>
> both source and dest sides of the chosen action and operation progress.<br>
><br>
> The "dnd" client has been updated too (although minimally), so it<br>
> notifies the compositor of a "move" action on both sides.<br>
><br>
> Signed-off-by: Carlos Garnacho <<a href="mailto:carlosg@gnome.org">carlosg@gnome.org</a>><br>
<br>
</span>Seems like a reasonable implementation of the proposed protocol.<br>
<br>
Reviewed-by: Bryce Harrington <<a href="mailto:bryce@osg.samsung.com">bryce@osg.samsung.com</a>><br>
<div class="HOEnZb"><div class="h5"><br>
> ---<br>
> clients/dnd.c | 26 +++++++++++++++-<br>
> clients/window.c | 17 ++++++++++-<br>
> src/compositor.h | 5 +++<br>
> src/data-device.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++-----<br>
> 4 files changed, 130 insertions(+), 9 deletions(-)<br>
><br>
> diff --git a/clients/dnd.c b/clients/dnd.c<br>
> index e893d36..c9da1d0 100644<br>
> --- a/clients/dnd.c<br>
> +++ b/clients/dnd.c<br>
> @@ -70,6 +70,7 @@ struct dnd_drag {<br>
> struct item *item;<br>
> int x_offset, y_offset;<br>
> int width, height;<br>
> + uint32_t dnd_action;<br>
> const char *mime_type;<br>
><br>
> struct wl_surface *drag_surface;<br>
> @@ -337,10 +338,31 @@ data_source_cancelled(void *data, struct wl_data_source *source)<br>
> free(dnd_drag);<br>
> }<br>
><br>
> +static void<br>
> +data_source_action(void *data, struct wl_data_source *source, uint32_t dnd_action)<br>
> +{<br>
> + struct dnd_drag *dnd_drag = data;<br>
> +<br>
> + dnd_drag->dnd_action = dnd_action;<br>
> +}<br>
> +<br>
> +static void<br>
> +data_source_drop_performed(void *data, struct wl_data_source *source)<br>
> +{<br>
> +}<br>
> +<br>
> +static void<br>
> +data_source_finished(void *data, struct wl_data_source *source)<br>
> +{<br>
> +}<br>
> +<br>
> static const struct wl_data_source_listener data_source_listener = {<br>
> data_source_target,<br>
> data_source_send,<br>
> - data_source_cancelled<br>
> + data_source_cancelled,<br>
> + data_source_action,<br>
> + data_source_drop_performed,<br>
> + data_source_finished<br>
> };<br>
><br>
> static cairo_surface_t *<br>
> @@ -436,6 +458,8 @@ create_drag_source(struct dnd *dnd,<br>
> window_get_wl_surface(dnd->window),<br>
> dnd_drag->drag_surface,<br>
> serial);<br>
> + wl_data_source_notify_actions (dnd_drag->data_source,<br>
> + WL_DATA_DEVICE_MANAGER_DND_ACTION_MOVE);<br>
><br>
> dnd_drag->opaque =<br>
> create_drag_icon(dnd_drag, item, x, y, 1);<br>
> diff --git a/clients/window.c b/clients/window.c<br>
> index c5082ba..fa654df 100644<br>
> --- a/clients/window.c<br>
> +++ b/clients/window.c<br>
> @@ -3320,6 +3320,7 @@ struct data_offer {<br>
> int fd;<br>
> data_func_t func;<br>
> int32_t x, y;<br>
> + uint32_t dnd_action;<br>
> void *user_data;<br>
> };<br>
><br>
> @@ -3333,8 +3334,17 @@ data_offer_offer(void *data, struct wl_data_offer *wl_data_offer, const char *ty<br>
> *p = strdup(type);<br>
> }<br>
><br>
> +static void<br>
> +data_offer_action(void *data, struct wl_data_offer *wl_data_offer, uint32_t dnd_action)<br>
> +{<br>
> + struct data_offer *offer = data;<br>
> +<br>
> + offer->dnd_action = dnd_action;<br>
> +}<br>
> +<br>
> static const struct wl_data_offer_listener data_offer_listener = {<br>
> data_offer_offer,<br>
> + data_offer_action<br>
> };<br>
><br>
> static void<br>
> @@ -3398,6 +3408,11 @@ data_device_enter(void *data, struct wl_data_device *data_device,<br>
> *p = NULL;<br>
><br>
> types_data = input->drag_offer->types.data;<br>
> + wl_data_offer_notify_actions (offer,<br>
> + WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY |<br>
> + WL_DATA_DEVICE_MANAGER_DND_ACTION_MOVE,<br>
> + WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY);<br>
> +<br>
> } else {<br>
> input->drag_offer = NULL;<br>
> types_data = NULL;<br>
> @@ -5277,7 +5292,7 @@ registry_handle_global(void *data, struct wl_registry *registry, uint32_t id,<br>
> d->shm = wl_registry_bind(registry, id, &wl_shm_interface, 1);<br>
> wl_shm_add_listener(d->shm, &shm_listener, d);<br>
> } else if (strcmp(interface, "wl_data_device_manager") == 0) {<br>
> - d->data_device_manager_version = MIN(version, 2);<br>
> + d->data_device_manager_version = MIN(version, 3);<br>
> d->data_device_manager =<br>
> wl_registry_bind(registry, id,<br>
> &wl_data_device_manager_interface,<br>
> diff --git a/src/compositor.h b/src/compositor.h<br>
> index 5c0ea74..0adcde6 100644<br>
> --- a/src/compositor.h<br>
> +++ b/src/compositor.h<br>
> @@ -298,12 +298,17 @@ struct weston_data_offer {<br>
> struct wl_resource *resource;<br>
> struct weston_data_source *source;<br>
> struct wl_listener source_destroy_listener;<br>
> + uint32_t dnd_actions;<br>
> + uint32_t preferred_dnd_action;<br>
> };<br>
><br>
> struct weston_data_source {<br>
> struct wl_resource *resource;<br>
> struct wl_signal destroy_signal;<br>
> struct wl_array mime_types;<br>
> + struct weston_data_offer *offer;<br>
> + uint32_t dnd_actions;<br>
> + uint32_t current_dnd_action;<br>
><br>
> void (*accept)(struct weston_data_source *source,<br>
> uint32_t serial, const char *mime_type);<br>
> diff --git a/src/data-device.c b/src/data-device.c<br>
> index a0913a2..e5fa128 100644<br>
> --- a/src/data-device.c<br>
> +++ b/src/data-device.c<br>
> @@ -84,10 +84,57 @@ data_offer_destroy(struct wl_client *client, struct wl_resource *resource)<br>
> wl_resource_destroy(resource);<br>
> }<br>
><br>
> +static uint32_t<br>
> +data_offer_choose_action (struct weston_data_offer *offer)<br>
> +{<br>
> + uint32_t available_actions;<br>
> +<br>
> + available_actions = offer->dnd_actions & offer->source->dnd_actions;<br>
> +<br>
> + if (!available_actions)<br>
> + return 0;<br>
> +<br>
> + /* If the dest side has a preferred DnD action, use it */<br>
> + if ((offer->preferred_dnd_action & available_actions) != 0)<br>
> + return offer->preferred_dnd_action;<br>
> +<br>
> + /* Use the first found action, in bit order */<br>
> + return 1 << (ffs (available_actions) - 1);<br>
> +}<br>
> +<br>
> +static void<br>
> +data_offer_update_action (struct weston_data_offer *offer)<br>
> +{<br>
> + uint32_t action;<br>
> +<br>
> + action = data_offer_choose_action (offer);<br>
> +<br>
> + if (offer->source->current_dnd_action == action)<br>
> + return;<br>
> +<br>
> + offer->source->current_dnd_action = action;<br>
> + wl_data_source_send_action (offer->source->resource, action);<br>
> + wl_data_offer_send_action (offer->resource, action);<br>
> +}<br>
> +<br>
> +static void<br>
> +data_offer_notify_actions (struct wl_client *client,<br>
> + struct wl_resource *resource,<br>
> + uint32_t dnd_actions,<br>
> + uint32_t preferred_action)<br>
> +{<br>
> + struct weston_data_offer *offer = wl_resource_get_user_data(resource);<br>
> +<br>
> + offer->dnd_actions = dnd_actions;<br>
> + offer->preferred_dnd_action = preferred_action;<br>
> + data_offer_update_action (offer);<br>
> +}<br>
> +<br>
> static const struct wl_data_offer_interface data_offer_interface = {<br>
> data_offer_accept,<br>
> data_offer_receive,<br>
> data_offer_destroy,<br>
> + data_offer_notify_actions<br>
> };<br>
><br>
> static void<br>
> @@ -95,8 +142,14 @@ destroy_data_offer(struct wl_resource *resource)<br>
> {<br>
> struct weston_data_offer *offer = wl_resource_get_user_data(resource);<br>
><br>
> - if (offer->source)<br>
> + if (offer->source) {<br>
> + if (offer->source->offer == offer) {<br>
> + wl_data_source_send_finished(offer->source->resource);<br>
> + offer->source->offer = NULL;<br>
> + }<br>
> +<br>
> wl_list_remove(&offer->source_destroy_listener.link);<br>
> + }<br>
> free(offer);<br>
> }<br>
><br>
> @@ -124,7 +177,7 @@ weston_data_source_send_offer(struct weston_data_source *source,<br>
><br>
> offer->resource =<br>
> wl_resource_create(wl_resource_get_client(target),<br>
> - &wl_data_offer_interface, 1, 0);<br>
> + &wl_data_offer_interface, 3, 0);<br>
> if (offer->resource == NULL) {<br>
> free(offer);<br>
> return NULL;<br>
> @@ -143,6 +196,9 @@ weston_data_source_send_offer(struct weston_data_source *source,<br>
> wl_array_for_each(p, &source->mime_types)<br>
> wl_data_offer_send_offer(offer->resource, *p);<br>
><br>
> + data_offer_update_action (offer);<br>
> + source->offer = offer;<br>
> +<br>
> return offer->resource;<br>
> }<br>
><br>
> @@ -168,9 +224,24 @@ data_source_destroy(struct wl_client *client, struct wl_resource *resource)<br>
> wl_resource_destroy(resource);<br>
> }<br>
><br>
> +static void<br>
> +data_source_notify_actions (struct wl_client *client,<br>
> + struct wl_resource *resource,<br>
> + uint32_t dnd_actions)<br>
> +{<br>
> + struct weston_data_source *source =<br>
> + wl_resource_get_user_data(resource);<br>
> +<br>
> + source->dnd_actions = dnd_actions;<br>
> +<br>
> + if (source->offer)<br>
> + data_offer_update_action (source->offer);<br>
> +}<br>
> +<br>
> static struct wl_data_source_interface data_source_interface = {<br>
> data_source_offer,<br>
> - data_source_destroy<br>
> + data_source_destroy,<br>
> + data_source_notify_actions<br>
> };<br>
><br>
> static void<br>
> @@ -395,8 +466,14 @@ drag_grab_button(struct weston_pointer_grab *grab,<br>
><br>
> if (drag->base.focus_resource &&<br>
> pointer->grab_button == button &&<br>
> - state == WL_POINTER_BUTTON_STATE_RELEASED)<br>
> - wl_data_device_send_drop(drag->base.focus_resource);<br>
> + state == WL_POINTER_BUTTON_STATE_RELEASED) {<br>
> + if (drag->base.data_source->current_dnd_action) {<br>
> + wl_data_device_send_drop(drag->base.focus_resource);<br>
> + wl_data_source_send_drop_performed(drag->base.data_source->resource);<br>
> + } else if (drag->base.data_source) {<br>
> + wl_data_source_send_cancelled(drag->base.data_source->resource);<br>
> + }<br>
> + }<br>
><br>
> if (pointer->button_count == 0 &&<br>
> state == WL_POINTER_BUTTON_STATE_RELEASED) {<br>
> @@ -851,7 +928,7 @@ create_data_source(struct wl_client *client,<br>
> wl_array_init(&source->mime_types);<br>
><br>
> source->resource =<br>
> - wl_resource_create(client, &wl_data_source_interface, 1, id);<br>
> + wl_resource_create(client, &wl_data_source_interface, 3, id);<br>
> wl_resource_set_implementation(source->resource, &data_source_interface,<br>
> source, destroy_data_source);<br>
> }<br>
> @@ -937,7 +1014,7 @@ WL_EXPORT int<br>
> wl_data_device_manager_init(struct wl_display *display)<br>
> {<br>
> if (wl_global_create(display,<br>
> - &wl_data_device_manager_interface, 2,<br>
> + &wl_data_device_manager_interface, 3,<br>
> NULL, bind_manager) == NULL)<br>
> return -1;<br>
><br>
> --<br>
> 2.1.0<br>
><br>
> _______________________________________________<br>
> wayland-devel mailing list<br>
> <a href="mailto:wayland-devel@lists.freedesktop.org">wayland-devel@lists.freedesktop.org</a><br>
> <a href="http://lists.freedesktop.org/mailman/listinfo/wayland-devel" target="_blank">http://lists.freedesktop.org/mailman/listinfo/wayland-devel</a><br>
_______________________________________________<br>
wayland-devel mailing list<br>
<a href="mailto:wayland-devel@lists.freedesktop.org">wayland-devel@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/wayland-devel" target="_blank">http://lists.freedesktop.org/mailman/listinfo/wayland-devel</a><br>
</div></div></blockquote></div><br></div>