drag_motion (
  GtkWidget* self,
  GdkDragContext* context,
  gint x,
  gint y,
  guint time,
  gpointer user_data

Description [src]

The ::drag-motion signal is emitted on the drop site when the user moves the cursor over the widget during a drag. The signal handler must determine whether the cursor position is in a drop zone or not. If it is not in a drop zone, it returns FALSE and no further processing is necessary. Otherwise, the handler returns TRUE. In this case, the handler is responsible for providing the necessary information for displaying feedback to the user, by calling gdk_drag_status().

If the decision whether the drop will be accepted or rejected can’t be made based solely on the cursor position and the type of the data, the handler may inspect the dragged data by calling gtk_drag_get_data() and defer the gdk_drag_status() call to the GtkWidget::drag-data-received handler. Note that you must pass #GTK_DEST_DEFAULT_DROP,


when using the drag-motion signal that way.

Also note that there is no drag-enter signal. The drag receiver has to keep track of whether he has received any drag-motion signals since the last GtkWidget::drag-leave and if not, treat the drag-motion signal as an “enter” signal. Upon an “enter”, the handler will typically highlight the drop site with gtk_drag_highlight().

static void
drag_motion (GtkWidget      *widget,
             GdkDragContext *context,
             gint            x,
             gint            y,
             guint           time)
  GdkAtom target;

  PrivateData *private_data = GET_PRIVATE_DATA (widget);

  if (!private_data->drag_highlight)
     private_data->drag_highlight = 1;
     gtk_drag_highlight (widget);

  target = gtk_drag_dest_find_target (widget, context, NULL);
  if (target == GDK_NONE)
    gdk_drag_status (context, 0, time);
        = gdk_drag_context_get_suggested_action (context);
     gtk_drag_get_data (widget, context, target, time);

  return TRUE;

static void
drag_data_received (GtkWidget        *widget,
                    GdkDragContext   *context,
                    gint              x,
                    gint              y,
                    GtkSelectionData *selection_data,
                    guint             info,
                    guint             time)
  PrivateData *private_data = GET_PRIVATE_DATA (widget);

  if (private_data->suggested_action)
     private_data->suggested_action = 0;

     // We are getting this data due to a request in drag_motion,
     // rather than due to a request in drag_drop, so we are just
     // supposed to call gdk_drag_status(), not actually paste in
     // the data.

     str = gtk_selection_data_get_text (selection_data);
     if (!data_is_acceptable (str))
       gdk_drag_status (context, 0, time);
       gdk_drag_status (context,
     // accept the drop
Default handler:

The default handler is called after the handlers added via g_signal_connect().


context GdkDragContext

The drag context.

 The data is owned by the caller of the function.
x gint

The x coordinate of the current cursor position.

y gint

The y coordinate of the current cursor position.

time guint

The timestamp of the motion event.

Return value

Returns: gboolean

Whether the cursor position is in a drop zone.