]> Pileus Git - ~andy/gtk/blobdiff - gdk/x11/gdkdnd-x11.c
Cleanups
[~andy/gtk] / gdk / x11 / gdkdnd-x11.c
index 1d04e25ac3b9cdadb78ee9628baa2d31b3d50cff..f9104313301fb46ca04589f8387c93cfef2aa60b 100644 (file)
@@ -38,6 +38,7 @@
 #include "gdkinternals.h"
 #include "gdkscreen-x11.h"
 #include "gdkdisplay-x11.h"
+#include "gdkalias.h"
 
 typedef struct _GdkDragContextPrivateX11 GdkDragContextPrivateX11;
 
@@ -80,9 +81,12 @@ struct _GdkDragContextPrivateX11 {
   Window drop_xid;            /* The (non-proxied) window that is receiving drops */
   guint xdnd_targets_set : 1;   /* Whether we've already set XdndTypeList */
   guint xdnd_actions_set : 1;   /* Whether we've already set XdndActionList */
-  guint xdnd_have_actions : 1; /* Whether an XdndActionList was provided */
+  guint xdnd_have_actions : 1;  /* Whether an XdndActionList was provided */
   guint motif_targets_set : 1;  /* Whether we've already set motif initiator info */
   guint drag_status : 4;       /* current status of drag */
+  
+  guint drop_failed : 1;        /* Whether the drop was unsuccessful */
+  guint version;                /* Xdnd protocol version */
 
   GSList *window_caches;
 };
@@ -122,14 +126,11 @@ static void   xdnd_manage_source_filter (GdkDragContext *context,
                                         GdkWindow      *window,
                                         gboolean        add_filter);
 
-static void gdk_drag_context_init       (GdkDragContext      *dragcontext);
-static void gdk_drag_context_class_init (GdkDragContextClass *klass);
 static void gdk_drag_context_finalize   (GObject              *object);
 
-static gpointer parent_class = NULL;
 static GList *contexts;
 
-const static struct {
+static const struct {
   const char *atom_name;
   GdkFilterFunc func;
 } xdnd_filters[] = {
@@ -141,41 +142,17 @@ const static struct {
   { "XdndDrop",     xdnd_drop_filter },
 };
              
-GType
-gdk_drag_context_get_type (void)
-{
-  static GType object_type = 0;
-
-  if (!object_type)
-    {
-      static const GTypeInfo object_info =
-      {
-        sizeof (GdkDragContextClass),
-        (GBaseInitFunc) NULL,
-        (GBaseFinalizeFunc) NULL,
-        (GClassInitFunc) gdk_drag_context_class_init,
-        NULL,           /* class_finalize */
-        NULL,           /* class_data */
-        sizeof (GdkDragContext),
-        0,              /* n_preallocs */
-        (GInstanceInitFunc) gdk_drag_context_init,
-      };
-      
-      object_type = g_type_register_static (G_TYPE_OBJECT,
-                                            "GdkDragContext",
-                                            &object_info, 0);
-    }
-  
-  return object_type;
-}
+G_DEFINE_TYPE (GdkDragContext, gdk_drag_context, G_TYPE_OBJECT)
 
 static void
 gdk_drag_context_init (GdkDragContext *dragcontext)
 {
   GdkDragContextPrivateX11 *private;
 
-  private = g_new0 (GdkDragContextPrivateX11, 1);
-
+  private = G_TYPE_INSTANCE_GET_PRIVATE (dragcontext, 
+                                        GDK_TYPE_DRAG_CONTEXT, 
+                                        GdkDragContextPrivateX11);
+  
   dragcontext->windowing_data = private;
 
   contexts = g_list_prepend (contexts, dragcontext);
@@ -186,9 +163,9 @@ gdk_drag_context_class_init (GdkDragContextClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
-  parent_class = g_type_class_peek_parent (klass);
-
   object_class->finalize = gdk_drag_context_finalize;
+
+  g_type_class_add_private (object_class, sizeof (GdkDragContextPrivateX11));
 }
 
 static void
@@ -218,9 +195,7 @@ gdk_drag_context_finalize (GObject *object)
   
   contexts = g_list_remove (contexts, context);
 
-  g_free (private);
-  
-  G_OBJECT_CLASS (parent_class)->finalize (object);
+  G_OBJECT_CLASS (gdk_drag_context_parent_class)->finalize (object);
 }
 
 /* Drag Contexts */
@@ -233,9 +208,9 @@ gdk_drag_context_finalize (GObject *object)
  * Return value: the newly created #GdkDragContext.
  **/
 GdkDragContext *
-gdk_drag_context_new        (void)
+gdk_drag_context_new (void)
 {
-  return g_object_new (gdk_drag_context_get_type (), NULL);
+  return g_object_new (GDK_TYPE_DRAG_CONTEXT, NULL);
 }
 
 /**
@@ -485,6 +460,25 @@ gdk_window_cache_new (GdkScreen *screen)
 
   XGetWindowAttributes (xdisplay, GDK_WINDOW_XWINDOW (root_window), &xwa);
   result->old_event_mask = xwa.your_event_mask;
+
+  if (G_UNLIKELY (!GDK_DISPLAY_X11 (GDK_SCREEN_X11 (screen)->display)->trusted_client)) 
+    {
+      GList *toplevel_windows, *list;
+      GdkWindow *window;
+      gint x, y, width, height;
+      
+      toplevel_windows = gdk_screen_get_toplevel_windows (screen);
+      for (list = toplevel_windows; list; list = list->next) {
+       window = GDK_WINDOW (list->data);
+       gdk_window_get_geometry (window, &x, &y, &width, &height, NULL);
+       gdk_window_cache_add (result, GDK_WINDOW_XID (window), 
+                             x, y, width, height, 
+                             gdk_window_is_visible (window));
+      }
+      g_list_free (toplevel_windows);
+      return result;
+    }
+
   XSelectInput (xdisplay, GDK_WINDOW_XWINDOW (root_window),
                result->old_event_mask | SubstructureNotifyMask);
   gdk_window_add_filter (root_window, gdk_window_cache_filter, result);
@@ -535,7 +529,7 @@ get_client_window_at_coords_recurse (GdkDisplay *display,
   unsigned int nchildren;
   int i;
   gboolean found_child = FALSE;
-  GdkChildInfoX11 child;
+  GdkChildInfoX11 child = { 0, };
   gboolean has_wm_state = FALSE;
 
   if (!_gdk_x11_get_window_child_info (display, win, TRUE,
@@ -544,7 +538,11 @@ get_client_window_at_coords_recurse (GdkDisplay *display,
     return None;
 
   if (has_wm_state)
-    return win;
+    {
+      g_free (children);
+
+      return win;
+    }
 
   for (i = nchildren - 1; (i >= 0) && !found_child; i--)
     {
@@ -849,7 +847,7 @@ motif_find_drag_window (GdkDisplay *display,
                XCreateWindow (persistant_xdisplay, 
                               RootWindow (persistant_xdisplay, 0),
                              -100, -100, 10, 10, 0, 0,
-                             InputOnly, CopyFromParent,
+                             InputOnly, (Visual *)CopyFromParent,
                              (CWOverrideRedirect | CWEventMask), &attr);
              
              GDK_NOTE (DND,
@@ -905,6 +903,7 @@ motif_read_target_table (GdkDisplay *display)
 
   if (motif_find_drag_window (display, FALSE))
     {
+      guchar *data;
       MotifTargetTableHeader *header = NULL;
       guchar *target_bytes = NULL;
       guchar *p;
@@ -917,11 +916,13 @@ motif_read_target_table (GdkDisplay *display)
                          0, (sizeof(MotifTargetTableHeader)+3)/4, FALSE,
                          motif_drag_targets_atom, 
                          &type, &format, &nitems, &bytes_after,
-                         (guchar **)&header);
+                         &data);
 
       if (gdk_error_trap_pop () || (format != 8) || (nitems < sizeof (MotifTargetTableHeader)))
        goto error;
 
+      header = (MotifTargetTableHeader *)data;
+
       header->n_lists = card16_to_host (header->n_lists, header->byte_order);
       header->total_size = card32_to_host (header->total_size, header->byte_order);
 
@@ -1256,6 +1257,7 @@ motif_check_dest (GdkDisplay *display,
                  Window      win)
 {
   gboolean retval = FALSE;
+  guchar *data;
   MotifDragReceiverInfo *info;
   Atom type = None;
   int format;
@@ -1267,12 +1269,14 @@ motif_check_dest (GdkDisplay *display,
                      motif_drag_receiver_info_atom, 
                      0, (sizeof(*info)+3)/4, False, AnyPropertyType,
                      &type, &format, &nitems, &after, 
-                     (guchar **)&info);
+                     &data);
 
   if (gdk_error_trap_pop() == 0)
     {
       if (type != None)
        {
+         info = (MotifDragReceiverInfo *)data;
+         
          if ((format == 8) && (nitems == sizeof(*info)))
            {
              if ((info->protocol_version == 0) &&
@@ -1302,6 +1306,9 @@ motif_send_enter (GdkDragContext  *context,
   GdkDisplay *display = GDK_DRAWABLE_DISPLAY (context->source_window);
   XEvent xev;
 
+  if (!G_LIKELY (GDK_DISPLAY_X11 (display)->trusted_client))
+    return; /* Motif Dnd requires getting properties on the root window */
+
   xev.xclient.type = ClientMessage;
   xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_MOTIF_DRAG_AND_DROP_MESSAGE");
   xev.xclient.format = 8;
@@ -1452,6 +1459,7 @@ motif_read_initiator_info (GdkDisplay *display,
   gint format;
   gulong nitems;
   gulong bytes_after;
+  guchar *data;
   MotifDragInitiatorInfo *initiator_info;
   
   GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
@@ -1461,7 +1469,7 @@ motif_read_initiator_info (GdkDisplay *display,
                      0, sizeof(*initiator_info), FALSE,
                      gdk_x11_get_xatom_by_name_for_display (display, "_MOTIF_DRAG_INITIATOR_INFO"),
                      &type, &format, &nitems, &bytes_after,
-                     (guchar **)&initiator_info);
+                     &data);
 
   if (gdk_error_trap_pop () || (format != 8) || (nitems != sizeof (MotifDragInitiatorInfo)) || (bytes_after != 0))
     {
@@ -1469,6 +1477,8 @@ motif_read_initiator_info (GdkDisplay *display,
       return FALSE;
     }
 
+  initiator_info = (MotifDragInitiatorInfo *)data;
+
   motif_read_target_table (display);
 
   initiator_info->targets_index = 
@@ -1728,6 +1738,8 @@ motif_drop_start (GdkEvent *event,
   event->dnd.x_root = x_root;
   event->dnd.y_root = y_root;
 
+  gdk_x11_window_set_user_time (event->any.window, timestamp);
+
   g_object_ref (new_context);
   display_x11->current_dest_drag = new_context;
 
@@ -1879,7 +1891,7 @@ motif_dnd_filter (GdkXEvent *xev,
 /* Utility functions */
 
 static struct {
-  gchar *name;
+  const gchar *name;
   GdkAtom atom;
   GdkDragAction action;
 } xdnd_actions_table[] = {
@@ -1900,7 +1912,7 @@ xdnd_initialize_actions (void)
   
   xdnd_actions_initialized = TRUE;
   for (i=0; i < xdnd_n_actions; i++)
-    xdnd_actions_table[i].atom = gdk_atom_intern (xdnd_actions_table[i].name, FALSE);
+    xdnd_actions_table[i].atom = gdk_atom_intern_static_string (xdnd_actions_table[i].name);
 }
 
 static GdkDragAction
@@ -1997,6 +2009,7 @@ xdnd_finished_filter (GdkXEvent *xev,
   XEvent *xevent = (XEvent *)xev;
   guint32 dest_window = xevent->xclient.data.l[0];
   GdkDragContext *context;
+  GdkDragContextPrivateX11 *private;
 
   if (!event->any.window ||
       gdk_window_get_window_type (event->any.window) == GDK_WINDOW_FOREIGN)
@@ -2010,10 +2023,16 @@ xdnd_finished_filter (GdkXEvent *xev,
   
   if (context)
     {
+      private = PRIVATE_DATA (context);
+      if (private->version == 5)
+       private->drop_failed = xevent->xclient.data.l[1] == 0;
+      
       event->dnd.type = GDK_DROP_FINISHED;
       event->dnd.context = context;
       g_object_ref (context);
 
+      event->dnd.time = GDK_CURRENT_TIME; /* FIXME? */
+
       return GDK_FILTER_TRANSLATE;
     }
 
@@ -2195,7 +2214,7 @@ xdnd_send_xevent (GdkDragContext *context,
              if  ((*xdnd_filters[i].func) (event_send, &temp_event, NULL) == GDK_FILTER_TRANSLATE)
                {
                  gdk_event_put (&temp_event);
-                 g_object_unref (tmp_event.dnd.context);
+                 g_object_unref (temp_event.dnd.context);
                }
              
              return TRUE;
@@ -2230,11 +2249,14 @@ xdnd_send_enter (GdkDragContext *context)
                            private->drop_xid : 
                            GDK_DRAWABLE_XID (context->dest_window);
   xev.xclient.data.l[0] = GDK_DRAWABLE_XID (context->source_window);
-  xev.xclient.data.l[1] = (3 << 24); /* version */
+  xev.xclient.data.l[1] = (private->version << 24); /* version */
   xev.xclient.data.l[2] = 0;
   xev.xclient.data.l[3] = 0;
   xev.xclient.data.l[4] = 0;
 
+  GDK_NOTE(DND,
+          g_message ("Sending enter source window %#lx XDND protocol version %d\n",
+                     GDK_DRAWABLE_XID (context->source_window), private->version));
   if (g_list_length (context->targets) > 3)
     {
       if (!private->xdnd_targets_set)
@@ -2364,12 +2386,14 @@ xdnd_send_motion (GdkDragContext *context,
 
 static guint32
 xdnd_check_dest (GdkDisplay *display,
-                Window      win)
+                Window      win,
+                guint      *xdnd_version)
 {
   gboolean retval = FALSE;
   Atom type = None;
   int format;
   unsigned long nitems, after;
+  guchar *data;
   Atom *version;
   Window *proxy_data;
   Window proxy;
@@ -2384,17 +2408,19 @@ xdnd_check_dest (GdkDisplay *display,
                          xdnd_proxy_atom, 0, 
                          1, False, AnyPropertyType,
                          &type, &format, &nitems, &after, 
-                         (guchar **)&proxy_data) == Success)
+                         &data) == Success)
     {
       if (type != None)
        {
+         proxy_data = (Window *)data;
+         
          if ((format == 32) && (nitems == 1))
            {
              proxy = *proxy_data;
            }
          else
            GDK_NOTE (DND, 
-                     g_warning ("Invalid XdndOwner "
+                     g_warning ("Invalid XdndProxy "
                                 "property on window %ld\n", win));
          
          XFree (proxy_data);
@@ -2404,17 +2430,22 @@ xdnd_check_dest (GdkDisplay *display,
                               xdnd_aware_atom, 0, 
                               1, False, AnyPropertyType,
                               &type, &format, &nitems, &after, 
-                              (guchar **)&version) == Success) &&
+                              &data) == Success) &&
          type != None)
        {
+         version = (Atom *)data;
+         
          if ((format == 32) && (nitems == 1))
            {
              if (*version >= 3)
                retval = TRUE;
+             if (xdnd_version)
+               *xdnd_version = *version;
            }
          else
            GDK_NOTE (DND, 
-                     g_warning ("Invalid XdndAware property on window %ld\n", win));
+                     g_warning ("Invalid XdndAware "
+                                "property on window %ld\n", win));
          
          XFree (version);
        }
@@ -2434,7 +2465,8 @@ xdnd_read_actions (GdkDragContext *context)
   Atom type;
   int format;
   gulong nitems, after;
-  Atom *data;
+  guchar *data;
+  Atom *atoms;
 
   gint i;
   
@@ -2451,13 +2483,15 @@ xdnd_read_actions (GdkDragContext *context)
                              gdk_x11_get_xatom_by_name_for_display (display, "XdndActionList"),
                              0, 65536,
                              False, XA_ATOM, &type, &format, &nitems,
-                             &after, (guchar **)&data) == Success &&
+                             &after, &data) == Success &&
          type == XA_ATOM)
        {
+         atoms = (Atom *)data;
+         
          context->actions = 0;
          
          for (i=0; i<nitems; i++)
-           context->actions |= xdnd_action_from_atom (display, data[i]);
+           context->actions |= xdnd_action_from_atom (display, atoms[i]);
          
          PRIVATE_DATA (context)->xdnd_have_actions = TRUE;
          
@@ -2479,8 +2513,10 @@ xdnd_read_actions (GdkDragContext *context)
            }
 #endif /* G_ENABLE_DEBUG */
          
-         XFree(data);
        }
+
+      if (data)
+       XFree (data);
       
       gdk_error_trap_pop ();
     }
@@ -2628,7 +2664,8 @@ xdnd_enter_filter (GdkXEvent *xev,
   Atom type;
   int format;
   gulong nitems, after;
-  Atom *data;
+  guchar *data;
+  Atom *atoms;
 
   guint32 source_window;
   gboolean get_types;
@@ -2651,7 +2688,7 @@ xdnd_enter_filter (GdkXEvent *xev,
            g_message ("XdndEnter: source_window: %#x, version: %#x",
                       source_window, version));
 
-  if (version != 3)
+  if (version < 3)
     {
       /* Old source ignore */
       GDK_NOTE (DND, g_message ("Ignored old XdndEnter message"));
@@ -2666,7 +2703,7 @@ xdnd_enter_filter (GdkXEvent *xev,
 
   new_context = gdk_drag_context_new ();
   new_context->protocol = GDK_DRAG_PROTO_XDND;
-  new_context->is_source = FALSE;
+  PRIVATE_DATA(new_context)->version = version;
 
   new_context->source_window = gdk_window_lookup_for_display (display, source_window);
   if (new_context->source_window)
@@ -2692,21 +2729,27 @@ xdnd_enter_filter (GdkXEvent *xev,
                          gdk_x11_get_xatom_by_name_for_display (display, "XdndTypeList"),
                          0, 65536,
                          False, XA_ATOM, &type, &format, &nitems,
-                         &after, (guchar **)&data);
+                         &after, &data);
 
       if (gdk_error_trap_pop () || (format != 32) || (type != XA_ATOM))
        {
          g_object_unref (new_context);
+
+         if (data)
+           XFree (data);
+
          return GDK_FILTER_REMOVE;
        }
 
+      atoms = (Atom *)data;
+
       for (i=0; i<nitems; i++)
        new_context->targets = 
          g_list_append (new_context->targets,
                         GDK_ATOM_TO_POINTER (gdk_x11_xatom_to_atom_for_display (display,
-                                                                                data[i])));
+                                                                                atoms[i])));
 
-      XFree(data);
+      XFree(atoms);
     }
   else
     {
@@ -2868,6 +2911,8 @@ xdnd_drop_filter (GdkXEvent *xev,
       event->dnd.time = time;
       event->dnd.x_root = private->last_x;
       event->dnd.y_root = private->last_y;
+
+      gdk_x11_window_set_user_time (event->any.window, time);
       
       return GDK_FILTER_TRANSLATE;
     }
@@ -2886,14 +2931,14 @@ _gdk_dnd_init (GdkDisplay *display)
 
   gdk_display_add_client_message_filter (
        display,
-       gdk_atom_intern ("_MOTIF_DRAG_AND_DROP_MESSAGE", FALSE),
+       gdk_atom_intern_static_string ("_MOTIF_DRAG_AND_DROP_MESSAGE"),
        motif_dnd_filter, NULL);
   
   for (i = 0; i < G_N_ELEMENTS (xdnd_filters); i++)
     {
       gdk_display_add_client_message_filter (
        display,
-       gdk_atom_intern (xdnd_filters[i].atom_name, FALSE),
+       gdk_atom_intern_static_string (xdnd_filters[i].atom_name),
        xdnd_filters[i].func, NULL);
     }
 }                    
@@ -2956,23 +3001,12 @@ gdk_drag_begin (GdkWindow     *window,
   return new_context;
 }
 
-/**
- * gdk_drag_get_protocol_for_display:
- * @display: the #GdkDisplay where the destination window resides
- * @xid: the X id of the destination window.
- * @protocol: location where the supported DND protocol is returned.
- * @returns: the X id of the window where the drop should happen. This 
- *     may be @xid or the X id of a proxy window, or None if @xid doesn't
- *     support Drag and Drop.
- *
- * Finds out the DND protocol supported by a window.
- *
- * Since: 2.2
- */ 
-guint32
-gdk_drag_get_protocol_for_display (GdkDisplay      *display,
-                                  guint32          xid,
-                                  GdkDragProtocol *protocol)
+static guint32
+_gdk_drag_get_protocol_for_display (GdkDisplay      *display,
+                                   guint32          xid,
+                                   GdkDragProtocol *protocol,
+                                   guint           *version)
+
 {
   GdkWindow *window;
   guint32 retval;
@@ -2989,15 +3023,19 @@ gdk_drag_get_protocol_for_display (GdkDisplay      *display,
       if (g_object_get_data (G_OBJECT (window), "gdk-dnd-registered") != NULL)
        {
          *protocol = GDK_DRAG_PROTO_XDND;
+         *version = 5;
          xdnd_precache_atoms (display);
          GDK_NOTE (DND, g_message ("Entering local Xdnd window %#x\n", xid));
          return xid;
        }
-      else
-       return None;
+      else if (_gdk_x11_display_is_root_window (display, (Window) xid))
+       {
+         *protocol = GDK_DRAG_PROTO_ROOTWIN;
+         GDK_NOTE (DND, g_message ("Entering root window\n"));
+         return xid;
+       }
     }
-  
-  if ((retval = xdnd_check_dest (display, xid)))
+  else if ((retval = xdnd_check_dest (display, xid, version)))
     {
       *protocol = GDK_DRAG_PROTO_XDND;
       xdnd_precache_atoms (display);
@@ -3050,7 +3088,10 @@ gdk_drag_get_protocol_for_display (GdkDisplay      *display,
                                  0, 0, False, AnyPropertyType,
                                  &type, &format, &nitems, &data) &&
              type != None)
-           rootwin = TRUE;
+           {
+             XFree (data);
+             rootwin = TRUE;
+           }
        }
 #endif      
 
@@ -3058,6 +3099,7 @@ gdk_drag_get_protocol_for_display (GdkDisplay      *display,
 
       if (rootwin)
        {
+         GDK_NOTE (DND, g_message ("Entering root window\n"));
          *protocol = GDK_DRAG_PROTO_ROOTWIN;
          return xid;
        }
@@ -3067,6 +3109,27 @@ gdk_drag_get_protocol_for_display (GdkDisplay      *display,
   return None;
 }
 
+/**
+ * gdk_drag_get_protocol_for_display:
+ * @display: the #GdkDisplay where the destination window resides
+ * @xid: the X id of the destination window.
+ * @protocol: location where the supported DND protocol is returned.
+ * @returns: the X id of the window where the drop should happen. This 
+ *     may be @xid or the X id of a proxy window, or None if @xid doesn't
+ *     support Drag and Drop.
+ *
+ * Finds out the DND protocol supported by a window.
+ *
+ * Since: 2.2
+ */ 
+guint32
+gdk_drag_get_protocol_for_display (GdkDisplay      *display,
+                                  guint32          xid,
+                                  GdkDragProtocol *protocol)
+{
+  return _gdk_drag_get_protocol_for_display (display, xid, protocol, NULL);
+}
+
 static GdkWindowCache *
 drag_context_find_window_cache (GdkDragContext  *context,
                                GdkScreen       *screen)
@@ -3145,7 +3208,8 @@ gdk_drag_find_window_for_screen (GdkDragContext  *context,
        * two are passed explicitely, the third implicitly through
        * protocol->dest_xid.
        */
-      if ((recipient = gdk_drag_get_protocol_for_display (display, dest, protocol)))
+      if ((recipient = _gdk_drag_get_protocol_for_display (display, dest, 
+                                                          protocol, &private->version)))
        {
          *dest_window = gdk_window_lookup_for_display (display, recipient);
          if (*dest_window)
@@ -3203,7 +3267,27 @@ gdk_drag_motion (GdkDragContext *context,
   
   if (private->old_actions != possible_actions)
     private->xdnd_actions_set = FALSE;
-      
+  
+  if (protocol == GDK_DRAG_PROTO_XDND && private->version == 0)
+    {
+      /* This ugly hack is necessary since GTK+ doesn't know about
+       * the XDND protocol version, and in particular doesn't know 
+       * that gdk_drag_find_window_for_screen() has the side-effect 
+       * of setting private->version, and therefore sometimes call
+       * gdk_drag_motion() without a prior call to 
+       * gdk_drag_find_window_for_screen(). This happens, e.g.
+       * when GTK+ is proxying DND events to embedded windows.
+       */ 
+      if (dest_window)
+       {
+         GdkDisplay *display = GDK_WINDOW_DISPLAY (dest_window);
+         
+         xdnd_check_dest (display, 
+                          GDK_DRAWABLE_XID (dest_window), 
+                          &private->version);
+       }
+    }
+
   /* When we have a Xdnd target, make sure our XdndActionList
    * matches the current actions;
    */
@@ -3321,8 +3405,8 @@ gdk_drag_motion (GdkDragContext *context,
                /* GTK+ traditionally has used application/x-rootwin-drop,
                 * but the XDND spec specifies x-rootwindow-drop.
                 */
-               GdkAtom target1 = gdk_atom_intern ("application/x-rootwindow-drop", FALSE);
-               GdkAtom target2 = gdk_atom_intern ("application/x-rootwin-drop", FALSE);
+               GdkAtom target1 = gdk_atom_intern_static_string ("application/x-rootwindow-drop");
+               GdkAtom target2 = gdk_atom_intern_static_string ("application/x-rootwin-drop");
 
                if (g_list_find (context->targets,
                                 GDK_ATOM_TO_POINTER (target1)) ||
@@ -3626,8 +3710,17 @@ gdk_drop_finish (GdkDragContext   *context,
       xev.xclient.window = GDK_DRAWABLE_XID (context->source_window);
       
       xev.xclient.data.l[0] = GDK_DRAWABLE_XID (context->dest_window);
-      xev.xclient.data.l[1] = 0;
-      xev.xclient.data.l[2] = 0;
+      if (success)
+       {
+         xev.xclient.data.l[1] = 1;
+         xev.xclient.data.l[2] = xdnd_action_to_atom (display, 
+                                                      context->action);
+       }
+      else
+       {
+         xev.xclient.data.l[1] = 0;
+         xev.xclient.data.l[2] = None;
+       }
       xev.xclient.data.l[3] = 0;
       xev.xclient.data.l[4] = 0;
 
@@ -3643,7 +3736,7 @@ gdk_drop_finish (GdkDragContext   *context,
 void            
 gdk_window_register_dnd (GdkWindow      *window)
 {
-  static gulong xdnd_version = 3;
+  static const gulong xdnd_version = 5;
   MotifDragReceiverInfo info;
   Atom motif_drag_receiver_info_atom;
   GdkDisplay *display = gdk_drawable_get_display (window);
@@ -3661,6 +3754,8 @@ gdk_window_register_dnd (GdkWindow      *window)
 
   motif_drag_receiver_info_atom = gdk_x11_get_xatom_by_name_for_display (display,
                                                                         "_MOTIF_DRAG_RECEIVER_INFO");
+  /* initialize to zero to avoid writing uninitialized data to socket */
+  memset(&info, 0, sizeof(info));
   info.byte_order = local_byte_order;
   info.protocol_version = 0;
   info.protocol_style = XmDRAG_DYNAMIC;
@@ -3702,8 +3797,35 @@ gdk_drag_get_selection (GdkDragContext *context)
     return gdk_x11_xatom_to_atom_for_display (GDK_DRAWABLE_DISPLAY (context->source_window),
                                              (PRIVATE_DATA (context))->motif_selection);
   else if (context->protocol == GDK_DRAG_PROTO_XDND)
-    return gdk_atom_intern ("XdndSelection", FALSE);
+    return gdk_atom_intern_static_string ("XdndSelection");
   else
     return GDK_NONE;
 }
 
+/**
+ * gdk_drag_drop_succeeded:
+ * @context: a #GdkDragContext
+ * 
+ * Returns wether the dropped data has been successfully 
+ * transferred. This function is intended to be used while 
+ * handling a %GDK_DROP_FINISHED event, its return value is
+ * meaningless at other times.
+ * 
+ * Return value: %TRUE if the drop was successful.
+ *
+ * Since: 2.6
+ **/
+gboolean 
+gdk_drag_drop_succeeded (GdkDragContext *context)
+{
+  GdkDragContextPrivateX11 *private;
+
+  g_return_val_if_fail (context != NULL, FALSE);
+
+  private = PRIVATE_DATA (context);
+
+  return !private->drop_failed;
+}
+
+#define __GDK_DND_X11_C__
+#include "gdkaliasdef.c"