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 g_return_if_fail (context != NULL);
127 ((GdkDragContextPrivate *)context)->ref_count++;
131 gdk_drag_context_unref (GdkDragContext *context)
133 GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
134 private->ref_count--;
136 g_return_if_fail (context != NULL);
138 if (private->ref_count == 0)
140 g_dataset_destroy (private);
142 g_list_free (context->targets);
144 if (context->source_window)
145 gdk_window_unref (context->source_window);
147 if (context->dest_window)
148 gdk_window_unref (context->dest_window);
150 if (private->window_cache)
151 gdk_window_cache_destroy (private->window_cache);
153 contexts = g_list_remove (contexts, private);
158 static GdkDragContext *
159 gdk_drag_context_find (gboolean is_source,
163 GList *tmp_list = contexts;
164 GdkDragContext *context;
168 context = (GdkDragContext *)tmp_list->data;
170 if ((!context->is_source == !is_source) &&
171 ((source_xid == None) || (context->source_window &&
172 (GDK_WINDOW_XWINDOW (context->source_window) == source_xid))) &&
173 ((dest_xid == None) || (context->dest_window &&
174 (GDK_WINDOW_XWINDOW (context->dest_window) == dest_xid))))
177 tmp_list = tmp_list->next;
183 /* Utility functions */
186 gdk_window_cache_add (GdkWindowCache *cache,
188 gint x, gint y, gint width, gint height,
191 GdkCacheChild *child = g_new (GdkCacheChild, 1);
196 child->width = width;
197 child->height = height;
198 child->mapped = mapped;
200 cache->children = g_list_prepend (cache->children, child);
201 g_hash_table_insert (cache->child_hash, GUINT_TO_POINTER (xid),
205 static GdkFilterReturn
206 gdk_window_cache_filter (GdkXEvent *xev,
210 XEvent *xevent = (XEvent *)xev;
211 GdkWindowCache *cache = data;
213 switch (xevent->type)
215 case CirculateNotify:
217 case ConfigureNotify:
219 XConfigureEvent *xce = &xevent->xconfigure;
222 node = g_hash_table_lookup (cache->child_hash,
223 GUINT_TO_POINTER (xce->window));
226 GdkCacheChild *child = node->data;
229 child->width = xce->width;
230 child->height = xce->height;
231 if (xce->above == None && (node->next))
233 GList *last = g_list_last (cache->children);
234 cache->children = g_list_remove_link (cache->children, node);
241 GList *above_node = g_hash_table_lookup (cache->child_hash,
242 GUINT_TO_POINTER (xce->above));
243 if (above_node && node->prev != above_node)
245 cache->children = g_list_remove_link (cache->children, node);
246 node->next = above_node->next;
247 node->prev = above_node;
248 above_node->next = node;
256 XCreateWindowEvent *xcwe = &xevent->xcreatewindow;
257 if (!g_hash_table_lookup (cache->child_hash,
258 GUINT_TO_POINTER (xcwe->window)))
259 gdk_window_cache_add (cache, xcwe->window,
260 xcwe->x, xcwe->y, xcwe->width, xcwe->height,
266 XDestroyWindowEvent *xdwe = &xevent->xdestroywindow;
269 node = g_hash_table_lookup (cache->child_hash,
270 GUINT_TO_POINTER (xdwe->window));
273 g_hash_table_remove (cache->child_hash,
274 GUINT_TO_POINTER (xdwe->window));
275 cache->children = g_list_remove_link (cache->children, node);
277 g_list_free_1 (node);
283 XMapEvent *xme = &xevent->xmap;
286 node = g_hash_table_lookup (cache->child_hash,
287 GUINT_TO_POINTER (xme->window));
290 GdkCacheChild *child = node->data;
291 child->mapped = TRUE;
299 XMapEvent *xume = &xevent->xmap;
302 node = g_hash_table_lookup (cache->child_hash,
303 GUINT_TO_POINTER (xume->window));
306 GdkCacheChild *child = node->data;
307 child->mapped = FALSE;
312 return GDK_FILTER_CONTINUE;
314 return GDK_FILTER_REMOVE;
317 static GdkWindowCache *
318 gdk_window_cache_new (void)
320 XWindowAttributes xwa;
321 Window root, parent, *children;
322 unsigned int nchildren;
325 gint old_warnings = gdk_error_warnings;
327 GdkWindowCache *result = g_new (GdkWindowCache, 1);
329 result->children = NULL;
330 result->child_hash = g_hash_table_new (g_direct_hash, NULL);
332 XGetWindowAttributes (gdk_display, gdk_root_window, &xwa);
333 result->old_event_mask = xwa.your_event_mask;
334 XSelectInput (gdk_display, gdk_root_window,
335 result->old_event_mask | SubstructureNotifyMask);
336 gdk_window_add_filter ((GdkWindow *)&gdk_root_parent,
337 gdk_window_cache_filter, result);
340 gdk_error_warnings = 0;
342 if (XQueryTree(gdk_display, gdk_root_window,
343 &root, &parent, &children, &nchildren) == 0)
346 for (i = 0; i < nchildren ; i++)
348 XGetWindowAttributes (gdk_display, children[i], &xwa);
350 gdk_window_cache_add (result, children[i],
351 xwa.x, xwa.y, xwa.width, xwa.height,
352 xwa.map_state != IsUnmapped);
354 if (gdk_error_code != 0)
358 gdk_window_cache_add (result, children[i],
359 xwa.x, xwa.y, xwa.width, xwa.height,
360 (xwa.map_state != IsUnmapped));
366 gdk_error_warnings = old_warnings;
372 gdk_window_cache_destroy (GdkWindowCache *cache)
374 XSelectInput (gdk_display, gdk_root_window, cache->old_event_mask);
375 gdk_window_remove_filter ((GdkWindow *)&gdk_root_parent,
376 gdk_window_cache_filter, cache);
378 g_list_foreach (cache->children, (GFunc)g_free, NULL);
379 g_list_free (cache->children);
380 g_hash_table_destroy (cache->child_hash);
384 get_client_window_at_coords_recurse (Window win,
388 Window root, tmp_parent, *children;
389 unsigned int nchildren;
394 unsigned long nitems, after;
397 static Atom wm_state_atom = None;
400 wm_state_atom = gdk_atom_intern ("WM_STATE", FALSE);
402 XGetWindowProperty (gdk_display, win,
403 wm_state_atom, 0, 0, False, AnyPropertyType,
404 &type, &format, &nitems, &after, &data);
406 if (gdk_error_code != 0)
419 /* This is beautiful! Damn Enlightenment and click-to-focus */
420 XTranslateCoordinates (gdk_display, gdk_root_window, win,
421 x_root, y_root, &dest_x, &dest_y, &child);
423 if (gdk_error_code != 0)
430 if (XQueryTree(gdk_display, win,
431 &root, &tmp_parent, &children, &nchildren) == 0)
434 if (gdk_error_code == 0)
436 for (i = nchildren - 1; (i >= 0) && (child == None); i--)
438 XWindowAttributes xwa;
440 XGetWindowAttributes (gdk_display, children[i], &xwa);
442 if (gdk_error_code != 0)
444 else if ((xwa.map_state == IsViewable) && (xwa.class == InputOutput) &&
445 (x >= xwa.x) && (x < xwa.x + (gint)xwa.width) &&
446 (y >= xwa.y) && (y < xwa.y + (gint)xwa.height))
461 return get_client_window_at_coords_recurse (child, x, y);
467 get_client_window_at_coords (GdkWindowCache *cache,
473 Window retval = None;
475 gint old_warnings = gdk_error_warnings;
478 gdk_error_warnings = 0;
480 tmp_list = cache->children;
482 while (tmp_list && !retval)
484 GdkCacheChild *child = tmp_list->data;
486 if ((child->xid != ignore) && (child->mapped))
488 if ((x_root >= child->x) && (x_root < child->x + child->width) &&
489 (y_root >= child->y) && (y_root < child->y + child->height))
491 retval = get_client_window_at_coords_recurse (child->xid,
499 tmp_list = tmp_list->next;
502 gdk_error_warnings = old_warnings;
506 return gdk_root_window;
511 get_client_window_at_coords_recurse (Window win,
518 unsigned long nitems, after;
522 static Atom wm_state_atom = None;
525 wm_state_atom = gdk_atom_intern ("WM_STATE", FALSE);
527 XGetWindowProperty (gdk_display, win,
528 wm_state_atom, 0, 0, False, AnyPropertyType,
529 &type, &format, &nitems, &after, &data);
531 if (gdk_error_code != 0)
543 XTranslateCoordinates (gdk_display, gdk_root_window, win,
544 x_root, y_root, &dest_x, &dest_y, &child);
546 if (gdk_error_code != 0)
553 return get_client_window_at_coords_recurse (child, x_root, y_root);
559 get_client_window_at_coords (Window ignore,
563 Window root, parent, *children;
564 unsigned int nchildren;
566 Window retval = None;
568 gint old_warnings = gdk_error_warnings;
571 gdk_error_warnings = 0;
573 if (XQueryTree(gdk_display, gdk_root_window,
574 &root, &parent, &children, &nchildren) == 0)
577 for (i = nchildren - 1; (i >= 0) && (retval == None); i--)
579 if (children[i] != ignore)
581 XWindowAttributes xwa;
583 XGetWindowAttributes (gdk_display, children[i], &xwa);
585 if (gdk_error_code != 0)
587 else if ((xwa.map_state == IsViewable) &&
588 (x_root >= xwa.x) && (x_root < xwa.x + (gint)xwa.width) &&
589 (y_root >= xwa.y) && (y_root < xwa.y + (gint)xwa.height))
591 retval = get_client_window_at_coords_recurse (children[i],
594 retval = children[i];
601 gdk_error_warnings = old_warnings;
605 return gdk_root_window;
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 /* Static data for MOTIF DND */
661 static GList **motif_target_lists = NULL;
662 static gint motif_n_target_lists = -1;
664 /* Byte swapping routines. The motif specification leaves it
665 * up to us to save a few bytes in the client messages
667 static gchar local_byte_order = '\0';
669 #ifdef G_ENABLE_DEBUG
671 print_target_list (GList *targets)
675 gchar *name = gdk_atom_name (GPOINTER_TO_INT (targets->data));
676 g_message ("\t%s", name);
678 targets = targets->next;
681 #endif /* G_ENABLE_DEBUG */
684 init_byte_order (void)
686 guint32 myint = 0x01020304;
687 local_byte_order = (*(gchar *)&myint == 1) ? 'B' : 'l';
691 card16_to_host (guint16 x, gchar byte_order) {
692 if (byte_order == local_byte_order)
695 return (x << 8) | (x >> 8);
699 card32_to_host (guint32 x, gchar byte_order) {
700 if (byte_order == local_byte_order)
703 return (x << 24) | ((x & 0xff00) << 8) | ((x & 0xff0000) >> 8) | (x >> 24);
707 /***** Dest side ***********/
709 /* Property placed on source windows */
710 typedef struct _MotifDragInitiatorInfo {
712 guint8 protocol_version;
713 guint16 targets_index;
714 guint32 selection_atom;
715 } MotifDragInitiatorInfo;
717 /* Header for target table on the drag window */
718 typedef struct _MotifTargetTableHeader {
720 guchar protocol_version;
723 } MotifTargetTableHeader;
725 /* Property placed on target windows */
726 typedef struct _MotifDragReceiverInfo {
728 guint8 protocol_version;
729 guint8 protocol_style;
731 guint32 proxy_window;
732 guint16 num_drop_sites;
735 } MotifDragReceiverInfo;
737 static Window motif_drag_window = None;
738 static GdkWindow *motif_drag_gdk_window = NULL;
740 static GdkAtom motif_drag_targets_atom = GDK_NONE;
741 static GdkAtom motif_drag_receiver_info_atom = GDK_NONE;
743 /* Target table handling */
746 motif_drag_window_filter (GdkXEvent *xevent,
750 XEvent *xev = (XEvent *)xevent;
752 switch (xev->xany.type)
755 motif_drag_window = None;
756 motif_drag_gdk_window = NULL;
759 if (motif_target_lists &&
760 motif_drag_targets_atom &&
761 (xev->xproperty.atom == motif_drag_targets_atom))
762 motif_read_target_table();
765 return GDK_FILTER_REMOVE;
768 static GdkAtom motif_drag_window_atom = GDK_NONE;
771 motif_lookup_drag_window (Display *display)
773 Window retval = None;
774 gulong bytes_after, nitems;
779 XGetWindowProperty (gdk_display, gdk_root_window, motif_drag_window_atom,
780 0, sizeof(Window)/4, FALSE,
781 XA_WINDOW, &type, &format, &nitems, &bytes_after,
784 if ((format == 8*sizeof(Window)) && (nitems == 1) && (bytes_after == 0))
786 retval = *(Window *)data;
788 g_message ("Found drag window %#lx\n", motif_drag_window));
797 /* Finds the window where global Motif drag information is stored.
798 * If it doesn't exist and 'create' is TRUE, create one.
801 motif_find_drag_window (gboolean create)
803 if (!motif_drag_window)
805 if (!motif_drag_window_atom)
806 motif_drag_window_atom = gdk_atom_intern ("_MOTIF_DRAG_WINDOW", TRUE);
808 motif_drag_window = motif_lookup_drag_window (gdk_display);
810 if (!motif_drag_window && create)
812 /* Create a persistant window. (Copied from LessTif) */
815 XSetWindowAttributes attr;
816 display = XOpenDisplay (NULL);
817 XSetCloseDownMode (display, RetainPermanent);
819 XGrabServer (display);
821 motif_drag_window = motif_lookup_drag_window (display);
823 if (!motif_drag_window)
825 attr.override_redirect = True;
826 attr.event_mask = PropertyChangeMask;
829 XCreateWindow(display, DefaultRootWindow(display),
830 -100, -100, 10, 10, 0, 0,
831 InputOnly, CopyFromParent,
832 (CWOverrideRedirect | CWEventMask), &attr);
835 g_message ("Created drag window %#lx\n", motif_drag_window));
837 XChangeProperty (display, gdk_root_window,
838 motif_drag_window_atom, XA_WINDOW,
840 (guchar *)&motif_drag_window_atom, 1);
843 XUngrabServer (display);
844 XCloseDisplay (display);
847 /* There is a miniscule race condition here if the drag window
848 * gets destroyed exactly now.
850 if (motif_drag_window)
852 motif_drag_gdk_window = gdk_window_foreign_new (motif_drag_window);
853 gdk_window_add_filter (motif_drag_gdk_window,
854 motif_drag_window_filter,
859 return motif_drag_window;
863 motif_read_target_table (void)
865 gulong bytes_after, nitems;
870 if (!motif_drag_targets_atom)
871 motif_drag_targets_atom = gdk_atom_intern ("_MOTIF_DRAG_TARGETS", FALSE);
873 if (motif_target_lists)
875 for (i=0; i<motif_n_target_lists; i++)
876 g_list_free (motif_target_lists[i]);
878 g_free (motif_target_lists);
879 motif_target_lists = NULL;
880 motif_n_target_lists = 0;
883 if (motif_find_drag_window (FALSE))
885 MotifTargetTableHeader *header = NULL;
886 guchar *target_bytes = NULL;
888 gboolean success = FALSE;
890 XGetWindowProperty (gdk_display, motif_drag_window,
891 motif_drag_targets_atom,
892 0, (sizeof(MotifTargetTableHeader)+3)/4, FALSE,
893 motif_drag_targets_atom,
894 &type, &format, &nitems, &bytes_after,
897 if ((format != 8) || (nitems < sizeof (MotifTargetTableHeader)))
900 header->n_lists = card16_to_host (header->n_lists, header->byte_order);
901 header->total_size = card32_to_host (header->total_size, header->byte_order);
903 XGetWindowProperty (gdk_display, motif_drag_window, motif_drag_targets_atom,
904 (sizeof(MotifTargetTableHeader)+3)/4,
905 (header->total_size - sizeof(MotifTargetTableHeader) + 3)/4,
907 motif_drag_targets_atom, &type, &format, &nitems,
908 &bytes_after, &target_bytes);
910 if ((format != 8) || (bytes_after != 0) ||
911 (nitems != header->total_size - sizeof(MotifTargetTableHeader)))
914 motif_n_target_lists = header->n_lists;
915 motif_target_lists = g_new0 (GList *, motif_n_target_lists);
918 for (i=0; i<header->n_lists; i++)
923 if (p + sizeof(guint16) - target_bytes > nitems)
926 n_targets = card16_to_host (*(gushort *)p, header->byte_order);
928 /* We need to make a copy of the targets, since it may
931 targets = g_new (guint32, n_targets);
932 memcpy (targets, p + sizeof(guint16), sizeof(guint32) * n_targets);
934 p += sizeof(guint16) + n_targets * sizeof(guint32);
935 if (p - target_bytes > nitems)
938 for (j=0; j<n_targets; j++)
939 motif_target_lists[i] =
940 g_list_prepend (motif_target_lists[i],
941 GUINT_TO_POINTER (card32_to_host (targets[j],
942 header->byte_order)));
944 motif_target_lists[i] = g_list_reverse (motif_target_lists[i]);
954 XFree (target_bytes);
958 if (motif_target_lists)
960 g_free (motif_target_lists);
961 motif_target_lists = NULL;
962 motif_n_target_lists = 0;
964 g_warning ("Error reading Motif target table\n");
970 targets_sort_func (gconstpointer a, gconstpointer b)
972 return (GPOINTER_TO_UINT (a) < GPOINTER_TO_UINT (b)) ?
973 -1 : ((GPOINTER_TO_UINT (a) > GPOINTER_TO_UINT (b)) ? 1 : 0);
976 /* Check if given (sorted) list is in the targets table */
978 motif_target_table_check (GList *sorted)
980 GList *tmp_list1, *tmp_list2;
983 for (i=0; i<motif_n_target_lists; i++)
985 tmp_list1 = motif_target_lists[i];
988 while (tmp_list1 && tmp_list2)
990 if (tmp_list1->data != tmp_list2->data)
993 tmp_list1 = tmp_list1->next;
994 tmp_list2 = tmp_list2->next;
996 if (!tmp_list1 && !tmp_list2) /* Found it */
1004 motif_add_to_target_table (GList *targets)
1006 GList *sorted = NULL;
1011 /* make a sorted copy of the list */
1015 sorted = g_list_insert_sorted (sorted, targets->data, targets_sort_func);
1016 targets = targets->next;
1019 /* First check if it is their already */
1021 if (motif_target_lists)
1022 index = motif_target_table_check (sorted);
1024 /* We need to grab the server while doing this, to ensure
1030 /* We need to make sure that it exists _before_ we grab the
1031 * server, since we can't open a new connection after we
1034 motif_find_drag_window (TRUE);
1036 XGrabServer(gdk_display);
1037 motif_read_target_table();
1039 /* Check again, in case it was added in the meantime */
1041 if (motif_target_lists)
1042 index = motif_target_table_check (sorted);
1046 guint32 total_size = 0;
1050 MotifTargetTableHeader *header;
1052 if (!motif_target_lists)
1054 motif_target_lists = g_new (GList *, 1);
1055 motif_n_target_lists = 1;
1059 motif_n_target_lists++;
1060 motif_target_lists = g_realloc (motif_target_lists,
1061 sizeof(GList *) * motif_n_target_lists);
1063 motif_target_lists[motif_n_target_lists - 1] = sorted;
1065 index = motif_n_target_lists - 1;
1067 total_size = sizeof (MotifTargetTableHeader);
1068 for (i = 0; i < motif_n_target_lists ; i++)
1069 total_size += sizeof(guint16) + sizeof(guint32) * g_list_length (motif_target_lists[i]);
1071 data = g_malloc (total_size);
1073 header = (MotifTargetTableHeader *)data;
1074 p = data + sizeof(MotifTargetTableHeader);
1076 header->byte_order = local_byte_order;
1077 header->protocol_version = 0;
1078 header->n_lists = motif_n_target_lists;
1079 header->total_size = total_size;
1081 for (i = 0; i < motif_n_target_lists ; i++)
1083 guint16 n_targets = g_list_length (motif_target_lists[i]);
1084 guint32 *targets = g_new (guint32, n_targets);
1085 guint32 *p32 = targets;
1087 tmp_list = motif_target_lists[i];
1090 *p32 = GPOINTER_TO_UINT (tmp_list->data);
1092 tmp_list = tmp_list->next;
1097 p += sizeof(guint16);
1099 memcpy (p, targets, n_targets * sizeof(guint32));
1102 p += sizeof(guint32) * n_targets;
1106 XChangeProperty (gdk_display, motif_drag_window,
1107 motif_drag_targets_atom,
1108 motif_drag_targets_atom,
1112 XUngrabServer(gdk_display);
1115 g_list_free (sorted);
1119 /* Translate flags */
1122 motif_dnd_translate_flags (GdkDragContext *context, guint16 flags)
1124 guint recommended_op = flags & 0x000f;
1125 guint possible_ops = (flags & 0x0f0) >> 4;
1127 switch (recommended_op)
1130 context->suggested_action = GDK_ACTION_MOVE;
1133 context->suggested_action = GDK_ACTION_COPY;
1136 context->suggested_action = GDK_ACTION_LINK;
1139 context->suggested_action = GDK_ACTION_COPY;
1143 context->actions = 0;
1144 if (possible_ops & XmDROP_MOVE)
1145 context->actions |= GDK_ACTION_MOVE;
1146 if (possible_ops & XmDROP_COPY)
1147 context->actions |= GDK_ACTION_COPY;
1148 if (possible_ops & XmDROP_LINK)
1149 context->actions |= GDK_ACTION_LINK;
1153 motif_dnd_get_flags (GdkDragContext *context)
1157 switch (context->suggested_action)
1159 case GDK_ACTION_MOVE:
1160 flags = XmDROP_MOVE;
1162 case GDK_ACTION_COPY:
1163 flags = XmDROP_COPY;
1165 case GDK_ACTION_LINK:
1166 flags = XmDROP_LINK;
1169 flags = XmDROP_NOOP;
1173 if (context->actions & GDK_ACTION_MOVE)
1174 flags |= XmDROP_MOVE << 8;
1175 if (context->actions & GDK_ACTION_COPY)
1176 flags |= XmDROP_COPY << 8;
1177 if (context->actions & GDK_ACTION_LINK)
1178 flags |= XmDROP_LINK << 8;
1186 motif_set_targets (GdkDragContext *context)
1188 GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
1189 MotifDragInitiatorInfo info;
1191 static GdkAtom motif_drag_initiator_info = GDK_NONE;
1193 if (!motif_drag_initiator_info)
1194 motif_drag_initiator_info = gdk_atom_intern ("_MOTIF_DRAG_INITIATOR_INFO", FALSE);
1196 info.byte_order = local_byte_order;
1197 info.protocol_version = 0;
1199 info.targets_index = motif_add_to_target_table (context->targets);
1204 g_snprintf(buf, 20, "_GDK_SELECTION_%d", i);
1206 private->motif_selection = gdk_atom_intern (buf, FALSE);
1207 if (!XGetSelectionOwner (gdk_display, private->motif_selection))
1211 info.selection_atom = private->motif_selection;
1213 XChangeProperty (GDK_WINDOW_XDISPLAY (context->source_window),
1214 GDK_WINDOW_XWINDOW (context->source_window),
1215 private->motif_selection,
1216 motif_drag_initiator_info, 8, PropModeReplace,
1217 (guchar *)&info, sizeof (info));
1219 private->motif_targets_set = 1;
1223 motif_check_dest (Window win)
1225 gboolean retval = FALSE;
1226 MotifDragReceiverInfo *info;
1229 unsigned long nitems, after;
1231 if (!motif_drag_receiver_info_atom)
1232 motif_drag_receiver_info_atom = gdk_atom_intern ("_MOTIF_DRAG_RECEIVER_INFO", FALSE);
1234 XGetWindowProperty (gdk_display, win,
1235 motif_drag_receiver_info_atom,
1236 0, (sizeof(*info)+3)/4, False, AnyPropertyType,
1237 &type, &format, &nitems, &after,
1242 if ((format == 8) && (nitems == sizeof(*info)))
1244 if ((info->protocol_version == 0) &&
1245 ((info->protocol_style == XmDRAG_PREFER_PREREGISTER) ||
1246 (info->protocol_style == XmDRAG_PREFER_DYNAMIC) ||
1247 (info->protocol_style == XmDRAG_DYNAMIC)))
1253 g_warning ("Invalid Motif drag receiver property on window %ld\n", win));
1259 return retval ? win : GDK_NONE;
1264 motif_send_enter (GdkDragContext *context,
1268 GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
1270 xev.xclient.type = ClientMessage;
1271 xev.xclient.message_type = gdk_atom_intern ("_MOTIF_DRAG_AND_DROP_MESSAGE", FALSE);
1272 xev.xclient.format = 8;
1273 xev.xclient.window = GDK_WINDOW_XWINDOW (context->dest_window);
1275 xev.xclient.data.b[0] = XmTOP_LEVEL_ENTER;
1276 xev.xclient.data.b[1] = local_byte_order;
1277 xev.xclient.data.s[1] = 0;
1278 xev.xclient.data.l[1] = time;
1279 xev.xclient.data.l[2] = GDK_WINDOW_XWINDOW (context->source_window);
1281 if (!private->motif_targets_set)
1282 motif_set_targets (context);
1284 xev.xclient.data.l[3] = private->motif_selection;
1286 if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->dest_window),
1289 g_message ("Send event to %lx failed",
1290 GDK_WINDOW_XWINDOW (context->dest_window)));
1294 motif_send_leave (GdkDragContext *context,
1299 xev.xclient.type = ClientMessage;
1300 xev.xclient.message_type = gdk_atom_intern ("_MOTIF_DRAG_AND_DROP_MESSAGE", FALSE);
1301 xev.xclient.format = 8;
1302 xev.xclient.window = GDK_WINDOW_XWINDOW (context->dest_window);
1304 xev.xclient.data.b[0] = XmTOP_LEVEL_LEAVE;
1305 xev.xclient.data.b[1] = local_byte_order;
1306 xev.xclient.data.s[1] = 0;
1307 xev.xclient.data.l[1] = time;
1308 xev.xclient.data.l[2] = GDK_WINDOW_XWINDOW (context->source_window);
1309 xev.xclient.data.l[3] = 0;
1311 if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->dest_window),
1314 g_message ("Send event to %lx failed",
1315 GDK_WINDOW_XWINDOW (context->dest_window)));
1319 motif_send_motion (GdkDragContext *context,
1322 GdkDragAction action,
1327 GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
1329 xev.xclient.type = ClientMessage;
1330 xev.xclient.message_type = gdk_atom_intern ("_MOTIF_DRAG_AND_DROP_MESSAGE", FALSE);
1331 xev.xclient.format = 8;
1332 xev.xclient.window = GDK_WINDOW_XWINDOW (context->dest_window);
1334 xev.xclient.data.b[1] = local_byte_order;
1335 xev.xclient.data.s[1] = motif_dnd_get_flags (context);
1336 xev.xclient.data.l[1] = time;
1338 if (context->suggested_action != private->old_action)
1340 xev.xclient.data.b[0] = XmOPERATION_CHANGED;
1342 private->drag_status = GDK_DRAG_STATUS_ACTION_WAIT;
1347 xev.xclient.data.b[0] = XmDRAG_MOTION;
1349 xev.xclient.data.s[4] = x_root;
1350 xev.xclient.data.s[5] = y_root;
1352 private->drag_status = GDK_DRAG_STATUS_MOTION_WAIT;
1356 if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->dest_window),
1359 g_message ("Send event to %lx failed",
1360 GDK_WINDOW_XWINDOW (context->dest_window)));
1366 motif_send_drop (GdkDragContext *context, guint32 time)
1369 GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
1371 xev.xclient.type = ClientMessage;
1372 xev.xclient.message_type = gdk_atom_intern ("_MOTIF_DRAG_AND_DROP_MESSAGE", FALSE);
1373 xev.xclient.format = 8;
1374 xev.xclient.window = GDK_WINDOW_XWINDOW (context->dest_window);
1376 xev.xclient.data.b[0] = XmDROP_START;
1377 xev.xclient.data.b[1] = local_byte_order;
1378 xev.xclient.data.s[1] = motif_dnd_get_flags (context);
1379 xev.xclient.data.l[1] = time;
1381 xev.xclient.data.s[4] = private->last_x;
1382 xev.xclient.data.s[5] = private->last_y;
1384 xev.xclient.data.l[3] = private->motif_selection;
1385 xev.xclient.data.l[4] = GDK_WINDOW_XWINDOW (context->source_window);
1387 if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->dest_window),
1390 g_message ("Send event to %lx failed",
1391 GDK_WINDOW_XWINDOW (context->dest_window)));
1397 motif_read_initiator_info (Window source_window,
1403 static GdkAtom motif_drag_initiator_info = GDK_NONE;
1409 MotifDragInitiatorInfo *initiator_info;
1411 if (!motif_drag_initiator_info)
1412 motif_drag_initiator_info = gdk_atom_intern ("_MOTIF_DRAG_INITIATOR_INFO", FALSE);
1414 XGetWindowProperty (gdk_display, source_window, atom,
1415 0, sizeof(*initiator_info), FALSE,
1416 motif_drag_initiator_info,
1417 &type, &format, &nitems, &bytes_after,
1418 (guchar **)&initiator_info);
1420 if ((format != 8) || (nitems != sizeof (MotifDragInitiatorInfo)) || (bytes_after != 0))
1422 g_warning ("Error reading initiator info\n");
1426 motif_read_target_table ();
1428 if (initiator_info->targets_index >= motif_n_target_lists)
1430 g_warning ("Invalid target index in TOP_LEVEL_ENTER MESSAGE");
1431 XFree (initiator_info);
1432 return GDK_FILTER_REMOVE;
1435 tmp_list = g_list_last (motif_target_lists[initiator_info->targets_index]);
1440 *targets = g_list_prepend (*targets,
1442 tmp_list = tmp_list->prev;
1445 #ifdef G_ENABLE_DEBUG
1446 if (gdk_debug_flags & GDK_DEBUG_DND)
1447 print_target_list (*targets);
1448 #endif /* G_ENABLE_DEBUG */
1450 *selection = initiator_info->selection_atom;
1452 XFree (initiator_info);
1457 static GdkDragContext *
1458 motif_drag_context_new (GdkWindow *dest_window,
1460 guint32 source_window,
1463 GdkDragContext *new_context;
1464 GdkDragContextPrivate *private;
1466 /* FIXME, current_dest_drag really shouldn't be NULL'd
1467 * if we error below.
1469 if (current_dest_drag != NULL)
1471 if (timestamp >= current_dest_drag->start_time)
1473 gdk_drag_context_unref (current_dest_drag);
1474 current_dest_drag = NULL;
1480 new_context = gdk_drag_context_new ();
1481 private = (GdkDragContextPrivate *)new_context;
1483 new_context->protocol = GDK_DRAG_PROTO_MOTIF;
1484 new_context->is_source = FALSE;
1486 new_context->source_window = gdk_window_lookup (source_window);
1487 if (new_context->source_window)
1488 gdk_window_ref (new_context->source_window);
1491 new_context->source_window = gdk_window_foreign_new (source_window);
1492 if (!new_context->source_window)
1494 gdk_drag_context_unref (new_context);
1499 new_context->dest_window = dest_window;
1500 gdk_window_ref (dest_window);
1501 new_context->start_time = timestamp;
1503 if (!motif_read_initiator_info(source_window,
1505 &new_context->targets,
1506 &private->motif_selection))
1508 gdk_drag_context_unref (new_context);
1516 * The MOTIF drag protocol has no real provisions for distinguishing
1517 * multiple simultaneous drops. If the sources grab the pointer
1518 * when doing drags, that shouldn't happen, in any case. If it
1519 * does, we can't do much except hope for the best.
1522 static GdkFilterReturn
1523 motif_top_level_enter (GdkEvent *event,
1526 guint32 source_window,
1529 GdkDragContext *new_context;
1531 GDK_NOTE(DND, g_message ("Motif DND top level enter: flags: %#4x time: %d source_widow: %#4x atom: %d",
1532 flags, timestamp, source_window, atom));
1534 new_context = motif_drag_context_new (event->any.window, timestamp, source_window, atom);
1536 return GDK_FILTER_REMOVE;
1538 event->dnd.type = GDK_DRAG_ENTER;
1539 event->dnd.context = new_context;
1540 gdk_drag_context_ref (new_context);
1542 current_dest_drag = new_context;
1544 return GDK_FILTER_TRANSLATE;
1548 motif_top_level_leave (GdkEvent *event,
1552 GDK_NOTE(DND, g_message ("Motif DND top level leave: flags: %#4x time: %d",
1555 if ((current_dest_drag != NULL) &&
1556 (current_dest_drag->protocol == GDK_DRAG_PROTO_MOTIF) &&
1557 (timestamp >= current_dest_drag->start_time))
1559 event->dnd.type = GDK_DRAG_LEAVE;
1560 /* Pass ownership of context to the event */
1561 event->dnd.context = current_dest_drag;
1563 current_dest_drag = NULL;
1565 return GDK_FILTER_TRANSLATE;
1568 return GDK_FILTER_REMOVE;
1572 motif_motion (GdkEvent *event,
1578 GdkDragContextPrivate *private;
1580 GDK_NOTE(DND, g_message ("Motif DND motion: flags: %#4x time: %d (%d, %d)",
1581 flags, timestamp, x_root, y_root));
1583 if ((current_dest_drag != NULL) &&
1584 (current_dest_drag->protocol == GDK_DRAG_PROTO_MOTIF) &&
1585 (timestamp >= current_dest_drag->start_time))
1587 private = (GdkDragContextPrivate *)current_dest_drag;
1589 event->dnd.type = GDK_DRAG_MOTION;
1590 event->dnd.context = current_dest_drag;
1591 gdk_drag_context_ref (current_dest_drag);
1593 event->dnd.time = timestamp;
1595 motif_dnd_translate_flags (current_dest_drag, flags);
1597 event->dnd.x_root = x_root;
1598 event->dnd.y_root = y_root;
1600 private->last_x = x_root;
1601 private->last_y = y_root;
1603 private->drag_status = GDK_DRAG_STATUS_MOTION_WAIT;
1605 return GDK_FILTER_TRANSLATE;
1608 return GDK_FILTER_REMOVE;
1612 motif_operation_changed (GdkEvent *event,
1616 GdkDragContextPrivate *private;
1618 GDK_NOTE(DND, g_message ("Motif DND operation changed: flags: %#4x time: %d",
1621 if ((current_dest_drag != NULL) &&
1622 (current_dest_drag->protocol == GDK_DRAG_PROTO_MOTIF) &&
1623 (timestamp >= current_dest_drag->start_time))
1625 event->dnd.type = GDK_DRAG_MOTION;
1626 event->dnd.send_event = FALSE;
1627 event->dnd.context = current_dest_drag;
1628 gdk_drag_context_ref (current_dest_drag);
1630 event->dnd.time = timestamp;
1631 private = (GdkDragContextPrivate *)current_dest_drag;
1633 motif_dnd_translate_flags (current_dest_drag, flags);
1635 event->dnd.x_root = private->last_x;
1636 event->dnd.y_root = private->last_y;
1638 private->drag_status = GDK_DRAG_STATUS_ACTION_WAIT;
1640 return GDK_FILTER_TRANSLATE;
1643 return GDK_FILTER_REMOVE;
1647 motif_drop_start (GdkEvent *event,
1650 guint32 source_window,
1655 GdkDragContext *new_context;
1658 GDK_NOTE(DND, g_message ("Motif DND drop start: flags: %#4x time: %d (%d, %d) source_widow: %#4x atom: %d",
1659 flags, timestamp, x_root, y_root, source_window, atom));
1661 new_context = motif_drag_context_new (event->any.window, timestamp, source_window, atom);
1663 return GDK_FILTER_REMOVE;
1665 motif_dnd_translate_flags (new_context, flags);
1667 event->dnd.type = GDK_DROP_START;
1668 event->dnd.context = new_context;
1669 event->dnd.time = timestamp;
1670 event->dnd.x_root = x_root;
1671 event->dnd.y_root = y_root;
1673 gdk_drag_context_ref (new_context);
1674 current_dest_drag = new_context;
1676 return GDK_FILTER_TRANSLATE;
1680 motif_drag_status (GdkEvent *event,
1684 GdkDragContext *context;
1687 g_message ("Motif status message: flags %x", flags));
1689 context = gdk_drag_context_find (TRUE,
1690 GDK_WINDOW_XWINDOW (event->any.window),
1695 GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
1696 if (private->drag_status == GDK_DRAG_STATUS_MOTION_WAIT)
1697 private->drag_status = GDK_DRAG_STATUS_DRAG;
1699 event->dnd.type = GDK_DRAG_STATUS;
1700 event->dnd.send_event = FALSE;
1701 event->dnd.context = context;
1702 gdk_drag_context_ref (context);
1704 event->dnd.time = timestamp;
1706 if ((flags & 0x00f0) >> 4 == XmDROP_SITE_VALID)
1708 switch (flags & 0x000f)
1711 context->action = 0;
1714 context->action = GDK_ACTION_MOVE;
1717 context->action = GDK_ACTION_COPY;
1720 context->action = GDK_ACTION_LINK;
1725 context->action = 0;
1727 return GDK_FILTER_TRANSLATE;
1729 return GDK_FILTER_REMOVE;
1733 motif_dnd_filter (GdkXEvent *xev,
1737 XEvent *xevent = (XEvent *)xev;
1738 XClientMessageEvent *xce = &xevent->xclient;
1744 guint32 source_window;
1746 gint16 x_root, y_root;
1749 /* First read some fields common to all Motif DND messages */
1751 reason = xce->data.b[0];
1752 byte_order = xce->data.b[1];
1753 flags = card16_to_host (xce->data.s[1], byte_order);
1754 timestamp = card32_to_host (xce->data.l[1], byte_order);
1756 is_reply = ((reason & 0x80) != 0);
1758 switch (reason & 0x7f)
1760 case XmTOP_LEVEL_ENTER:
1761 source_window = card32_to_host (xce->data.l[2], byte_order);
1762 atom = card32_to_host (xce->data.l[3], byte_order);
1763 return motif_top_level_enter (event, flags, timestamp, source_window, atom);
1764 case XmTOP_LEVEL_LEAVE:
1765 return motif_top_level_leave (event, flags, timestamp);
1768 x_root = card16_to_host (xce->data.s[4], byte_order);
1769 y_root = card16_to_host (xce->data.s[5], byte_order);
1772 return motif_motion (event, flags, timestamp, x_root, y_root);
1774 return motif_drag_status (event, flags, timestamp);
1776 case XmDROP_SITE_ENTER:
1777 return motif_drag_status (event, flags, timestamp);
1779 case XmDROP_SITE_LEAVE:
1780 return motif_drag_status (event,
1781 XmNO_DROP_SITE << 8 | XmDROP_NOOP,
1784 x_root = card16_to_host (xce->data.s[4], byte_order);
1785 y_root = card16_to_host (xce->data.s[5], byte_order);
1786 atom = card32_to_host (xce->data.l[3], byte_order);
1787 source_window = card32_to_host (xce->data.l[4], byte_order);
1790 return motif_drop_start (event, flags, timestamp, source_window, atom, x_root, y_root);
1793 case XmOPERATION_CHANGED:
1795 return motif_operation_changed (event, flags, timestamp);
1797 return motif_drag_status (event, flags, timestamp);
1800 /* To the best of my knowledge, these next two messages are
1801 * not part of the protocol, though they are defined in
1805 case XmDRAG_DROP_FINISH:
1809 return GDK_FILTER_REMOVE;
1812 /*************************************************************
1813 ***************************** XDND **************************
1814 *************************************************************/
1816 /* Utility functions */
1821 GdkDragAction action;
1822 } xdnd_actions_table[] = {
1823 { "XdndActionCopy", GDK_NONE, GDK_ACTION_COPY },
1824 { "XdndActionMove", GDK_NONE, GDK_ACTION_MOVE },
1825 { "XdndActionLink", GDK_NONE, GDK_ACTION_LINK },
1826 { "XdndActionAsk", GDK_NONE, GDK_ACTION_ASK },
1827 { "XdndActionPrivate", GDK_NONE, GDK_ACTION_COPY },
1830 static const gint xdnd_n_actions = sizeof(xdnd_actions_table) / sizeof(xdnd_actions_table[0]);
1831 static gboolean xdnd_actions_initialized = FALSE;
1834 xdnd_initialize_actions (void)
1838 xdnd_actions_initialized = TRUE;
1839 for (i=0; i < xdnd_n_actions; i++)
1840 xdnd_actions_table[i].atom = gdk_atom_intern (xdnd_actions_table[i].name, FALSE);
1843 static GdkDragAction
1844 xdnd_action_from_atom (GdkAtom atom)
1848 if (!xdnd_actions_initialized)
1849 xdnd_initialize_actions();
1851 for (i=0; i<xdnd_n_actions; i++)
1852 if (atom == xdnd_actions_table[i].atom)
1853 return xdnd_actions_table[i].action;
1859 xdnd_action_to_atom (GdkDragAction action)
1863 if (!xdnd_actions_initialized)
1864 xdnd_initialize_actions();
1866 for (i=0; i<xdnd_n_actions; i++)
1867 if (action == xdnd_actions_table[i].action)
1868 return xdnd_actions_table[i].atom;
1873 static GdkAtom xdnd_aware_atom = GDK_NONE;
1877 static GdkFilterReturn
1878 xdnd_status_filter (GdkXEvent *xev,
1882 XEvent *xevent = (XEvent *)xev;
1883 guint32 dest_window = xevent->xclient.data.l[0];
1884 guint32 flags = xevent->xclient.data.l[1];
1885 GdkAtom action = xevent->xclient.data.l[4];
1886 GdkDragContext *context;
1889 g_message ("XdndStatus: dest_window: %#x action: %ld",
1890 dest_window, action));
1893 context = gdk_drag_context_find (TRUE, xevent->xclient.window, dest_window);
1896 GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
1897 if (private->drag_status == GDK_DRAG_STATUS_MOTION_WAIT)
1898 private->drag_status = GDK_DRAG_STATUS_DRAG;
1900 event->dnd.send_event = FALSE;
1901 event->dnd.type = GDK_DRAG_STATUS;
1902 event->dnd.context = context;
1903 gdk_drag_context_ref (context);
1905 event->dnd.time = GDK_CURRENT_TIME; /* FIXME? */
1906 if (!(action != 0) != !(flags & 1))
1909 g_warning ("Received status event with flags not corresponding to action!\n"));
1913 context->action = xdnd_action_from_atom (action);
1915 return GDK_FILTER_TRANSLATE;
1918 return GDK_FILTER_REMOVE;
1921 static GdkFilterReturn
1922 xdnd_finished_filter (GdkXEvent *xev,
1926 XEvent *xevent = (XEvent *)xev;
1927 guint32 dest_window = xevent->xclient.data.l[0];
1928 GdkDragContext *context;
1931 g_message ("XdndFinished: dest_window: %#x", dest_window));
1933 context = gdk_drag_context_find (TRUE, xevent->xclient.window, dest_window);
1936 event->dnd.type = GDK_DROP_FINISHED;
1937 event->dnd.context = context;
1938 gdk_drag_context_ref (context);
1940 return GDK_FILTER_TRANSLATE;
1943 return GDK_FILTER_REMOVE;
1947 xdnd_set_targets (GdkDragContext *context)
1949 GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
1951 GList *tmp_list = context->targets;
1953 gint n_targets = g_list_length (context->targets);
1955 typelist = g_new (GdkAtom, n_targets);
1959 typelist[i] = GPOINTER_TO_INT (tmp_list->data);
1960 tmp_list = tmp_list->next;
1964 XChangeProperty (GDK_WINDOW_XDISPLAY (context->source_window),
1965 GDK_WINDOW_XWINDOW (context->source_window),
1966 gdk_atom_intern ("XdndTypeList", FALSE),
1967 XA_ATOM, 32, PropModeReplace,
1968 (guchar *)typelist, n_targets);
1970 private->xdnd_targets_set = 1;
1974 xdnd_send_enter (GdkDragContext *context)
1977 GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
1979 xev.xclient.type = ClientMessage;
1980 xev.xclient.message_type = gdk_atom_intern ("XdndEnter", FALSE);
1981 xev.xclient.format = 32;
1982 xev.xclient.window = GDK_WINDOW_XWINDOW (context->dest_window);
1983 xev.xclient.data.l[0] = GDK_WINDOW_XWINDOW (context->source_window);
1984 xev.xclient.data.l[1] = (3 << 24); /* version */
1985 xev.xclient.data.l[2] = 0;
1986 xev.xclient.data.l[3] = 0;
1987 xev.xclient.data.l[4] = 0;
1989 if (!private->xdnd_selection)
1990 private->xdnd_selection = gdk_atom_intern ("XdndSelection", FALSE);
1992 if (g_list_length (context->targets) > 3)
1994 if (!private->xdnd_targets_set)
1995 xdnd_set_targets (context);
1996 xev.xclient.data.l[1] |= 1;
2000 GList *tmp_list = context->targets;
2005 xev.xclient.data.l[i] = GPOINTER_TO_INT (tmp_list->data);
2006 tmp_list = tmp_list->next;
2011 if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->dest_window),
2015 g_message ("Send event to %lx failed",
2016 GDK_WINDOW_XWINDOW (context->dest_window)));
2017 gdk_window_unref (context->dest_window);
2018 context->dest_window = NULL;
2023 xdnd_send_leave (GdkDragContext *context)
2027 xev.xclient.type = ClientMessage;
2028 xev.xclient.message_type = gdk_atom_intern ("XdndLeave", FALSE);
2029 xev.xclient.format = 32;
2030 xev.xclient.window = GDK_WINDOW_XWINDOW (context->dest_window);
2031 xev.xclient.data.l[0] = GDK_WINDOW_XWINDOW (context->source_window);
2032 xev.xclient.data.l[1] = 0;
2033 xev.xclient.data.l[2] = 0;
2034 xev.xclient.data.l[3] = 0;
2035 xev.xclient.data.l[4] = 0;
2037 if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->dest_window),
2041 g_message ("Send event to %lx failed",
2042 GDK_WINDOW_XWINDOW (context->dest_window)));
2043 gdk_window_unref (context->dest_window);
2044 context->dest_window = NULL;
2049 xdnd_send_drop (GdkDragContext *context, guint32 time)
2053 xev.xclient.type = ClientMessage;
2054 xev.xclient.message_type = gdk_atom_intern ("XdndDrop", FALSE);
2055 xev.xclient.format = 32;
2056 xev.xclient.window = GDK_WINDOW_XWINDOW (context->dest_window);
2057 xev.xclient.data.l[0] = GDK_WINDOW_XWINDOW (context->source_window);
2058 xev.xclient.data.l[1] = 0;
2059 xev.xclient.data.l[2] = time;
2060 xev.xclient.data.l[3] = 0;
2061 xev.xclient.data.l[4] = 0;
2063 if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->dest_window),
2067 g_message ("Send event to %lx failed",
2068 GDK_WINDOW_XWINDOW (context->dest_window)));
2069 gdk_window_unref (context->dest_window);
2070 context->dest_window = NULL;
2075 xdnd_send_motion (GdkDragContext *context,
2078 GdkDragAction action,
2081 GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
2084 xev.xclient.type = ClientMessage;
2085 xev.xclient.message_type = gdk_atom_intern ("XdndPosition", FALSE);
2086 xev.xclient.format = 32;
2087 xev.xclient.window = GDK_WINDOW_XWINDOW (context->dest_window);
2088 xev.xclient.data.l[0] = GDK_WINDOW_XWINDOW (context->source_window);
2089 xev.xclient.data.l[1] = 0;
2090 xev.xclient.data.l[2] = (x_root << 16) | y_root;
2091 xev.xclient.data.l[3] = time;
2092 xev.xclient.data.l[4] = xdnd_action_to_atom (action);
2094 if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->dest_window),
2098 g_message ("Send event to %lx failed",
2099 GDK_WINDOW_XWINDOW (context->dest_window)));
2100 gdk_window_unref (context->dest_window);
2101 context->dest_window = NULL;
2103 private->drag_status = GDK_DRAG_STATUS_MOTION_WAIT;
2107 xdnd_check_dest (Window win)
2109 gboolean retval = FALSE;
2112 unsigned long nitems, after;
2116 static GdkAtom xdnd_proxy_atom = GDK_NONE;
2118 gint old_warnings = gdk_error_warnings;
2120 if (!xdnd_proxy_atom)
2121 xdnd_proxy_atom = gdk_atom_intern ("XdndProxy", FALSE);
2123 if (!xdnd_aware_atom)
2124 xdnd_aware_atom = gdk_atom_intern ("XdndAware", FALSE);
2129 gdk_error_warnings = 0;
2131 XGetWindowProperty (gdk_display, win,
2133 1, False, AnyPropertyType,
2134 &type, &format, &nitems, &after,
2135 (guchar **)&proxy_data);
2137 if (!gdk_error_code)
2141 if ((format == 32) && (nitems == 1))
2143 proxy = *proxy_data;
2147 g_warning ("Invalid XdndOwner property on window %ld\n", win));
2152 XGetWindowProperty (gdk_display, proxy ? proxy : win,
2154 1, False, AnyPropertyType,
2155 &type, &format, &nitems, &after,
2156 (guchar **)&version);
2158 if (!gdk_error_code && type != None)
2160 if ((format == 32) && (nitems == 1))
2167 g_warning ("Invalid XdndAware property on window %ld\n", win));
2174 gdk_error_warnings = old_warnings;
2177 return retval ? (proxy ? proxy : win) : GDK_NONE;
2182 static GdkFilterReturn
2183 xdnd_enter_filter (GdkXEvent *xev,
2187 XEvent *xevent = (XEvent *)xev;
2188 GdkDragContext *new_context;
2191 guint32 source_window = xevent->xclient.data.l[0];
2192 gboolean get_types = ((xevent->xclient.data.l[1] & 1) != 0);
2193 gint version = (xevent->xclient.data.l[1] & 0xff000000) >> 24;
2196 g_message ("XdndEnter: source_window: %#x, version: %#x",
2197 source_window, version));
2201 /* Old source ignore */
2202 GDK_NOTE (DND, g_message ("Ignored old XdndEnter message"));
2203 return GDK_FILTER_REMOVE;
2206 if (current_dest_drag != NULL)
2208 gdk_drag_context_unref (current_dest_drag);
2209 current_dest_drag = NULL;
2212 new_context = gdk_drag_context_new ();
2213 new_context->protocol = GDK_DRAG_PROTO_XDND;
2214 new_context->is_source = FALSE;
2216 new_context->source_window = gdk_window_lookup (source_window);
2217 if (new_context->source_window)
2218 gdk_window_ref (new_context->source_window);
2221 new_context->source_window = gdk_window_foreign_new (source_window);
2222 if (!new_context->source_window)
2224 gdk_drag_context_unref (new_context);
2225 return GDK_FILTER_REMOVE;
2228 new_context->dest_window = event->any.window;
2229 gdk_window_ref (new_context->dest_window);
2231 new_context->targets = NULL;
2236 gulong nitems, after;
2239 XGetWindowProperty (GDK_WINDOW_XDISPLAY (event->any.window),
2241 gdk_atom_intern ("XdndTypeList", FALSE), 0, 65536,
2242 False, XA_ATOM, &type, &format, &nitems,
2243 &after, (guchar **)&data);
2245 if ((format != 32) || (type != XA_ATOM))
2247 gdk_drag_context_unref (new_context);
2248 return GDK_FILTER_REMOVE;
2251 for (i=0; i<nitems; i++)
2252 new_context->targets = g_list_append (new_context->targets,
2253 GUINT_TO_POINTER (data[i]));
2260 if (xevent->xclient.data.l[2+i])
2261 new_context->targets = g_list_append (new_context->targets,
2262 GUINT_TO_POINTER (xevent->xclient.data.l[2+i]));
2265 #ifdef G_ENABLE_DEBUG
2266 if (gdk_debug_flags & GDK_DEBUG_DND)
2267 print_target_list (new_context->targets);
2268 #endif /* G_ENABLE_DEBUG */
2270 event->dnd.type = GDK_DRAG_ENTER;
2271 event->dnd.context = new_context;
2272 gdk_drag_context_ref (new_context);
2274 current_dest_drag = new_context;
2275 ((GdkDragContextPrivate *)new_context)->xdnd_selection =
2276 gdk_atom_intern ("XdndSelection", FALSE);
2278 return GDK_FILTER_TRANSLATE;
2281 static GdkFilterReturn
2282 xdnd_leave_filter (GdkXEvent *xev,
2286 XEvent *xevent = (XEvent *)xev;
2287 guint32 source_window = xevent->xclient.data.l[0];
2290 g_message ("XdndLeave: source_window: %#x",
2293 if ((current_dest_drag != NULL) &&
2294 (current_dest_drag->protocol == GDK_DRAG_PROTO_XDND) &&
2295 (GDK_WINDOW_XWINDOW (current_dest_drag->source_window) == source_window))
2297 event->dnd.type = GDK_DRAG_LEAVE;
2298 /* Pass ownership of context to the event */
2299 event->dnd.context = current_dest_drag;
2301 current_dest_drag = NULL;
2303 return GDK_FILTER_TRANSLATE;
2306 return GDK_FILTER_REMOVE;
2309 static GdkFilterReturn
2310 xdnd_position_filter (GdkXEvent *xev,
2314 XEvent *xevent = (XEvent *)xev;
2315 guint32 source_window = xevent->xclient.data.l[0];
2316 gint16 x_root = xevent->xclient.data.l[2] >> 16;
2317 gint16 y_root = xevent->xclient.data.l[2] & 0xffff;
2318 guint32 time = xevent->xclient.data.l[3];
2319 GdkAtom action = xevent->xclient.data.l[4];
2322 g_message ("XdndPosition: source_window: %#x position: (%d, %d) time: %d action: %ld",
2323 source_window, x_root, y_root, time, action));
2326 if ((current_dest_drag != NULL) &&
2327 (current_dest_drag->protocol == GDK_DRAG_PROTO_XDND) &&
2328 (GDK_WINDOW_XWINDOW (current_dest_drag->source_window) == source_window))
2330 event->dnd.type = GDK_DRAG_MOTION;
2331 event->dnd.context = current_dest_drag;
2332 gdk_drag_context_ref (current_dest_drag);
2334 event->dnd.time = time;
2336 current_dest_drag->suggested_action = xdnd_action_from_atom (action);
2338 event->dnd.x_root = x_root;
2339 event->dnd.y_root = y_root;
2341 ((GdkDragContextPrivate *)current_dest_drag)->last_x = x_root;
2342 ((GdkDragContextPrivate *)current_dest_drag)->last_y = y_root;
2344 return GDK_FILTER_TRANSLATE;
2347 return GDK_FILTER_REMOVE;
2350 static GdkFilterReturn
2351 xdnd_drop_filter (GdkXEvent *xev,
2355 XEvent *xevent = (XEvent *)xev;
2356 guint32 source_window = xevent->xclient.data.l[0];
2357 guint32 time = xevent->xclient.data.l[2];
2360 g_message ("XdndDrop: source_window: %#x time: %d",
2361 source_window, time));
2363 if ((current_dest_drag != NULL) &&
2364 (current_dest_drag->protocol == GDK_DRAG_PROTO_XDND) &&
2365 (GDK_WINDOW_XWINDOW (current_dest_drag->source_window) == source_window))
2367 GdkDragContextPrivate *private;
2368 private = (GdkDragContextPrivate *)current_dest_drag;
2370 event->dnd.type = GDK_DROP_START;
2372 event->dnd.context = current_dest_drag;
2373 gdk_drag_context_ref (current_dest_drag);
2375 event->dnd.time = time;
2376 event->dnd.x_root = private->last_x;
2377 event->dnd.y_root = private->last_y;
2379 return GDK_FILTER_TRANSLATE;
2382 return GDK_FILTER_REMOVE;
2385 /*************************************************************
2386 ************************** Public API ***********************
2387 *************************************************************/
2394 gdk_add_client_message_filter (
2395 gdk_atom_intern ("_MOTIF_DRAG_AND_DROP_MESSAGE", FALSE),
2396 motif_dnd_filter, NULL);
2397 gdk_add_client_message_filter (
2398 gdk_atom_intern ("XdndEnter", FALSE),
2399 xdnd_enter_filter, NULL);
2400 gdk_add_client_message_filter (
2401 gdk_atom_intern ("XdndLeave", FALSE),
2402 xdnd_leave_filter, NULL);
2403 gdk_add_client_message_filter (
2404 gdk_atom_intern ("XdndPosition", FALSE),
2405 xdnd_position_filter, NULL);
2406 gdk_add_client_message_filter (
2407 gdk_atom_intern ("XdndStatus", FALSE),
2408 xdnd_status_filter, NULL);
2409 gdk_add_client_message_filter (
2410 gdk_atom_intern ("XdndFinished", FALSE),
2411 xdnd_finished_filter, NULL);
2412 gdk_add_client_message_filter (
2413 gdk_atom_intern ("XdndDrop", FALSE),
2414 xdnd_drop_filter, NULL);
2420 gdk_drag_do_leave (GdkDragContext *context, guint32 time)
2422 if (context->dest_window)
2424 switch (context->protocol)
2426 case GDK_DRAG_PROTO_MOTIF:
2427 motif_send_leave (context, time);
2429 case GDK_DRAG_PROTO_XDND:
2430 xdnd_send_leave (context);
2432 case GDK_DRAG_PROTO_ROOTWIN:
2436 gdk_window_unref (context->dest_window);
2437 context->dest_window = NULL;
2442 gdk_drag_begin (GdkWindow *window,
2444 GdkDragAction actions)
2447 GdkDragContext *new_context;
2449 g_return_val_if_fail (window != NULL, NULL);
2451 new_context = gdk_drag_context_new ();
2452 new_context->is_source = TRUE;
2453 new_context->source_window = window;
2454 gdk_window_ref (window);
2456 tmp_list = g_list_last (targets);
2457 new_context->targets = NULL;
2460 new_context->targets = g_list_prepend (new_context->targets,
2462 tmp_list = tmp_list->prev;
2465 new_context->actions = actions;
2471 gdk_drag_get_protocol (guint32 xid,
2472 GdkDragProtocol *protocol)
2476 if ((retval = xdnd_check_dest (xid)))
2478 *protocol = GDK_DRAG_PROTO_XDND;
2479 GDK_NOTE (DND, g_message ("Entering dnd window %#x\n", xid));
2482 else if ((retval = motif_check_dest (xid)))
2484 *protocol = GDK_DRAG_PROTO_MOTIF;
2485 GDK_NOTE (DND, g_message ("Entering motif window %#x\n", xid));
2490 /* Check if this is a root window */
2492 gboolean rootwin = FALSE;
2493 gint old_warnings = gdk_error_warnings;
2496 unsigned long nitems, after;
2497 unsigned char *data;
2499 if (xid == gdk_root_window)
2506 XGetWindowProperty (gdk_display, xid,
2507 gdk_atom_intern ("ENLIGHTENMENT_DESKTOP", FALSE),
2508 0, 0, False, AnyPropertyType,
2509 &type, &format, &nitems, &after, &data);
2510 if ((gdk_error_code == 0) && type != None)
2517 /* Until I find out what window manager the next one is for,
2518 * I'm leaving it commented out. It's supported in the
2519 * xscreensaver sources, though.
2526 XGetWindowProperty (gdk_display, win,
2527 gdk_atom_intern ("__SWM_VROOT", FALSE),
2528 0, 0, False, AnyPropertyType,
2529 &type, &format, &nitems, &data);
2530 if ((gdk_error_code == 0) && type != None)
2535 gdk_error_warnings = old_warnings;
2539 *protocol = GDK_DRAG_PROTO_ROOTWIN;
2544 *protocol = GDK_DRAG_PROTO_NONE;
2549 gdk_drag_find_window (GdkDragContext *context,
2550 GdkWindow *drag_window,
2553 GdkWindow **dest_window,
2554 GdkDragProtocol *protocol)
2556 GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
2559 g_return_if_fail (context != NULL);
2561 if (!private->window_cache)
2562 private->window_cache = gdk_window_cache_new();
2564 dest = get_client_window_at_coords (private->window_cache,
2566 GDK_WINDOW_XWINDOW (drag_window) : GDK_NONE,
2569 if (private->dest_xid != dest)
2572 private->dest_xid = dest;
2574 /* Check if new destination accepts drags, and which protocol */
2576 if ((recipient = gdk_drag_get_protocol (dest, protocol)))
2578 *dest_window = gdk_window_lookup (recipient);
2580 gdk_window_ref (*dest_window);
2582 *dest_window = gdk_window_foreign_new (recipient);
2585 *dest_window = NULL;
2589 *dest_window = context->dest_window;
2591 gdk_window_ref (*dest_window);
2592 *protocol = context->protocol;
2597 gdk_drag_motion (GdkDragContext *context,
2598 GdkWindow *dest_window,
2599 GdkDragProtocol protocol,
2602 GdkDragAction action,
2605 GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
2607 g_return_val_if_fail (context != NULL, FALSE);
2609 if (context->dest_window != dest_window)
2611 GdkEvent temp_event;
2613 /* Send a leave to the last destination */
2614 gdk_drag_do_leave (context, time);
2615 private->drag_status = GDK_DRAG_STATUS_DRAG;
2617 /* Check if new destination accepts drags, and which protocol */
2621 context->dest_window = dest_window;
2622 gdk_window_ref (context->dest_window);
2623 context->protocol = protocol;
2627 case GDK_DRAG_PROTO_MOTIF:
2628 motif_send_enter (context, time);
2631 case GDK_DRAG_PROTO_XDND:
2632 xdnd_send_enter (context);
2635 case GDK_DRAG_PROTO_ROOTWIN:
2638 private->old_action = action;
2639 context->suggested_action = action;
2643 context->dest_window = NULL;
2644 context->action = 0;
2647 /* Push a status event, to let the client know that
2651 temp_event.dnd.type = GDK_DRAG_STATUS;
2652 temp_event.dnd.window = context->source_window;
2653 /* We use this to signal a synthetic status. Perhaps
2654 * we should use an extra field...
2656 temp_event.dnd.send_event = TRUE;
2658 temp_event.dnd.context = context;
2659 temp_event.dnd.time = time;
2661 gdk_event_put (&temp_event);
2665 private->old_action = context->suggested_action;
2666 context->suggested_action = action;
2669 /* Send a drag-motion event */
2671 private->last_x = x_root;
2672 private->last_y = y_root;
2674 if (context->dest_window)
2676 if (private->drag_status == GDK_DRAG_STATUS_DRAG)
2678 switch (context->protocol)
2680 case GDK_DRAG_PROTO_MOTIF:
2681 motif_send_motion (context, x_root, y_root, action, time);
2684 case GDK_DRAG_PROTO_XDND:
2685 xdnd_send_motion (context, x_root, y_root, action, time);
2688 case GDK_DRAG_PROTO_ROOTWIN:
2690 GdkEvent temp_event;
2692 if (g_list_find (context->targets,
2693 GUINT_TO_POINTER (gdk_atom_intern ("application/x-rootwin-drop", FALSE))))
2694 context->action = context->suggested_action;
2696 context->action = 0;
2698 temp_event.dnd.type = GDK_DRAG_STATUS;
2699 temp_event.dnd.window = context->source_window;
2700 temp_event.dnd.send_event = FALSE;
2701 temp_event.dnd.context = context;
2702 temp_event.dnd.time = time;
2704 gdk_event_put (&temp_event);
2717 gdk_drag_drop (GdkDragContext *context,
2720 g_return_if_fail (context != NULL);
2722 if (context->dest_window)
2724 switch (context->protocol)
2726 case GDK_DRAG_PROTO_MOTIF:
2727 motif_send_leave (context, time);
2728 motif_send_drop (context, time);
2731 case GDK_DRAG_PROTO_XDND:
2732 xdnd_send_drop (context, time);
2735 case GDK_DRAG_PROTO_ROOTWIN:
2736 g_warning ("Drops for GDK_DRAG_PROTO_ROOTWIN must be handled internally");
2743 gdk_drag_abort (GdkDragContext *context,
2746 g_return_if_fail (context != NULL);
2748 gdk_drag_do_leave (context, time);
2751 /* Destination side */
2754 gdk_drag_status (GdkDragContext *context,
2755 GdkDragAction action,
2758 GdkDragContextPrivate *private;
2761 g_return_if_fail (context != NULL);
2763 private = (GdkDragContextPrivate *)context;
2765 context->action = action;
2767 if (context->protocol == GDK_DRAG_PROTO_MOTIF)
2769 xev.xclient.type = ClientMessage;
2770 xev.xclient.message_type = gdk_atom_intern ("_MOTIF_DRAG_AND_DROP_MESSAGE", FALSE);
2771 xev.xclient.format = 8;
2772 xev.xclient.window = GDK_WINDOW_XWINDOW (context->source_window);
2774 if (private->drag_status == GDK_DRAG_STATUS_ACTION_WAIT)
2776 xev.xclient.data.b[0] = XmOPERATION_CHANGED | 0x80;
2780 if ((action != 0) != (private->old_action != 0))
2783 xev.xclient.data.b[0] = XmDROP_SITE_ENTER | 0x80;
2785 xev.xclient.data.b[0] = XmDROP_SITE_LEAVE | 0x80;
2788 xev.xclient.data.b[0] = XmDRAG_MOTION | 0x80;
2791 xev.xclient.data.b[1] = local_byte_order;
2795 case GDK_ACTION_MOVE:
2796 xev.xclient.data.s[1] = XmDROP_MOVE;
2798 case GDK_ACTION_COPY:
2799 xev.xclient.data.s[1] = XmDROP_COPY;
2801 case GDK_ACTION_LINK:
2802 xev.xclient.data.s[1] = XmDROP_LINK;
2805 xev.xclient.data.s[1] = XmDROP_NOOP;
2810 xev.xclient.data.s[1] |= (XmDROP_SITE_VALID << 4);
2812 xev.xclient.data.s[1] |= (XmNO_DROP_SITE << 4);
2814 xev.xclient.data.l[1] = time;
2815 xev.xclient.data.s[4] = private->last_x;
2816 xev.xclient.data.s[5] = private->last_y;
2818 if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->source_window),
2821 g_message ("Send event to %lx failed",
2822 GDK_WINDOW_XWINDOW (context->source_window)));
2824 else if (context->protocol == GDK_DRAG_PROTO_XDND)
2826 xev.xclient.type = ClientMessage;
2827 xev.xclient.message_type = gdk_atom_intern ("XdndStatus", FALSE);
2828 xev.xclient.format = 32;
2829 xev.xclient.window = GDK_WINDOW_XWINDOW (context->source_window);
2831 xev.xclient.data.l[0] = GDK_WINDOW_XWINDOW (context->dest_window);
2832 xev.xclient.data.l[1] = (action != 0) ? (2 | 1) : 0;
2833 xev.xclient.data.l[2] = 0;
2834 xev.xclient.data.l[3] = 0;
2835 xev.xclient.data.l[4] = xdnd_action_to_atom (action);
2837 if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->source_window),
2840 g_message ("Send event to %lx failed",
2841 GDK_WINDOW_XWINDOW (context->source_window)));
2844 private->old_action = action;
2848 gdk_drop_reply (GdkDragContext *context,
2852 GdkDragContextPrivate *private;
2854 g_return_if_fail (context != NULL);
2856 private = (GdkDragContextPrivate *)context;
2858 if (context->protocol == GDK_DRAG_PROTO_MOTIF)
2862 xev.xclient.type = ClientMessage;
2863 xev.xclient.message_type = gdk_atom_intern ("_MOTIF_DRAG_AND_DROP_MESSAGE", FALSE);
2864 xev.xclient.format = 8;
2866 xev.xclient.data.b[0] = XmDROP_START | 0x80;
2867 xev.xclient.data.b[1] = local_byte_order;
2869 xev.xclient.data.s[1] = XmDROP_COPY |
2870 (XmDROP_SITE_VALID << 4) |
2871 (XmDROP_NOOP << 8) |
2874 xev.xclient.data.s[1] = XmDROP_NOOP |
2875 (XmNO_DROP_SITE << 4) |
2876 (XmDROP_NOOP << 8) |
2877 (XmDROP_CANCEL << 12);
2878 xev.xclient.data.s[2] = private->last_x;
2879 xev.xclient.data.s[3] = private->last_y;
2881 gdk_send_xevent (GDK_WINDOW_XWINDOW (context->source_window),
2887 gdk_drop_finish (GdkDragContext *context,
2891 g_return_if_fail (context != NULL);
2893 if (context->protocol == GDK_DRAG_PROTO_XDND)
2897 xev.xclient.type = ClientMessage;
2898 xev.xclient.message_type = gdk_atom_intern ("XdndFinished", FALSE);
2899 xev.xclient.format = 32;
2900 xev.xclient.window = GDK_WINDOW_XWINDOW (context->source_window);
2902 xev.xclient.data.l[0] = GDK_WINDOW_XWINDOW (context->dest_window);
2903 xev.xclient.data.l[1] = 0;
2904 xev.xclient.data.l[2] = 0;
2905 xev.xclient.data.l[3] = 0;
2906 xev.xclient.data.l[4] = 0;
2908 if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->source_window),
2911 g_message ("Send event to %lx failed",
2912 GDK_WINDOW_XWINDOW (context->source_window)));
2918 gdk_window_register_dnd (GdkWindow *window)
2920 static guint32 xdnd_version = 3;
2921 MotifDragReceiverInfo info;
2923 g_return_if_fail (window != NULL);
2925 /* Set Motif drag receiver information property */
2927 if (!motif_drag_receiver_info_atom)
2928 motif_drag_receiver_info_atom = gdk_atom_intern ("_MOTIF_DRAG_RECEIVER_INFO", FALSE);
2930 info.byte_order = local_byte_order;
2931 info.protocol_version = 0;
2932 info.protocol_style = XmDRAG_DYNAMIC;
2933 info.proxy_window = GDK_NONE;
2934 info.num_drop_sites = 0;
2935 info.total_size = sizeof(info);
2937 XChangeProperty (gdk_display, GDK_WINDOW_XWINDOW (window),
2938 motif_drag_receiver_info_atom,
2939 motif_drag_receiver_info_atom,
2946 if (!xdnd_aware_atom)
2947 xdnd_aware_atom = gdk_atom_intern ("XdndAware", FALSE);
2949 /* The property needs to be of type XA_ATOM, not XA_INTEGER. Blech */
2950 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
2951 GDK_WINDOW_XWINDOW (window),
2952 xdnd_aware_atom, XA_ATOM,
2953 32, PropModeReplace,
2954 (guchar *)&xdnd_version, 1);
2957 /*************************************************************
2958 * gdk_drag_get_selection:
2959 * Returns the selection atom for the current source window
2963 *************************************************************/
2966 gdk_drag_get_selection (GdkDragContext *context)
2968 g_return_val_if_fail (context != NULL, GDK_NONE);
2970 if (context->protocol == GDK_DRAG_PROTO_MOTIF)
2971 return ((GdkDragContextPrivate *)context)->motif_selection;
2972 else if (context->protocol == GDK_DRAG_PROTO_XDND)
2973 return ((GdkDragContextPrivate *)context)->xdnd_selection;