+/** @brief Called when a drag moves within a candidate destination
+ * @param w Destination widget
+ * @param dc Drag context
+ * @param x Current pointer location
+ * @param y Current pointer location
+ * @param time_ Current time
+ * @param user_data Pointer to queuelike
+ * @return TRUE in a dropzone, otherwise FALSE
+ *
+ * This is the handler for the "drag-motion" signal.
+ */
+static gboolean ql_drag_motion(GtkWidget *w,
+ GdkDragContext *dc,
+ gint x,
+ gint y,
+ guint time_,
+ gpointer user_data) {
+ struct queuelike *const ql = user_data;
+ GdkDragAction action = 0;
+
+ // GTK_DEST_DEFAULT_MOTION vets actions as follows:
+ // 1) if dc->suggested_action is in the gtk_drag_dest_set actions
+ // then dc->suggested_action is taken as the action.
+ // 2) otherwise if dc->actions intersects the gtk_drag_dest_set actions
+ // then the lowest-numbered member of the intersection is chosen.
+ // 3) otherwise no member is chosen and gdk_drag_status() is called
+ // with action=0 to refuse the drop.
+ if(dc->suggested_action) {
+ if(dc->suggested_action & (GDK_ACTION_MOVE|GDK_ACTION_COPY))
+ action = dc->suggested_action;
+ } else if(dc->actions & GDK_ACTION_MOVE)
+ action = GDK_ACTION_MOVE;
+ else if(dc->actions & GDK_ACTION_COPY)
+ action = GDK_ACTION_COPY;
+ /* TODO this comes up with the wrong answer sometimes. If we are in the
+ * middle of a rearrange then the suggested action will be COPY, which we'll
+ * take, even though MOVE would actually be appropriate. The drag still
+ * seems to work, but it _is_ wrong. The answer is to take the target into
+ * account. */
+ /*fprintf(stderr, "suggested %s actions %s result %s\n",
+ act(dc->suggested_action), act(dc->actions), act(action));*/
+ if(action) {
+ // If the action is acceptable then we see if this widget is acceptable
+ if(gtk_drag_dest_find_target(w, dc, NULL) == GDK_NONE)
+ action = 0;
+ }
+ // Report the status
+ //fprintf(stderr, "drag action: %u\n", action);
+ gdk_drag_status(dc, action, time_);
+ if(action) {
+ GtkTreeViewDropPosition pos;
+
+ // Find the drop target
+ GtkTreePath *path = ql_drop_path(w, GTK_TREE_MODEL(ql->store), x, y, &pos);
+ // Highlight drop target
+ gtk_tree_view_set_drag_dest_row(GTK_TREE_VIEW(w), path, pos);
+ if(path)
+ gtk_tree_path_free(path);
+ }
+ autoscroll_add(GTK_TREE_VIEW(w));
+ return TRUE; /* We are (always) in a drop zone */
+}