[PATCH weston v3] data-device: Implement DnD actions

Carlos Garnacho carlosg at gnome.org
Mon Nov 2 08:53:58 PST 2015


On Sat, Oct 31, 2015 at 12:22 AM, Michael Catanzaro
<mcatanzaro at igalia.com> wrote:
> On Fri, 2015-10-30 at 22:06 +0100, Carlos Garnacho wrote:
>> --- a/clients/dnd.c
>> +++ b/clients/dnd.c
>> @@ -72,6 +72,7 @@ struct dnd_drag {
>>       struct item *item;
>>       int x_offset, y_offset;
>>       int width, height;
>> +     uint32_t dnd_action;
>>       const char *mime_type;
>>
>>       struct wl_surface *drag_surface;
>> @@ -360,12 +361,21 @@ data_source_drag_finished(void *data, struct
>> wl_data_source *source)
>>       destroy_dnd_drag(dnd_drag);
>>  }
>>
>> +static void
>> +data_source_action(void *data, struct wl_data_source *source,
>> uint32_t dnd_action)
>> +{
>> +     struct dnd_drag *dnd_drag = data;
>> +
>> +     dnd_drag->dnd_action = dnd_action;
>> +}
>> +
>>  static const struct wl_data_source_listener data_source_listener = {
>>       data_source_target,
>>       data_source_send,
>>       data_source_cancelled,
>>       data_source_drop_performed,
>>       data_source_drag_finished,
>> +     data_source_action,
>>  };
>>
>>  static cairo_surface_t *
>> @@ -461,6 +471,8 @@ create_drag_source(struct dnd *dnd,
>>                                         window_get_wl_surface(dnd
>> ->window),
>>                                         dnd_drag->drag_surface,
>>                                         serial);
>> +             wl_data_source_set_actions(dnd_drag->data_source,
>> +
>>  WL_DATA_DEVICE_MANAGER_DND_ACTION_MOVE);
>>
>>               dnd_drag->opaque =
>>                       create_drag_icon(dnd_drag, item, x, y, 1);
>> diff --git a/clients/window.c b/clients/window.c
>> index 24aa517..146d4a7 100644
>> --- a/clients/window.c
>> +++ b/clients/window.c
>> @@ -3362,6 +3362,8 @@ struct data_offer {
>>       int fd;
>>       data_func_t func;
>>       int32_t x, y;
>> +     uint32_t dnd_action;
>> +     uint32_t source_actions;
>>       void *user_data;
>>  };
>>
>> @@ -3375,8 +3377,26 @@ data_offer_offer(void *data, struct
>> wl_data_offer *wl_data_offer, const char *ty
>>       *p = strdup(type);
>>  }
>>
>> +static void
>> +data_offer_source_actions(void *data, struct wl_data_offer
>> *wl_data_offer, uint32_t source_actions)
>> +{
>> +     struct data_offer *offer = data;
>> +
>> +     offer->source_actions = source_actions;
>> +}
>> +
>> +static void
>> +data_offer_action(void *data, struct wl_data_offer *wl_data_offer,
>> uint32_t dnd_action)
>> +{
>> +     struct data_offer *offer = data;
>> +
>> +     offer->dnd_action = dnd_action;
>> +}
>> +
>>  static const struct wl_data_offer_listener data_offer_listener = {
>>       data_offer_offer,
>> +     data_offer_source_actions,
>> +     data_offer_action
>>  };
>>
>>  static void
>> @@ -3440,6 +3460,11 @@ data_device_enter(void *data, struct
>> wl_data_device *data_device,
>>               *p = NULL;
>>
>>               types_data = input->drag_offer->types.data;
>> +             wl_data_offer_set_actions(offer,
>> +
>>  WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY |
>> +
>>  WL_DATA_DEVICE_MANAGER_DND_ACTION_MOVE,
>> +
>>  WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY);
>> +
>>       } else {
>>               input->drag_offer = NULL;
>>               types_data = NULL;
>
> Is it normal to add unused variables in the example clients
> (dnd_drag.source_action, data_offer.dnd_action,
> data_offer.source_actions)? I guess there is some value in terms of
> serving as an example -- is that why you've done this? -- but it seems
> a bit silly to me; I would have left the implementations of those
> functions empty.

Yeah, you're right It doesn't make too much of an example... I changed
it locally to make it control the drag icon surface together with
data_source.target, so you need mime_type != NULL && action != 0 in
order to get the opaque icon, that's as realistic as it can get given
the dnd client workings I guess...

>
> Reviewed-by: Michael Catanzaro <mcatanzaro at igalia.com>

Thanks!

  Carlos


More information about the wayland-devel mailing list