I am trying to create a drag-and-drop area in GTK widget. If a file is dropped, print URI in console.
#include <gtk/gtk.h>
void
onDragDataReceived(GtkWidget *wgt, GdkDragContext *context, int x, int y,
GtkSelectionData *seldata, guint info, guint time,
gpointer userdata)
{
printf("Data: %s\n", (gchar*)seldata->data);
}
int main(int argc, char **argv)
{
...
g_signal_connect(globals->treeview, "drag_data_received", G_CALLBACK(onDragDataReceived), NULL);
}
However, when compiling, I get the following error:
../src/main.c: In function ‘onDragDataReceived’:
../src/main.c:45:41: error: dereferencing pointer to incomplete type ‘GtkSelectionData {aka struct _GtkSelectionData}’
printf("Data: %s\n", (gchar*)seldata->data);
According to the gnome developer docs, no extra includes are needed. What's going on?
This is analogous to how GTK3 no longer gives us direct access to the ->window
or ->parent
members of a GtkWidget
. You will need to get the data by calling
const guchar *data = gtk_selection_data_get_data(seldata);