<div dir="ltr"><div>Can you please explain in detail the difference between the actions being "COPY + MOVE" and being "COPY + MOVE + ASK". I do not at all understand the purpose of "ASK". It might also help to specify what should happen if ASK is combined with less than 2 other actions.<br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jan 11, 2016 at 12:30 AM, Jonas Ådahl <span dir="ltr"><<a href="mailto:jadahl@gmail.com" target="_blank">jadahl@gmail.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 Thu, Dec 24, 2015 at 02:00:38AM +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 set_actions requests on both wl_data_source and<br>
> wl_data_offer, weston now will emit the newly added "action" events<br>
> notifying both source and dest of the chosen action.<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>
<br>
</span>Mostly looks good; but I have some questions/comments related to how<br>
'ask' is implemented.<br>
<div><div class="h5"><br>
> Changes since v5:<br>
>   - Use enum types and values for not-a-bitfield stored values.<br>
>     handle errors when finding unexpected dnd_actions values.<br>
><br>
> Changes since v4:<br>
>   - Added compositor-side version checks. Spaces vs tabs fixes.<br>
>     Fixed resource versioning. Initialized new weston_data_source/offer<br>
>     fields.<br>
><br>
> Changes since v3:<br>
>   - Put data_source.action to use in the dnd client, now updates<br>
>     the dnd surface like data_source.target events do.<br>
><br>
> Changes since v2:<br>
>   - Split from DnD progress notification changes.<br>
><br>
> Changes since v1:<br>
>   - Updated to v2 of DnD actions protocol changes, implement<br>
>     wl_data_offer.source_actions.<br>
>   - Fixed coding style issues.<br>
><br>
> Signed-off-by: Carlos Garnacho <<a href="mailto:carlosg@gnome.org">carlosg@gnome.org</a>><br>
> Reviewed-by: Michael Catanzaro <<a href="mailto:mcatanzaro@igalia.com">mcatanzaro@igalia.com</a>><br>
> ---<br>
>  clients/dnd.c     |  32 ++++++++++---<br>
>  clients/window.c  |  25 +++++++++++<br>
>  src/compositor.h  |   4 ++<br>
>  src/data-device.c | 131 ++++++++++++++++++++++++++++++++++++++++++++++++++++--<br>
>  4 files changed, 183 insertions(+), 9 deletions(-)<br>
><br>
> diff --git a/clients/dnd.c b/clients/dnd.c<br>
> index 48111d9..ddf3fcc 100644<br>
> --- a/clients/dnd.c<br>
> +++ b/clients/dnd.c<br>
> @@ -72,6 +72,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>
> @@ -266,16 +267,13 @@ dnd_get_item(struct dnd *dnd, int32_t x, int32_t y)<br>
>  }<br>
><br>
>  static void<br>
> -data_source_target(void *data,<br>
> -                struct wl_data_source *source, const char *mime_type)<br>
> +dnd_drag_update_surface(struct dnd_drag *dnd_drag)<br>
>  {<br>
> -     struct dnd_drag *dnd_drag = data;<br>
>       struct dnd *dnd = dnd_drag->dnd;<br>
>       cairo_surface_t *surface;<br>
>       struct wl_buffer *buffer;<br>
><br>
> -     dnd_drag->mime_type = mime_type;<br>
> -     if (mime_type)<br>
> +     if (dnd_drag->mime_type && dnd_drag->dnd_action)<br>
>               surface = dnd_drag->opaque;<br>
>       else<br>
>               surface = dnd_drag->translucent;<br>
> @@ -288,6 +286,16 @@ data_source_target(void *data,<br>
>  }<br>
><br>
>  static void<br>
> +data_source_target(void *data,<br>
> +                struct wl_data_source *source, const char *mime_type)<br>
> +{<br>
> +     struct dnd_drag *dnd_drag = data;<br>
> +<br>
> +     dnd_drag->mime_type = mime_type;<br>
> +     dnd_drag_update_surface(dnd_drag);<br>
> +}<br>
> +<br>
> +static void<br>
>  data_source_send(void *data, struct wl_data_source *source,<br>
>                const char *mime_type, int32_t fd)<br>
>  {<br>
> @@ -360,12 +368,22 @@ data_source_drag_finished(void *data, struct wl_data_source *source)<br>
>       dnd_drag_destroy(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>
> +     dnd_drag_update_surface(dnd_drag);<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_drop_performed,<br>
>       data_source_drag_finished,<br>
> +     data_source_action,<br>
>  };<br>
><br>
>  static cairo_surface_t *<br>
> @@ -428,6 +446,8 @@ create_drag_source(struct dnd *dnd,<br>
>               dnd_drag->item = item;<br>
>               dnd_drag->x_offset = x - item->x;<br>
>               dnd_drag->y_offset = y - item->y;<br>
> +             dnd_drag->dnd_action = WL_DATA_DEVICE_MANAGER_DND_ACTION_MOVE;<br>
> +             dnd_drag->mime_type = NULL;<br>
><br>
>               for (i = 0; i < ARRAY_LENGTH(dnd->items); i++) {<br>
>                       if (item == dnd->items[i]){<br>
> @@ -461,6 +481,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_set_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 db96185..9c67b91 100644<br>
> --- a/clients/window.c<br>
> +++ b/clients/window.c<br>
> @@ -3362,6 +3362,8 @@ struct data_offer {<br>
>       int fd;<br>
>       data_func_t func;<br>
>       int32_t x, y;<br>
> +     uint32_t dnd_action;<br>
> +     uint32_t source_actions;<br>
>       void *user_data;<br>
>  };<br>
><br>
> @@ -3375,8 +3377,26 @@ 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_source_actions(void *data, struct wl_data_offer *wl_data_offer, uint32_t source_actions)<br>
> +{<br>
> +     struct data_offer *offer = data;<br>
> +<br>
> +     offer->source_actions = source_actions;<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_source_actions,<br>
> +     data_offer_action<br>
>  };<br>
><br>
>  static void<br>
> @@ -3440,6 +3460,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_set_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_MOVE);<br>
> +<br>
>       } else {<br>
>               input->drag_offer = NULL;<br>
>               types_data = NULL;<br>
> diff --git a/src/compositor.h b/src/compositor.h<br>
> index 83d6f7f..2956f98 100644<br>
> --- a/src/compositor.h<br>
> +++ b/src/compositor.h<br>
> @@ -298,6 +298,8 @@ 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>
> +     enum wl_data_device_manager_dnd_action preferred_dnd_action;<br>
>  };<br>
><br>
>  struct weston_data_source {<br>
> @@ -307,6 +309,8 @@ struct weston_data_source {<br>
>       struct weston_data_offer *offer;<br>
>       struct weston_seat *seat;<br>
>       bool accepted;<br>
> +     uint32_t dnd_actions;<br>
> +     enum wl_data_device_manager_dnd_action 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 9942a66..ab81ba9 100644<br>
> --- a/src/data-device.c<br>
> +++ b/src/data-device.c<br>
> @@ -56,6 +56,10 @@ struct weston_touch_drag {<br>
>       struct weston_touch_grab grab;<br>
>  };<br>
><br>
> +#define ALL_ACTIONS (WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY | \<br>
> +                  WL_DATA_DEVICE_MANAGER_DND_ACTION_MOVE | \<br>
> +                  WL_DATA_DEVICE_MANAGER_DND_ACTION_ASK)<br>
> +<br>
>  static void<br>
>  data_offer_accept(struct wl_client *client, struct wl_resource *resource,<br>
>                 uint32_t serial, const char *mime_type)<br>
> @@ -101,7 +105,8 @@ data_offer_notify_finish(struct weston_data_offer *offer)<br>
><br>
>       if (wl_resource_get_version(offer->source->resource) >=<br>
>           WL_DATA_SOURCE_DND_FINISHED_SINCE_VERSION) {<br>
> -             if (offer->source->accepted)<br>
> +             if (offer->source->accepted &&<br>
> +                 offer->source->current_dnd_action)<br>
>                       wl_data_source_send_dnd_finished(offer->source->resource);<br>
>               else<br>
>                       wl_data_source_send_cancelled(offer->source->resource);<br>
> @@ -110,6 +115,86 @@ data_offer_notify_finish(struct weston_data_offer *offer)<br>
>       offer->source->offer = NULL;<br>
>  }<br>
><br>
> +static uint32_t<br>
> +data_offer_choose_action(struct weston_data_offer *offer)<br>
> +{<br>
> +     uint32_t available_actions, preferred_action = 0;<br>
> +     uint32_t source_actions, offer_actions;<br>
> +<br>
> +     if (wl_resource_get_version(offer->resource) >=<br>
> +         WL_DATA_OFFER_ACTION_SINCE_VERSION) {<br>
> +             offer_actions = offer->dnd_actions;<br>
> +             preferred_action = offer->preferred_dnd_action;<br>
> +     } else {<br>
> +             offer_actions = WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY;<br>
> +     }<br>
> +<br>
> +     if (wl_resource_get_version(offer->source->resource) >=<br>
> +         WL_DATA_SOURCE_ACTION_SINCE_VERSION)<br>
> +             source_actions = offer->source->dnd_actions;<br>
> +     else<br>
> +             source_actions = WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY;<br>
> +<br>
> +     available_actions = offer_actions & source_actions;<br>
> +<br>
> +     if (!available_actions)<br>
> +             return WL_DATA_DEVICE_MANAGER_DND_ACTION_NONE;<br>
> +<br>
> +     /* If the dest side has a preferred DnD action, use it */<br>
> +     if ((preferred_action & available_actions) != 0)<br>
> +             return preferred_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>
> +<br>
> +     if (wl_resource_get_version(offer->source->resource) >=<br>
> +         WL_DATA_SOURCE_ACTION_SINCE_VERSION)<br>
> +             wl_data_source_send_action(offer->source->resource, action);<br>
> +<br>
> +     if (wl_resource_get_version(offer->resource) >=<br>
> +         WL_DATA_OFFER_ACTION_SINCE_VERSION)<br>
> +             wl_data_offer_send_action(offer->resource, action);<br>
<br>
</div></div>Should we still send action after an 'ask' was dropped and the<br>
destination chose a final action?<br>
<span class=""><br>
> +}<br>
> +<br>
> +static void<br>
> +data_offer_set_actions(struct wl_client *client,<br>
> +                    struct wl_resource *resource,<br>
> +                    uint32_t dnd_actions, uint32_t preferred_action)<br>
> +{<br>
> +     struct weston_data_offer *offer = wl_resource_get_user_data(resource);<br>
> +<br>
> +     if (dnd_actions & ~ALL_ACTIONS) {<br>
> +             wl_resource_post_error(offer->resource,<br>
> +                                    WL_DATA_OFFER_ERROR_INVALID_ACTION_MASK,<br>
> +                                    "invalid action mask %x", dnd_actions);<br>
> +             return;<br>
> +     }<br>
> +<br>
> +     if (__builtin_popcount(preferred_action) > 1) {<br>
> +             wl_resource_post_error(offer->resource,<br>
> +                                    WL_DATA_OFFER_ERROR_INVALID_ACTION,<br>
> +                                    "invalid action %x", preferred_action);<br>
> +             return;<br>
> +     }<br>
<br>
</span>Should we not error if a destination set more than one action after an<br>
'ask' was performed?<br>
<span class=""><br>
> +<br>
> +     offer->dnd_actions = dnd_actions;<br>
> +     offer->preferred_dnd_action = preferred_action;<br>
> +     data_offer_update_action(offer);<br>
> +}<br>
> +<br>
>  static void<br>
>  data_offer_finish(struct wl_client *client, struct wl_resource *resource)<br>
>  {<br>
> @@ -134,6 +219,7 @@ static const struct wl_data_offer_interface data_offer_interface = {<br>
>       data_offer_receive,<br>
>       data_offer_destroy,<br>
>       data_offer_finish,<br>
> +     data_offer_set_actions,<br>
>  };<br>
><br>
>  static void<br>
> @@ -146,7 +232,7 @@ destroy_data_offer(struct wl_resource *resource)<br>
>                * won't be called, so do this here as a safety net, because<br>
>                * we still want the version >=3 drag source to be happy.<br>
>                */<br>
> -             if (wl_resource_get_version (offer->source->resource) <<br>
> +             if (wl_resource_get_version(offer->source->resource) <<br>
<br>
</span>Seems this change leaked over from the previous patch.<br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
Jonas<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
>                   WL_DATA_SOURCE_DND_FINISHED_SINCE_VERSION)<br>
>                       data_offer_notify_finish(offer);<br>
>               else<br>
> @@ -181,7 +267,8 @@ 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,<br>
> +                                wl_resource_get_version(source->resource), 0);<br>
>       if (offer->resource == NULL) {<br>
>               free(offer);<br>
>               return NULL;<br>
> @@ -190,6 +277,8 @@ weston_data_source_send_offer(struct weston_data_source *source,<br>
>       wl_resource_set_implementation(offer->resource, &data_offer_interface,<br>
>                                      offer, destroy_data_offer);<br>
><br>
> +     offer->dnd_actions = 0;<br>
> +     offer->preferred_dnd_action = WL_DATA_DEVICE_MANAGER_DND_ACTION_NONE;<br>
>       offer->source = source;<br>
>       offer->source_destroy_listener.notify = destroy_offer_data_source;<br>
>       wl_signal_add(&source->destroy_signal,<br>
> @@ -202,6 +291,7 @@ weston_data_source_send_offer(struct weston_data_source *source,<br>
><br>
>       source->offer = offer;<br>
>       source->accepted = false;<br>
> +     data_offer_update_action(offer);<br>
><br>
>       return offer->resource;<br>
>  }<br>
> @@ -228,9 +318,40 @@ data_source_destroy(struct wl_client *client, struct wl_resource *resource)<br>
>       wl_resource_destroy(resource);<br>
>  }<br>
><br>
> +static void<br>
> +data_source_set_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>
> +     if (dnd_actions & ~ALL_ACTIONS) {<br>
> +             wl_resource_post_error(source->resource,<br>
> +                                    WL_DATA_SOURCE_ERROR_INVALID_ACTION_MASK,<br>
> +                                    "invalid action mask %x", dnd_actions);<br>
> +             return;<br>
> +     }<br>
> +<br>
> +     if (source->dnd_actions == dnd_actions)<br>
> +             return;<br>
> +<br>
> +     source->dnd_actions = dnd_actions;<br>
> +<br>
> +     if (source->offer) {<br>
> +             if (wl_resource_get_version(source->offer->resource) >=<br>
> +                 WL_DATA_OFFER_SOURCE_ACTIONS_SINCE_VERSION) {<br>
> +                     wl_data_offer_send_source_actions(source->offer->resource,<br>
> +                                                       dnd_actions);<br>
> +             }<br>
> +             data_offer_update_action(source->offer);<br>
> +     }<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_set_actions<br>
>  };<br>
><br>
>  static void<br>
> @@ -951,6 +1072,8 @@ create_data_source(struct wl_client *client,<br>
>       source->cancel = client_source_cancel;<br>
>       source->offer = NULL;<br>
>       source->accepted = false;<br>
> +     source->dnd_actions = 0;<br>
> +     source->current_dnd_action = WL_DATA_DEVICE_MANAGER_DND_ACTION_NONE;<br>
><br>
>       wl_array_init(&source->mime_types);<br>
><br>
> --<br>
> 2.5.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" rel="noreferrer" 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" rel="noreferrer" target="_blank">http://lists.freedesktop.org/mailman/listinfo/wayland-devel</a><br>
</div></div></blockquote></div><br></div>