data-device: Implement DnD actions

The policy in weston in order to determine the chosen DnD action is
deliberately simple, and is probably the minimals that any compositor
should be doing here.

Besides honoring the set_actions requests on both wl_data_source and
wl_data_offer, weston now will emit the newly added "action" events
notifying both source and dest of the chosen action.

The "dnd" client has been updated too (although minimally), so it
notifies the compositor of a "move" action on both sides.

Changes since v8:
  - Add back wl_data_offer.source_actions emission, gone during last
    code shuffling. Fix nits found in review.

Changes since v7:
  - Fixes spotted during review. Add client-side version checks.
    Implement .action emission as specified in protocol patch v11.

Changes since v6:
  - Emit errors as defined in DnD actions patch v10.

Changes since v5:
  - Use enum types and values for not-a-bitfield stored values.
    handle errors when finding unexpected dnd_actions values.

Changes since v4:
  - Added compositor-side version checks. Spaces vs tabs fixes.
    Fixed resource versioning. Initialized new weston_data_source/offer
    fields.

Changes since v3:
  - Put data_source.action to use in the dnd client, now updates
    the dnd surface like data_source.target events do.

Changes since v2:
  - Split from DnD progress notification changes.

Changes since v1:
  - Updated to v2 of DnD actions protocol changes, implement
    wl_data_offer.source_actions.
  - Fixed coding style issues.

Signed-off-by: Carlos Garnacho <carlosg@gnome.org>
Reviewed-by: Michael Catanzaro <mcatanzaro@igalia.com>
Reviewed-by: Jonas Ådahl <jadahl@gmail.com>
diff --git a/clients/window.c b/clients/window.c
index 1b3cbb1..5cd33dd 100644
--- a/clients/window.c
+++ b/clients/window.c
@@ -3418,6 +3418,8 @@
 	int fd;
 	data_func_t func;
 	int32_t x, y;
+	uint32_t dnd_action;
+	uint32_t source_actions;
 	void *user_data;
 };
 
@@ -3431,8 +3433,26 @@
 	*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
@@ -3496,6 +3516,14 @@
 		*p = NULL;
 
 		types_data = input->drag_offer->types.data;
+
+		if (input->display->data_device_manager_version >=
+		    WL_DATA_OFFER_SET_ACTIONS_SINCE_VERSION) {
+			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_MOVE);
+		}
 	} else {
 		input->drag_offer = NULL;
 		types_data = NULL;
@@ -5932,6 +5960,12 @@
 	display->running = 0;
 }
 
+int
+display_get_data_device_manager_version(struct display *display)
+{
+	return display->data_device_manager_version;
+}
+
 void
 keysym_modifiers_add(struct wl_array *modifiers_map,
 		     const char *name)