1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-1997 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 Library 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 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library 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.
20 #include <X11/Xatom.h>
23 #include "gdk/gdkprivate.h"
26 typedef struct _GdkDragContextPrivate GdkDragContextPrivate;
30 GDK_DRAG_STATUS_MOTION_WAIT,
31 GDK_DRAG_STATUS_ACTION_WAIT,
37 gint x, y, width, height;
43 GHashTable *child_hash;
47 /* Structure that holds information about a drag in progress.
48 * this is used on both source and destination sides.
50 struct _GdkDragContextPrivate {
51 GdkDragContext context;
53 GdkAtom motif_selection;
54 GdkAtom xdnd_selection;
57 guint16 last_x; /* Coordinates from last event */
59 GdkDragAction old_action; /* The last action we sent to the source */
62 guint xdnd_targets_set : 1; /* Whether we've already set XdndTypeList */
63 guint motif_targets_set : 1; /* Whether we've already set motif initiator info */
64 guint drag_status : 4; /* current status of drag */
66 GdkWindowCache *window_cache;
69 GdkDragContext *current_dest_drag = NULL;
71 /* Forward declarations */
73 static void gdk_window_cache_destroy (GdkWindowCache *cache);
75 static void motif_read_target_table (void);
76 static GdkFilterReturn motif_dnd_filter (GdkXEvent *xev,
80 static GdkFilterReturn xdnd_enter_filter (GdkXEvent *xev,
84 static GdkFilterReturn xdnd_leave_filter (GdkXEvent *xev,
88 static GdkFilterReturn xdnd_position_filter (GdkXEvent *xev,
92 static GdkFilterReturn xdnd_status_filter (GdkXEvent *xev,
96 static GdkFilterReturn xdnd_finished_filter (GdkXEvent *xev,
100 static GdkFilterReturn xdnd_drop_filter (GdkXEvent *xev,
106 static GList *contexts;
109 gdk_drag_context_new (void)
111 GdkDragContextPrivate *result;
113 result = g_new0 (GdkDragContextPrivate, 1);
115 result->ref_count = 1;
117 contexts = g_list_prepend (contexts, result);
119 return (GdkDragContext *)result;
123 gdk_drag_context_ref (GdkDragContext *context)
125 ((GdkDragContextPrivate *)context)->ref_count++;
129 gdk_drag_context_unref (GdkDragContext *context)
131 GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
132 private->ref_count--;
134 if (private->ref_count == 0)
136 g_dataset_destroy (private);
138 g_list_free (context->targets);
140 if (context->source_window)
141 gdk_window_unref (context->source_window);
143 if (context->dest_window)
144 gdk_window_unref (context->dest_window);
146 if (private->window_cache)
147 gdk_window_cache_destroy (private->window_cache);
149 contexts = g_list_remove (contexts, private);
154 static GdkDragContext *
155 gdk_drag_context_find (gboolean is_source,
159 GList *tmp_list = contexts;
163 GdkDragContext *context = (GdkDragContext *)tmp_list->data;
165 if ((!context->is_source == !is_source) &&
166 ((source_xid == None) || (context->source_window &&
167 (GDK_WINDOW_XWINDOW (context->source_window) == source_xid))) &&
168 ((dest_xid == None) || (context->dest_window &&
169 (GDK_WINDOW_XWINDOW (context->dest_window) == dest_xid))))
172 tmp_list = tmp_list->next;
178 /* Utility functions */
181 gdk_window_cache_add (GdkWindowCache *cache,
183 gint x, gint y, gint width, gint height,
186 GdkCacheChild *child = g_new (GdkCacheChild, 1);
191 child->width = width;
192 child->height = height;
193 child->mapped = mapped;
195 cache->children = g_list_prepend (cache->children, child);
196 g_hash_table_insert (cache->child_hash, GUINT_TO_POINTER (xid),
200 static GdkFilterReturn
201 gdk_window_cache_filter (GdkXEvent *xev,
205 XEvent *xevent = (XEvent *)xev;
206 GdkWindowCache *cache = data;
208 switch (xevent->type)
210 case CirculateNotify:
212 case ConfigureNotify:
214 XConfigureEvent *xce = &xevent->xconfigure;
217 node = g_hash_table_lookup (cache->child_hash,
218 GUINT_TO_POINTER (xce->window));
221 GdkCacheChild *child = node->data;
224 child->width = xce->width;
225 child->height = xce->height;
226 if (xce->above == None && (node->next))
228 GList *last = g_list_last (cache->children);
229 cache->children = g_list_remove_link (cache->children, node);
236 GList *above_node = g_hash_table_lookup (cache->child_hash,
237 GUINT_TO_POINTER (xce->above));
238 if (above_node && node->prev != above_node)
240 cache->children = g_list_remove_link (cache->children, node);
241 node->next = above_node->next;
242 node->prev = above_node;
243 above_node->next = node;
251 XCreateWindowEvent *xcwe = &xevent->xcreatewindow;
252 if (!g_hash_table_lookup (cache->child_hash,
253 GUINT_TO_POINTER (xcwe->window)))
254 gdk_window_cache_add (cache, xcwe->window,
255 xcwe->x, xcwe->y, xcwe->width, xcwe->height,
261 XDestroyWindowEvent *xdwe = &xevent->xdestroywindow;
264 node = g_hash_table_lookup (cache->child_hash,
265 GUINT_TO_POINTER (xdwe->window));
268 g_hash_table_remove (cache->child_hash,
269 GUINT_TO_POINTER (xdwe->window));
270 cache->children = g_list_remove_link (cache->children, node);
272 g_list_free_1 (node);
278 XMapEvent *xme = &xevent->xmap;
281 node = g_hash_table_lookup (cache->child_hash,
282 GUINT_TO_POINTER (xme->window));
285 GdkCacheChild *child = node->data;
286 child->mapped = TRUE;
294 XMapEvent *xume = &xevent->xmap;
297 node = g_hash_table_lookup (cache->child_hash,
298 GUINT_TO_POINTER (xume->window));
301 GdkCacheChild *child = node->data;
302 child->mapped = FALSE;
307 return GDK_FILTER_CONTINUE;
309 return GDK_FILTER_REMOVE;
312 static GdkWindowCache *
313 gdk_window_cache_new (void)
315 XWindowAttributes xwa;
316 Window root, parent, *children;
317 unsigned int nchildren;
320 gint old_warnings = gdk_error_warnings;
322 GdkWindowCache *result = g_new (GdkWindowCache, 1);
324 result->children = NULL;
325 result->child_hash = g_hash_table_new (g_direct_hash, NULL);
327 XGetWindowAttributes (gdk_display, gdk_root_window, &xwa);
328 result->old_event_mask = xwa.your_event_mask;
329 XSelectInput (gdk_display, gdk_root_window,
330 result->old_event_mask | SubstructureNotifyMask);
331 gdk_window_add_filter ((GdkWindow *)&gdk_root_parent,
332 gdk_window_cache_filter, result);
335 gdk_error_warnings = 0;
337 if (XQueryTree(gdk_display, gdk_root_window,
338 &root, &parent, &children, &nchildren) == 0)
341 for (i = 0; i < nchildren ; i++)
343 XGetWindowAttributes (gdk_display, children[i], &xwa);
345 gdk_window_cache_add (result, children[i],
346 xwa.x, xwa.y, xwa.width, xwa.height,
347 xwa.map_state != IsUnmapped);
349 if (gdk_error_code != 0)
353 gdk_window_cache_add (result, children[i],
354 xwa.x, xwa.y, xwa.width, xwa.height,
355 (xwa.map_state != IsUnmapped));
361 gdk_error_warnings = old_warnings;
367 gdk_window_cache_destroy (GdkWindowCache *cache)
369 XSelectInput (gdk_display, gdk_root_window, cache->old_event_mask);
370 gdk_window_remove_filter ((GdkWindow *)&gdk_root_parent,
371 gdk_window_cache_filter, cache);
373 g_list_foreach (cache->children, (GFunc)g_free, NULL);
374 g_list_free (cache->children);
375 g_hash_table_destroy (cache->child_hash);
379 get_client_window_at_coords_recurse (Window win,
383 Window root, tmp_parent, *children;
384 unsigned int nchildren;
389 unsigned long nitems, after;
392 static Atom wm_state_atom = None;
395 wm_state_atom = gdk_atom_intern ("WM_STATE", FALSE);
397 XGetWindowProperty (gdk_display, win,
398 wm_state_atom, 0, 0, False, AnyPropertyType,
399 &type, &format, &nitems, &after, &data);
401 if (gdk_error_code != 0)
414 /* This is beautiful! Damn Enlightenment and click-to-focus */
415 XTranslateCoordinates (gdk_display, gdk_root_window, win,
416 x_root, y_root, &dest_x, &dest_y, &child);
418 if (gdk_error_code != 0)
425 if (XQueryTree(gdk_display, win,
426 &root, &tmp_parent, &children, &nchildren) == 0)
429 if (gdk_error_code == 0)
431 for (i = nchildren - 1; (i >= 0) && (child == None); i--)
433 XWindowAttributes xwa;
435 XGetWindowAttributes (gdk_display, children[i], &xwa);
437 if (gdk_error_code != 0)
439 else if ((xwa.map_state == IsViewable) && (xwa.class == InputOutput) &&
440 (x >= xwa.x) && (x < xwa.x + (gint)xwa.width) &&
441 (y >= xwa.y) && (y < xwa.y + (gint)xwa.height))
456 return get_client_window_at_coords_recurse (child, x, y);
462 get_client_window_at_coords (GdkWindowCache *cache,
468 Window retval = None;
470 gint old_warnings = gdk_error_warnings;
473 gdk_error_warnings = 0;
475 tmp_list = cache->children;
477 while (tmp_list && !retval)
479 GdkCacheChild *child = tmp_list->data;
481 if ((child->xid != ignore) && (child->mapped))
483 if ((x_root >= child->x) && (x_root < child->x + child->width) &&
484 (y_root >= child->y) && (y_root < child->y + child->height))
486 retval = get_client_window_at_coords_recurse (child->xid,
494 tmp_list = tmp_list->next;
497 gdk_error_warnings = old_warnings;
501 return gdk_root_window;
506 get_client_window_at_coords_recurse (Window win,
513 unsigned long nitems, after;
517 static Atom wm_state_atom = None;
520 wm_state_atom = gdk_atom_intern ("WM_STATE", FALSE);
522 XGetWindowProperty (gdk_display, win,
523 wm_state_atom, 0, 0, False, AnyPropertyType,
524 &type, &format, &nitems, &after, &data);
526 if (gdk_error_code != 0)
538 XTranslateCoordinates (gdk_display, gdk_root_window, win,
539 x_root, y_root, &dest_x, &dest_y, &child);
541 if (gdk_error_code != 0)
548 return get_client_window_at_coords_recurse (child, x_root, y_root);
554 get_client_window_at_coords (Window ignore,
558 Window root, parent, *children;
559 unsigned int nchildren;
561 Window retval = None;
563 gint old_warnings = gdk_error_warnings;
566 gdk_error_warnings = 0;
568 if (XQueryTree(gdk_display, gdk_root_window,
569 &root, &parent, &children, &nchildren) == 0)
572 for (i = nchildren - 1; (i >= 0) && (retval == None); i--)
574 if (children[i] != ignore)
576 XWindowAttributes xwa;
578 XGetWindowAttributes (gdk_display, children[i], &xwa);
580 if (gdk_error_code != 0)
582 else if ((xwa.map_state == IsViewable) &&
583 (x_root >= xwa.x) && (x_root < xwa.x + (gint)xwa.width) &&
584 (y_root >= xwa.y) && (y_root < xwa.y + (gint)xwa.height))
586 retval = get_client_window_at_coords_recurse (children[i],
589 retval = children[i];
596 gdk_error_warnings = old_warnings;
600 return gdk_root_window;
604 /*************************************************************
605 ***************************** MOTIF *************************
606 *************************************************************/
608 /* values used in the message type for Motif DND */
621 /* Values used to specify type of protocol to use */
625 XmDRAG_PREFER_PREREGISTER,
627 XmDRAG_PREFER_DYNAMIC,
629 XmDRAG_PREFER_RECEIVER
632 /* Operation codes */
640 /* Drop site status */
642 XmNO_DROP_SITE = 0x01,
643 XmDROP_SITE_INVALID = 0x02,
644 XmDROP_SITE_VALID = 0x03
647 /* completion status */
655 /* Static data for MOTIF DND */
656 static GList **motif_target_lists = NULL;
657 static gint motif_n_target_lists = -1;
659 /* Byte swapping routines. The motif specification leaves it
660 * up to us to save a few bytes in the client messages
662 static gchar local_byte_order = '\0';
664 #ifdef G_ENABLE_DEBUG
666 print_target_list (GList *targets)
670 gchar *name = gdk_atom_name (GPOINTER_TO_INT (targets->data));
671 g_message ("\t%s", name);
673 targets = targets->next;
676 #endif /* G_ENABLE_DEBUG */
679 init_byte_order (void)
681 guint32 myint = 0x01020304;
682 local_byte_order = (*(gchar *)&myint == 1) ? 'B' : 'l';
686 card16_to_host (guint16 x, gchar byte_order) {
687 if (byte_order == local_byte_order)
690 return (x << 8) | (x >> 8);
694 card32_to_host (guint32 x, gchar byte_order) {
695 if (byte_order == local_byte_order)
698 return (x << 24) | ((x & 0xff00) << 8) | ((x & 0xff0000) >> 8) | (x >> 24);
702 /***** Dest side ***********/
704 /* Property placed on source windows */
705 typedef struct _MotifDragInitiatorInfo {
707 guint8 protocol_version;
708 guint16 targets_index;
709 guint32 selection_atom;
710 } MotifDragInitiatorInfo;
712 /* Header for target table on the drag window */
713 typedef struct _MotifTargetTableHeader {
715 guchar protocol_version;
718 } MotifTargetTableHeader;
720 /* Property placed on target windows */
721 typedef struct _MotifDragReceiverInfo {
723 guint8 protocol_version;
724 guint8 protocol_style;
726 guint32 proxy_window;
727 guint16 num_drop_sites;
730 } MotifDragReceiverInfo;
732 static Window motif_drag_window = None;
733 static GdkWindow *motif_drag_gdk_window = NULL;
735 static GdkAtom motif_drag_targets_atom = GDK_NONE;
736 static GdkAtom motif_drag_receiver_info_atom = GDK_NONE;
738 /* Target table handling */
741 motif_drag_window_filter (GdkXEvent *xevent,
745 XEvent *xev = (XEvent *)xevent;
747 switch (xev->xany.type)
750 motif_drag_window = None;
751 motif_drag_gdk_window = NULL;
754 if (motif_target_lists &&
755 motif_drag_targets_atom &&
756 (xev->xproperty.atom == motif_drag_targets_atom))
757 motif_read_target_table();
760 return GDK_FILTER_REMOVE;
763 static GdkAtom motif_drag_window_atom = GDK_NONE;
766 motif_lookup_drag_window (Display *display)
768 Window retval = None;
769 gulong bytes_after, nitems;
774 XGetWindowProperty (gdk_display, gdk_root_window, motif_drag_window_atom,
775 0, sizeof(Window)/4, FALSE,
776 XA_WINDOW, &type, &format, &nitems, &bytes_after,
779 if ((format == 8*sizeof(Window)) && (nitems == 1) && (bytes_after == 0))
781 retval = *(Window *)data;
783 g_message ("Found drag window %#lx\n", motif_drag_window));
792 /* Finds the window where global Motif drag information is stored.
793 * If it doesn't exist and 'create' is TRUE, create one.
796 motif_find_drag_window (gboolean create)
798 if (!motif_drag_window)
800 if (!motif_drag_window_atom)
801 motif_drag_window_atom = gdk_atom_intern ("_MOTIF_DRAG_WINDOW", TRUE);
803 motif_drag_window = motif_lookup_drag_window (gdk_display);
805 if (!motif_drag_window && create)
807 /* Create a persistant window. (Copied from LessTif) */
810 XSetWindowAttributes attr;
811 display = XOpenDisplay (NULL);
812 XSetCloseDownMode (display, RetainPermanent);
814 XGrabServer (display);
816 motif_drag_window = motif_lookup_drag_window (display);
818 if (!motif_drag_window)
820 attr.override_redirect = True;
821 attr.event_mask = PropertyChangeMask;
824 XCreateWindow(display, DefaultRootWindow(display),
825 -100, -100, 10, 10, 0, 0,
826 InputOnly, CopyFromParent,
827 (CWOverrideRedirect | CWEventMask), &attr);
830 g_message ("Created drag window %#lx\n", motif_drag_window));
832 XChangeProperty (display, gdk_root_window,
833 motif_drag_window_atom, XA_WINDOW,
835 (guchar *)&motif_drag_window_atom, 1);
838 XUngrabServer (display);
839 XCloseDisplay (display);
842 /* There is a miniscule race condition here if the drag window
843 * gets destroyed exactly now.
845 if (motif_drag_window)
847 motif_drag_gdk_window = gdk_window_foreign_new (motif_drag_window);
848 gdk_window_add_filter (motif_drag_gdk_window,
849 motif_drag_window_filter,
854 return motif_drag_window;
858 motif_read_target_table (void)
860 gulong bytes_after, nitems;
865 if (!motif_drag_targets_atom)
866 motif_drag_targets_atom = gdk_atom_intern ("_MOTIF_DRAG_TARGETS", FALSE);
868 if (motif_target_lists)
870 for (i=0; i<motif_n_target_lists; i++)
871 g_list_free (motif_target_lists[i]);
873 g_free (motif_target_lists);
874 motif_target_lists = NULL;
875 motif_n_target_lists = 0;
878 if (motif_find_drag_window (FALSE))
880 MotifTargetTableHeader *header = NULL;
881 guchar *target_bytes = NULL;
883 gboolean success = FALSE;
885 XGetWindowProperty (gdk_display, motif_drag_window,
886 motif_drag_targets_atom,
887 0, (sizeof(MotifTargetTableHeader)+3)/4, FALSE,
888 motif_drag_targets_atom,
889 &type, &format, &nitems, &bytes_after,
892 if ((format != 8) || (nitems < sizeof (MotifTargetTableHeader)))
895 header->n_lists = card16_to_host (header->n_lists, header->byte_order);
896 header->total_size = card32_to_host (header->total_size, header->byte_order);
898 XGetWindowProperty (gdk_display, motif_drag_window, motif_drag_targets_atom,
899 (sizeof(MotifTargetTableHeader)+3)/4,
900 (header->total_size - sizeof(MotifTargetTableHeader) + 3)/4,
902 motif_drag_targets_atom, &type, &format, &nitems,
903 &bytes_after, &target_bytes);
905 if ((format != 8) || (bytes_after != 0) ||
906 (nitems != header->total_size - sizeof(MotifTargetTableHeader)))
909 motif_n_target_lists = header->n_lists;
910 motif_target_lists = g_new0 (GList *, motif_n_target_lists);
913 for (i=0; i<header->n_lists; i++)
918 if (p + sizeof(guint16) - target_bytes > nitems)
921 n_targets = card16_to_host (*(gushort *)p, header->byte_order);
923 /* We need to make a copy of the targets, since it may
926 targets = g_new (guint32, n_targets);
927 memcpy (targets, p + sizeof(guint16), sizeof(guint32) * n_targets);
929 p += sizeof(guint16) + n_targets * sizeof(guint32);
930 if (p - target_bytes > nitems)
933 for (j=0; j<n_targets; j++)
934 motif_target_lists[i] =
935 g_list_prepend (motif_target_lists[i],
936 GUINT_TO_POINTER (card32_to_host (targets[j],
937 header->byte_order)));
939 motif_target_lists[i] = g_list_reverse (motif_target_lists[i]);
949 XFree (target_bytes);
953 if (motif_target_lists)
955 g_free (motif_target_lists);
956 motif_target_lists = NULL;
957 motif_n_target_lists = 0;
959 g_warning ("Error reading Motif target table\n");
965 targets_sort_func (gconstpointer a, gconstpointer b)
967 return (GPOINTER_TO_UINT (a) < GPOINTER_TO_UINT (b)) ?
968 -1 : ((GPOINTER_TO_UINT (a) > GPOINTER_TO_UINT (b)) ? 1 : 0);
971 /* Check if given (sorted) list is in the targets table */
973 motif_target_table_check (GList *sorted)
975 GList *tmp_list1, *tmp_list2;
978 for (i=0; i<motif_n_target_lists; i++)
980 tmp_list1 = motif_target_lists[i];
983 while (tmp_list1 && tmp_list2)
985 if (tmp_list1->data != tmp_list2->data)
988 tmp_list1 = tmp_list1->next;
989 tmp_list2 = tmp_list2->next;
991 if (!tmp_list1 && !tmp_list2) /* Found it */
999 motif_add_to_target_table (GList *targets)
1001 GList *sorted = NULL;
1006 /* make a sorted copy of the list */
1010 sorted = g_list_insert_sorted (sorted, targets->data, targets_sort_func);
1011 targets = targets->next;
1014 /* First check if it is their already */
1016 if (motif_target_lists)
1017 index = motif_target_table_check (sorted);
1019 /* We need to grab the server while doing this, to ensure
1025 /* We need to make sure that it exists _before_ we grab the
1026 * server, since we can't open a new connection after we
1029 motif_find_drag_window (TRUE);
1031 XGrabServer(gdk_display);
1032 motif_read_target_table();
1034 /* Check again, in case it was added in the meantime */
1036 if (motif_target_lists)
1037 index = motif_target_table_check (sorted);
1041 guint32 total_size = 0;
1045 MotifTargetTableHeader *header;
1047 if (!motif_target_lists)
1049 motif_target_lists = g_new (GList *, 1);
1050 motif_n_target_lists = 1;
1054 motif_n_target_lists++;
1055 motif_target_lists = g_realloc (motif_target_lists,
1056 sizeof(GList *) * motif_n_target_lists);
1058 motif_target_lists[motif_n_target_lists - 1] = sorted;
1060 index = motif_n_target_lists - 1;
1062 total_size = sizeof (MotifTargetTableHeader);
1063 for (i = 0; i < motif_n_target_lists ; i++)
1064 total_size += sizeof(guint16) + sizeof(guint32) * g_list_length (motif_target_lists[i]);
1066 data = g_malloc (total_size);
1068 header = (MotifTargetTableHeader *)data;
1069 p = data + sizeof(MotifTargetTableHeader);
1071 header->byte_order = local_byte_order;
1072 header->protocol_version = 0;
1073 header->n_lists = motif_n_target_lists;
1074 header->total_size = total_size;
1076 for (i = 0; i < motif_n_target_lists ; i++)
1078 guint16 n_targets = g_list_length (motif_target_lists[i]);
1079 guint32 *targets = g_new (guint32, n_targets);
1080 guint32 *p32 = targets;
1082 tmp_list = motif_target_lists[i];
1085 *p32 = GPOINTER_TO_UINT (tmp_list->data);
1087 tmp_list = tmp_list->next;
1092 p += sizeof(guint16);
1094 memcpy (p, targets, n_targets * sizeof(guint32));
1097 p += sizeof(guint32) * n_targets;
1101 XChangeProperty (gdk_display, motif_drag_window,
1102 motif_drag_targets_atom,
1103 motif_drag_targets_atom,
1107 XUngrabServer(gdk_display);
1110 g_list_free (sorted);
1114 /* Translate flags */
1117 motif_dnd_translate_flags (GdkDragContext *context, guint16 flags)
1119 guint recommended_op = flags & 0x000f;
1120 guint possible_ops = (flags & 0x0f0) >> 4;
1122 switch (recommended_op)
1125 context->suggested_action = GDK_ACTION_MOVE;
1128 context->suggested_action = GDK_ACTION_COPY;
1131 context->suggested_action = GDK_ACTION_LINK;
1134 context->suggested_action = GDK_ACTION_COPY;
1138 context->actions = 0;
1139 if (possible_ops & XmDROP_MOVE)
1140 context->actions |= GDK_ACTION_MOVE;
1141 if (possible_ops & XmDROP_COPY)
1142 context->actions |= GDK_ACTION_COPY;
1143 if (possible_ops & XmDROP_LINK)
1144 context->actions |= GDK_ACTION_LINK;
1148 motif_dnd_get_flags (GdkDragContext *context)
1152 switch (context->suggested_action)
1154 case GDK_ACTION_MOVE:
1155 flags = XmDROP_MOVE;
1157 case GDK_ACTION_COPY:
1158 flags = XmDROP_COPY;
1160 case GDK_ACTION_LINK:
1161 flags = XmDROP_LINK;
1164 flags = XmDROP_NOOP;
1168 if (context->actions & GDK_ACTION_MOVE)
1169 flags |= XmDROP_MOVE << 8;
1170 if (context->actions & GDK_ACTION_COPY)
1171 flags |= XmDROP_COPY << 8;
1172 if (context->actions & GDK_ACTION_LINK)
1173 flags |= XmDROP_LINK << 8;
1181 motif_set_targets (GdkDragContext *context)
1183 GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
1184 MotifDragInitiatorInfo info;
1186 static GdkAtom motif_drag_initiator_info = GDK_NONE;
1188 if (!motif_drag_initiator_info)
1189 motif_drag_initiator_info = gdk_atom_intern ("_MOTIF_DRAG_INITIATOR_INFO", FALSE);
1191 info.byte_order = local_byte_order;
1192 info.protocol_version = 0;
1194 info.targets_index = motif_add_to_target_table (context->targets);
1199 g_snprintf(buf, 20, "_GDK_SELECTION_%d", i);
1201 private->motif_selection = gdk_atom_intern (buf, FALSE);
1202 if (!XGetSelectionOwner (gdk_display, private->motif_selection))
1206 info.selection_atom = private->motif_selection;
1208 XChangeProperty (GDK_WINDOW_XDISPLAY (context->source_window),
1209 GDK_WINDOW_XWINDOW (context->source_window),
1210 private->motif_selection,
1211 motif_drag_initiator_info, 8, PropModeReplace,
1212 (guchar *)&info, sizeof (info));
1214 private->motif_targets_set = 1;
1218 motif_check_dest (Window win)
1220 gboolean retval = FALSE;
1221 MotifDragReceiverInfo *info;
1224 unsigned long nitems, after;
1226 if (!motif_drag_receiver_info_atom)
1227 motif_drag_receiver_info_atom = gdk_atom_intern ("_MOTIF_DRAG_RECEIVER_INFO", FALSE);
1229 XGetWindowProperty (gdk_display, win,
1230 motif_drag_receiver_info_atom,
1231 0, (sizeof(*info)+3)/4, False, AnyPropertyType,
1232 &type, &format, &nitems, &after,
1237 if ((format == 8) && (nitems == sizeof(*info)))
1239 if ((info->protocol_version == 0) &&
1240 ((info->protocol_style == XmDRAG_PREFER_PREREGISTER) ||
1241 (info->protocol_style == XmDRAG_PREFER_DYNAMIC) ||
1242 (info->protocol_style == XmDRAG_DYNAMIC)))
1248 g_warning ("Invalid Motif drag receiver property on window %ld\n", win));
1254 return retval ? win : GDK_NONE;
1259 motif_send_enter (GdkDragContext *context,
1263 GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
1265 xev.xclient.type = ClientMessage;
1266 xev.xclient.message_type = gdk_atom_intern ("_MOTIF_DRAG_AND_DROP_MESSAGE", FALSE);
1267 xev.xclient.format = 8;
1268 xev.xclient.window = GDK_WINDOW_XWINDOW (context->dest_window);
1270 xev.xclient.data.b[0] = XmTOP_LEVEL_ENTER;
1271 xev.xclient.data.b[1] = local_byte_order;
1272 xev.xclient.data.s[1] = 0;
1273 xev.xclient.data.l[1] = time;
1274 xev.xclient.data.l[2] = GDK_WINDOW_XWINDOW (context->source_window);
1276 if (!private->motif_targets_set)
1277 motif_set_targets (context);
1279 xev.xclient.data.l[3] = private->motif_selection;
1281 if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->dest_window),
1284 g_message ("Send event to %lx failed",
1285 GDK_WINDOW_XWINDOW (context->dest_window)));
1289 motif_send_leave (GdkDragContext *context,
1294 xev.xclient.type = ClientMessage;
1295 xev.xclient.message_type = gdk_atom_intern ("_MOTIF_DRAG_AND_DROP_MESSAGE", FALSE);
1296 xev.xclient.format = 8;
1297 xev.xclient.window = GDK_WINDOW_XWINDOW (context->dest_window);
1299 xev.xclient.data.b[0] = XmTOP_LEVEL_LEAVE;
1300 xev.xclient.data.b[1] = local_byte_order;
1301 xev.xclient.data.s[1] = 0;
1302 xev.xclient.data.l[1] = time;
1303 xev.xclient.data.l[2] = GDK_WINDOW_XWINDOW (context->source_window);
1304 xev.xclient.data.l[3] = 0;
1306 if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->dest_window),
1309 g_message ("Send event to %lx failed",
1310 GDK_WINDOW_XWINDOW (context->dest_window)));
1314 motif_send_motion (GdkDragContext *context,
1317 GdkDragAction action,
1322 GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
1324 xev.xclient.type = ClientMessage;
1325 xev.xclient.message_type = gdk_atom_intern ("_MOTIF_DRAG_AND_DROP_MESSAGE", FALSE);
1326 xev.xclient.format = 8;
1327 xev.xclient.window = GDK_WINDOW_XWINDOW (context->dest_window);
1329 xev.xclient.data.b[1] = local_byte_order;
1330 xev.xclient.data.s[1] = motif_dnd_get_flags (context);
1331 xev.xclient.data.l[1] = time;
1333 if (context->suggested_action != private->old_action)
1335 xev.xclient.data.b[0] = XmOPERATION_CHANGED;
1337 private->drag_status = GDK_DRAG_STATUS_ACTION_WAIT;
1342 xev.xclient.data.b[0] = XmDRAG_MOTION;
1344 xev.xclient.data.s[4] = x_root;
1345 xev.xclient.data.s[5] = y_root;
1347 private->drag_status = GDK_DRAG_STATUS_MOTION_WAIT;
1351 if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->dest_window),
1354 g_message ("Send event to %lx failed",
1355 GDK_WINDOW_XWINDOW (context->dest_window)));
1361 motif_send_drop (GdkDragContext *context, guint32 time)
1364 GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
1366 xev.xclient.type = ClientMessage;
1367 xev.xclient.message_type = gdk_atom_intern ("_MOTIF_DRAG_AND_DROP_MESSAGE", FALSE);
1368 xev.xclient.format = 8;
1369 xev.xclient.window = GDK_WINDOW_XWINDOW (context->dest_window);
1371 xev.xclient.data.b[0] = XmDROP_START;
1372 xev.xclient.data.b[1] = local_byte_order;
1373 xev.xclient.data.s[1] = motif_dnd_get_flags (context);
1374 xev.xclient.data.l[1] = time;
1376 xev.xclient.data.s[4] = private->last_x;
1377 xev.xclient.data.s[5] = private->last_y;
1379 xev.xclient.data.l[3] = private->motif_selection;
1380 xev.xclient.data.l[4] = GDK_WINDOW_XWINDOW (context->source_window);
1382 if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->dest_window),
1385 g_message ("Send event to %lx failed",
1386 GDK_WINDOW_XWINDOW (context->dest_window)));
1392 motif_read_initiator_info (Window source_window,
1398 static GdkAtom motif_drag_initiator_info = GDK_NONE;
1404 MotifDragInitiatorInfo *initiator_info;
1406 if (!motif_drag_initiator_info)
1407 motif_drag_initiator_info = gdk_atom_intern ("_MOTIF_DRAG_INITIATOR_INFO", FALSE);
1409 XGetWindowProperty (gdk_display, source_window, atom,
1410 0, sizeof(*initiator_info), FALSE,
1411 motif_drag_initiator_info,
1412 &type, &format, &nitems, &bytes_after,
1413 (guchar **)&initiator_info);
1415 if ((format != 8) || (nitems != sizeof (MotifDragInitiatorInfo)) || (bytes_after != 0))
1417 g_warning ("Error reading initiator info\n");
1421 motif_read_target_table ();
1423 if (initiator_info->targets_index >= motif_n_target_lists)
1425 g_warning ("Invalid target index in TOP_LEVEL_ENTER MESSAGE");
1426 XFree (initiator_info);
1427 return GDK_FILTER_REMOVE;
1430 tmp_list = g_list_last (motif_target_lists[initiator_info->targets_index]);
1435 *targets = g_list_prepend (*targets,
1437 tmp_list = tmp_list->prev;
1440 #ifdef G_ENABLE_DEBUG
1441 if (gdk_debug_flags & GDK_DEBUG_DND)
1442 print_target_list (*targets);
1443 #endif /* G_ENABLE_DEBUG */
1445 *selection = initiator_info->selection_atom;
1447 XFree (initiator_info);
1452 static GdkDragContext *
1453 motif_drag_context_new (GdkWindow *dest_window,
1455 guint32 source_window,
1458 GdkDragContext *new_context;
1459 GdkDragContextPrivate *private;
1461 /* FIXME, current_dest_drag really shouldn't be NULL'd
1462 * if we error below.
1464 if (current_dest_drag != NULL)
1466 if (timestamp >= current_dest_drag->start_time)
1468 gdk_drag_context_unref (current_dest_drag);
1469 current_dest_drag = NULL;
1475 new_context = gdk_drag_context_new ();
1476 private = (GdkDragContextPrivate *)new_context;
1478 new_context->protocol = GDK_DRAG_PROTO_MOTIF;
1479 new_context->is_source = FALSE;
1481 new_context->source_window = gdk_window_lookup (source_window);
1482 if (new_context->source_window)
1483 gdk_window_ref (new_context->source_window);
1486 new_context->source_window = gdk_window_foreign_new (source_window);
1487 if (!new_context->source_window)
1489 gdk_drag_context_unref (new_context);
1494 new_context->dest_window = dest_window;
1495 gdk_window_ref (dest_window);
1496 new_context->start_time = timestamp;
1498 if (!motif_read_initiator_info(source_window,
1500 &new_context->targets,
1501 &private->motif_selection))
1503 gdk_drag_context_unref (new_context);
1511 * The MOTIF drag protocol has no real provisions for distinguishing
1512 * multiple simultaneous drops. If the sources grab the pointer
1513 * when doing drags, that shouldn't happen, in any case. If it
1514 * does, we can't do much except hope for the best.
1517 static GdkFilterReturn
1518 motif_top_level_enter (GdkEvent *event,
1521 guint32 source_window,
1524 GdkDragContext *new_context;
1526 GDK_NOTE(DND, g_message ("Motif DND top level enter: flags: %#4x time: %d source_widow: %#4x atom: %d",
1527 flags, timestamp, source_window, atom));
1529 new_context = motif_drag_context_new (event->any.window, timestamp, source_window, atom);
1531 return GDK_FILTER_REMOVE;
1533 event->dnd.type = GDK_DRAG_ENTER;
1534 event->dnd.context = new_context;
1535 gdk_drag_context_ref (new_context);
1537 current_dest_drag = new_context;
1539 return GDK_FILTER_TRANSLATE;
1543 motif_top_level_leave (GdkEvent *event,
1547 GDK_NOTE(DND, g_message ("Motif DND top level leave: flags: %#4x time: %d",
1550 if ((current_dest_drag != NULL) &&
1551 (current_dest_drag->protocol == GDK_DRAG_PROTO_MOTIF) &&
1552 (timestamp >= current_dest_drag->start_time))
1554 event->dnd.type = GDK_DRAG_LEAVE;
1555 /* Pass ownership of context to the event */
1556 event->dnd.context = current_dest_drag;
1558 current_dest_drag = NULL;
1560 return GDK_FILTER_TRANSLATE;
1563 return GDK_FILTER_REMOVE;
1567 motif_motion (GdkEvent *event,
1573 GdkDragContextPrivate *private;
1575 GDK_NOTE(DND, g_message ("Motif DND motion: flags: %#4x time: %d (%d, %d)",
1576 flags, timestamp, x_root, y_root));
1578 if ((current_dest_drag != NULL) &&
1579 (current_dest_drag->protocol == GDK_DRAG_PROTO_MOTIF) &&
1580 (timestamp >= current_dest_drag->start_time))
1582 private = (GdkDragContextPrivate *)current_dest_drag;
1584 event->dnd.type = GDK_DRAG_MOTION;
1585 event->dnd.context = current_dest_drag;
1586 gdk_drag_context_ref (current_dest_drag);
1588 event->dnd.time = timestamp;
1590 motif_dnd_translate_flags (current_dest_drag, flags);
1592 event->dnd.x_root = x_root;
1593 event->dnd.y_root = y_root;
1595 private->last_x = x_root;
1596 private->last_y = y_root;
1598 private->drag_status = GDK_DRAG_STATUS_MOTION_WAIT;
1600 return GDK_FILTER_TRANSLATE;
1603 return GDK_FILTER_REMOVE;
1607 motif_operation_changed (GdkEvent *event,
1611 GdkDragContextPrivate *private;
1613 GDK_NOTE(DND, g_message ("Motif DND operation changed: flags: %#4x time: %d",
1616 if ((current_dest_drag != NULL) &&
1617 (current_dest_drag->protocol == GDK_DRAG_PROTO_MOTIF) &&
1618 (timestamp >= current_dest_drag->start_time))
1620 event->dnd.type = GDK_DRAG_MOTION;
1621 event->dnd.send_event = FALSE;
1622 event->dnd.context = current_dest_drag;
1623 gdk_drag_context_ref (current_dest_drag);
1625 event->dnd.time = timestamp;
1626 private = (GdkDragContextPrivate *)current_dest_drag;
1628 motif_dnd_translate_flags (current_dest_drag, flags);
1630 event->dnd.x_root = private->last_x;
1631 event->dnd.y_root = private->last_y;
1633 private->drag_status = GDK_DRAG_STATUS_ACTION_WAIT;
1635 return GDK_FILTER_TRANSLATE;
1638 return GDK_FILTER_REMOVE;
1642 motif_drop_start (GdkEvent *event,
1645 guint32 source_window,
1650 GdkDragContext *new_context;
1653 GDK_NOTE(DND, g_message ("Motif DND drop start: flags: %#4x time: %d (%d, %d) source_widow: %#4x atom: %d",
1654 flags, timestamp, x_root, y_root, source_window, atom));
1656 new_context = motif_drag_context_new (event->any.window, timestamp, source_window, atom);
1658 return GDK_FILTER_REMOVE;
1660 motif_dnd_translate_flags (new_context, flags);
1662 event->dnd.type = GDK_DROP_START;
1663 event->dnd.context = new_context;
1664 event->dnd.time = timestamp;
1665 event->dnd.x_root = x_root;
1666 event->dnd.y_root = y_root;
1668 gdk_drag_context_ref (new_context);
1669 current_dest_drag = new_context;
1671 return GDK_FILTER_TRANSLATE;
1675 motif_drag_status (GdkEvent *event,
1679 GdkDragContext *context;
1682 g_message ("Motif status message: flags %x", flags));
1684 context = gdk_drag_context_find (TRUE,
1685 GDK_WINDOW_XWINDOW (event->any.window),
1690 GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
1691 if (private->drag_status == GDK_DRAG_STATUS_MOTION_WAIT)
1692 private->drag_status = GDK_DRAG_STATUS_DRAG;
1694 event->dnd.type = GDK_DRAG_STATUS;
1695 event->dnd.send_event = FALSE;
1696 event->dnd.context = context;
1697 gdk_drag_context_ref (context);
1699 event->dnd.time = timestamp;
1701 if ((flags & 0x00f0) >> 4 == XmDROP_SITE_VALID)
1703 switch (flags & 0x000f)
1706 context->action = 0;
1709 context->action = GDK_ACTION_MOVE;
1712 context->action = GDK_ACTION_COPY;
1715 context->action = GDK_ACTION_LINK;
1720 context->action = 0;
1722 return GDK_FILTER_TRANSLATE;
1724 return GDK_FILTER_REMOVE;
1728 motif_dnd_filter (GdkXEvent *xev,
1732 XEvent *xevent = (XEvent *)xev;
1733 XClientMessageEvent *xce = &xevent->xclient;
1739 guint32 source_window;
1741 gint16 x_root, y_root;
1744 /* First read some fields common to all Motif DND messages */
1746 reason = xce->data.b[0];
1747 byte_order = xce->data.b[1];
1748 flags = card16_to_host (xce->data.s[1], byte_order);
1749 timestamp = card32_to_host (xce->data.l[1], byte_order);
1751 is_reply = ((reason & 0x80) != 0);
1753 switch (reason & 0x7f)
1755 case XmTOP_LEVEL_ENTER:
1756 source_window = card32_to_host (xce->data.l[2], byte_order);
1757 atom = card32_to_host (xce->data.l[3], byte_order);
1758 return motif_top_level_enter (event, flags, timestamp, source_window, atom);
1759 case XmTOP_LEVEL_LEAVE:
1760 return motif_top_level_leave (event, flags, timestamp);
1763 x_root = card16_to_host (xce->data.s[4], byte_order);
1764 y_root = card16_to_host (xce->data.s[5], byte_order);
1767 return motif_motion (event, flags, timestamp, x_root, y_root);
1769 return motif_drag_status (event, flags, timestamp);
1771 case XmDROP_SITE_ENTER:
1772 return motif_drag_status (event, flags, timestamp);
1774 case XmDROP_SITE_LEAVE:
1775 return motif_drag_status (event,
1776 XmNO_DROP_SITE << 8 | XmDROP_NOOP,
1779 x_root = card16_to_host (xce->data.s[4], byte_order);
1780 y_root = card16_to_host (xce->data.s[5], byte_order);
1781 atom = card32_to_host (xce->data.l[3], byte_order);
1782 source_window = card32_to_host (xce->data.l[4], byte_order);
1785 return motif_drop_start (event, flags, timestamp, source_window, atom, x_root, y_root);
1788 case XmOPERATION_CHANGED:
1790 return motif_operation_changed (event, flags, timestamp);
1792 return motif_drag_status (event, flags, timestamp);
1795 /* To the best of my knowledge, these next two messages are
1796 * not part of the protocol, though they are defined in
1800 case XmDRAG_DROP_FINISH:
1804 return GDK_FILTER_REMOVE;
1807 /*************************************************************
1808 ***************************** XDND **************************
1809 *************************************************************/
1811 /* Utility functions */
1816 GdkDragAction action;
1817 } xdnd_actions_table[] = {
1818 { "XdndActionCopy", GDK_NONE, GDK_ACTION_COPY },
1819 { "XdndActionMove", GDK_NONE, GDK_ACTION_MOVE },
1820 { "XdndActionLink", GDK_NONE, GDK_ACTION_LINK },
1821 { "XdndActionAsk", GDK_NONE, GDK_ACTION_ASK },
1822 { "XdndActionPrivate", GDK_NONE, GDK_ACTION_COPY },
1825 static const gint xdnd_n_actions = sizeof(xdnd_actions_table) / sizeof(xdnd_actions_table[0]);
1826 static gboolean xdnd_actions_initialized = FALSE;
1829 xdnd_initialize_actions (void)
1833 xdnd_actions_initialized = TRUE;
1834 for (i=0; i < xdnd_n_actions; i++)
1835 xdnd_actions_table[i].atom = gdk_atom_intern (xdnd_actions_table[i].name, FALSE);
1838 static GdkDragAction
1839 xdnd_action_from_atom (GdkAtom atom)
1843 if (!xdnd_actions_initialized)
1844 xdnd_initialize_actions();
1846 for (i=0; i<xdnd_n_actions; i++)
1847 if (atom == xdnd_actions_table[i].atom)
1848 return xdnd_actions_table[i].action;
1854 xdnd_action_to_atom (GdkDragAction action)
1858 if (!xdnd_actions_initialized)
1859 xdnd_initialize_actions();
1861 for (i=0; i<xdnd_n_actions; i++)
1862 if (action == xdnd_actions_table[i].action)
1863 return xdnd_actions_table[i].atom;
1868 static GdkAtom xdnd_aware_atom = GDK_NONE;
1872 static GdkFilterReturn
1873 xdnd_status_filter (GdkXEvent *xev,
1877 XEvent *xevent = (XEvent *)xev;
1878 guint32 dest_window = xevent->xclient.data.l[0];
1879 guint32 flags = xevent->xclient.data.l[1];
1880 GdkAtom action = xevent->xclient.data.l[4];
1881 GdkDragContext *context;
1884 g_message ("XdndStatus: dest_window: %#x action: %ld",
1885 dest_window, action));
1888 context = gdk_drag_context_find (TRUE, xevent->xclient.window, dest_window);
1891 GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
1892 if (private->drag_status == GDK_DRAG_STATUS_MOTION_WAIT)
1893 private->drag_status = GDK_DRAG_STATUS_DRAG;
1895 event->dnd.send_event = FALSE;
1896 event->dnd.type = GDK_DRAG_STATUS;
1897 event->dnd.context = context;
1898 gdk_drag_context_ref (context);
1900 event->dnd.time = GDK_CURRENT_TIME; /* FIXME? */
1901 if (!(action != 0) != !(flags & 1))
1904 g_warning ("Received status event with flags not corresponding to action!\n"));
1908 context->action = xdnd_action_from_atom (action);
1910 return GDK_FILTER_TRANSLATE;
1913 return GDK_FILTER_REMOVE;
1916 static GdkFilterReturn
1917 xdnd_finished_filter (GdkXEvent *xev,
1921 XEvent *xevent = (XEvent *)xev;
1922 guint32 dest_window = xevent->xclient.data.l[0];
1923 GdkDragContext *context;
1926 g_message ("XdndFinished: dest_window: %#x", dest_window));
1928 context = gdk_drag_context_find (TRUE, xevent->xclient.window, dest_window);
1931 event->dnd.type = GDK_DROP_FINISHED;
1932 event->dnd.context = context;
1933 gdk_drag_context_ref (context);
1935 return GDK_FILTER_TRANSLATE;
1938 return GDK_FILTER_REMOVE;
1942 xdnd_set_targets (GdkDragContext *context)
1944 GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
1946 GList *tmp_list = context->targets;
1948 gint n_targets = g_list_length (context->targets);
1950 typelist = g_new (GdkAtom, n_targets);
1954 typelist[i] = GPOINTER_TO_INT (tmp_list->data);
1955 tmp_list = tmp_list->next;
1959 XChangeProperty (GDK_WINDOW_XDISPLAY (context->source_window),
1960 GDK_WINDOW_XWINDOW (context->source_window),
1961 gdk_atom_intern ("XdndTypeList", FALSE),
1962 XA_ATOM, 32, PropModeReplace,
1963 (guchar *)typelist, n_targets);
1965 private->xdnd_targets_set = 1;
1969 xdnd_send_enter (GdkDragContext *context)
1972 GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
1974 xev.xclient.type = ClientMessage;
1975 xev.xclient.message_type = gdk_atom_intern ("XdndEnter", FALSE);
1976 xev.xclient.format = 32;
1977 xev.xclient.window = GDK_WINDOW_XWINDOW (context->dest_window);
1978 xev.xclient.data.l[0] = GDK_WINDOW_XWINDOW (context->source_window);
1979 xev.xclient.data.l[1] = (3 << 24); /* version */
1980 xev.xclient.data.l[2] = 0;
1981 xev.xclient.data.l[3] = 0;
1982 xev.xclient.data.l[4] = 0;
1984 if (!private->xdnd_selection)
1985 private->xdnd_selection = gdk_atom_intern ("XdndSelection", FALSE);
1987 if (g_list_length (context->targets) > 3)
1989 if (!private->xdnd_targets_set)
1990 xdnd_set_targets (context);
1991 xev.xclient.data.l[1] |= 1;
1995 GList *tmp_list = context->targets;
2000 xev.xclient.data.l[i] = GPOINTER_TO_INT (tmp_list->data);
2001 tmp_list = tmp_list->next;
2006 if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->dest_window),
2010 g_message ("Send event to %lx failed",
2011 GDK_WINDOW_XWINDOW (context->dest_window)));
2012 gdk_window_unref (context->dest_window);
2013 context->dest_window = NULL;
2018 xdnd_send_leave (GdkDragContext *context)
2022 xev.xclient.type = ClientMessage;
2023 xev.xclient.message_type = gdk_atom_intern ("XdndLeave", FALSE);
2024 xev.xclient.format = 32;
2025 xev.xclient.window = GDK_WINDOW_XWINDOW (context->dest_window);
2026 xev.xclient.data.l[0] = GDK_WINDOW_XWINDOW (context->source_window);
2027 xev.xclient.data.l[1] = 0;
2028 xev.xclient.data.l[2] = 0;
2029 xev.xclient.data.l[3] = 0;
2030 xev.xclient.data.l[4] = 0;
2032 if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->dest_window),
2036 g_message ("Send event to %lx failed",
2037 GDK_WINDOW_XWINDOW (context->dest_window)));
2038 gdk_window_unref (context->dest_window);
2039 context->dest_window = NULL;
2044 xdnd_send_drop (GdkDragContext *context, guint32 time)
2048 xev.xclient.type = ClientMessage;
2049 xev.xclient.message_type = gdk_atom_intern ("XdndDrop", FALSE);
2050 xev.xclient.format = 32;
2051 xev.xclient.window = GDK_WINDOW_XWINDOW (context->dest_window);
2052 xev.xclient.data.l[0] = GDK_WINDOW_XWINDOW (context->source_window);
2053 xev.xclient.data.l[1] = 0;
2054 xev.xclient.data.l[2] = time;
2055 xev.xclient.data.l[3] = 0;
2056 xev.xclient.data.l[4] = 0;
2058 if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->dest_window),
2062 g_message ("Send event to %lx failed",
2063 GDK_WINDOW_XWINDOW (context->dest_window)));
2064 gdk_window_unref (context->dest_window);
2065 context->dest_window = NULL;
2070 xdnd_send_motion (GdkDragContext *context,
2073 GdkDragAction action,
2076 GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
2079 xev.xclient.type = ClientMessage;
2080 xev.xclient.message_type = gdk_atom_intern ("XdndPosition", FALSE);
2081 xev.xclient.format = 32;
2082 xev.xclient.window = GDK_WINDOW_XWINDOW (context->dest_window);
2083 xev.xclient.data.l[0] = GDK_WINDOW_XWINDOW (context->source_window);
2084 xev.xclient.data.l[1] = 0;
2085 xev.xclient.data.l[2] = (x_root << 16) | y_root;
2086 xev.xclient.data.l[3] = time;
2087 xev.xclient.data.l[4] = xdnd_action_to_atom (action);
2089 if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->dest_window),
2093 g_message ("Send event to %lx failed",
2094 GDK_WINDOW_XWINDOW (context->dest_window)));
2095 gdk_window_unref (context->dest_window);
2096 context->dest_window = NULL;
2098 private->drag_status = GDK_DRAG_STATUS_MOTION_WAIT;
2102 xdnd_check_dest (Window win)
2104 gboolean retval = FALSE;
2107 unsigned long nitems, after;
2111 static GdkAtom xdnd_proxy_atom = GDK_NONE;
2113 gint old_warnings = gdk_error_warnings;
2115 if (!xdnd_proxy_atom)
2116 xdnd_proxy_atom = gdk_atom_intern ("XdndProxy", FALSE);
2118 if (!xdnd_aware_atom)
2119 xdnd_aware_atom = gdk_atom_intern ("XdndAware", FALSE);
2124 gdk_error_warnings = 0;
2126 XGetWindowProperty (gdk_display, win,
2128 1, False, AnyPropertyType,
2129 &type, &format, &nitems, &after,
2130 (guchar **)&proxy_data);
2132 if (!gdk_error_code)
2136 if ((format == 32) && (nitems == 1))
2138 proxy = *proxy_data;
2142 g_warning ("Invalid XdndOwner property on window %ld\n", win));
2147 XGetWindowProperty (gdk_display, proxy ? proxy : win,
2149 1, False, AnyPropertyType,
2150 &type, &format, &nitems, &after,
2151 (guchar **)&version);
2153 if (!gdk_error_code && type != None)
2155 if ((format == 32) && (nitems == 1))
2162 g_warning ("Invalid XdndAware property on window %ld\n", win));
2169 gdk_error_warnings = old_warnings;
2172 return retval ? (proxy ? proxy : win) : GDK_NONE;
2177 static GdkFilterReturn
2178 xdnd_enter_filter (GdkXEvent *xev,
2182 XEvent *xevent = (XEvent *)xev;
2183 GdkDragContext *new_context;
2186 guint32 source_window = xevent->xclient.data.l[0];
2187 gboolean get_types = ((xevent->xclient.data.l[1] & 1) != 0);
2188 gint version = (xevent->xclient.data.l[1] & 0xff000000) >> 24;
2191 g_message ("XdndEnter: source_window: %#x, version: %#x",
2192 source_window, version));
2196 /* Old source ignore */
2197 GDK_NOTE (DND, g_message ("Ignored old XdndEnter message"));
2198 return GDK_FILTER_REMOVE;
2201 if (current_dest_drag != NULL)
2203 gdk_drag_context_unref (current_dest_drag);
2204 current_dest_drag = NULL;
2207 new_context = gdk_drag_context_new ();
2208 new_context->protocol = GDK_DRAG_PROTO_XDND;
2209 new_context->is_source = FALSE;
2211 new_context->source_window = gdk_window_lookup (source_window);
2212 if (new_context->source_window)
2213 gdk_window_ref (new_context->source_window);
2216 new_context->source_window = gdk_window_foreign_new (source_window);
2217 if (!new_context->source_window)
2219 gdk_drag_context_unref (new_context);
2220 return GDK_FILTER_REMOVE;
2223 new_context->dest_window = event->any.window;
2224 gdk_window_ref (new_context->dest_window);
2226 new_context->targets = NULL;
2231 gulong nitems, after;
2234 XGetWindowProperty (GDK_WINDOW_XDISPLAY (event->any.window),
2236 gdk_atom_intern ("XdndTypeList", FALSE), 0, 65536,
2237 False, XA_ATOM, &type, &format, &nitems,
2238 &after, (guchar **)&data);
2240 if ((format != 32) || (type != XA_ATOM))
2242 gdk_drag_context_unref (new_context);
2243 return GDK_FILTER_REMOVE;
2246 for (i=0; i<nitems; i++)
2247 new_context->targets = g_list_append (new_context->targets,
2248 GUINT_TO_POINTER (data[i]));
2255 if (xevent->xclient.data.l[2+i])
2256 new_context->targets = g_list_append (new_context->targets,
2257 GUINT_TO_POINTER (xevent->xclient.data.l[2+i]));
2260 #ifdef G_ENABLE_DEBUG
2261 if (gdk_debug_flags & GDK_DEBUG_DND)
2262 print_target_list (new_context->targets);
2263 #endif /* G_ENABLE_DEBUG */
2265 event->dnd.type = GDK_DRAG_ENTER;
2266 event->dnd.context = new_context;
2267 gdk_drag_context_ref (new_context);
2269 current_dest_drag = new_context;
2270 ((GdkDragContextPrivate *)new_context)->xdnd_selection =
2271 gdk_atom_intern ("XdndSelection", FALSE);
2273 return GDK_FILTER_TRANSLATE;
2276 static GdkFilterReturn
2277 xdnd_leave_filter (GdkXEvent *xev,
2281 XEvent *xevent = (XEvent *)xev;
2282 guint32 source_window = xevent->xclient.data.l[0];
2285 g_message ("XdndLeave: source_window: %#x",
2288 if ((current_dest_drag != NULL) &&
2289 (current_dest_drag->protocol == GDK_DRAG_PROTO_XDND) &&
2290 (GDK_WINDOW_XWINDOW (current_dest_drag->source_window) == source_window))
2292 event->dnd.type = GDK_DRAG_LEAVE;
2293 /* Pass ownership of context to the event */
2294 event->dnd.context = current_dest_drag;
2296 current_dest_drag = NULL;
2298 return GDK_FILTER_TRANSLATE;
2301 return GDK_FILTER_REMOVE;
2304 static GdkFilterReturn
2305 xdnd_position_filter (GdkXEvent *xev,
2309 XEvent *xevent = (XEvent *)xev;
2310 guint32 source_window = xevent->xclient.data.l[0];
2311 gint16 x_root = xevent->xclient.data.l[2] >> 16;
2312 gint16 y_root = xevent->xclient.data.l[2] & 0xffff;
2313 guint32 time = xevent->xclient.data.l[3];
2314 GdkAtom action = xevent->xclient.data.l[4];
2317 g_message ("XdndPosition: source_window: %#x position: (%d, %d) time: %d action: %ld",
2318 source_window, x_root, y_root, time, action));
2321 if ((current_dest_drag != NULL) &&
2322 (current_dest_drag->protocol == GDK_DRAG_PROTO_XDND) &&
2323 (GDK_WINDOW_XWINDOW (current_dest_drag->source_window) == source_window))
2325 event->dnd.type = GDK_DRAG_MOTION;
2326 event->dnd.context = current_dest_drag;
2327 gdk_drag_context_ref (current_dest_drag);
2329 event->dnd.time = time;
2331 current_dest_drag->suggested_action = xdnd_action_from_atom (action);
2333 event->dnd.x_root = x_root;
2334 event->dnd.y_root = y_root;
2336 ((GdkDragContextPrivate *)current_dest_drag)->last_x = x_root;
2337 ((GdkDragContextPrivate *)current_dest_drag)->last_y = y_root;
2339 return GDK_FILTER_TRANSLATE;
2342 return GDK_FILTER_REMOVE;
2345 static GdkFilterReturn
2346 xdnd_drop_filter (GdkXEvent *xev,
2350 XEvent *xevent = (XEvent *)xev;
2351 guint32 source_window = xevent->xclient.data.l[0];
2352 guint32 time = xevent->xclient.data.l[2];
2355 g_message ("XdndDrop: source_window: %#x time: %d",
2356 source_window, time));
2358 if ((current_dest_drag != NULL) &&
2359 (current_dest_drag->protocol == GDK_DRAG_PROTO_XDND) &&
2360 (GDK_WINDOW_XWINDOW (current_dest_drag->source_window) == source_window))
2362 GdkDragContextPrivate *private;
2363 private = (GdkDragContextPrivate *)current_dest_drag;
2365 event->dnd.type = GDK_DROP_START;
2367 event->dnd.context = current_dest_drag;
2368 gdk_drag_context_ref (current_dest_drag);
2370 event->dnd.time = time;
2371 event->dnd.x_root = private->last_x;
2372 event->dnd.y_root = private->last_y;
2374 return GDK_FILTER_TRANSLATE;
2377 return GDK_FILTER_REMOVE;
2380 /*************************************************************
2381 ************************** Public API ***********************
2382 *************************************************************/
2389 gdk_add_client_message_filter (
2390 gdk_atom_intern ("_MOTIF_DRAG_AND_DROP_MESSAGE", FALSE),
2391 motif_dnd_filter, NULL);
2392 gdk_add_client_message_filter (
2393 gdk_atom_intern ("XdndEnter", FALSE),
2394 xdnd_enter_filter, NULL);
2395 gdk_add_client_message_filter (
2396 gdk_atom_intern ("XdndLeave", FALSE),
2397 xdnd_leave_filter, NULL);
2398 gdk_add_client_message_filter (
2399 gdk_atom_intern ("XdndPosition", FALSE),
2400 xdnd_position_filter, NULL);
2401 gdk_add_client_message_filter (
2402 gdk_atom_intern ("XdndStatus", FALSE),
2403 xdnd_status_filter, NULL);
2404 gdk_add_client_message_filter (
2405 gdk_atom_intern ("XdndFinished", FALSE),
2406 xdnd_finished_filter, NULL);
2407 gdk_add_client_message_filter (
2408 gdk_atom_intern ("XdndDrop", FALSE),
2409 xdnd_drop_filter, NULL);
2415 gdk_drag_do_leave (GdkDragContext *context, guint32 time)
2417 if (context->dest_window)
2419 switch (context->protocol)
2421 case GDK_DRAG_PROTO_MOTIF:
2422 motif_send_leave (context, time);
2424 case GDK_DRAG_PROTO_XDND:
2425 xdnd_send_leave (context);
2427 case GDK_DRAG_PROTO_ROOTWIN:
2431 gdk_window_unref (context->dest_window);
2432 context->dest_window = NULL;
2437 gdk_drag_begin (GdkWindow *window,
2439 GdkDragAction actions)
2442 GdkDragContext *new_context;
2444 g_return_val_if_fail (window != NULL, NULL);
2446 new_context = gdk_drag_context_new ();
2447 new_context->is_source = TRUE;
2448 new_context->source_window = window;
2449 gdk_window_ref (window);
2451 tmp_list = g_list_last (targets);
2452 new_context->targets = NULL;
2455 new_context->targets = g_list_prepend (new_context->targets,
2457 tmp_list = tmp_list->prev;
2460 new_context->actions = actions;
2466 gdk_drag_get_protocol (guint32 xid,
2467 GdkDragProtocol *protocol)
2471 if ((retval = xdnd_check_dest (xid)))
2473 *protocol = GDK_DRAG_PROTO_XDND;
2474 GDK_NOTE (DND, g_message ("Entering dnd window %#x\n", xid));
2477 else if ((retval = motif_check_dest (xid)))
2479 *protocol = GDK_DRAG_PROTO_MOTIF;
2480 GDK_NOTE (DND, g_message ("Entering motif window %#x\n", xid));
2485 /* Check if this is a root window */
2487 gboolean rootwin = FALSE;
2488 gint old_warnings = gdk_error_warnings;
2491 unsigned long nitems, after;
2492 unsigned char *data;
2494 if (xid == gdk_root_window)
2501 XGetWindowProperty (gdk_display, xid,
2502 gdk_atom_intern ("ENLIGHTENMENT_DESKTOP", FALSE),
2503 0, 0, False, AnyPropertyType,
2504 &type, &format, &nitems, &after, &data);
2505 if ((gdk_error_code == 0) && type != None)
2512 /* Until I find out what window manager the next one is for,
2513 * I'm leaving it commented out. It's supported in the
2514 * xscreensaver sources, though.
2521 XGetWindowProperty (gdk_display, win,
2522 gdk_atom_intern ("__SWM_VROOT", FALSE),
2523 0, 0, False, AnyPropertyType,
2524 &type, &format, &nitems, &data);
2525 if ((gdk_error_code == 0) && type != None)
2530 gdk_error_warnings = old_warnings;
2534 *protocol = GDK_DRAG_PROTO_ROOTWIN;
2543 gdk_drag_find_window (GdkDragContext *context,
2544 GdkWindow *drag_window,
2547 GdkWindow **dest_window,
2548 GdkDragProtocol *protocol)
2550 GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
2553 if (!private->window_cache)
2554 private->window_cache = gdk_window_cache_new();
2556 dest = get_client_window_at_coords (private->window_cache,
2558 GDK_WINDOW_XWINDOW (drag_window) : GDK_NONE,
2561 if (private->dest_xid != dest)
2564 private->dest_xid = dest;
2566 /* Check if new destination accepts drags, and which protocol */
2568 if ((recipient = gdk_drag_get_protocol (dest, protocol)))
2570 *dest_window = gdk_window_lookup (recipient);
2572 gdk_window_ref (*dest_window);
2574 *dest_window = gdk_window_foreign_new (recipient);
2577 *dest_window = NULL;
2581 *dest_window = context->dest_window;
2583 gdk_window_ref (*dest_window);
2584 *protocol = context->protocol;
2589 gdk_drag_motion (GdkDragContext *context,
2590 GdkWindow *dest_window,
2591 GdkDragProtocol protocol,
2594 GdkDragAction action,
2597 GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
2599 if (context->dest_window != dest_window)
2601 GdkEvent temp_event;
2603 /* Send a leave to the last destination */
2604 gdk_drag_do_leave (context, time);
2605 private->drag_status = GDK_DRAG_STATUS_DRAG;
2607 /* Check if new destination accepts drags, and which protocol */
2611 context->dest_window = dest_window;
2612 gdk_window_ref (context->dest_window);
2613 context->protocol = protocol;
2617 case GDK_DRAG_PROTO_MOTIF:
2618 motif_send_enter (context, time);
2621 case GDK_DRAG_PROTO_XDND:
2622 xdnd_send_enter (context);
2625 case GDK_DRAG_PROTO_ROOTWIN:
2628 private->old_action = action;
2629 context->suggested_action = action;
2633 context->dest_window = NULL;
2634 context->action = 0;
2637 /* Push a status event, to let the client know that
2641 temp_event.dnd.type = GDK_DRAG_STATUS;
2642 temp_event.dnd.window = context->source_window;
2643 /* We use this to signal a synthetic status. Perhaps
2644 * we should use an extra field...
2646 temp_event.dnd.send_event = TRUE;
2648 temp_event.dnd.context = context;
2649 temp_event.dnd.time = time;
2651 gdk_event_put (&temp_event);
2655 private->old_action = context->suggested_action;
2656 context->suggested_action = action;
2659 /* Send a drag-motion event */
2661 private->last_x = x_root;
2662 private->last_y = y_root;
2664 if (context->dest_window)
2666 if (private->drag_status == GDK_DRAG_STATUS_DRAG)
2668 switch (context->protocol)
2670 case GDK_DRAG_PROTO_MOTIF:
2671 motif_send_motion (context, x_root, y_root, action, time);
2674 case GDK_DRAG_PROTO_XDND:
2675 xdnd_send_motion (context, x_root, y_root, action, time);
2678 case GDK_DRAG_PROTO_ROOTWIN:
2680 GdkEvent temp_event;
2682 if (g_list_find (context->targets,
2683 GUINT_TO_POINTER (gdk_atom_intern ("application/x-rootwin-drop", FALSE))))
2684 context->action = context->suggested_action;
2686 context->action = 0;
2688 temp_event.dnd.type = GDK_DRAG_STATUS;
2689 temp_event.dnd.window = context->source_window;
2690 temp_event.dnd.send_event = FALSE;
2691 temp_event.dnd.context = context;
2692 temp_event.dnd.time = time;
2694 gdk_event_put (&temp_event);
2707 gdk_drag_drop (GdkDragContext *context,
2710 if (context->dest_window)
2712 switch (context->protocol)
2714 case GDK_DRAG_PROTO_MOTIF:
2715 motif_send_leave (context, time);
2716 motif_send_drop (context, time);
2719 case GDK_DRAG_PROTO_XDND:
2720 xdnd_send_drop (context, time);
2723 case GDK_DRAG_PROTO_ROOTWIN:
2724 g_warning ("Drops for GDK_DRAG_PROTO_ROOTWIN must be handled internally");
2731 gdk_drag_abort (GdkDragContext *context,
2734 gdk_drag_do_leave (context, time);
2737 /* Destination side */
2740 gdk_drag_status (GdkDragContext *context,
2741 GdkDragAction action,
2744 GdkDragContextPrivate *private;
2747 g_return_if_fail (context != 0);
2749 private = (GdkDragContextPrivate *)context;
2751 context->action = action;
2753 if (context->protocol == GDK_DRAG_PROTO_MOTIF)
2755 xev.xclient.type = ClientMessage;
2756 xev.xclient.message_type = gdk_atom_intern ("_MOTIF_DRAG_AND_DROP_MESSAGE", FALSE);
2757 xev.xclient.format = 8;
2758 xev.xclient.window = GDK_WINDOW_XWINDOW (context->source_window);
2760 if (private->drag_status == GDK_DRAG_STATUS_ACTION_WAIT)
2762 xev.xclient.data.b[0] = XmOPERATION_CHANGED | 0x80;
2766 if ((action != 0) != (private->old_action != 0))
2769 xev.xclient.data.b[0] = XmDROP_SITE_ENTER | 0x80;
2771 xev.xclient.data.b[0] = XmDROP_SITE_LEAVE | 0x80;
2774 xev.xclient.data.b[0] = XmDRAG_MOTION | 0x80;
2777 xev.xclient.data.b[1] = local_byte_order;
2781 case GDK_ACTION_MOVE:
2782 xev.xclient.data.s[1] = XmDROP_MOVE;
2784 case GDK_ACTION_COPY:
2785 xev.xclient.data.s[1] = XmDROP_COPY;
2787 case GDK_ACTION_LINK:
2788 xev.xclient.data.s[1] = XmDROP_LINK;
2791 xev.xclient.data.s[1] = XmDROP_NOOP;
2796 xev.xclient.data.s[1] |= (XmDROP_SITE_VALID << 4);
2798 xev.xclient.data.s[1] |= (XmNO_DROP_SITE << 4);
2800 xev.xclient.data.l[1] = time;
2801 xev.xclient.data.s[4] = private->last_x;
2802 xev.xclient.data.s[5] = private->last_y;
2804 if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->source_window),
2807 g_message ("Send event to %lx failed",
2808 GDK_WINDOW_XWINDOW (context->source_window)));
2810 else if (context->protocol == GDK_DRAG_PROTO_XDND)
2812 xev.xclient.type = ClientMessage;
2813 xev.xclient.message_type = gdk_atom_intern ("XdndStatus", FALSE);
2814 xev.xclient.format = 32;
2815 xev.xclient.window = GDK_WINDOW_XWINDOW (context->source_window);
2817 xev.xclient.data.l[0] = GDK_WINDOW_XWINDOW (context->dest_window);
2818 xev.xclient.data.l[1] = (action != 0) ? (2 | 1) : 0;
2819 xev.xclient.data.l[2] = 0;
2820 xev.xclient.data.l[3] = 0;
2821 xev.xclient.data.l[4] = xdnd_action_to_atom (action);
2823 if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->source_window),
2826 g_message ("Send event to %lx failed",
2827 GDK_WINDOW_XWINDOW (context->source_window)));
2830 private->old_action = action;
2834 gdk_drop_reply (GdkDragContext *context,
2838 GdkDragContextPrivate *private;
2840 g_return_if_fail (context != 0);
2842 private = (GdkDragContextPrivate *)context;
2844 if (context->protocol == GDK_DRAG_PROTO_MOTIF)
2848 xev.xclient.type = ClientMessage;
2849 xev.xclient.message_type = gdk_atom_intern ("_MOTIF_DRAG_AND_DROP_MESSAGE", FALSE);
2850 xev.xclient.format = 8;
2852 xev.xclient.data.b[0] = XmDROP_START | 0x80;
2853 xev.xclient.data.b[1] = local_byte_order;
2855 xev.xclient.data.s[1] = XmDROP_COPY |
2856 (XmDROP_SITE_VALID << 4) |
2857 (XmDROP_NOOP << 8) |
2860 xev.xclient.data.s[1] = XmDROP_NOOP |
2861 (XmNO_DROP_SITE << 4) |
2862 (XmDROP_NOOP << 8) |
2863 (XmDROP_CANCEL << 12);
2864 xev.xclient.data.s[2] = private->last_x;
2865 xev.xclient.data.s[3] = private->last_y;
2867 gdk_send_xevent (GDK_WINDOW_XWINDOW (context->source_window),
2873 gdk_drop_finish (GdkDragContext *context,
2877 if (context->protocol == GDK_DRAG_PROTO_XDND)
2881 xev.xclient.type = ClientMessage;
2882 xev.xclient.message_type = gdk_atom_intern ("XdndFinished", FALSE);
2883 xev.xclient.format = 32;
2884 xev.xclient.window = GDK_WINDOW_XWINDOW (context->source_window);
2886 xev.xclient.data.l[0] = GDK_WINDOW_XWINDOW (context->dest_window);
2887 xev.xclient.data.l[1] = 0;
2888 xev.xclient.data.l[2] = 0;
2889 xev.xclient.data.l[3] = 0;
2890 xev.xclient.data.l[4] = 0;
2892 if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->source_window),
2895 g_message ("Send event to %lx failed",
2896 GDK_WINDOW_XWINDOW (context->source_window)));
2902 gdk_window_register_dnd (GdkWindow *window)
2904 static guint32 xdnd_version = 3;
2906 MotifDragReceiverInfo info;
2908 /* Set Motif drag receiver information property */
2910 if (!motif_drag_receiver_info_atom)
2911 motif_drag_receiver_info_atom = gdk_atom_intern ("_MOTIF_DRAG_RECEIVER_INFO", FALSE);
2913 info.byte_order = local_byte_order;
2914 info.protocol_version = 0;
2915 info.protocol_style = XmDRAG_DYNAMIC;
2916 info.proxy_window = GDK_NONE;
2917 info.num_drop_sites = 0;
2918 info.total_size = sizeof(info);
2920 XChangeProperty (gdk_display, GDK_WINDOW_XWINDOW (window),
2921 motif_drag_receiver_info_atom,
2922 motif_drag_receiver_info_atom,
2929 if (!xdnd_aware_atom)
2930 xdnd_aware_atom = gdk_atom_intern ("XdndAware", FALSE);
2932 /* The property needs to be of type XA_ATOM, not XA_INTEGER. Blech */
2933 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
2934 GDK_WINDOW_XWINDOW (window),
2935 xdnd_aware_atom, XA_ATOM,
2936 32, PropModeReplace,
2937 (guchar *)&xdnd_version,
2938 sizeof (xdnd_version));
2941 /*************************************************************
2942 * gdk_drag_get_selection:
2943 * Returns the selection atom for the current source window
2947 *************************************************************/
2950 gdk_drag_get_selection (GdkDragContext *context)
2952 g_return_val_if_fail (context != NULL, GDK_NONE);
2954 if (context->protocol == GDK_DRAG_PROTO_MOTIF)
2955 return ((GdkDragContextPrivate *)context)->motif_selection;
2956 else if (context->protocol == GDK_DRAG_PROTO_XDND)
2957 return ((GdkDragContextPrivate *)context)->xdnd_selection;