1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-1999 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
28 #include <X11/Xatom.h>
31 #include "gdk.h" /* For gdk_flush() */
34 #include "gdkproperty.h"
35 #include "gdkprivate-x11.h"
36 #include "gdkinternals.h"
37 #include "gdkscreen-x11.h"
38 #include "gdkdisplay-x11.h"
40 typedef struct _GdkDragContextPrivateX11 GdkDragContextPrivateX11;
44 GDK_DRAG_STATUS_MOTION_WAIT,
45 GDK_DRAG_STATUS_ACTION_WAIT,
51 gint x, y, width, height;
57 GHashTable *child_hash;
62 /* Structure that holds information about a drag in progress.
63 * this is used on both source and destination sides.
65 struct _GdkDragContextPrivateX11 {
66 GdkDragContext context;
72 guint16 last_x; /* Coordinates from last event */
74 GdkDragAction old_action; /* The last action we sent to the source */
75 GdkDragAction old_actions; /* The last actions we sent to the source */
76 GdkDragAction xdnd_actions; /* What is currently set in XdndActionList */
78 Window dest_xid; /* The last window we looked up */
79 Window drop_xid; /* The (non-proxied) window that is receiving drops */
80 guint xdnd_targets_set : 1; /* Whether we've already set XdndTypeList */
81 guint xdnd_actions_set : 1; /* Whether we've already set XdndActionList */
82 guint xdnd_have_actions : 1; /* Whether an XdndActionList was provided */
83 guint motif_targets_set : 1; /* Whether we've already set motif initiator info */
84 guint drag_status : 4; /* current status of drag */
86 GSList *window_caches;
89 #define PRIVATE_DATA(context) ((GdkDragContextPrivateX11 *) GDK_DRAG_CONTEXT (context)->windowing_data)
91 /* Forward declarations */
93 static void gdk_window_cache_destroy (GdkWindowCache *cache);
95 static void motif_read_target_table (GdkDisplay *display);
97 static GdkFilterReturn motif_dnd_filter (GdkXEvent *xev,
101 static GdkFilterReturn xdnd_enter_filter (GdkXEvent *xev,
105 static GdkFilterReturn xdnd_leave_filter (GdkXEvent *xev,
109 static GdkFilterReturn xdnd_position_filter (GdkXEvent *xev,
113 static GdkFilterReturn xdnd_status_filter (GdkXEvent *xev,
117 static GdkFilterReturn xdnd_finished_filter (GdkXEvent *xev,
121 static GdkFilterReturn xdnd_drop_filter (GdkXEvent *xev,
125 static void xdnd_manage_source_filter (GdkDragContext *context,
127 gboolean add_filter);
129 static void gdk_drag_context_init (GdkDragContext *dragcontext);
130 static void gdk_drag_context_class_init (GdkDragContextClass *klass);
131 static void gdk_drag_context_finalize (GObject *object);
133 static gpointer parent_class = NULL;
134 static GList *contexts;
137 gdk_drag_context_get_type (void)
139 static GType object_type = 0;
143 static const GTypeInfo object_info =
145 sizeof (GdkDragContextClass),
146 (GBaseInitFunc) NULL,
147 (GBaseFinalizeFunc) NULL,
148 (GClassInitFunc) gdk_drag_context_class_init,
149 NULL, /* class_finalize */
150 NULL, /* class_data */
151 sizeof (GdkDragContext),
153 (GInstanceInitFunc) gdk_drag_context_init,
156 object_type = g_type_register_static (G_TYPE_OBJECT,
165 gdk_drag_context_init (GdkDragContext *dragcontext)
167 GdkDragContextPrivateX11 *private;
169 private = g_new0 (GdkDragContextPrivateX11, 1);
171 dragcontext->windowing_data = private;
173 contexts = g_list_prepend (contexts, dragcontext);
177 gdk_drag_context_class_init (GdkDragContextClass *klass)
179 GObjectClass *object_class = G_OBJECT_CLASS (klass);
181 parent_class = g_type_class_peek_parent (klass);
183 object_class->finalize = gdk_drag_context_finalize;
187 gdk_drag_context_finalize (GObject *object)
189 GdkDragContext *context = GDK_DRAG_CONTEXT (object);
190 GdkDragContextPrivateX11 *private = PRIVATE_DATA (context);
193 g_list_free (context->targets);
195 if (context->source_window)
197 if ((context->protocol == GDK_DRAG_PROTO_XDND) &&
199 xdnd_manage_source_filter (context, context->source_window, FALSE);
201 g_object_unref (context->source_window);
204 if (context->dest_window)
205 g_object_unref (context->dest_window);
207 for (tmp_list = private->window_caches; tmp_list; tmp_list = tmp_list->next)
208 gdk_window_cache_destroy (tmp_list->data);
209 g_slist_free (private->window_caches);
211 contexts = g_list_remove (contexts, context);
215 G_OBJECT_CLASS (parent_class)->finalize (object);
221 * gdk_drag_context_new:
223 * Creates a new #GdkDragContext.
225 * Return value: the newly created #GdkDragContext.
228 gdk_drag_context_new (void)
230 return g_object_new (gdk_drag_context_get_type (), NULL);
234 * gdk_drag_context_ref:
235 * @context: a #GdkDragContext.
237 * Deprecated function; use g_object_ref() instead.
240 gdk_drag_context_ref (GdkDragContext *context)
242 g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
244 g_object_ref (context);
248 * gdk_drag_context_unref:
249 * @context: a #GdkDragContext.
251 * Deprecated function; use g_object_unref() instead.
254 gdk_drag_context_unref (GdkDragContext *context)
256 g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
258 g_object_unref (context);
261 static GdkDragContext *
262 gdk_drag_context_find (GdkDisplay *display,
267 GList *tmp_list = contexts;
268 GdkDragContext *context;
269 GdkDragContextPrivateX11 *private;
270 Window context_dest_xid;
274 context = (GdkDragContext *)tmp_list->data;
275 private = PRIVATE_DATA (context);
277 if ((context->source_window && gdk_drawable_get_display (context->source_window) != display) ||
278 (context->dest_window && gdk_drawable_get_display (context->dest_window) != display))
281 context_dest_xid = context->dest_window ?
284 GDK_DRAWABLE_XID (context->dest_window)) :
287 if ((!context->is_source == !is_source) &&
288 ((source_xid == None) || (context->source_window &&
289 (GDK_DRAWABLE_XID (context->source_window) == source_xid))) &&
290 ((dest_xid == None) || (context_dest_xid == dest_xid)))
293 tmp_list = tmp_list->next;
299 /* Utility functions */
302 gdk_window_cache_add (GdkWindowCache *cache,
304 gint x, gint y, gint width, gint height,
307 GdkCacheChild *child = g_new (GdkCacheChild, 1);
312 child->width = width;
313 child->height = height;
314 child->mapped = mapped;
316 cache->children = g_list_prepend (cache->children, child);
317 g_hash_table_insert (cache->child_hash, GUINT_TO_POINTER (xid),
321 static GdkFilterReturn
322 gdk_window_cache_filter (GdkXEvent *xev,
326 XEvent *xevent = (XEvent *)xev;
327 GdkWindowCache *cache = data;
329 switch (xevent->type)
331 case CirculateNotify:
333 case ConfigureNotify:
335 XConfigureEvent *xce = &xevent->xconfigure;
338 node = g_hash_table_lookup (cache->child_hash,
339 GUINT_TO_POINTER (xce->window));
342 GdkCacheChild *child = node->data;
345 child->width = xce->width;
346 child->height = xce->height;
347 if (xce->above == None && (node->next))
349 GList *last = g_list_last (cache->children);
350 cache->children = g_list_remove_link (cache->children, node);
357 GList *above_node = g_hash_table_lookup (cache->child_hash,
358 GUINT_TO_POINTER (xce->above));
359 if (above_node && node->next != above_node)
361 /* Put the window above (before in the list) above_node
363 cache->children = g_list_remove_link (cache->children, node);
364 node->prev = above_node->prev;
366 node->prev->next = node;
368 cache->children = node;
369 node->next = above_node;
370 above_node->prev = node;
378 XCreateWindowEvent *xcwe = &xevent->xcreatewindow;
380 if (!g_hash_table_lookup (cache->child_hash,
381 GUINT_TO_POINTER (xcwe->window)))
382 gdk_window_cache_add (cache, xcwe->window,
383 xcwe->x, xcwe->y, xcwe->width, xcwe->height,
389 XDestroyWindowEvent *xdwe = &xevent->xdestroywindow;
392 node = g_hash_table_lookup (cache->child_hash,
393 GUINT_TO_POINTER (xdwe->window));
396 g_hash_table_remove (cache->child_hash,
397 GUINT_TO_POINTER (xdwe->window));
398 cache->children = g_list_remove_link (cache->children, node);
400 g_list_free_1 (node);
406 XMapEvent *xme = &xevent->xmap;
409 node = g_hash_table_lookup (cache->child_hash,
410 GUINT_TO_POINTER (xme->window));
413 GdkCacheChild *child = node->data;
414 child->mapped = TRUE;
422 XMapEvent *xume = &xevent->xmap;
425 node = g_hash_table_lookup (cache->child_hash,
426 GUINT_TO_POINTER (xume->window));
429 GdkCacheChild *child = node->data;
430 child->mapped = FALSE;
435 return GDK_FILTER_CONTINUE;
437 return GDK_FILTER_REMOVE;
440 static GdkWindowCache *
441 gdk_window_cache_new (GdkScreen *screen)
443 XWindowAttributes xwa;
444 Window root, parent, *children;
445 unsigned int nchildren;
447 Display *xdisplay = GDK_SCREEN_XDISPLAY (screen);
448 GdkWindow *root_window = gdk_screen_get_root_window (screen);
450 GdkWindowCache *result = g_new (GdkWindowCache, 1);
452 result->children = NULL;
453 result->child_hash = g_hash_table_new (g_direct_hash, NULL);
454 result->screen = screen;
456 XGetWindowAttributes (xdisplay, GDK_WINDOW_XWINDOW (root_window), &xwa);
457 result->old_event_mask = xwa.your_event_mask;
458 XSelectInput (xdisplay, GDK_WINDOW_XWINDOW (root_window),
459 result->old_event_mask | SubstructureNotifyMask);
460 gdk_window_add_filter (root_window, gdk_window_cache_filter, result);
462 gdk_error_trap_push ();
464 if (!XQueryTree(xdisplay, GDK_WINDOW_XWINDOW (root_window),
465 &root, &parent, &children, &nchildren))
467 gdk_error_trap_pop ();
471 for (i = 0; i < nchildren ; i++)
473 if (XGetWindowAttributes (xdisplay, children[i], &xwa))
474 gdk_window_cache_add (result, children[i],
475 xwa.x, xwa.y, xwa.width, xwa.height,
476 xwa.map_state != IsUnmapped);
480 gdk_error_trap_pop ();
486 gdk_window_cache_destroy (GdkWindowCache *cache)
488 GdkWindow *root_window = gdk_screen_get_root_window (cache->screen);
490 XSelectInput (GDK_WINDOW_XDISPLAY (root_window),
491 GDK_WINDOW_XWINDOW (root_window),
492 cache->old_event_mask);
493 gdk_window_remove_filter (root_window, gdk_window_cache_filter, cache);
495 g_list_foreach (cache->children, (GFunc)g_free, NULL);
496 g_list_free (cache->children);
497 g_hash_table_destroy (cache->child_hash);
503 get_client_window_at_coords_recurse (GdkDisplay *display,
508 Window root, tmp_parent, *children;
509 unsigned int nchildren;
514 unsigned long nitems, after;
517 if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY(display), win,
518 gdk_x11_get_xatom_by_name_for_display (display, "WM_STATE"),
519 0, 0, False, AnyPropertyType,
520 &type, &format, &nitems, &after, &data) != Success)
530 /* This is beautiful! Damn Enlightenment and click-to-focus */
531 if (!XTranslateCoordinates (gdk_display, _gdk_root_window, win,
532 x_root, y_root, &dest_x, &dest_y, &child))
536 if (!XQueryTree (GDK_DISPLAY_XDISPLAY (display), win,
537 &root, &tmp_parent, &children, &nchildren))
540 for (i = nchildren - 1; (i >= 0) && (child == None); i--)
542 XWindowAttributes xwa;
544 if (XGetWindowAttributes (GDK_DISPLAY_XDISPLAY (display),
547 if ((xwa.map_state == IsViewable) && (xwa.class == InputOutput) &&
548 (x >= xwa.x) && (x < xwa.x + (gint)xwa.width) &&
549 (y >= xwa.y) && (y < xwa.y + (gint)xwa.height))
562 return get_client_window_at_coords_recurse (display, child, x, y);
568 get_client_window_at_coords (GdkWindowCache *cache,
574 Window retval = None;
576 gdk_error_trap_push ();
578 tmp_list = cache->children;
580 while (tmp_list && !retval)
582 GdkCacheChild *child = tmp_list->data;
584 if ((child->xid != ignore) && (child->mapped))
586 if ((x_root >= child->x) && (x_root < child->x + child->width) &&
587 (y_root >= child->y) && (y_root < child->y + child->height))
589 retval = get_client_window_at_coords_recurse (gdk_screen_get_display (cache->screen),
598 tmp_list = tmp_list->next;
601 gdk_error_trap_pop ();
606 return GDK_WINDOW_XWINDOW (gdk_screen_get_root_window (cache->screen));
609 /*************************************************************
610 ***************************** MOTIF *************************
611 *************************************************************/
613 /* values used in the message type for Motif DND */
626 /* Values used to specify type of protocol to use */
630 XmDRAG_PREFER_PREREGISTER,
632 XmDRAG_PREFER_DYNAMIC,
634 XmDRAG_PREFER_RECEIVER
637 /* Operation codes */
645 /* Drop site status */
647 XmNO_DROP_SITE = 0x01,
648 XmDROP_SITE_INVALID = 0x02,
649 XmDROP_SITE_VALID = 0x03
652 /* completion status */
660 /* Byte swapping routines. The motif specification leaves it
661 * up to us to save a few bytes in the client messages
663 static gchar local_byte_order = '\0';
665 #ifdef G_ENABLE_DEBUG
667 print_target_list (GList *targets)
671 gchar *name = gdk_atom_name (GDK_POINTER_TO_ATOM (targets->data));
672 g_message ("\t%s", name);
674 targets = targets->next;
677 #endif /* G_ENABLE_DEBUG */
680 init_byte_order (void)
682 guint32 myint = 0x01020304;
683 local_byte_order = (*(gchar *)&myint == 1) ? 'B' : 'l';
687 card16_to_host (guint16 x, gchar byte_order) {
688 if (byte_order == local_byte_order)
691 return (x << 8) | (x >> 8);
695 card32_to_host (guint32 x, gchar byte_order) {
696 if (byte_order == local_byte_order)
699 return (x << 24) | ((x & 0xff00) << 8) | ((x & 0xff0000) >> 8) | (x >> 24);
702 /* Motif packs together fields of varying length into the
703 * client message. We can't rely on accessing these
704 * through data.s[], data.l[], etc, because on some architectures
705 * (i.e., Alpha) these won't be valid for format == 8.
708 #define MOTIF_XCLIENT_BYTE(xevent,i) \
709 (xevent)->xclient.data.b[i]
710 #define MOTIF_XCLIENT_SHORT(xevent,i) \
711 ((gint16 *)&((xevent)->xclient.data.b[0]))[i]
712 #define MOTIF_XCLIENT_LONG(xevent,i) \
713 ((gint32 *)&((xevent)->xclient.data.b[0]))[i]
715 #define MOTIF_UNPACK_BYTE(xevent,i) MOTIF_XCLIENT_BYTE(xevent,i)
716 #define MOTIF_UNPACK_SHORT(xevent,i) \
717 card16_to_host (MOTIF_XCLIENT_SHORT(xevent,i), MOTIF_XCLIENT_BYTE(xevent, 1))
718 #define MOTIF_UNPACK_LONG(xevent,i) \
719 card32_to_host (MOTIF_XCLIENT_LONG(xevent,i), MOTIF_XCLIENT_BYTE(xevent, 1))
721 /***** Dest side ***********/
723 /* Property placed on source windows */
724 typedef struct _MotifDragInitiatorInfo {
726 guint8 protocol_version;
727 guint16 targets_index;
728 guint32 selection_atom;
729 } MotifDragInitiatorInfo;
731 /* Header for target table on the drag window */
732 typedef struct _MotifTargetTableHeader {
734 guchar protocol_version;
737 } MotifTargetTableHeader;
739 /* Property placed on target windows */
740 typedef struct _MotifDragReceiverInfo {
742 guint8 protocol_version;
743 guint8 protocol_style;
745 guint32 proxy_window;
746 guint16 num_drop_sites;
749 } MotifDragReceiverInfo;
751 /* Target table handling */
753 static GdkFilterReturn
754 motif_drag_window_filter (GdkXEvent *xevent,
758 XEvent *xev = (XEvent *)xevent;
759 GdkDisplay *display = GDK_WINDOW_DISPLAY (event->any.window);
760 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
762 switch (xev->xany.type)
765 display_x11->motif_drag_window = None;
766 display_x11->motif_drag_gdk_window = NULL;
769 if (display_x11->motif_target_lists &&
770 (xev->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (display, "_MOTIF_DRAG_TARGETS")))
771 motif_read_target_table (display);
774 return GDK_FILTER_REMOVE;
778 motif_lookup_drag_window (GdkDisplay *display,
779 Display *lookup_xdisplay)
781 Window retval = None;
782 gulong bytes_after, nitems;
787 XGetWindowProperty (lookup_xdisplay, RootWindow (lookup_xdisplay, 0),
788 gdk_x11_get_xatom_by_name_for_display (display, "_MOTIF_DRAG_WINDOW"),
790 XA_WINDOW, &type, &format, &nitems, &bytes_after,
793 if ((format == 32) && (nitems == 1) && (bytes_after == 0))
795 retval = *(Window *)data;
797 g_message ("Found drag window %#lx\n", GDK_DISPLAY_X11 (display)->motif_drag_window));
806 /* Finds the window where global Motif drag information is stored.
807 * If it doesn't exist and 'create' is TRUE, create one.
810 motif_find_drag_window (GdkDisplay *display,
813 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
815 if (!display_x11->motif_drag_window)
817 Atom motif_drag_window_atom = gdk_x11_get_xatom_by_name_for_display (display, "_MOTIF_DRAG_WINDOW");
818 display_x11->motif_drag_window = motif_lookup_drag_window (display, display_x11->xdisplay);
820 if (!display_x11->motif_drag_window && create)
822 /* Create a persistant window. (Copied from LessTif) */
824 Display *persistant_xdisplay;
825 XSetWindowAttributes attr;
826 persistant_xdisplay = XOpenDisplay (gdk_display_get_name (display));
827 XSetCloseDownMode (persistant_xdisplay, RetainPermanent);
829 XGrabServer (persistant_xdisplay);
831 display_x11->motif_drag_window = motif_lookup_drag_window (display, persistant_xdisplay);
833 if (!display_x11->motif_drag_window)
835 attr.override_redirect = True;
836 attr.event_mask = PropertyChangeMask;
838 display_x11->motif_drag_window =
839 XCreateWindow (persistant_xdisplay,
840 RootWindow (persistant_xdisplay, 0),
841 -100, -100, 10, 10, 0, 0,
842 InputOnly, CopyFromParent,
843 (CWOverrideRedirect | CWEventMask), &attr);
846 g_message ("Created drag window %#lx\n", display_x11->motif_drag_window));
848 XChangeProperty (persistant_xdisplay,
849 RootWindow (persistant_xdisplay, 0),
850 motif_drag_window_atom, XA_WINDOW,
852 (guchar *)&motif_drag_window_atom, 1);
855 XUngrabServer (persistant_xdisplay);
856 XCloseDisplay (persistant_xdisplay);
859 /* There is a miniscule race condition here if the drag window
860 * gets destroyed exactly now.
862 if (display_x11->motif_drag_window)
864 display_x11->motif_drag_gdk_window =
865 gdk_window_foreign_new_for_display (display, display_x11->motif_drag_window);
866 gdk_window_add_filter (display_x11->motif_drag_gdk_window,
867 motif_drag_window_filter,
872 return display_x11->motif_drag_window;
876 motif_read_target_table (GdkDisplay *display)
878 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
879 gulong bytes_after, nitems;
884 Atom motif_drag_targets_atom = gdk_x11_get_xatom_by_name_for_display (display, "_MOTIF_DRAG_TARGETS");
886 if (display_x11->motif_target_lists)
888 for (i=0; i<display_x11->motif_n_target_lists; i++)
889 g_list_free (display_x11->motif_target_lists[i]);
891 g_free (display_x11->motif_target_lists);
892 display_x11->motif_target_lists = NULL;
893 display_x11->motif_n_target_lists = 0;
896 if (motif_find_drag_window (display, FALSE))
898 MotifTargetTableHeader *header = NULL;
899 guchar *target_bytes = NULL;
901 gboolean success = FALSE;
903 gdk_error_trap_push ();
904 XGetWindowProperty (display_x11->xdisplay,
905 display_x11->motif_drag_window,
906 motif_drag_targets_atom,
907 0, (sizeof(MotifTargetTableHeader)+3)/4, FALSE,
908 motif_drag_targets_atom,
909 &type, &format, &nitems, &bytes_after,
912 if (gdk_error_trap_pop () || (format != 8) || (nitems < sizeof (MotifTargetTableHeader)))
915 header->n_lists = card16_to_host (header->n_lists, header->byte_order);
916 header->total_size = card32_to_host (header->total_size, header->byte_order);
918 gdk_error_trap_push ();
919 XGetWindowProperty (display_x11->xdisplay,
920 display_x11->motif_drag_window,
921 motif_drag_targets_atom,
922 (sizeof(MotifTargetTableHeader)+3)/4,
923 (header->total_size + 3)/4 - (sizeof(MotifTargetTableHeader) + 3)/4,
925 motif_drag_targets_atom, &type, &format, &nitems,
926 &bytes_after, &target_bytes);
928 if (gdk_error_trap_pop () || (format != 8) || (bytes_after != 0) ||
929 (nitems != header->total_size - sizeof(MotifTargetTableHeader)))
932 display_x11->motif_n_target_lists = header->n_lists;
933 display_x11->motif_target_lists = g_new0 (GList *, display_x11->motif_n_target_lists);
936 for (i=0; i<header->n_lists; i++)
941 if (p + sizeof(guint16) - target_bytes > nitems)
944 n_targets = card16_to_host (*(gushort *)p, header->byte_order);
946 /* We need to make a copy of the targets, since it may
949 targets = g_new (guint32, n_targets);
950 memcpy (targets, p + sizeof(guint16), sizeof(guint32) * n_targets);
952 p += sizeof(guint16) + n_targets * sizeof(guint32);
953 if (p - target_bytes > nitems)
956 for (j=0; j<n_targets; j++)
957 display_x11->motif_target_lists[i] =
958 g_list_prepend (display_x11->motif_target_lists[i],
959 GUINT_TO_POINTER (card32_to_host (targets[j],
960 header->byte_order)));
962 display_x11->motif_target_lists[i] = g_list_reverse (display_x11->motif_target_lists[i]);
972 XFree (target_bytes);
976 if (display_x11->motif_target_lists)
978 g_free (display_x11->motif_target_lists);
979 display_x11->motif_target_lists = NULL;
980 display_x11->motif_n_target_lists = 0;
982 g_warning ("Error reading Motif target table\n");
988 targets_sort_func (gconstpointer a, gconstpointer b)
990 return (GPOINTER_TO_UINT (a) < GPOINTER_TO_UINT (b)) ?
991 -1 : ((GPOINTER_TO_UINT (a) > GPOINTER_TO_UINT (b)) ? 1 : 0);
994 /* Check if given (sorted) list is in the targets table */
996 motif_target_table_check (GdkDisplay *display,
999 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
1000 GList *tmp_list1, *tmp_list2;
1003 for (i=0; i<display_x11->motif_n_target_lists; i++)
1005 tmp_list1 = display_x11->motif_target_lists[i];
1008 while (tmp_list1 && tmp_list2)
1010 if (tmp_list1->data != tmp_list2->data)
1013 tmp_list1 = tmp_list1->next;
1014 tmp_list2 = tmp_list2->next;
1016 if (!tmp_list1 && !tmp_list2) /* Found it */
1024 motif_add_to_target_table (GdkDisplay *display,
1025 GList *targets) /* targets is list of GdkAtom */
1027 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
1028 GList *sorted = NULL;
1033 /* make a sorted copy of the list */
1037 Atom xatom = gdk_x11_atom_to_xatom_for_display (display, GDK_POINTER_TO_ATOM (targets->data));
1038 sorted = g_list_insert_sorted (sorted, GUINT_TO_POINTER (xatom), targets_sort_func);
1039 targets = targets->next;
1042 /* First check if it is there already */
1044 if (display_x11->motif_target_lists)
1045 index = motif_target_table_check (display, sorted);
1047 /* We need to grab the server while doing this, to ensure
1053 /* We need to make sure that it exists _before_ we grab the
1054 * server, since we can't open a new connection after we
1057 motif_find_drag_window (display, TRUE);
1059 gdk_x11_display_grab (display);
1060 motif_read_target_table (display);
1062 /* Check again, in case it was added in the meantime */
1064 if (display_x11->motif_target_lists)
1065 index = motif_target_table_check (display, sorted);
1069 guint32 total_size = 0;
1073 MotifTargetTableHeader *header;
1075 if (!display_x11->motif_target_lists)
1077 display_x11->motif_target_lists = g_new (GList *, 1);
1078 display_x11->motif_n_target_lists = 1;
1082 display_x11->motif_n_target_lists++;
1083 display_x11->motif_target_lists = g_realloc (display_x11->motif_target_lists,
1084 sizeof(GList *) * display_x11->motif_n_target_lists);
1086 display_x11->motif_target_lists[display_x11->motif_n_target_lists - 1] = sorted;
1088 index = display_x11->motif_n_target_lists - 1;
1090 total_size = sizeof (MotifTargetTableHeader);
1091 for (i = 0; i < display_x11->motif_n_target_lists ; i++)
1092 total_size += sizeof(guint16) + sizeof(guint32) * g_list_length (display_x11->motif_target_lists[i]);
1094 data = g_malloc (total_size);
1096 header = (MotifTargetTableHeader *)data;
1097 p = data + sizeof(MotifTargetTableHeader);
1099 header->byte_order = local_byte_order;
1100 header->protocol_version = 0;
1101 header->n_lists = display_x11->motif_n_target_lists;
1102 header->total_size = total_size;
1104 for (i = 0; i < display_x11->motif_n_target_lists ; i++)
1106 guint16 n_targets = g_list_length (display_x11->motif_target_lists[i]);
1107 guint32 *targets = g_new (guint32, n_targets);
1108 guint32 *p32 = targets;
1110 tmp_list = display_x11->motif_target_lists[i];
1113 *p32 = GPOINTER_TO_UINT (tmp_list->data);
1115 tmp_list = tmp_list->next;
1120 p += sizeof(guint16);
1122 memcpy (p, targets, n_targets * sizeof(guint32));
1125 p += sizeof(guint32) * n_targets;
1129 XChangeProperty (display_x11->xdisplay,
1130 display_x11->motif_drag_window,
1131 gdk_x11_get_xatom_by_name_for_display (display, "_MOTIF_DRAG_TARGETS"),
1132 gdk_x11_get_xatom_by_name_for_display (display, "_MOTIF_DRAG_TARGETS"),
1136 gdk_x11_display_ungrab (display);
1139 g_list_free (sorted);
1143 /* Translate flags */
1146 motif_dnd_translate_flags (GdkDragContext *context, guint16 flags)
1148 guint recommended_op = flags & 0x000f;
1149 guint possible_ops = (flags & 0x0f0) >> 4;
1151 switch (recommended_op)
1154 context->suggested_action = GDK_ACTION_MOVE;
1157 context->suggested_action = GDK_ACTION_COPY;
1160 context->suggested_action = GDK_ACTION_LINK;
1163 context->suggested_action = GDK_ACTION_COPY;
1167 context->actions = 0;
1168 if (possible_ops & XmDROP_MOVE)
1169 context->actions |= GDK_ACTION_MOVE;
1170 if (possible_ops & XmDROP_COPY)
1171 context->actions |= GDK_ACTION_COPY;
1172 if (possible_ops & XmDROP_LINK)
1173 context->actions |= GDK_ACTION_LINK;
1177 motif_dnd_get_flags (GdkDragContext *context)
1181 switch (context->suggested_action)
1183 case GDK_ACTION_MOVE:
1184 flags = XmDROP_MOVE;
1186 case GDK_ACTION_COPY:
1187 flags = XmDROP_COPY;
1189 case GDK_ACTION_LINK:
1190 flags = XmDROP_LINK;
1193 flags = XmDROP_NOOP;
1197 if (context->actions & GDK_ACTION_MOVE)
1198 flags |= XmDROP_MOVE << 8;
1199 if (context->actions & GDK_ACTION_COPY)
1200 flags |= XmDROP_COPY << 8;
1201 if (context->actions & GDK_ACTION_LINK)
1202 flags |= XmDROP_LINK << 8;
1210 motif_set_targets (GdkDragContext *context)
1212 GdkDragContextPrivateX11 *private = PRIVATE_DATA (context);
1213 MotifDragInitiatorInfo info;
1215 GdkDisplay *display = GDK_DRAWABLE_DISPLAY (context->source_window);
1217 info.byte_order = local_byte_order;
1218 info.protocol_version = 0;
1220 info.targets_index = motif_add_to_target_table (display, context->targets);
1225 g_snprintf(buf, 20, "_GDK_SELECTION_%d", i);
1227 private->motif_selection = gdk_x11_get_xatom_by_name_for_display (display, buf);
1228 if (!XGetSelectionOwner (GDK_DISPLAY_XDISPLAY (display), private->motif_selection))
1232 info.selection_atom = private->motif_selection;
1234 XChangeProperty (GDK_DRAWABLE_XDISPLAY (context->source_window),
1235 GDK_DRAWABLE_XID (context->source_window),
1236 private->motif_selection,
1237 gdk_x11_get_xatom_by_name_for_display (display, "_MOTIF_DRAG_INITIATOR_INFO"),
1239 (guchar *)&info, sizeof (info));
1241 private->motif_targets_set = 1;
1245 motif_check_dest (GdkDisplay *display,
1248 gboolean retval = FALSE;
1249 MotifDragReceiverInfo *info;
1252 unsigned long nitems, after;
1253 Atom motif_drag_receiver_info_atom = gdk_x11_get_xatom_by_name_for_display (display, "_MOTIF_DRAG_RECEIVER_INFO");
1255 gdk_error_trap_push ();
1256 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), win,
1257 motif_drag_receiver_info_atom,
1258 0, (sizeof(*info)+3)/4, False, AnyPropertyType,
1259 &type, &format, &nitems, &after,
1262 if (gdk_error_trap_pop() == 0)
1266 if ((format == 8) && (nitems == sizeof(*info)))
1268 if ((info->protocol_version == 0) &&
1269 ((info->protocol_style == XmDRAG_PREFER_PREREGISTER) ||
1270 (info->protocol_style == XmDRAG_PREFER_DYNAMIC) ||
1271 (info->protocol_style == XmDRAG_DYNAMIC)))
1277 g_warning ("Invalid Motif drag receiver property on window %ld\n", win));
1284 return retval ? win : None;
1288 motif_send_enter (GdkDragContext *context,
1291 GdkDragContextPrivateX11 *private = PRIVATE_DATA (context);
1292 GdkDisplay *display = GDK_DRAWABLE_DISPLAY (context->source_window);
1295 xev.xclient.type = ClientMessage;
1296 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_MOTIF_DRAG_AND_DROP_MESSAGE");
1297 xev.xclient.format = 8;
1298 xev.xclient.window = GDK_DRAWABLE_XID (context->dest_window);
1300 MOTIF_XCLIENT_BYTE (&xev, 0) = XmTOP_LEVEL_ENTER;
1301 MOTIF_XCLIENT_BYTE (&xev, 1) = local_byte_order;
1302 MOTIF_XCLIENT_SHORT (&xev, 1) = 0;
1303 MOTIF_XCLIENT_LONG (&xev, 1) = time;
1304 MOTIF_XCLIENT_LONG (&xev, 2) = GDK_DRAWABLE_XID (context->source_window);
1306 if (!private->motif_targets_set)
1307 motif_set_targets (context);
1309 MOTIF_XCLIENT_LONG (&xev, 3) = private->motif_selection;
1310 MOTIF_XCLIENT_LONG (&xev, 4) = 0;
1312 if (!_gdk_send_xevent (display,
1313 GDK_DRAWABLE_XID (context->dest_window),
1316 g_message ("Send event to %lx failed",
1317 GDK_DRAWABLE_XID (context->dest_window)));
1321 motif_send_leave (GdkDragContext *context,
1324 GdkDisplay *display = GDK_DRAWABLE_DISPLAY (context->source_window);
1327 xev.xclient.type = ClientMessage;
1328 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_MOTIF_DRAG_AND_DROP_MESSAGE");
1329 xev.xclient.format = 8;
1330 xev.xclient.window = GDK_DRAWABLE_XID (context->dest_window);
1332 MOTIF_XCLIENT_BYTE (&xev, 0) = XmTOP_LEVEL_LEAVE;
1333 MOTIF_XCLIENT_BYTE (&xev, 1) = local_byte_order;
1334 MOTIF_XCLIENT_SHORT (&xev, 1) = 0;
1335 MOTIF_XCLIENT_LONG (&xev, 1) = time;
1336 MOTIF_XCLIENT_LONG (&xev, 2) = 0;
1337 MOTIF_XCLIENT_LONG (&xev, 3) = 0;
1338 MOTIF_XCLIENT_LONG (&xev, 4) = 0;
1340 if (!_gdk_send_xevent (display,
1341 GDK_DRAWABLE_XID (context->dest_window),
1344 g_message ("Send event to %lx failed",
1345 GDK_DRAWABLE_XID (context->dest_window)));
1349 motif_send_motion (GdkDragContext *context,
1352 GdkDragAction action,
1355 GdkDragContextPrivateX11 *private = PRIVATE_DATA (context);
1356 GdkDisplay *display = GDK_DRAWABLE_DISPLAY (context->source_window);
1360 xev.xclient.type = ClientMessage;
1361 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_MOTIF_DRAG_AND_DROP_MESSAGE");
1362 xev.xclient.format = 8;
1363 xev.xclient.window = GDK_DRAWABLE_XID (context->dest_window);
1365 MOTIF_XCLIENT_BYTE (&xev, 1) = local_byte_order;
1366 MOTIF_XCLIENT_SHORT (&xev, 1) = motif_dnd_get_flags (context);
1367 MOTIF_XCLIENT_LONG (&xev, 1) = time;
1368 MOTIF_XCLIENT_LONG (&xev, 3) = 0;
1369 MOTIF_XCLIENT_LONG (&xev, 4) = 0;
1371 if ((context->suggested_action != private->old_action) ||
1372 (context->actions != private->old_actions))
1374 MOTIF_XCLIENT_BYTE (&xev, 0) = XmOPERATION_CHANGED;
1376 /* private->drag_status = GDK_DRAG_STATUS_ACTION_WAIT; */
1381 MOTIF_XCLIENT_BYTE (&xev, 0) = XmDRAG_MOTION;
1383 MOTIF_XCLIENT_SHORT (&xev, 4) = x_root;
1384 MOTIF_XCLIENT_SHORT (&xev, 5) = y_root;
1386 private->drag_status = GDK_DRAG_STATUS_MOTION_WAIT;
1390 if (!_gdk_send_xevent (display,
1391 GDK_DRAWABLE_XID (context->dest_window),
1394 g_message ("Send event to %lx failed",
1395 GDK_DRAWABLE_XID (context->dest_window)));
1401 motif_send_drop (GdkDragContext *context, guint32 time)
1403 GdkDragContextPrivateX11 *private = PRIVATE_DATA (context);
1404 GdkDisplay *display = GDK_DRAWABLE_DISPLAY (context->source_window);
1407 xev.xclient.type = ClientMessage;
1408 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_MOTIF_DRAG_AND_DROP_MESSAGE");
1409 xev.xclient.format = 8;
1410 xev.xclient.window = GDK_DRAWABLE_XID (context->dest_window);
1412 MOTIF_XCLIENT_BYTE (&xev, 0) = XmDROP_START;
1413 MOTIF_XCLIENT_BYTE (&xev, 1) = local_byte_order;
1414 MOTIF_XCLIENT_SHORT (&xev, 1) = motif_dnd_get_flags (context);
1415 MOTIF_XCLIENT_LONG (&xev, 1) = time;
1417 MOTIF_XCLIENT_SHORT (&xev, 4) = private->last_x;
1418 MOTIF_XCLIENT_SHORT (&xev, 5) = private->last_y;
1420 MOTIF_XCLIENT_LONG (&xev, 3) = private->motif_selection;
1421 MOTIF_XCLIENT_LONG (&xev, 4) = GDK_DRAWABLE_XID (context->source_window);
1423 if (!_gdk_send_xevent (display,
1424 GDK_DRAWABLE_XID (context->dest_window),
1427 g_message ("Send event to %lx failed",
1428 GDK_DRAWABLE_XID (context->dest_window)));
1434 motif_read_initiator_info (GdkDisplay *display,
1435 Window source_window,
1445 MotifDragInitiatorInfo *initiator_info;
1447 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
1449 gdk_error_trap_push ();
1450 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), source_window, atom,
1451 0, sizeof(*initiator_info), FALSE,
1452 gdk_x11_get_xatom_by_name_for_display (display, "_MOTIF_DRAG_INITIATOR_INFO"),
1453 &type, &format, &nitems, &bytes_after,
1454 (guchar **)&initiator_info);
1456 if (gdk_error_trap_pop () || (format != 8) || (nitems != sizeof (MotifDragInitiatorInfo)) || (bytes_after != 0))
1458 g_warning ("Error reading initiator info\n");
1462 motif_read_target_table (display);
1464 initiator_info->targets_index =
1465 card16_to_host (initiator_info->targets_index, initiator_info->byte_order);
1466 initiator_info->selection_atom =
1467 card32_to_host (initiator_info->selection_atom, initiator_info->byte_order);
1469 if (initiator_info->targets_index >= display_x11->motif_n_target_lists)
1471 g_warning ("Invalid target index in TOP_LEVEL_ENTER MESSAGE");
1472 XFree (initiator_info);
1476 tmp_list = g_list_last (display_x11->motif_target_lists[initiator_info->targets_index]);
1481 GdkAtom atom = gdk_x11_xatom_to_atom_for_display (display, GPOINTER_TO_UINT (tmp_list->data));
1482 *targets = g_list_prepend (*targets, GDK_ATOM_TO_POINTER (atom));
1483 tmp_list = tmp_list->prev;
1486 #ifdef G_ENABLE_DEBUG
1487 if (_gdk_debug_flags & GDK_DEBUG_DND)
1488 print_target_list (*targets);
1489 #endif /* G_ENABLE_DEBUG */
1491 *selection = initiator_info->selection_atom;
1493 XFree (initiator_info);
1498 static GdkDragContext *
1499 motif_drag_context_new (GdkWindow *dest_window,
1501 guint32 source_window,
1504 GdkDragContext *new_context;
1505 GdkDragContextPrivateX11 *private;
1506 GdkDisplay *display = GDK_DRAWABLE_DISPLAY (dest_window);
1507 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
1509 /* FIXME, current_dest_drag really shouldn't be NULL'd
1510 * if we error below.
1512 if (display_x11->current_dest_drag != NULL)
1514 if (timestamp >= display_x11->current_dest_drag->start_time)
1516 g_object_unref (display_x11->current_dest_drag);
1517 display_x11->current_dest_drag = NULL;
1523 new_context = gdk_drag_context_new ();
1524 private = PRIVATE_DATA (new_context);
1526 new_context->protocol = GDK_DRAG_PROTO_MOTIF;
1527 new_context->is_source = FALSE;
1529 new_context->source_window = gdk_window_lookup_for_display (display, source_window);
1530 if (new_context->source_window)
1531 g_object_ref (new_context->source_window);
1534 new_context->source_window = gdk_window_foreign_new_for_display (display, source_window);
1535 if (!new_context->source_window)
1537 g_object_unref (new_context);
1542 new_context->dest_window = dest_window;
1543 g_object_ref (dest_window);
1544 new_context->start_time = timestamp;
1546 if (!motif_read_initiator_info (GDK_WINDOW_DISPLAY (dest_window),
1549 &new_context->targets,
1550 &private->motif_selection))
1552 g_object_unref (new_context);
1560 * The MOTIF drag protocol has no real provisions for distinguishing
1561 * multiple simultaneous drops. If the sources grab the pointer
1562 * when doing drags, that shouldn't happen, in any case. If it
1563 * does, we can't do much except hope for the best.
1566 static GdkFilterReturn
1567 motif_top_level_enter (GdkEvent *event,
1570 guint32 source_window,
1573 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (GDK_DRAWABLE_DISPLAY (event->any.window));
1574 GdkDragContext *new_context;
1576 GDK_NOTE(DND, g_message ("Motif DND top level enter: flags: %#4x time: %d source_widow: %#4x atom: %d",
1577 flags, timestamp, source_window, atom));
1579 new_context = motif_drag_context_new (event->any.window, timestamp, source_window, atom);
1581 return GDK_FILTER_REMOVE;
1583 event->dnd.type = GDK_DRAG_ENTER;
1584 event->dnd.context = new_context;
1585 g_object_ref (new_context);
1587 display_x11->current_dest_drag = new_context;
1589 return GDK_FILTER_TRANSLATE;
1592 static GdkFilterReturn
1593 motif_top_level_leave (GdkEvent *event,
1597 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (GDK_DRAWABLE_DISPLAY (event->any.window));
1599 GDK_NOTE(DND, g_message ("Motif DND top level leave: flags: %#4x time: %d",
1602 if ((display_x11->current_dest_drag != NULL) &&
1603 (display_x11->current_dest_drag->protocol == GDK_DRAG_PROTO_MOTIF) &&
1604 (timestamp >= display_x11->current_dest_drag->start_time))
1606 event->dnd.type = GDK_DRAG_LEAVE;
1607 /* Pass ownership of context to the event */
1608 event->dnd.context = display_x11->current_dest_drag;
1610 display_x11->current_dest_drag = NULL;
1612 return GDK_FILTER_TRANSLATE;
1615 return GDK_FILTER_REMOVE;
1618 static GdkFilterReturn
1619 motif_motion (GdkEvent *event,
1625 GdkDragContextPrivateX11 *private;
1626 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (GDK_DRAWABLE_DISPLAY (event->any.window));
1628 GDK_NOTE(DND, g_message ("Motif DND motion: flags: %#4x time: %d (%d, %d)",
1629 flags, timestamp, x_root, y_root));
1631 if ((display_x11->current_dest_drag != NULL) &&
1632 (display_x11->current_dest_drag->protocol == GDK_DRAG_PROTO_MOTIF) &&
1633 (timestamp >= display_x11->current_dest_drag->start_time))
1635 private = PRIVATE_DATA (display_x11->current_dest_drag);
1637 event->dnd.type = GDK_DRAG_MOTION;
1638 event->dnd.context = display_x11->current_dest_drag;
1639 g_object_ref (display_x11->current_dest_drag);
1641 event->dnd.time = timestamp;
1643 motif_dnd_translate_flags (display_x11->current_dest_drag, flags);
1645 event->dnd.x_root = x_root;
1646 event->dnd.y_root = y_root;
1648 private->last_x = x_root;
1649 private->last_y = y_root;
1651 private->drag_status = GDK_DRAG_STATUS_MOTION_WAIT;
1653 return GDK_FILTER_TRANSLATE;
1656 return GDK_FILTER_REMOVE;
1659 static GdkFilterReturn
1660 motif_operation_changed (GdkEvent *event,
1664 GdkDragContextPrivateX11 *private;
1665 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (GDK_DRAWABLE_DISPLAY (event->any.window));
1666 GDK_NOTE(DND, g_message ("Motif DND operation changed: flags: %#4x time: %d",
1669 if ((display_x11->current_dest_drag != NULL) &&
1670 (display_x11->current_dest_drag->protocol == GDK_DRAG_PROTO_MOTIF) &&
1671 (timestamp >= display_x11->current_dest_drag->start_time))
1673 event->dnd.type = GDK_DRAG_MOTION;
1674 event->dnd.send_event = FALSE;
1675 event->dnd.context = display_x11->current_dest_drag;
1676 g_object_ref (display_x11->current_dest_drag);
1678 event->dnd.time = timestamp;
1679 private = PRIVATE_DATA (display_x11->current_dest_drag);
1681 motif_dnd_translate_flags (display_x11->current_dest_drag, flags);
1683 event->dnd.x_root = private->last_x;
1684 event->dnd.y_root = private->last_y;
1686 private->drag_status = GDK_DRAG_STATUS_ACTION_WAIT;
1688 return GDK_FILTER_TRANSLATE;
1691 return GDK_FILTER_REMOVE;
1694 static GdkFilterReturn
1695 motif_drop_start (GdkEvent *event,
1698 guint32 source_window,
1703 GdkDragContext *new_context;
1704 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (GDK_DRAWABLE_DISPLAY (event->any.window));
1706 GDK_NOTE(DND, g_message ("Motif DND drop start: flags: %#4x time: %d (%d, %d) source_widow: %#4x atom: %d",
1707 flags, timestamp, x_root, y_root, source_window, atom));
1709 new_context = motif_drag_context_new (event->any.window, timestamp, source_window, atom);
1711 return GDK_FILTER_REMOVE;
1713 motif_dnd_translate_flags (new_context, flags);
1715 event->dnd.type = GDK_DROP_START;
1716 event->dnd.context = new_context;
1717 event->dnd.time = timestamp;
1718 event->dnd.x_root = x_root;
1719 event->dnd.y_root = y_root;
1721 g_object_ref (new_context);
1722 display_x11->current_dest_drag = new_context;
1724 return GDK_FILTER_TRANSLATE;
1727 static GdkFilterReturn
1728 motif_drag_status (GdkEvent *event,
1732 GdkDragContext *context;
1733 GdkDisplay *display;
1736 g_message ("Motif status message: flags %x", flags));
1738 display = gdk_drawable_get_display (event->any.window);
1740 return GDK_FILTER_REMOVE;
1742 context = gdk_drag_context_find (display, TRUE, GDK_DRAWABLE_XID (event->any.window), None);
1746 GdkDragContextPrivateX11 *private = PRIVATE_DATA (context);
1747 if ((private->drag_status == GDK_DRAG_STATUS_MOTION_WAIT) ||
1748 (private->drag_status == GDK_DRAG_STATUS_ACTION_WAIT))
1749 private->drag_status = GDK_DRAG_STATUS_DRAG;
1751 event->dnd.type = GDK_DRAG_STATUS;
1752 event->dnd.send_event = FALSE;
1753 event->dnd.context = context;
1754 g_object_ref (context);
1756 event->dnd.time = timestamp;
1758 if ((flags & 0x00f0) >> 4 == XmDROP_SITE_VALID)
1760 switch (flags & 0x000f)
1763 context->action = 0;
1766 context->action = GDK_ACTION_MOVE;
1769 context->action = GDK_ACTION_COPY;
1772 context->action = GDK_ACTION_LINK;
1777 context->action = 0;
1779 return GDK_FILTER_TRANSLATE;
1781 return GDK_FILTER_REMOVE;
1784 static GdkFilterReturn
1785 motif_dnd_filter (GdkXEvent *xev,
1789 XEvent *xevent = (XEvent *)xev;
1794 guint32 source_window;
1796 gint16 x_root, y_root;
1799 if (!event->any.window ||
1800 gdk_window_get_window_type (event->any.window) == GDK_WINDOW_FOREIGN)
1801 return GDK_FILTER_CONTINUE; /* Not for us */
1803 /* First read some fields common to all Motif DND messages */
1805 reason = MOTIF_UNPACK_BYTE (xevent, 0);
1806 flags = MOTIF_UNPACK_SHORT (xevent, 1);
1807 timestamp = MOTIF_UNPACK_LONG (xevent, 1);
1809 is_reply = ((reason & 0x80) != 0);
1811 switch (reason & 0x7f)
1813 case XmTOP_LEVEL_ENTER:
1814 source_window = MOTIF_UNPACK_LONG (xevent, 2);
1815 atom = MOTIF_UNPACK_LONG (xevent, 3);
1816 return motif_top_level_enter (event, flags, timestamp, source_window, atom);
1817 case XmTOP_LEVEL_LEAVE:
1818 return motif_top_level_leave (event, flags, timestamp);
1821 x_root = MOTIF_UNPACK_SHORT (xevent, 4);
1822 y_root = MOTIF_UNPACK_SHORT (xevent, 5);
1825 return motif_motion (event, flags, timestamp, x_root, y_root);
1827 return motif_drag_status (event, flags, timestamp);
1829 case XmDROP_SITE_ENTER:
1830 return motif_drag_status (event, flags, timestamp);
1832 case XmDROP_SITE_LEAVE:
1833 return motif_drag_status (event,
1834 XmNO_DROP_SITE << 8 | XmDROP_NOOP,
1837 x_root = MOTIF_UNPACK_SHORT (xevent, 4);
1838 y_root = MOTIF_UNPACK_SHORT (xevent, 5);
1839 atom = MOTIF_UNPACK_LONG (xevent, 3);
1840 source_window = MOTIF_UNPACK_LONG (xevent, 4);
1843 return motif_drop_start (event, flags, timestamp, source_window, atom, x_root, y_root);
1846 case XmOPERATION_CHANGED:
1848 return motif_operation_changed (event, flags, timestamp);
1850 return motif_drag_status (event, flags, timestamp);
1853 /* To the best of my knowledge, these next two messages are
1854 * not part of the protocol, though they are defined in
1858 case XmDRAG_DROP_FINISH:
1862 return GDK_FILTER_REMOVE;
1865 /*************************************************************
1866 ***************************** XDND **************************
1867 *************************************************************/
1869 /* Utility functions */
1874 GdkDragAction action;
1875 } xdnd_actions_table[] = {
1876 { "XdndActionCopy", None, GDK_ACTION_COPY },
1877 { "XdndActionMove", None, GDK_ACTION_MOVE },
1878 { "XdndActionLink", None, GDK_ACTION_LINK },
1879 { "XdndActionAsk", None, GDK_ACTION_ASK },
1880 { "XdndActionPrivate", None, GDK_ACTION_COPY },
1883 static const gint xdnd_n_actions = sizeof(xdnd_actions_table) / sizeof(xdnd_actions_table[0]);
1884 static gboolean xdnd_actions_initialized = FALSE;
1887 xdnd_initialize_actions (void)
1891 xdnd_actions_initialized = TRUE;
1892 for (i=0; i < xdnd_n_actions; i++)
1893 xdnd_actions_table[i].atom = gdk_atom_intern (xdnd_actions_table[i].name, FALSE);
1896 static GdkDragAction
1897 xdnd_action_from_atom (GdkDisplay *display,
1900 GdkAtom atom = gdk_x11_xatom_to_atom_for_display (display, xatom);
1903 if (!xdnd_actions_initialized)
1904 xdnd_initialize_actions();
1906 for (i=0; i<xdnd_n_actions; i++)
1907 if (atom == xdnd_actions_table[i].atom)
1908 return xdnd_actions_table[i].action;
1914 xdnd_action_to_atom (GdkDisplay *display,
1915 GdkDragAction action)
1919 if (!xdnd_actions_initialized)
1920 xdnd_initialize_actions();
1922 for (i=0; i<xdnd_n_actions; i++)
1923 if (action == xdnd_actions_table[i].action)
1924 return gdk_x11_atom_to_xatom_for_display (display, xdnd_actions_table[i].atom);
1931 static GdkFilterReturn
1932 xdnd_status_filter (GdkXEvent *xev,
1936 GdkDisplay *display;
1937 XEvent *xevent = (XEvent *)xev;
1938 guint32 dest_window = xevent->xclient.data.l[0];
1939 guint32 flags = xevent->xclient.data.l[1];
1940 Atom action = xevent->xclient.data.l[4];
1941 GdkDragContext *context;
1943 if (!event->any.window ||
1944 gdk_window_get_window_type (event->any.window) == GDK_WINDOW_FOREIGN)
1945 return GDK_FILTER_CONTINUE; /* Not for us */
1948 g_message ("XdndStatus: dest_window: %#x action: %ld",
1949 dest_window, action));
1951 display = gdk_drawable_get_display (event->any.window);
1952 context = gdk_drag_context_find (display, TRUE, xevent->xclient.window, dest_window);
1956 GdkDragContextPrivateX11 *private = PRIVATE_DATA (context);
1957 if (private->drag_status == GDK_DRAG_STATUS_MOTION_WAIT)
1958 private->drag_status = GDK_DRAG_STATUS_DRAG;
1960 event->dnd.send_event = FALSE;
1961 event->dnd.type = GDK_DRAG_STATUS;
1962 event->dnd.context = context;
1963 g_object_ref (context);
1965 event->dnd.time = GDK_CURRENT_TIME; /* FIXME? */
1966 if (!(action != 0) != !(flags & 1))
1969 g_warning ("Received status event with flags not corresponding to action!\n"));
1973 context->action = xdnd_action_from_atom (display, action);
1975 return GDK_FILTER_TRANSLATE;
1978 return GDK_FILTER_REMOVE;
1981 static GdkFilterReturn
1982 xdnd_finished_filter (GdkXEvent *xev,
1986 GdkDisplay *display;
1987 XEvent *xevent = (XEvent *)xev;
1988 guint32 dest_window = xevent->xclient.data.l[0];
1989 GdkDragContext *context;
1991 if (!event->any.window ||
1992 gdk_window_get_window_type (event->any.window) == GDK_WINDOW_FOREIGN)
1993 return GDK_FILTER_CONTINUE; /* Not for us */
1996 g_message ("XdndFinished: dest_window: %#x", dest_window));
1998 display = gdk_drawable_get_display (event->any.window);
1999 context = gdk_drag_context_find (display, TRUE, xevent->xclient.window, dest_window);
2003 event->dnd.type = GDK_DROP_FINISHED;
2004 event->dnd.context = context;
2005 g_object_ref (context);
2007 return GDK_FILTER_TRANSLATE;
2010 return GDK_FILTER_REMOVE;
2014 xdnd_set_targets (GdkDragContext *context)
2016 GdkDragContextPrivateX11 *private = PRIVATE_DATA (context);
2018 GList *tmp_list = context->targets;
2020 gint n_atoms = g_list_length (context->targets);
2021 GdkDisplay *display = GDK_DRAWABLE_DISPLAY (context->source_window);
2023 atomlist = g_new (Atom, n_atoms);
2027 atomlist[i] = gdk_x11_atom_to_xatom_for_display (display, GDK_POINTER_TO_ATOM (tmp_list->data));
2028 tmp_list = tmp_list->next;
2032 XChangeProperty (GDK_DRAWABLE_XDISPLAY (context->source_window),
2033 GDK_DRAWABLE_XID (context->source_window),
2034 gdk_x11_get_xatom_by_name_for_display (display, "XdndTypeList"),
2035 XA_ATOM, 32, PropModeReplace,
2036 (guchar *)atomlist, n_atoms);
2040 private->xdnd_targets_set = 1;
2044 xdnd_set_actions (GdkDragContext *context)
2046 GdkDragContextPrivateX11 *private = PRIVATE_DATA (context);
2051 GdkDisplay *display = GDK_DRAWABLE_DISPLAY (context->source_window);
2053 if (!xdnd_actions_initialized)
2054 xdnd_initialize_actions();
2056 actions = context->actions;
2058 for (i=0; i<xdnd_n_actions; i++)
2060 if (actions & xdnd_actions_table[i].action)
2062 actions &= ~xdnd_actions_table[i].action;
2067 atomlist = g_new (Atom, n_atoms);
2069 actions = context->actions;
2071 for (i=0; i<xdnd_n_actions; i++)
2073 if (actions & xdnd_actions_table[i].action)
2075 actions &= ~xdnd_actions_table[i].action;
2076 atomlist[n_atoms] = gdk_x11_atom_to_xatom_for_display (display, xdnd_actions_table[i].atom);
2081 XChangeProperty (GDK_DRAWABLE_XDISPLAY (context->source_window),
2082 GDK_DRAWABLE_XID (context->source_window),
2083 gdk_x11_get_xatom_by_name_for_display (display, "XdndActionList"),
2084 XA_ATOM, 32, PropModeReplace,
2085 (guchar *)atomlist, n_atoms);
2089 private->xdnd_actions_set = 1;
2090 private->xdnd_actions = context->actions;
2093 /*************************************************************
2095 * Like gdk_send_event, but if the target is the root
2096 * window, sets an event mask of ButtonPressMask, otherwise
2097 * an event mask of 0.
2101 *************************************************************/
2104 xdnd_send_xevent (GdkDisplay *display,
2109 if (_gdk_x11_display_is_root_window (display, window))
2110 return _gdk_send_xevent (display, window, propagate, ButtonPressMask, event_send);
2112 return _gdk_send_xevent (display, window, propagate, 0, event_send);
2116 xdnd_send_enter (GdkDragContext *context)
2119 GdkDragContextPrivateX11 *private = PRIVATE_DATA (context);
2120 GdkDisplay *display = GDK_DRAWABLE_DISPLAY (context->dest_window);
2122 xev.xclient.type = ClientMessage;
2123 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "XdndEnter");
2124 xev.xclient.format = 32;
2125 xev.xclient.window = private->drop_xid ?
2127 GDK_DRAWABLE_XID (context->dest_window);
2128 xev.xclient.data.l[0] = GDK_DRAWABLE_XID (context->source_window);
2129 xev.xclient.data.l[1] = (3 << 24); /* version */
2130 xev.xclient.data.l[2] = 0;
2131 xev.xclient.data.l[3] = 0;
2132 xev.xclient.data.l[4] = 0;
2134 if (!private->xdnd_selection)
2135 private->xdnd_selection = gdk_x11_get_xatom_by_name_for_display (display, "XdndSelection");
2137 if (g_list_length (context->targets) > 3)
2139 if (!private->xdnd_targets_set)
2140 xdnd_set_targets (context);
2141 xev.xclient.data.l[1] |= 1;
2145 GList *tmp_list = context->targets;
2150 xev.xclient.data.l[i] = gdk_x11_atom_to_xatom_for_display (display,
2151 GDK_POINTER_TO_ATOM (tmp_list->data));
2152 tmp_list = tmp_list->next;
2157 if (!xdnd_send_xevent (display,
2158 GDK_DRAWABLE_XID (context->dest_window),
2162 g_message ("Send event to %lx failed",
2163 GDK_DRAWABLE_XID (context->dest_window)));
2164 g_object_unref (context->dest_window);
2165 context->dest_window = NULL;
2170 xdnd_send_leave (GdkDragContext *context)
2172 GdkDisplay *display = GDK_DRAWABLE_DISPLAY (context->source_window);
2175 GdkDragContextPrivateX11 *private = PRIVATE_DATA (context);
2177 xev.xclient.type = ClientMessage;
2178 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "XdndLeave");
2179 xev.xclient.format = 32;
2180 xev.xclient.window = private->drop_xid ?
2182 GDK_DRAWABLE_XID (context->dest_window);
2183 xev.xclient.data.l[0] = GDK_DRAWABLE_XID (context->source_window);
2184 xev.xclient.data.l[1] = 0;
2185 xev.xclient.data.l[2] = 0;
2186 xev.xclient.data.l[3] = 0;
2187 xev.xclient.data.l[4] = 0;
2189 if (!xdnd_send_xevent (display,
2190 GDK_DRAWABLE_XID (context->dest_window),
2194 g_message ("Send event to %lx failed",
2195 GDK_DRAWABLE_XID (context->dest_window)));
2196 g_object_unref (context->dest_window);
2197 context->dest_window = NULL;
2202 xdnd_send_drop (GdkDragContext *context, guint32 time)
2204 GdkDragContextPrivateX11 *private = PRIVATE_DATA (context);
2205 GdkDisplay *display = GDK_DRAWABLE_DISPLAY (context->source_window);
2208 xev.xclient.type = ClientMessage;
2209 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "XdndDrop");
2210 xev.xclient.format = 32;
2211 xev.xclient.window = private->drop_xid ?
2213 GDK_DRAWABLE_XID (context->dest_window);
2214 xev.xclient.data.l[0] = GDK_DRAWABLE_XID (context->source_window);
2215 xev.xclient.data.l[1] = 0;
2216 xev.xclient.data.l[2] = time;
2217 xev.xclient.data.l[3] = 0;
2218 xev.xclient.data.l[4] = 0;
2220 if (!xdnd_send_xevent (display,
2221 GDK_DRAWABLE_XID (context->dest_window),
2225 g_message ("Send event to %lx failed",
2226 GDK_DRAWABLE_XID (context->dest_window)));
2227 g_object_unref (context->dest_window);
2228 context->dest_window = NULL;
2233 xdnd_send_motion (GdkDragContext *context,
2236 GdkDragAction action,
2239 GdkDragContextPrivateX11 *private = PRIVATE_DATA (context);
2240 GdkDisplay *display = GDK_DRAWABLE_DISPLAY (context->source_window);
2243 xev.xclient.type = ClientMessage;
2244 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "XdndPosition");
2245 xev.xclient.format = 32;
2246 xev.xclient.window = private->drop_xid ?
2248 GDK_DRAWABLE_XID (context->dest_window);
2249 xev.xclient.data.l[0] = GDK_DRAWABLE_XID (context->source_window);
2250 xev.xclient.data.l[1] = 0;
2251 xev.xclient.data.l[2] = (x_root << 16) | y_root;
2252 xev.xclient.data.l[3] = time;
2253 xev.xclient.data.l[4] = xdnd_action_to_atom (display, action);
2255 if (!xdnd_send_xevent (display,
2256 GDK_DRAWABLE_XID (context->dest_window),
2260 g_message ("Send event to %lx failed",
2261 GDK_DRAWABLE_XID (context->dest_window)));
2262 g_object_unref (context->dest_window);
2263 context->dest_window = NULL;
2265 private->drag_status = GDK_DRAG_STATUS_MOTION_WAIT;
2269 xdnd_check_dest (GdkDisplay *display,
2272 gboolean retval = FALSE;
2275 unsigned long nitems, after;
2279 Atom xdnd_proxy_atom = gdk_x11_get_xatom_by_name_for_display (display, "XdndProxy");
2280 Atom xdnd_aware_atom = gdk_x11_get_xatom_by_name_for_display (display, "XdndAware");
2284 gdk_error_trap_push ();
2286 if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), win,
2288 1, False, AnyPropertyType,
2289 &type, &format, &nitems, &after,
2290 (guchar **)&proxy_data) == Success)
2294 if ((format == 32) && (nitems == 1))
2296 proxy = *proxy_data;
2300 g_warning ("Invalid XdndOwner "
2301 "property on window %ld\n", win));
2306 if ((XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), proxy ? proxy : win,
2308 1, False, AnyPropertyType,
2309 &type, &format, &nitems, &after,
2310 (guchar **)&version) == Success) &&
2313 if ((format == 32) && (nitems == 1))
2320 g_warning ("Invalid XdndAware property on window %ld\n", win));
2326 gdk_error_trap_pop ();
2328 return retval ? (proxy ? proxy : win) : None;
2334 xdnd_read_actions (GdkDragContext *context)
2336 GdkDisplay *display = GDK_WINDOW_DISPLAY (context->source_window);
2339 gulong nitems, after;
2344 /* Get the XdndActionList, if set */
2346 gdk_error_trap_push ();
2348 if (XGetWindowProperty (GDK_DRAWABLE_XDISPLAY (context->source_window),
2349 GDK_DRAWABLE_XID (context->source_window),
2350 gdk_x11_get_xatom_by_name_for_display (display, "XdndActionList"),
2352 False, XA_ATOM, &type, &format, &nitems,
2353 &after, (guchar **)&data) == Success &&
2356 context->actions = 0;
2358 for (i=0; i<nitems; i++)
2359 context->actions |= xdnd_action_from_atom (display, data[i]);
2361 (PRIVATE_DATA (context))->xdnd_have_actions = TRUE;
2363 #ifdef G_ENABLE_DEBUG
2364 if (_gdk_debug_flags & GDK_DEBUG_DND)
2366 GString *action_str = g_string_new (NULL);
2367 if (context->actions & GDK_ACTION_MOVE)
2368 g_string_append(action_str, "MOVE ");
2369 if (context->actions & GDK_ACTION_COPY)
2370 g_string_append(action_str, "COPY ");
2371 if (context->actions & GDK_ACTION_LINK)
2372 g_string_append(action_str, "LINK ");
2373 if (context->actions & GDK_ACTION_ASK)
2374 g_string_append(action_str, "ASK ");
2376 g_message("Xdnd actions = %s", action_str->str);
2377 g_string_free (action_str, TRUE);
2379 #endif /* G_ENABLE_DEBUG */
2384 gdk_error_trap_pop ();
2387 /* We have to make sure that the XdndActionList we keep internally
2388 * is up to date with the XdndActionList on the source window
2389 * because we get no notification, because Xdnd wasn't meant
2390 * to continually send actions. So we select on PropertyChangeMask
2391 * and add this filter.
2393 static GdkFilterReturn
2394 xdnd_source_window_filter (GdkXEvent *xev,
2398 XEvent *xevent = (XEvent *)xev;
2399 GdkDragContext *context = cb_data;
2400 GdkDisplay *display = GDK_WINDOW_DISPLAY(event->any.window);
2402 if ((xevent->xany.type == PropertyNotify) &&
2403 (xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (display, "XdndActionList")))
2405 xdnd_read_actions (context);
2407 return GDK_FILTER_REMOVE;
2410 return GDK_FILTER_CONTINUE;
2414 xdnd_manage_source_filter (GdkDragContext *context,
2416 gboolean add_filter)
2418 gdk_error_trap_push ();
2420 if (!GDK_WINDOW_DESTROYED (window))
2424 gdk_window_set_events (window,
2425 gdk_window_get_events (window) |
2426 GDK_PROPERTY_CHANGE_MASK);
2427 gdk_window_add_filter (window, xdnd_source_window_filter, context);
2432 gdk_window_remove_filter (window,
2433 xdnd_source_window_filter,
2435 /* Should we remove the GDK_PROPERTY_NOTIFY mask?
2436 * but we might want it for other reasons. (Like
2437 * INCR selection transactions).
2442 gdk_display_sync (gdk_drawable_get_display (window));
2443 gdk_error_trap_pop ();
2446 static GdkFilterReturn
2447 xdnd_enter_filter (GdkXEvent *xev,
2451 GdkDisplay *display;
2452 GdkDisplayX11 *display_x11;
2453 XEvent *xevent = (XEvent *)xev;
2454 GdkDragContext *new_context;
2459 gulong nitems, after;
2462 guint32 source_window;
2466 if (!event->any.window ||
2467 gdk_window_get_window_type (event->any.window) == GDK_WINDOW_FOREIGN)
2468 return GDK_FILTER_CONTINUE; /* Not for us */
2470 source_window = xevent->xclient.data.l[0];
2471 get_types = ((xevent->xclient.data.l[1] & 1) != 0);
2472 version = (xevent->xclient.data.l[1] & 0xff000000) >> 24;
2474 display = GDK_DRAWABLE_DISPLAY (event->any.window);
2475 display_x11 = GDK_DISPLAY_X11 (display);
2478 g_message ("XdndEnter: source_window: %#x, version: %#x",
2479 source_window, version));
2483 /* Old source ignore */
2484 GDK_NOTE (DND, g_message ("Ignored old XdndEnter message"));
2485 return GDK_FILTER_REMOVE;
2488 if (display_x11->current_dest_drag != NULL)
2490 g_object_unref (display_x11->current_dest_drag);
2491 display_x11->current_dest_drag = NULL;
2494 new_context = gdk_drag_context_new ();
2495 new_context->protocol = GDK_DRAG_PROTO_XDND;
2496 new_context->is_source = FALSE;
2498 new_context->source_window = gdk_window_lookup_for_display (display, source_window);
2499 if (new_context->source_window)
2500 g_object_ref (new_context->source_window);
2503 new_context->source_window = gdk_window_foreign_new_for_display (display, source_window);
2504 if (!new_context->source_window)
2506 g_object_unref (new_context);
2507 return GDK_FILTER_REMOVE;
2510 new_context->dest_window = event->any.window;
2511 g_object_ref (new_context->dest_window);
2513 new_context->targets = NULL;
2516 gdk_error_trap_push ();
2517 XGetWindowProperty (GDK_DRAWABLE_XDISPLAY (event->any.window),
2519 gdk_x11_get_xatom_by_name_for_display (display, "XdndTypeList"),
2521 False, XA_ATOM, &type, &format, &nitems,
2522 &after, (guchar **)&data);
2524 if (gdk_error_trap_pop () || (format != 32) || (type != XA_ATOM))
2526 g_object_unref (new_context);
2527 return GDK_FILTER_REMOVE;
2530 for (i=0; i<nitems; i++)
2531 new_context->targets =
2532 g_list_append (new_context->targets,
2533 GDK_ATOM_TO_POINTER (gdk_x11_xatom_to_atom_for_display (display,
2541 if (xevent->xclient.data.l[2+i])
2542 new_context->targets =
2543 g_list_append (new_context->targets,
2544 GDK_ATOM_TO_POINTER (gdk_x11_xatom_to_atom_for_display (display,
2545 xevent->xclient.data.l[2+i])));
2548 #ifdef G_ENABLE_DEBUG
2549 if (_gdk_debug_flags & GDK_DEBUG_DND)
2550 print_target_list (new_context->targets);
2551 #endif /* G_ENABLE_DEBUG */
2553 xdnd_manage_source_filter (new_context, new_context->source_window, TRUE);
2554 xdnd_read_actions (new_context);
2556 event->dnd.type = GDK_DRAG_ENTER;
2557 event->dnd.context = new_context;
2558 g_object_ref (new_context);
2560 display_x11->current_dest_drag = new_context;
2562 (PRIVATE_DATA (new_context))->xdnd_selection =
2563 gdk_x11_get_xatom_by_name_for_display (display, "XdndSelection");
2564 return GDK_FILTER_TRANSLATE;
2567 static GdkFilterReturn
2568 xdnd_leave_filter (GdkXEvent *xev,
2572 XEvent *xevent = (XEvent *)xev;
2573 guint32 source_window = xevent->xclient.data.l[0];
2574 GdkDisplayX11 *display_x11;
2576 if (!event->any.window ||
2577 gdk_window_get_window_type (event->any.window) == GDK_WINDOW_FOREIGN)
2578 return GDK_FILTER_CONTINUE; /* Not for us */
2581 g_message ("XdndLeave: source_window: %#x",
2584 display_x11 = GDK_DISPLAY_X11 (GDK_DRAWABLE_DISPLAY (event->any.window));
2586 if ((display_x11->current_dest_drag != NULL) &&
2587 (display_x11->current_dest_drag->protocol == GDK_DRAG_PROTO_XDND) &&
2588 (GDK_DRAWABLE_XID (display_x11->current_dest_drag->source_window) == source_window))
2590 event->dnd.type = GDK_DRAG_LEAVE;
2591 /* Pass ownership of context to the event */
2592 event->dnd.context = display_x11->current_dest_drag;
2594 display_x11->current_dest_drag = NULL;
2596 return GDK_FILTER_TRANSLATE;
2599 return GDK_FILTER_REMOVE;
2602 static GdkFilterReturn
2603 xdnd_position_filter (GdkXEvent *xev,
2607 XEvent *xevent = (XEvent *)xev;
2608 guint32 source_window = xevent->xclient.data.l[0];
2609 gint16 x_root = xevent->xclient.data.l[2] >> 16;
2610 gint16 y_root = xevent->xclient.data.l[2] & 0xffff;
2611 guint32 time = xevent->xclient.data.l[3];
2612 Atom action = xevent->xclient.data.l[4];
2614 GdkDisplay *display;
2615 GdkDisplayX11 *display_x11;
2617 if (!event->any.window ||
2618 gdk_window_get_window_type (event->any.window) == GDK_WINDOW_FOREIGN)
2619 return GDK_FILTER_CONTINUE; /* Not for us */
2622 g_message ("XdndPosition: source_window: %#x position: (%d, %d) time: %d action: %ld",
2623 source_window, x_root, y_root, time, action));
2625 display = GDK_DRAWABLE_DISPLAY (event->any.window);
2626 display_x11 = GDK_DISPLAY_X11 (display);
2628 if ((display_x11->current_dest_drag != NULL) &&
2629 (display_x11->current_dest_drag->protocol == GDK_DRAG_PROTO_XDND) &&
2630 (GDK_DRAWABLE_XID (display_x11->current_dest_drag->source_window) == source_window))
2632 event->dnd.type = GDK_DRAG_MOTION;
2633 event->dnd.context = display_x11->current_dest_drag;
2634 g_object_ref (display_x11->current_dest_drag);
2636 event->dnd.time = time;
2638 display_x11->current_dest_drag->suggested_action = xdnd_action_from_atom (display, action);
2640 if (!(PRIVATE_DATA (display_x11->current_dest_drag))->xdnd_have_actions)
2641 display_x11->current_dest_drag->actions = display_x11->current_dest_drag->suggested_action;
2643 event->dnd.x_root = x_root;
2644 event->dnd.y_root = y_root;
2646 (PRIVATE_DATA (display_x11->current_dest_drag))->last_x = x_root;
2647 (PRIVATE_DATA (display_x11->current_dest_drag))->last_y = y_root;
2649 return GDK_FILTER_TRANSLATE;
2652 return GDK_FILTER_REMOVE;
2655 static GdkFilterReturn
2656 xdnd_drop_filter (GdkXEvent *xev,
2660 XEvent *xevent = (XEvent *)xev;
2661 guint32 source_window = xevent->xclient.data.l[0];
2662 guint32 time = xevent->xclient.data.l[2];
2663 GdkDisplayX11 *display_x11;
2665 if (!event->any.window ||
2666 gdk_window_get_window_type (event->any.window) == GDK_WINDOW_FOREIGN)
2667 return GDK_FILTER_CONTINUE; /* Not for us */
2670 g_message ("XdndDrop: source_window: %#x time: %d",
2671 source_window, time));
2673 display_x11 = GDK_DISPLAY_X11 (GDK_DRAWABLE_DISPLAY (event->any.window));
2675 if ((display_x11->current_dest_drag != NULL) &&
2676 (display_x11->current_dest_drag->protocol == GDK_DRAG_PROTO_XDND) &&
2677 (GDK_DRAWABLE_XID (display_x11->current_dest_drag->source_window) == source_window))
2679 GdkDragContextPrivateX11 *private;
2680 private = PRIVATE_DATA (display_x11->current_dest_drag);
2682 event->dnd.type = GDK_DROP_START;
2684 event->dnd.context = display_x11->current_dest_drag;
2685 g_object_ref (display_x11->current_dest_drag);
2687 event->dnd.time = time;
2688 event->dnd.x_root = private->last_x;
2689 event->dnd.y_root = private->last_y;
2691 return GDK_FILTER_TRANSLATE;
2694 return GDK_FILTER_REMOVE;
2697 /*************************************************************
2698 ************************** Public API ***********************
2699 *************************************************************/
2701 _gdk_dnd_init (GdkDisplay *display)
2705 gdk_display_add_client_message_filter (
2707 gdk_atom_intern ("_MOTIF_DRAG_AND_DROP_MESSAGE", FALSE),
2708 motif_dnd_filter, NULL);
2709 gdk_display_add_client_message_filter (
2711 gdk_atom_intern ("XdndEnter", FALSE),
2712 xdnd_enter_filter, NULL);
2713 gdk_display_add_client_message_filter (
2715 gdk_atom_intern ("XdndLeave", FALSE),
2716 xdnd_leave_filter, NULL);
2717 gdk_display_add_client_message_filter (
2719 gdk_atom_intern ("XdndPosition", FALSE),
2720 xdnd_position_filter, NULL);
2721 gdk_display_add_client_message_filter (
2723 gdk_atom_intern ("XdndStatus", FALSE),
2724 xdnd_status_filter, NULL);
2725 gdk_display_add_client_message_filter (
2727 gdk_atom_intern ("XdndFinished", FALSE),
2728 xdnd_finished_filter, NULL);
2729 gdk_display_add_client_message_filter (
2731 gdk_atom_intern ("XdndDrop", FALSE),
2732 xdnd_drop_filter, NULL);
2738 gdk_drag_do_leave (GdkDragContext *context, guint32 time)
2740 if (context->dest_window)
2742 switch (context->protocol)
2744 case GDK_DRAG_PROTO_MOTIF:
2745 motif_send_leave (context, time);
2747 case GDK_DRAG_PROTO_XDND:
2748 xdnd_send_leave (context);
2750 case GDK_DRAG_PROTO_ROOTWIN:
2751 case GDK_DRAG_PROTO_NONE:
2756 g_object_unref (context->dest_window);
2757 context->dest_window = NULL;
2763 * @window: the source window for this drag.
2764 * @targets: the list of offered targets.
2766 * Starts a drag and creates a new drag context for it.
2768 * This function is called by the drag source.
2770 * Return value: a newly created #GdkDragContext.
2773 gdk_drag_begin (GdkWindow *window,
2776 GdkDragContext *new_context;
2778 g_return_val_if_fail (window != NULL, NULL);
2780 new_context = gdk_drag_context_new ();
2781 new_context->is_source = TRUE;
2782 new_context->source_window = window;
2783 g_object_ref (window);
2785 new_context->targets = g_list_copy (targets);
2786 new_context->actions = 0;
2792 * gdk_drag_get_protocol_for_display:
2793 * @display: the #GdkDisplay where the destination window resides
2794 * @xid: the X id of the destination window.
2795 * @protocol: location where the supported DND protocol is returned.
2796 * @returns: the X id of the window where the drop should happen. This
2797 * may be @xid or the X id of a proxy window, or None if @xid doesn't
2798 * support Drag and Drop.
2800 * Finds out the DND protocol supported by a window.
2805 gdk_drag_get_protocol_for_display (GdkDisplay *display,
2807 GdkDragProtocol *protocol)
2810 g_return_val_if_fail (GDK_IS_DISPLAY (display), None);
2812 if ((retval = xdnd_check_dest (display, xid)))
2814 *protocol = GDK_DRAG_PROTO_XDND;
2815 GDK_NOTE (DND, g_message ("Entering dnd window %#x\n", xid));
2818 else if ((retval = motif_check_dest (display, xid)))
2820 *protocol = GDK_DRAG_PROTO_MOTIF;
2821 GDK_NOTE (DND, g_message ("Entering motif window %#x\n", xid));
2826 /* Check if this is a root window */
2828 gboolean rootwin = FALSE;
2831 unsigned long nitems, after;
2832 unsigned char *data;
2834 if (_gdk_x11_display_is_root_window (display, (Window) xid))
2837 gdk_error_trap_push ();
2841 if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), xid,
2842 gdk_x11_get_xatom_by_name_for_display (display, "ENLIGHTENMENT_DESKTOP"),
2843 0, 0, False, AnyPropertyType,
2844 &type, &format, &nitems, &after, &data) == Success &&
2852 /* Until I find out what window manager the next one is for,
2853 * I'm leaving it commented out. It's supported in the
2854 * xscreensaver sources, though.
2859 if (XGetWindowProperty (gdk_display, win,
2860 gdk_x11_get_xatom_by_name ("__SWM_VROOT"),
2861 0, 0, False, AnyPropertyType,
2862 &type, &format, &nitems, &data) &&
2868 gdk_error_trap_pop ();
2872 *protocol = GDK_DRAG_PROTO_ROOTWIN;
2877 *protocol = GDK_DRAG_PROTO_NONE;
2881 static GdkWindowCache *
2882 drag_context_find_window_cache (GdkDragContext *context,
2885 GdkDragContextPrivateX11 *private = PRIVATE_DATA (context);
2887 GdkWindowCache *cache;
2889 for (tmp_list = private->window_caches; tmp_list; tmp_list = tmp_list->next)
2891 cache = tmp_list->data;
2892 if (cache->screen == screen)
2896 cache = gdk_window_cache_new (screen);
2897 private->window_caches = g_slist_prepend (private->window_caches, cache);
2903 * gdk_drag_find_window_for_screen:
2904 * @context: a #GdkDragContext
2905 * @drag_window: a window which may be at the pointer position, but
2906 * should be ignored, since it is put up by the drag source as an icon.
2907 * @screen: the screen where the destination window is sought.
2908 * @x_root: the x position of the pointer in root coordinates.
2909 * @y_root: the y position of the pointer in root coordinates.
2910 * @dest_window: location to store the destination window in.
2911 * @protocol: location to store the DND protocol in.
2913 * Finds the destination window and DND protocol to use at the
2914 * given pointer position.
2916 * This function is called by the drag source to obtain the
2917 * @dest_window and @protocol parameters for gdk_drag_motion().
2922 gdk_drag_find_window_for_screen (GdkDragContext *context,
2923 GdkWindow *drag_window,
2927 GdkWindow **dest_window,
2928 GdkDragProtocol *protocol)
2930 GdkDragContextPrivateX11 *private = PRIVATE_DATA (context);
2931 GdkWindowCache *window_cache;
2932 GdkDisplay *display;
2935 g_return_if_fail (context != NULL);
2937 display = GDK_WINDOW_DISPLAY (context->source_window);
2939 window_cache = drag_context_find_window_cache (context, screen);
2941 dest = get_client_window_at_coords (window_cache,
2943 GDK_DRAWABLE_XID (drag_window) : None,
2946 if (private->dest_xid != dest)
2949 private->dest_xid = dest;
2951 /* Check if new destination accepts drags, and which protocol */
2953 /* There is some ugliness here. We actually need to pass
2954 * _three_ pieces of information to drag_motion - dest_window,
2955 * protocol, and the XID of the unproxied window. The first
2956 * two are passed explicitely, the third implicitly through
2957 * protocol->dest_xid.
2959 if ((recipient = gdk_drag_get_protocol_for_display (display, dest, protocol)))
2961 *dest_window = gdk_window_lookup_for_display (display, recipient);
2963 g_object_ref (*dest_window);
2965 *dest_window = gdk_window_foreign_new_for_display (display, recipient);
2968 *dest_window = NULL;
2972 *dest_window = context->dest_window;
2974 g_object_ref (*dest_window);
2975 *protocol = context->protocol;
2981 * @context: a #GdkDragContext.
2982 * @dest_window: the new destination window, obtained by
2983 * gdk_drag_find_window().
2984 * @protocol: the DND protocol in use, obtained by gdk_drag_find_window().
2985 * @x_root: the x position of the pointer in root coordinates.
2986 * @y_root: the y position of the pointer in root coordinates.
2987 * @suggested_action: the suggested action.
2988 * @possible_actions: the possible actions.
2989 * @time_: the timestamp for this operation.
2991 * Updates the drag context when the pointer moves or the
2992 * set of actions changes.
2994 * This function is called by the drag source.
2996 * Return value: FIXME
2999 gdk_drag_motion (GdkDragContext *context,
3000 GdkWindow *dest_window,
3001 GdkDragProtocol protocol,
3004 GdkDragAction suggested_action,
3005 GdkDragAction possible_actions,
3008 GdkDragContextPrivateX11 *private = PRIVATE_DATA (context);
3010 g_return_val_if_fail (context != NULL, FALSE);
3012 /* When we have a Xdnd target, make sure our XdndActionList
3013 * matches the current actions;
3015 private->old_actions = context->actions;
3016 context->actions = possible_actions;
3018 if ((protocol == GDK_DRAG_PROTO_XDND) &&
3019 (!private->xdnd_actions_set ||
3020 private->xdnd_actions != possible_actions))
3021 xdnd_set_actions (context);
3023 if (context->dest_window != dest_window)
3025 GdkEvent temp_event;
3027 /* Send a leave to the last destination */
3028 gdk_drag_do_leave (context, time);
3029 private->drag_status = GDK_DRAG_STATUS_DRAG;
3031 /* Check if new destination accepts drags, and which protocol */
3035 context->dest_window = dest_window;
3036 private->drop_xid = private->dest_xid;
3037 g_object_ref (context->dest_window);
3038 context->protocol = protocol;
3042 case GDK_DRAG_PROTO_MOTIF:
3043 motif_send_enter (context, time);
3046 case GDK_DRAG_PROTO_XDND:
3047 xdnd_send_enter (context);
3050 case GDK_DRAG_PROTO_ROOTWIN:
3051 case GDK_DRAG_PROTO_NONE:
3055 private->old_action = suggested_action;
3056 context->suggested_action = suggested_action;
3057 private->old_actions = possible_actions;
3061 context->dest_window = NULL;
3062 private->drop_xid = None;
3063 context->action = 0;
3066 /* Push a status event, to let the client know that
3070 temp_event.dnd.type = GDK_DRAG_STATUS;
3071 temp_event.dnd.window = context->source_window;
3072 /* We use this to signal a synthetic status. Perhaps
3073 * we should use an extra field...
3075 temp_event.dnd.send_event = TRUE;
3077 temp_event.dnd.context = context;
3078 temp_event.dnd.time = time;
3080 gdk_event_put (&temp_event);
3084 private->old_action = context->suggested_action;
3085 context->suggested_action = suggested_action;
3088 /* Send a drag-motion event */
3090 private->last_x = x_root;
3091 private->last_y = y_root;
3093 if (context->dest_window)
3095 if (private->drag_status == GDK_DRAG_STATUS_DRAG)
3097 switch (context->protocol)
3099 case GDK_DRAG_PROTO_MOTIF:
3100 motif_send_motion (context, x_root, y_root, suggested_action, time);
3103 case GDK_DRAG_PROTO_XDND:
3104 xdnd_send_motion (context, x_root, y_root, suggested_action, time);
3107 case GDK_DRAG_PROTO_ROOTWIN:
3109 GdkEvent temp_event;
3110 /* GTK+ traditionally has used application/x-rootwin-drop,
3111 * but the XDND spec specifies x-rootwindow-drop.
3113 GdkAtom target1 = gdk_atom_intern ("application/x-rootwindow-drop", FALSE);
3114 GdkAtom target2 = gdk_atom_intern ("application/x-rootwin-drop", FALSE);
3116 if (g_list_find (context->targets,
3117 GDK_ATOM_TO_POINTER (target1)) ||
3118 g_list_find (context->targets,
3119 GDK_ATOM_TO_POINTER (target2)))
3120 context->action = context->suggested_action;
3122 context->action = 0;
3124 temp_event.dnd.type = GDK_DRAG_STATUS;
3125 temp_event.dnd.window = context->source_window;
3126 temp_event.dnd.send_event = FALSE;
3127 temp_event.dnd.context = context;
3128 temp_event.dnd.time = time;
3130 gdk_event_put (&temp_event);
3133 case GDK_DRAG_PROTO_NONE:
3134 g_warning ("GDK_DRAG_PROTO_NONE is not valid in gdk_drag_motion()");
3149 * @context: a #GdkDragContext.
3150 * @time_: the timestamp for this operation.
3152 * Drops on the current destination.
3154 * This function is called by the drag source.
3157 gdk_drag_drop (GdkDragContext *context,
3160 g_return_if_fail (context != NULL);
3162 if (context->dest_window)
3164 switch (context->protocol)
3166 case GDK_DRAG_PROTO_MOTIF:
3167 motif_send_leave (context, time);
3168 motif_send_drop (context, time);
3171 case GDK_DRAG_PROTO_XDND:
3172 xdnd_send_drop (context, time);
3175 case GDK_DRAG_PROTO_ROOTWIN:
3176 g_warning ("Drops for GDK_DRAG_PROTO_ROOTWIN must be handled internally");
3178 case GDK_DRAG_PROTO_NONE:
3179 g_warning ("GDK_DRAG_PROTO_NONE is not valid in gdk_drag_drop()");
3189 * @context: a #GdkDragContext.
3190 * @time_: the timestamp for this operation.
3192 * Aborts a drag without dropping.
3194 * This function is called by the drag source.
3197 gdk_drag_abort (GdkDragContext *context,
3200 g_return_if_fail (context != NULL);
3202 gdk_drag_do_leave (context, time);
3205 /* Destination side */
3209 * @context: a #GdkDragContext.
3210 * @action: the selected action which will be taken when a drop happens,
3211 * or 0 to indicate that a drop will not be accepted.
3212 * @time_: the timestamp for this operation.
3214 * Selects one of the actions offered by the drag source.
3216 * This function is called by the drag destination in response to
3217 * gdk_drag_motion() called by the drag source.
3220 gdk_drag_status (GdkDragContext *context,
3221 GdkDragAction action,
3224 GdkDragContextPrivateX11 *private;
3226 GdkDisplay *display;
3228 g_return_if_fail (context != NULL);
3230 private = PRIVATE_DATA (context);
3231 display = GDK_DRAWABLE_DISPLAY (context->source_window);
3233 context->action = action;
3235 if (context->protocol == GDK_DRAG_PROTO_MOTIF)
3237 gboolean need_coords = FALSE;
3239 xev.xclient.type = ClientMessage;
3240 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display,
3241 "_MOTIF_DRAG_AND_DROP_MESSAGE");
3242 xev.xclient.format = 8;
3243 xev.xclient.window = GDK_DRAWABLE_XID (context->source_window);
3245 if (private->drag_status == GDK_DRAG_STATUS_ACTION_WAIT)
3247 MOTIF_XCLIENT_BYTE (&xev, 0) = XmOPERATION_CHANGED | 0x80;
3251 if ((action != 0) != (private->old_action != 0))
3255 MOTIF_XCLIENT_BYTE (&xev, 0) = XmDROP_SITE_ENTER | 0x80;
3259 MOTIF_XCLIENT_BYTE (&xev, 0) = XmDROP_SITE_LEAVE | 0x80;
3263 MOTIF_XCLIENT_BYTE (&xev, 0) = XmDRAG_MOTION | 0x80;
3268 MOTIF_XCLIENT_BYTE (&xev, 1) = local_byte_order;
3272 case GDK_ACTION_MOVE:
3273 MOTIF_XCLIENT_SHORT (&xev, 1) = XmDROP_MOVE;
3275 case GDK_ACTION_COPY:
3276 MOTIF_XCLIENT_SHORT (&xev, 1) = XmDROP_COPY;
3278 case GDK_ACTION_LINK:
3279 MOTIF_XCLIENT_SHORT (&xev, 1) = XmDROP_LINK;
3282 MOTIF_XCLIENT_SHORT (&xev, 1) = XmDROP_NOOP;
3287 MOTIF_XCLIENT_SHORT (&xev, 1) |= (XmDROP_SITE_VALID << 4);
3289 MOTIF_XCLIENT_SHORT (&xev, 1) |= (XmNO_DROP_SITE << 4);
3291 MOTIF_XCLIENT_LONG (&xev, 1) = time;
3295 MOTIF_XCLIENT_SHORT (&xev, 4) = private->last_x;
3296 MOTIF_XCLIENT_SHORT (&xev, 5) = private->last_y;
3299 MOTIF_XCLIENT_LONG (&xev, 2) = 0;
3301 MOTIF_XCLIENT_LONG (&xev, 3) = 0;
3302 MOTIF_XCLIENT_LONG (&xev, 4) = 0;
3304 if (!_gdk_send_xevent (display,
3305 GDK_DRAWABLE_XID (context->source_window),
3308 g_message ("Send event to %lx failed",
3309 GDK_DRAWABLE_XID (context->source_window)));
3311 else if (context->protocol == GDK_DRAG_PROTO_XDND)
3313 xev.xclient.type = ClientMessage;
3314 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "XdndStatus");
3315 xev.xclient.format = 32;
3316 xev.xclient.window = GDK_DRAWABLE_XID (context->source_window);
3318 xev.xclient.data.l[0] = GDK_DRAWABLE_XID (context->dest_window);
3319 xev.xclient.data.l[1] = (action != 0) ? (2 | 1) : 0;
3320 xev.xclient.data.l[2] = 0;
3321 xev.xclient.data.l[3] = 0;
3322 xev.xclient.data.l[4] = xdnd_action_to_atom (display, action);
3324 if (!xdnd_send_xevent (display,
3325 GDK_DRAWABLE_XID (context->source_window),
3328 g_message ("Send event to %lx failed",
3329 GDK_DRAWABLE_XID (context->source_window)));
3332 private->old_action = action;
3337 * @context: a #GdkDragContext.
3338 * @ok: %TRUE if the drop is accepted.
3339 * @time_: the timestamp for this operation.
3341 * Accepts or rejects a drop.
3343 * This function is called by the drag destination in response
3344 * to a drop initiated by the drag source.
3347 gdk_drop_reply (GdkDragContext *context,
3351 GdkDragContextPrivateX11 *private;
3353 g_return_if_fail (context != NULL);
3355 private = PRIVATE_DATA (context);
3357 if (context->protocol == GDK_DRAG_PROTO_MOTIF)
3359 GdkDisplay *display = GDK_DRAWABLE_DISPLAY (context->source_window);
3362 xev.xclient.type = ClientMessage;
3363 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display,
3364 "_MOTIF_DRAG_AND_DROP_MESSAGE");
3365 xev.xclient.format = 8;
3367 MOTIF_XCLIENT_BYTE (&xev, 0) = XmDROP_START | 0x80;
3368 MOTIF_XCLIENT_BYTE (&xev, 1) = local_byte_order;
3370 MOTIF_XCLIENT_SHORT (&xev, 1) = XmDROP_COPY |
3371 (XmDROP_SITE_VALID << 4) |
3372 (XmDROP_NOOP << 8) |
3375 MOTIF_XCLIENT_SHORT (&xev, 1) = XmDROP_NOOP |
3376 (XmNO_DROP_SITE << 4) |
3377 (XmDROP_NOOP << 8) |
3378 (XmDROP_CANCEL << 12);
3379 MOTIF_XCLIENT_SHORT (&xev, 2) = private->last_x;
3380 MOTIF_XCLIENT_SHORT (&xev, 3) = private->last_y;
3381 MOTIF_XCLIENT_LONG (&xev, 2) = 0;
3382 MOTIF_XCLIENT_LONG (&xev, 3) = 0;
3383 MOTIF_XCLIENT_LONG (&xev, 4) = 0;
3385 _gdk_send_xevent (display,
3386 GDK_DRAWABLE_XID (context->source_window),
3393 * @context: a #GtkDragContext.
3394 * @success: %TRUE if the data was successfully received.
3395 * @time_: the timestamp for this operation.
3397 * Ends the drag operation after a drop.
3399 * This function is called by the drag destination.
3402 gdk_drop_finish (GdkDragContext *context,
3406 g_return_if_fail (context != NULL);
3408 if (context->protocol == GDK_DRAG_PROTO_XDND)
3410 GdkDisplay *display = GDK_DRAWABLE_DISPLAY (context->source_window);
3413 xev.xclient.type = ClientMessage;
3414 xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "XdndFinished");
3415 xev.xclient.format = 32;
3416 xev.xclient.window = GDK_DRAWABLE_XID (context->source_window);
3418 xev.xclient.data.l[0] = GDK_DRAWABLE_XID (context->dest_window);
3419 xev.xclient.data.l[1] = 0;
3420 xev.xclient.data.l[2] = 0;
3421 xev.xclient.data.l[3] = 0;
3422 xev.xclient.data.l[4] = 0;
3424 if (!xdnd_send_xevent (display,
3425 GDK_DRAWABLE_XID (context->source_window),
3428 g_message ("Send event to %lx failed",
3429 GDK_DRAWABLE_XID (context->source_window)));
3435 gdk_window_register_dnd (GdkWindow *window)
3437 static gulong xdnd_version = 3;
3438 MotifDragReceiverInfo info;
3439 Atom motif_drag_receiver_info_atom;
3440 GdkDisplay *display = gdk_drawable_get_display (window);
3442 g_return_if_fail (window != NULL);
3444 if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (window), "gdk-dnd-registered")))
3447 g_object_set_data (G_OBJECT (window), "gdk-dnd-registered", GINT_TO_POINTER (TRUE));
3449 /* Set Motif drag receiver information property */
3451 motif_drag_receiver_info_atom = gdk_x11_get_xatom_by_name_for_display (display,
3452 "_MOTIF_DRAG_RECEIVER_INFO");
3453 info.byte_order = local_byte_order;
3454 info.protocol_version = 0;
3455 info.protocol_style = XmDRAG_DYNAMIC;
3456 info.proxy_window = None;
3457 info.num_drop_sites = 0;
3458 info.total_size = sizeof(info);
3460 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_DRAWABLE_XID (window),
3461 motif_drag_receiver_info_atom,
3462 motif_drag_receiver_info_atom,
3469 /* The property needs to be of type XA_ATOM, not XA_INTEGER. Blech */
3470 XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
3471 GDK_DRAWABLE_XID (window),
3472 gdk_x11_get_xatom_by_name_for_display (display, "XdndAware"),
3473 XA_ATOM, 32, PropModeReplace,
3474 (guchar *)&xdnd_version, 1);
3478 * gdk_drag_get_selection:
3479 * @context: a #GdkDragContext.
3481 * Returns the selection atom for the current source window.
3483 * Return value: the selection atom.
3486 gdk_drag_get_selection (GdkDragContext *context)
3488 g_return_val_if_fail (context != NULL, GDK_NONE);
3490 if (context->protocol == GDK_DRAG_PROTO_MOTIF)
3491 return gdk_x11_xatom_to_atom_for_display (GDK_DRAWABLE_DISPLAY (context->source_window),
3492 (PRIVATE_DATA (context))->motif_selection);
3493 else if (context->protocol == GDK_DRAG_PROTO_XDND)
3494 return gdk_x11_xatom_to_atom_for_display (GDK_DRAWABLE_DISPLAY (context->source_window),
3495 (PRIVATE_DATA (context))->xdnd_selection);