Hi, I am trying to implement drag and drop. Currently just trying to get the destination working. I have the basics working, but if I attempt to do custom "drag-motion" validation and I call gtk_drag_get_data() the Xserver locks with a drag cursor. The only way to get out is to Alt-F1 then kill the xserver (just the program doesn't unlock). Has anyone encountered this before?
I am probably missing something simple. Here is my code, thanks. Tar'd with build script: http://www.slello.com/tmp/testdnd.tar.gz Dan /*http://www.jirka.org/gob2.1.html*/ %h{ #include <gtk/gtk.h> %} %{ enum { INFO_DEFAULT = 0, INFO_INT32, INFO_STRING, INFO_ROOTWIN }; static GtkTargetEntry target_list[] = { //{ "INTEGER", 0, TARGET_INT32 }, //{ "STRING", 0, TARGET_STRING }, { "text/plain", 0, INFO_STRING }, { "text/uri-list", 0, INFO_STRING }, //{ "application/x-rootwindow-drop", 0, TARGET_ROOTWIN } }; static guint n_targets = G_N_ELEMENTS (target_list); %} class Test:App from G:Object { private GtkBuilder* builder = {gtk_builder_new()} unrefwith g_object_unref; private GtkWindow* window = NULL; private GtkButton* button = NULL; init(self) { gtk_builder_add_from_file(selfp->builder,"MainWindow.glade", NULL); selfp->window = GTK_WINDOW(gtk_builder_get_object(selfp->builder,"window1")); selfp->button = GTK_BUTTON(gtk_builder_get_object(selfp->builder,"button1")); gtk_builder_connect_signals (selfp->builder, NULL); g_signal_connect (selfp->window, "destroy", G_CALLBACK (gtk_main_quit), NULL); gtk_drag_dest_set(GTK_WIDGET(selfp->button), GTK_DEST_DEFAULT_HIGHLIGHT|GTK_DEST_DEFAULT_DROP, target_list, n_targets, GDK_ACTION_COPY); g_signal_connect (GTK_OBJECT(selfp->button), "drag-data-received", G_CALLBACK(test_app_do_drag_data_recieved), self); g_signal_connect (GTK_OBJECT(selfp->button), "drag-motion", G_CALLBACK(test_app_do_drag_motion), self); gtk_widget_show_all(GTK_WIDGET(selfp->window)); } private gboolean drag_highlight = FALSE; private gboolean drag_pending = FALSE; private void do_drag_motion(GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint time, gpointer user_data) { g_print("do_drag_motion\n"); GdkAtom target; Self* self = SELF(user_data); if (FALSE == selfp->drag_highlight) { selfp->drag_highlight = TRUE; gtk_drag_highlight(widget); } target = gtk_drag_dest_find_target (widget, context, NULL); if (target == GDK_NONE) { g_print("1\n"); gdk_drag_status (context, 0, time); } else { g_print("2\n"); selfp->drag_pending = TRUE; gtk_drag_get_data(widget, context, target, time); //gdk_drag_status(context,GDK_ACTION_COPY,time); } return TRUE; } private void do_drag_data_recieved(GtkWidget* widget, GdkDragContext* context, gint x, gint y, GtkSelectionData* data, guint info, guint time, gpointer user_data) { g_print("do_drag_data_recieved\n"); Self* self = SELF(user_data); if (selfp->drag_pending) { g_print("asdhfajklshdfljkash\n"); gdk_drag_status(context,GDK_ACTION_COPY,time); selfp->drag_pending = FALSE; } else { if (selfp->drag_highlight) { selfp->drag_highlight = FALSE; gtk_drag_unhighlight(widget); } if (NULL != data && data->length >= 0) { //switch(info) //{ //} g_print("do_drag_data_recieved %u %s\n",info,data->data); } } } } _______________________________________________ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list