Proper finalization of GdkDrop in GtkDropAreaAsync

Hi, while setting up GtkDropAreaAsync I hit a problem with finishing a drop. I’m struggling to understand when exactly a drop needs to be finalized.

If I finalize a drop with gdk_drop_finish(drop, GDK_ACTION_DROP) after starting an async input stream read an in-app drag-n-drop operation finishes successfully but a cross-app drag-n-drop operation does not yield any data (respectively, bytes_read of g_input_stream_read_all_finish is equal to 0).

On the other hand, If I don’t finalize a drop at all (which is as stated by the documentation), an in-app drag-n-drop operation yields a warning

(../gdk/gdkdrop.c:301):gdk_drop_finalize: runtime check failed: (priv->state != GDK_DROP_STATE_DROPPING)

but a drag-n-drop operation, where the drag originates from a different application (cross-app drag-n-drop), the operation finishes without any warnings and the data is properly transferred (respectively, copied).

Thank you for any pointers!

static const char*drop_types[] = {
    "application/x-color",
    NULL,
};
static uint16_t dnd_buf[16];

static void
drop_finish (GObject        *object,
             GAsyncResult   *res,
             gpointer        data)
{
    gint length;

    g_input_stream_read_all_finish (G_INPUT_STREAM (object), res, &length, NULL)

    // length == 0 for cross-app drag-n-drop
    // length > 0 for in-app drag-n-drop
    /* processing */
}

static void
drop_read   (GObject        *object,
             GAsyncResult   *res,
             gpointer        data)
{
    GdkDrop *drop = GDK_DROP (object);
    GInputStream *drop_stream = gdk_drop_read_finish (drop, res, drop_types, NULL);

    g_input_stream_read_all_async (drop_stream,
                                   dnd_buf,
                                   DND_BUF_SIZE,
                                   G_PRIORITY_DEFAULT,
                                   NULL,
                                   drop_finish,
                                   data);

    gdk_drop_finish (drop, GDK_ACTION_COPY); // The problematic GdkDrop finalization
}

static gboolean
data_drop (GtkDropTargetAsync *drop_target,
           GdkDrop            *drop,
           gdouble             x,
           gdouble             y,
           gpointer            data)
{
    gdk_drop_read_async (drop,
                         drop_types,
                         G_PRIORITY_DEFAULT,
                         NULL,
                         drop_read,
                         data);

    return TRUE;
}

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.