1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-1999 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU 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 xdnd_actions_set : 1; /* Whether we've already set XdndActionsList */
64 guint xdnd_have_actions : 1; /* Whether an XdndActionList was provided */
65 guint motif_targets_set : 1; /* Whether we've already set motif initiator info */
66 guint drag_status : 4; /* current status of drag */
68 GdkWindowCache *window_cache;
71 GdkDragContext *current_dest_drag = NULL;
73 /* Forward declarations */
75 static void gdk_window_cache_destroy (GdkWindowCache *cache);
77 static void motif_read_target_table (void);
78 static GdkFilterReturn motif_dnd_filter (GdkXEvent *xev,
82 static GdkFilterReturn xdnd_enter_filter (GdkXEvent *xev,
86 static GdkFilterReturn xdnd_leave_filter (GdkXEvent *xev,
90 static GdkFilterReturn xdnd_position_filter (GdkXEvent *xev,
94 static GdkFilterReturn xdnd_status_filter (GdkXEvent *xev,
98 static GdkFilterReturn xdnd_finished_filter (GdkXEvent *xev,
102 static GdkFilterReturn xdnd_drop_filter (GdkXEvent *xev,
108 static GList *contexts;
111 gdk_drag_context_new (void)
113 GdkDragContextPrivate *result;
115 result = g_new0 (GdkDragContextPrivate, 1);
117 result->ref_count = 1;
119 contexts = g_list_prepend (contexts, result);
121 return (GdkDragContext *)result;
125 gdk_drag_context_ref (GdkDragContext *context)
127 g_return_if_fail (context != NULL);
129 ((GdkDragContextPrivate *)context)->ref_count++;
133 gdk_drag_context_unref (GdkDragContext *context)
135 GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
137 g_return_if_fail (context != NULL);
139 private->ref_count--;
141 if (private->ref_count == 0)
143 g_dataset_destroy (private);
145 g_list_free (context->targets);
147 if (context->source_window)
148 gdk_window_unref (context->source_window);
150 if (context->dest_window)
151 gdk_window_unref (context->dest_window);
153 if (private->window_cache)
154 gdk_window_cache_destroy (private->window_cache);
156 contexts = g_list_remove (contexts, private);
161 static GdkDragContext *
162 gdk_drag_context_find (gboolean is_source,
166 GList *tmp_list = contexts;
167 GdkDragContext *context;
171 context = (GdkDragContext *)tmp_list->data;
173 if ((!context->is_source == !is_source) &&
174 ((source_xid == None) || (context->source_window &&
175 (GDK_WINDOW_XWINDOW (context->source_window) == source_xid))) &&
176 ((dest_xid == None) || (context->dest_window &&
177 (GDK_WINDOW_XWINDOW (context->dest_window) == dest_xid))))
180 tmp_list = tmp_list->next;
186 /* Utility functions */
189 gdk_window_cache_add (GdkWindowCache *cache,
191 gint x, gint y, gint width, gint height,
194 GdkCacheChild *child = g_new (GdkCacheChild, 1);
199 child->width = width;
200 child->height = height;
201 child->mapped = mapped;
203 cache->children = g_list_prepend (cache->children, child);
204 g_hash_table_insert (cache->child_hash, GUINT_TO_POINTER (xid),
208 static GdkFilterReturn
209 gdk_window_cache_filter (GdkXEvent *xev,
213 XEvent *xevent = (XEvent *)xev;
214 GdkWindowCache *cache = data;
216 switch (xevent->type)
218 case CirculateNotify:
220 case ConfigureNotify:
222 XConfigureEvent *xce = &xevent->xconfigure;
225 node = g_hash_table_lookup (cache->child_hash,
226 GUINT_TO_POINTER (xce->window));
229 GdkCacheChild *child = node->data;
232 child->width = xce->width;
233 child->height = xce->height;
234 if (xce->above == None && (node->next))
236 GList *last = g_list_last (cache->children);
237 cache->children = g_list_remove_link (cache->children, node);
244 GList *above_node = g_hash_table_lookup (cache->child_hash,
245 GUINT_TO_POINTER (xce->above));
246 if (above_node && node->prev != above_node)
248 cache->children = g_list_remove_link (cache->children, node);
249 node->next = above_node->next;
251 node->next->prev = node;
252 node->prev = above_node;
253 above_node->next = node;
261 XCreateWindowEvent *xcwe = &xevent->xcreatewindow;
263 if (!g_hash_table_lookup (cache->child_hash,
264 GUINT_TO_POINTER (xcwe->window)))
265 gdk_window_cache_add (cache, xcwe->window,
266 xcwe->x, xcwe->y, xcwe->width, xcwe->height,
272 XDestroyWindowEvent *xdwe = &xevent->xdestroywindow;
275 node = g_hash_table_lookup (cache->child_hash,
276 GUINT_TO_POINTER (xdwe->window));
279 g_hash_table_remove (cache->child_hash,
280 GUINT_TO_POINTER (xdwe->window));
281 cache->children = g_list_remove_link (cache->children, node);
283 g_list_free_1 (node);
289 XMapEvent *xme = &xevent->xmap;
292 node = g_hash_table_lookup (cache->child_hash,
293 GUINT_TO_POINTER (xme->window));
296 GdkCacheChild *child = node->data;
297 child->mapped = TRUE;
305 XMapEvent *xume = &xevent->xmap;
308 node = g_hash_table_lookup (cache->child_hash,
309 GUINT_TO_POINTER (xume->window));
312 GdkCacheChild *child = node->data;
313 child->mapped = FALSE;
318 return GDK_FILTER_CONTINUE;
320 return GDK_FILTER_REMOVE;
323 static GdkWindowCache *
324 gdk_window_cache_new (void)
326 XWindowAttributes xwa;
327 Window root, parent, *children;
328 unsigned int nchildren;
331 gint old_warnings = gdk_error_warnings;
333 GdkWindowCache *result = g_new (GdkWindowCache, 1);
335 result->children = NULL;
336 result->child_hash = g_hash_table_new (g_direct_hash, NULL);
338 XGetWindowAttributes (gdk_display, gdk_root_window, &xwa);
339 result->old_event_mask = xwa.your_event_mask;
340 XSelectInput (gdk_display, gdk_root_window,
341 result->old_event_mask | SubstructureNotifyMask);
342 gdk_window_add_filter ((GdkWindow *)&gdk_root_parent,
343 gdk_window_cache_filter, result);
346 gdk_error_warnings = 0;
348 if (XQueryTree(gdk_display, gdk_root_window,
349 &root, &parent, &children, &nchildren) == 0)
352 for (i = 0; i < nchildren ; i++)
354 XGetWindowAttributes (gdk_display, children[i], &xwa);
356 gdk_window_cache_add (result, children[i],
357 xwa.x, xwa.y, xwa.width, xwa.height,
358 xwa.map_state != IsUnmapped);
360 if (gdk_error_code != 0)
364 gdk_window_cache_add (result, children[i],
365 xwa.x, xwa.y, xwa.width, xwa.height,
366 (xwa.map_state != IsUnmapped));
372 gdk_error_warnings = old_warnings;
378 gdk_window_cache_destroy (GdkWindowCache *cache)
380 XSelectInput (gdk_display, gdk_root_window, cache->old_event_mask);
381 gdk_window_remove_filter ((GdkWindow *)&gdk_root_parent,
382 gdk_window_cache_filter, cache);
384 g_list_foreach (cache->children, (GFunc)g_free, NULL);
385 g_list_free (cache->children);
386 g_hash_table_destroy (cache->child_hash);
392 get_client_window_at_coords_recurse (Window win,
396 Window root, tmp_parent, *children;
397 unsigned int nchildren;
402 unsigned long nitems, after;
405 static Atom wm_state_atom = None;
408 wm_state_atom = gdk_atom_intern ("WM_STATE", FALSE);
410 XGetWindowProperty (gdk_display, win,
411 wm_state_atom, 0, 0, False, AnyPropertyType,
412 &type, &format, &nitems, &after, &data);
414 if (gdk_error_code != 0)
427 /* This is beautiful! Damn Enlightenment and click-to-focus */
428 XTranslateCoordinates (gdk_display, gdk_root_window, win,
429 x_root, y_root, &dest_x, &dest_y, &child);
431 if (gdk_error_code != 0)
438 if (XQueryTree(gdk_display, win,
439 &root, &tmp_parent, &children, &nchildren) == 0)
442 if (gdk_error_code == 0)
444 for (i = nchildren - 1; (i >= 0) && (child == None); i--)
446 XWindowAttributes xwa;
448 XGetWindowAttributes (gdk_display, children[i], &xwa);
450 if (gdk_error_code != 0)
452 else if ((xwa.map_state == IsViewable) && (xwa.class == InputOutput) &&
453 (x >= xwa.x) && (x < xwa.x + (gint)xwa.width) &&
454 (y >= xwa.y) && (y < xwa.y + (gint)xwa.height))
469 return get_client_window_at_coords_recurse (child, x, y);
475 get_client_window_at_coords (GdkWindowCache *cache,
481 Window retval = None;
483 gint old_warnings = gdk_error_warnings;
486 gdk_error_warnings = 0;
488 tmp_list = cache->children;
490 while (tmp_list && !retval)
492 GdkCacheChild *child = tmp_list->data;
494 if ((child->xid != ignore) && (child->mapped))
496 if ((x_root >= child->x) && (x_root < child->x + child->width) &&
497 (y_root >= child->y) && (y_root < child->y + child->height))
499 retval = get_client_window_at_coords_recurse (child->xid,
507 tmp_list = tmp_list->next;
510 gdk_error_warnings = old_warnings;
514 return gdk_root_window;
519 get_client_window_at_coords_recurse (Window win,
526 unsigned long nitems, after;
530 static Atom wm_state_atom = None;
533 wm_state_atom = gdk_atom_intern ("WM_STATE", FALSE);
535 XGetWindowProperty (gdk_display, win,
536 wm_state_atom, 0, 0, False, AnyPropertyType,
537 &type, &format, &nitems, &after, &data);
539 if (gdk_error_code != 0)
551 XTranslateCoordinates (gdk_display, gdk_root_window, win,
552 x_root, y_root, &dest_x, &dest_y, &child);
554 if (gdk_error_code != 0)
561 return get_client_window_at_coords_recurse (child, x_root, y_root);
567 get_client_window_at_coords (Window ignore,
571 Window root, parent, *children;
572 unsigned int nchildren;
574 Window retval = None;
576 gint old_warnings = gdk_error_warnings;
579 gdk_error_warnings = 0;
581 if (XQueryTree(gdk_display, gdk_root_window,
582 &root, &parent, &children, &nchildren) == 0)
585 for (i = nchildren - 1; (i >= 0) && (retval == None); i--)
587 if (children[i] != ignore)
589 XWindowAttributes xwa;
591 XGetWindowAttributes (gdk_display, children[i], &xwa);
593 if (gdk_error_code != 0)
595 else if ((xwa.map_state == IsViewable) &&
596 (x_root >= xwa.x) && (x_root < xwa.x + (gint)xwa.width) &&
597 (y_root >= xwa.y) && (y_root < xwa.y + (gint)xwa.height))
599 retval = get_client_window_at_coords_recurse (children[i],
602 retval = children[i];
609 gdk_error_warnings = old_warnings;
613 return gdk_root_window;
617 /*************************************************************
618 ***************************** MOTIF *************************
619 *************************************************************/
621 /* values used in the message type for Motif DND */
634 /* Values used to specify type of protocol to use */
638 XmDRAG_PREFER_PREREGISTER,
640 XmDRAG_PREFER_DYNAMIC,
642 XmDRAG_PREFER_RECEIVER
645 /* Operation codes */
653 /* Drop site status */
655 XmNO_DROP_SITE = 0x01,
656 XmDROP_SITE_INVALID = 0x02,
657 XmDROP_SITE_VALID = 0x03
660 /* completion status */
668 /* Static data for MOTIF DND */
669 static GList **motif_target_lists = NULL;
670 static gint motif_n_target_lists = -1;
672 /* Byte swapping routines. The motif specification leaves it
673 * up to us to save a few bytes in the client messages
675 static gchar local_byte_order = '\0';
677 #ifdef G_ENABLE_DEBUG
679 print_target_list (GList *targets)
683 gchar *name = gdk_atom_name (GPOINTER_TO_INT (targets->data));
684 g_message ("\t%s", name);
686 targets = targets->next;
689 #endif /* G_ENABLE_DEBUG */
692 init_byte_order (void)
694 guint32 myint = 0x01020304;
695 local_byte_order = (*(gchar *)&myint == 1) ? 'B' : 'l';
699 card16_to_host (guint16 x, gchar byte_order) {
700 if (byte_order == local_byte_order)
703 return (x << 8) | (x >> 8);
707 card32_to_host (guint32 x, gchar byte_order) {
708 if (byte_order == local_byte_order)
711 return (x << 24) | ((x & 0xff00) << 8) | ((x & 0xff0000) >> 8) | (x >> 24);
715 /***** Dest side ***********/
717 /* Property placed on source windows */
718 typedef struct _MotifDragInitiatorInfo {
720 guint8 protocol_version;
721 guint16 targets_index;
722 guint32 selection_atom;
723 } MotifDragInitiatorInfo;
725 /* Header for target table on the drag window */
726 typedef struct _MotifTargetTableHeader {
728 guchar protocol_version;
731 } MotifTargetTableHeader;
733 /* Property placed on target windows */
734 typedef struct _MotifDragReceiverInfo {
736 guint8 protocol_version;
737 guint8 protocol_style;
739 guint32 proxy_window;
740 guint16 num_drop_sites;
743 } MotifDragReceiverInfo;
745 static Window motif_drag_window = None;
746 static GdkWindow *motif_drag_gdk_window = NULL;
748 static GdkAtom motif_drag_targets_atom = GDK_NONE;
749 static GdkAtom motif_drag_receiver_info_atom = GDK_NONE;
751 /* Target table handling */
754 motif_drag_window_filter (GdkXEvent *xevent,
758 XEvent *xev = (XEvent *)xevent;
760 switch (xev->xany.type)
763 motif_drag_window = None;
764 motif_drag_gdk_window = NULL;
767 if (motif_target_lists &&
768 motif_drag_targets_atom &&
769 (xev->xproperty.atom == motif_drag_targets_atom))
770 motif_read_target_table();
773 return GDK_FILTER_REMOVE;
776 static GdkAtom motif_drag_window_atom = GDK_NONE;
779 motif_lookup_drag_window (Display *display)
781 Window retval = None;
782 gulong bytes_after, nitems;
787 XGetWindowProperty (gdk_display, gdk_root_window, motif_drag_window_atom,
788 0, sizeof(Window)/4, FALSE,
789 XA_WINDOW, &type, &format, &nitems, &bytes_after,
792 if ((format == 8*sizeof(Window)) && (nitems == 1) && (bytes_after == 0))
794 retval = *(Window *)data;
796 g_message ("Found drag window %#lx\n", motif_drag_window));
805 /* Finds the window where global Motif drag information is stored.
806 * If it doesn't exist and 'create' is TRUE, create one.
809 motif_find_drag_window (gboolean create)
811 if (!motif_drag_window)
813 if (!motif_drag_window_atom)
814 motif_drag_window_atom = gdk_atom_intern ("_MOTIF_DRAG_WINDOW", TRUE);
816 motif_drag_window = motif_lookup_drag_window (gdk_display);
818 if (!motif_drag_window && create)
820 /* Create a persistant window. (Copied from LessTif) */
823 XSetWindowAttributes attr;
824 display = XOpenDisplay (NULL);
825 XSetCloseDownMode (display, RetainPermanent);
827 XGrabServer (display);
829 motif_drag_window = motif_lookup_drag_window (display);
831 if (!motif_drag_window)
833 attr.override_redirect = True;
834 attr.event_mask = PropertyChangeMask;
837 XCreateWindow(display, DefaultRootWindow(display),
838 -100, -100, 10, 10, 0, 0,
839 InputOnly, CopyFromParent,
840 (CWOverrideRedirect | CWEventMask), &attr);
843 g_message ("Created drag window %#lx\n", motif_drag_window));
845 XChangeProperty (display, gdk_root_window,
846 motif_drag_window_atom, XA_WINDOW,
848 (guchar *)&motif_drag_window_atom, 1);
851 XUngrabServer (display);
852 XCloseDisplay (display);
855 /* There is a miniscule race condition here if the drag window
856 * gets destroyed exactly now.
858 if (motif_drag_window)
860 motif_drag_gdk_window = gdk_window_foreign_new (motif_drag_window);
861 gdk_window_add_filter (motif_drag_gdk_window,
862 motif_drag_window_filter,
867 return motif_drag_window;
871 motif_read_target_table (void)
873 gulong bytes_after, nitems;
878 if (!motif_drag_targets_atom)
879 motif_drag_targets_atom = gdk_atom_intern ("_MOTIF_DRAG_TARGETS", FALSE);
881 if (motif_target_lists)
883 for (i=0; i<motif_n_target_lists; i++)
884 g_list_free (motif_target_lists[i]);
886 g_free (motif_target_lists);
887 motif_target_lists = NULL;
888 motif_n_target_lists = 0;
891 if (motif_find_drag_window (FALSE))
893 MotifTargetTableHeader *header = NULL;
894 guchar *target_bytes = NULL;
896 gboolean success = FALSE;
898 XGetWindowProperty (gdk_display, motif_drag_window,
899 motif_drag_targets_atom,
900 0, (sizeof(MotifTargetTableHeader)+3)/4, FALSE,
901 motif_drag_targets_atom,
902 &type, &format, &nitems, &bytes_after,
905 if ((format != 8) || (nitems < sizeof (MotifTargetTableHeader)))
908 header->n_lists = card16_to_host (header->n_lists, header->byte_order);
909 header->total_size = card32_to_host (header->total_size, header->byte_order);
911 XGetWindowProperty (gdk_display, motif_drag_window, motif_drag_targets_atom,
912 (sizeof(MotifTargetTableHeader)+3)/4,
913 (header->total_size - sizeof(MotifTargetTableHeader) + 3)/4,
915 motif_drag_targets_atom, &type, &format, &nitems,
916 &bytes_after, &target_bytes);
918 if ((format != 8) || (bytes_after != 0) ||
919 (nitems != header->total_size - sizeof(MotifTargetTableHeader)))
922 motif_n_target_lists = header->n_lists;
923 motif_target_lists = g_new0 (GList *, motif_n_target_lists);
926 for (i=0; i<header->n_lists; i++)
931 if (p + sizeof(guint16) - target_bytes > nitems)
934 n_targets = card16_to_host (*(gushort *)p, header->byte_order);
936 /* We need to make a copy of the targets, since it may
939 targets = g_new (guint32, n_targets);
940 memcpy (targets, p + sizeof(guint16), sizeof(guint32) * n_targets);
942 p += sizeof(guint16) + n_targets * sizeof(guint32);
943 if (p - target_bytes > nitems)
946 for (j=0; j<n_targets; j++)
947 motif_target_lists[i] =
948 g_list_prepend (motif_target_lists[i],
949 GUINT_TO_POINTER (card32_to_host (targets[j],
950 header->byte_order)));
952 motif_target_lists[i] = g_list_reverse (motif_target_lists[i]);
962 XFree (target_bytes);
966 if (motif_target_lists)
968 g_free (motif_target_lists);
969 motif_target_lists = NULL;
970 motif_n_target_lists = 0;
972 g_warning ("Error reading Motif target table\n");
978 targets_sort_func (gconstpointer a, gconstpointer b)
980 return (GPOINTER_TO_UINT (a) < GPOINTER_TO_UINT (b)) ?
981 -1 : ((GPOINTER_TO_UINT (a) > GPOINTER_TO_UINT (b)) ? 1 : 0);
984 /* Check if given (sorted) list is in the targets table */
986 motif_target_table_check (GList *sorted)
988 GList *tmp_list1, *tmp_list2;
991 for (i=0; i<motif_n_target_lists; i++)
993 tmp_list1 = motif_target_lists[i];
996 while (tmp_list1 && tmp_list2)
998 if (tmp_list1->data != tmp_list2->data)
1001 tmp_list1 = tmp_list1->next;
1002 tmp_list2 = tmp_list2->next;
1004 if (!tmp_list1 && !tmp_list2) /* Found it */
1012 motif_add_to_target_table (GList *targets)
1014 GList *sorted = NULL;
1019 /* make a sorted copy of the list */
1023 sorted = g_list_insert_sorted (sorted, targets->data, targets_sort_func);
1024 targets = targets->next;
1027 /* First check if it is their already */
1029 if (motif_target_lists)
1030 index = motif_target_table_check (sorted);
1032 /* We need to grab the server while doing this, to ensure
1038 /* We need to make sure that it exists _before_ we grab the
1039 * server, since we can't open a new connection after we
1042 motif_find_drag_window (TRUE);
1044 XGrabServer(gdk_display);
1045 motif_read_target_table();
1047 /* Check again, in case it was added in the meantime */
1049 if (motif_target_lists)
1050 index = motif_target_table_check (sorted);
1054 guint32 total_size = 0;
1058 MotifTargetTableHeader *header;
1060 if (!motif_target_lists)
1062 motif_target_lists = g_new (GList *, 1);
1063 motif_n_target_lists = 1;
1067 motif_n_target_lists++;
1068 motif_target_lists = g_realloc (motif_target_lists,
1069 sizeof(GList *) * motif_n_target_lists);
1071 motif_target_lists[motif_n_target_lists - 1] = sorted;
1073 index = motif_n_target_lists - 1;
1075 total_size = sizeof (MotifTargetTableHeader);
1076 for (i = 0; i < motif_n_target_lists ; i++)
1077 total_size += sizeof(guint16) + sizeof(guint32) * g_list_length (motif_target_lists[i]);
1079 data = g_malloc (total_size);
1081 header = (MotifTargetTableHeader *)data;
1082 p = data + sizeof(MotifTargetTableHeader);
1084 header->byte_order = local_byte_order;
1085 header->protocol_version = 0;
1086 header->n_lists = motif_n_target_lists;
1087 header->total_size = total_size;
1089 for (i = 0; i < motif_n_target_lists ; i++)
1091 guint16 n_targets = g_list_length (motif_target_lists[i]);
1092 guint32 *targets = g_new (guint32, n_targets);
1093 guint32 *p32 = targets;
1095 tmp_list = motif_target_lists[i];
1098 *p32 = GPOINTER_TO_UINT (tmp_list->data);
1100 tmp_list = tmp_list->next;
1105 p += sizeof(guint16);
1107 memcpy (p, targets, n_targets * sizeof(guint32));
1110 p += sizeof(guint32) * n_targets;
1114 XChangeProperty (gdk_display, motif_drag_window,
1115 motif_drag_targets_atom,
1116 motif_drag_targets_atom,
1120 XUngrabServer(gdk_display);
1123 g_list_free (sorted);
1127 /* Translate flags */
1130 motif_dnd_translate_flags (GdkDragContext *context, guint16 flags)
1132 guint recommended_op = flags & 0x000f;
1133 guint possible_ops = (flags & 0x0f0) >> 4;
1135 switch (recommended_op)
1138 context->suggested_action = GDK_ACTION_MOVE;
1141 context->suggested_action = GDK_ACTION_COPY;
1144 context->suggested_action = GDK_ACTION_LINK;
1147 context->suggested_action = GDK_ACTION_COPY;
1151 context->actions = 0;
1152 if (possible_ops & XmDROP_MOVE)
1153 context->actions |= GDK_ACTION_MOVE;
1154 if (possible_ops & XmDROP_COPY)
1155 context->actions |= GDK_ACTION_COPY;
1156 if (possible_ops & XmDROP_LINK)
1157 context->actions |= GDK_ACTION_LINK;
1161 motif_dnd_get_flags (GdkDragContext *context)
1165 switch (context->suggested_action)
1167 case GDK_ACTION_MOVE:
1168 flags = XmDROP_MOVE;
1170 case GDK_ACTION_COPY:
1171 flags = XmDROP_COPY;
1173 case GDK_ACTION_LINK:
1174 flags = XmDROP_LINK;
1177 flags = XmDROP_NOOP;
1181 if (context->actions & GDK_ACTION_MOVE)
1182 flags |= XmDROP_MOVE << 8;
1183 if (context->actions & GDK_ACTION_COPY)
1184 flags |= XmDROP_COPY << 8;
1185 if (context->actions & GDK_ACTION_LINK)
1186 flags |= XmDROP_LINK << 8;
1194 motif_set_targets (GdkDragContext *context)
1196 GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
1197 MotifDragInitiatorInfo info;
1199 static GdkAtom motif_drag_initiator_info = GDK_NONE;
1201 if (!motif_drag_initiator_info)
1202 motif_drag_initiator_info = gdk_atom_intern ("_MOTIF_DRAG_INITIATOR_INFO", FALSE);
1204 info.byte_order = local_byte_order;
1205 info.protocol_version = 0;
1207 info.targets_index = motif_add_to_target_table (context->targets);
1212 g_snprintf(buf, 20, "_GDK_SELECTION_%d", i);
1214 private->motif_selection = gdk_atom_intern (buf, FALSE);
1215 if (!XGetSelectionOwner (gdk_display, private->motif_selection))
1219 info.selection_atom = private->motif_selection;
1221 XChangeProperty (GDK_WINDOW_XDISPLAY (context->source_window),
1222 GDK_WINDOW_XWINDOW (context->source_window),
1223 private->motif_selection,
1224 motif_drag_initiator_info, 8, PropModeReplace,
1225 (guchar *)&info, sizeof (info));
1227 private->motif_targets_set = 1;
1231 motif_check_dest (Window win)
1233 gboolean retval = FALSE;
1234 MotifDragReceiverInfo *info;
1237 unsigned long nitems, after;
1239 if (!motif_drag_receiver_info_atom)
1240 motif_drag_receiver_info_atom = gdk_atom_intern ("_MOTIF_DRAG_RECEIVER_INFO", FALSE);
1242 XGetWindowProperty (gdk_display, win,
1243 motif_drag_receiver_info_atom,
1244 0, (sizeof(*info)+3)/4, False, AnyPropertyType,
1245 &type, &format, &nitems, &after,
1250 if ((format == 8) && (nitems == sizeof(*info)))
1252 if ((info->protocol_version == 0) &&
1253 ((info->protocol_style == XmDRAG_PREFER_PREREGISTER) ||
1254 (info->protocol_style == XmDRAG_PREFER_DYNAMIC) ||
1255 (info->protocol_style == XmDRAG_DYNAMIC)))
1261 g_warning ("Invalid Motif drag receiver property on window %ld\n", win));
1267 return retval ? win : GDK_NONE;
1272 motif_send_enter (GdkDragContext *context,
1276 GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
1278 xev.xclient.type = ClientMessage;
1279 xev.xclient.message_type = gdk_atom_intern ("_MOTIF_DRAG_AND_DROP_MESSAGE", FALSE);
1280 xev.xclient.format = 8;
1281 xev.xclient.window = GDK_WINDOW_XWINDOW (context->dest_window);
1283 xev.xclient.data.b[0] = XmTOP_LEVEL_ENTER;
1284 xev.xclient.data.b[1] = local_byte_order;
1285 xev.xclient.data.s[1] = 0;
1286 xev.xclient.data.l[1] = time;
1287 xev.xclient.data.l[2] = GDK_WINDOW_XWINDOW (context->source_window);
1289 if (!private->motif_targets_set)
1290 motif_set_targets (context);
1292 xev.xclient.data.l[3] = private->motif_selection;
1294 if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->dest_window),
1297 g_message ("Send event to %lx failed",
1298 GDK_WINDOW_XWINDOW (context->dest_window)));
1302 motif_send_leave (GdkDragContext *context,
1307 xev.xclient.type = ClientMessage;
1308 xev.xclient.message_type = gdk_atom_intern ("_MOTIF_DRAG_AND_DROP_MESSAGE", FALSE);
1309 xev.xclient.format = 8;
1310 xev.xclient.window = GDK_WINDOW_XWINDOW (context->dest_window);
1312 xev.xclient.data.b[0] = XmTOP_LEVEL_LEAVE;
1313 xev.xclient.data.b[1] = local_byte_order;
1314 xev.xclient.data.s[1] = 0;
1315 xev.xclient.data.l[1] = time;
1316 xev.xclient.data.l[2] = GDK_WINDOW_XWINDOW (context->source_window);
1317 xev.xclient.data.l[3] = 0;
1319 if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->dest_window),
1322 g_message ("Send event to %lx failed",
1323 GDK_WINDOW_XWINDOW (context->dest_window)));
1327 motif_send_motion (GdkDragContext *context,
1330 GdkDragAction action,
1335 GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
1337 xev.xclient.type = ClientMessage;
1338 xev.xclient.message_type = gdk_atom_intern ("_MOTIF_DRAG_AND_DROP_MESSAGE", FALSE);
1339 xev.xclient.format = 8;
1340 xev.xclient.window = GDK_WINDOW_XWINDOW (context->dest_window);
1342 xev.xclient.data.b[1] = local_byte_order;
1343 xev.xclient.data.s[1] = motif_dnd_get_flags (context);
1344 xev.xclient.data.l[1] = time;
1346 if (context->suggested_action != private->old_action)
1348 xev.xclient.data.b[0] = XmOPERATION_CHANGED;
1350 private->drag_status = GDK_DRAG_STATUS_ACTION_WAIT;
1355 xev.xclient.data.b[0] = XmDRAG_MOTION;
1357 xev.xclient.data.s[4] = x_root;
1358 xev.xclient.data.s[5] = y_root;
1360 private->drag_status = GDK_DRAG_STATUS_MOTION_WAIT;
1364 if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->dest_window),
1367 g_message ("Send event to %lx failed",
1368 GDK_WINDOW_XWINDOW (context->dest_window)));
1374 motif_send_drop (GdkDragContext *context, guint32 time)
1377 GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
1379 xev.xclient.type = ClientMessage;
1380 xev.xclient.message_type = gdk_atom_intern ("_MOTIF_DRAG_AND_DROP_MESSAGE", FALSE);
1381 xev.xclient.format = 8;
1382 xev.xclient.window = GDK_WINDOW_XWINDOW (context->dest_window);
1384 xev.xclient.data.b[0] = XmDROP_START;
1385 xev.xclient.data.b[1] = local_byte_order;
1386 xev.xclient.data.s[1] = motif_dnd_get_flags (context);
1387 xev.xclient.data.l[1] = time;
1389 xev.xclient.data.s[4] = private->last_x;
1390 xev.xclient.data.s[5] = private->last_y;
1392 xev.xclient.data.l[3] = private->motif_selection;
1393 xev.xclient.data.l[4] = GDK_WINDOW_XWINDOW (context->source_window);
1395 if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->dest_window),
1398 g_message ("Send event to %lx failed",
1399 GDK_WINDOW_XWINDOW (context->dest_window)));
1405 motif_read_initiator_info (Window source_window,
1411 static GdkAtom motif_drag_initiator_info = GDK_NONE;
1417 MotifDragInitiatorInfo *initiator_info;
1419 if (!motif_drag_initiator_info)
1420 motif_drag_initiator_info = gdk_atom_intern ("_MOTIF_DRAG_INITIATOR_INFO", FALSE);
1422 XGetWindowProperty (gdk_display, source_window, atom,
1423 0, sizeof(*initiator_info), FALSE,
1424 motif_drag_initiator_info,
1425 &type, &format, &nitems, &bytes_after,
1426 (guchar **)&initiator_info);
1428 if ((format != 8) || (nitems != sizeof (MotifDragInitiatorInfo)) || (bytes_after != 0))
1430 g_warning ("Error reading initiator info\n");
1434 motif_read_target_table ();
1436 if (initiator_info->targets_index >= motif_n_target_lists)
1438 g_warning ("Invalid target index in TOP_LEVEL_ENTER MESSAGE");
1439 XFree (initiator_info);
1440 return GDK_FILTER_REMOVE;
1443 tmp_list = g_list_last (motif_target_lists[initiator_info->targets_index]);
1448 *targets = g_list_prepend (*targets,
1450 tmp_list = tmp_list->prev;
1453 #ifdef G_ENABLE_DEBUG
1454 if (gdk_debug_flags & GDK_DEBUG_DND)
1455 print_target_list (*targets);
1456 #endif /* G_ENABLE_DEBUG */
1458 *selection = initiator_info->selection_atom;
1460 XFree (initiator_info);
1465 static GdkDragContext *
1466 motif_drag_context_new (GdkWindow *dest_window,
1468 guint32 source_window,
1471 GdkDragContext *new_context;
1472 GdkDragContextPrivate *private;
1474 /* FIXME, current_dest_drag really shouldn't be NULL'd
1475 * if we error below.
1477 if (current_dest_drag != NULL)
1479 if (timestamp >= current_dest_drag->start_time)
1481 gdk_drag_context_unref (current_dest_drag);
1482 current_dest_drag = NULL;
1488 new_context = gdk_drag_context_new ();
1489 private = (GdkDragContextPrivate *)new_context;
1491 new_context->protocol = GDK_DRAG_PROTO_MOTIF;
1492 new_context->is_source = FALSE;
1494 new_context->source_window = gdk_window_lookup (source_window);
1495 if (new_context->source_window)
1496 gdk_window_ref (new_context->source_window);
1499 new_context->source_window = gdk_window_foreign_new (source_window);
1500 if (!new_context->source_window)
1502 gdk_drag_context_unref (new_context);
1507 new_context->dest_window = dest_window;
1508 gdk_window_ref (dest_window);
1509 new_context->start_time = timestamp;
1511 if (!motif_read_initiator_info(source_window,
1513 &new_context->targets,
1514 &private->motif_selection))
1516 gdk_drag_context_unref (new_context);
1524 * The MOTIF drag protocol has no real provisions for distinguishing
1525 * multiple simultaneous drops. If the sources grab the pointer
1526 * when doing drags, that shouldn't happen, in any case. If it
1527 * does, we can't do much except hope for the best.
1530 static GdkFilterReturn
1531 motif_top_level_enter (GdkEvent *event,
1534 guint32 source_window,
1537 GdkDragContext *new_context;
1539 GDK_NOTE(DND, g_message ("Motif DND top level enter: flags: %#4x time: %d source_widow: %#4x atom: %d",
1540 flags, timestamp, source_window, atom));
1542 new_context = motif_drag_context_new (event->any.window, timestamp, source_window, atom);
1544 return GDK_FILTER_REMOVE;
1546 event->dnd.type = GDK_DRAG_ENTER;
1547 event->dnd.context = new_context;
1548 gdk_drag_context_ref (new_context);
1550 current_dest_drag = new_context;
1552 return GDK_FILTER_TRANSLATE;
1556 motif_top_level_leave (GdkEvent *event,
1560 GDK_NOTE(DND, g_message ("Motif DND top level leave: flags: %#4x time: %d",
1563 if ((current_dest_drag != NULL) &&
1564 (current_dest_drag->protocol == GDK_DRAG_PROTO_MOTIF) &&
1565 (timestamp >= current_dest_drag->start_time))
1567 event->dnd.type = GDK_DRAG_LEAVE;
1568 /* Pass ownership of context to the event */
1569 event->dnd.context = current_dest_drag;
1571 current_dest_drag = NULL;
1573 return GDK_FILTER_TRANSLATE;
1576 return GDK_FILTER_REMOVE;
1580 motif_motion (GdkEvent *event,
1586 GdkDragContextPrivate *private;
1588 GDK_NOTE(DND, g_message ("Motif DND motion: flags: %#4x time: %d (%d, %d)",
1589 flags, timestamp, x_root, y_root));
1591 if ((current_dest_drag != NULL) &&
1592 (current_dest_drag->protocol == GDK_DRAG_PROTO_MOTIF) &&
1593 (timestamp >= current_dest_drag->start_time))
1595 private = (GdkDragContextPrivate *)current_dest_drag;
1597 event->dnd.type = GDK_DRAG_MOTION;
1598 event->dnd.context = current_dest_drag;
1599 gdk_drag_context_ref (current_dest_drag);
1601 event->dnd.time = timestamp;
1603 motif_dnd_translate_flags (current_dest_drag, flags);
1605 event->dnd.x_root = x_root;
1606 event->dnd.y_root = y_root;
1608 private->last_x = x_root;
1609 private->last_y = y_root;
1611 private->drag_status = GDK_DRAG_STATUS_MOTION_WAIT;
1613 return GDK_FILTER_TRANSLATE;
1616 return GDK_FILTER_REMOVE;
1620 motif_operation_changed (GdkEvent *event,
1624 GdkDragContextPrivate *private;
1626 GDK_NOTE(DND, g_message ("Motif DND operation changed: flags: %#4x time: %d",
1629 if ((current_dest_drag != NULL) &&
1630 (current_dest_drag->protocol == GDK_DRAG_PROTO_MOTIF) &&
1631 (timestamp >= current_dest_drag->start_time))
1633 event->dnd.type = GDK_DRAG_MOTION;
1634 event->dnd.send_event = FALSE;
1635 event->dnd.context = current_dest_drag;
1636 gdk_drag_context_ref (current_dest_drag);
1638 event->dnd.time = timestamp;
1639 private = (GdkDragContextPrivate *)current_dest_drag;
1641 motif_dnd_translate_flags (current_dest_drag, flags);
1643 event->dnd.x_root = private->last_x;
1644 event->dnd.y_root = private->last_y;
1646 private->drag_status = GDK_DRAG_STATUS_ACTION_WAIT;
1648 return GDK_FILTER_TRANSLATE;
1651 return GDK_FILTER_REMOVE;
1655 motif_drop_start (GdkEvent *event,
1658 guint32 source_window,
1663 GdkDragContext *new_context;
1666 GDK_NOTE(DND, g_message ("Motif DND drop start: flags: %#4x time: %d (%d, %d) source_widow: %#4x atom: %d",
1667 flags, timestamp, x_root, y_root, source_window, atom));
1669 new_context = motif_drag_context_new (event->any.window, timestamp, source_window, atom);
1671 return GDK_FILTER_REMOVE;
1673 motif_dnd_translate_flags (new_context, flags);
1675 event->dnd.type = GDK_DROP_START;
1676 event->dnd.context = new_context;
1677 event->dnd.time = timestamp;
1678 event->dnd.x_root = x_root;
1679 event->dnd.y_root = y_root;
1681 gdk_drag_context_ref (new_context);
1682 current_dest_drag = new_context;
1684 return GDK_FILTER_TRANSLATE;
1688 motif_drag_status (GdkEvent *event,
1692 GdkDragContext *context;
1695 g_message ("Motif status message: flags %x", flags));
1697 context = gdk_drag_context_find (TRUE,
1698 GDK_WINDOW_XWINDOW (event->any.window),
1703 GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
1704 if (private->drag_status == GDK_DRAG_STATUS_MOTION_WAIT)
1705 private->drag_status = GDK_DRAG_STATUS_DRAG;
1707 event->dnd.type = GDK_DRAG_STATUS;
1708 event->dnd.send_event = FALSE;
1709 event->dnd.context = context;
1710 gdk_drag_context_ref (context);
1712 event->dnd.time = timestamp;
1714 if ((flags & 0x00f0) >> 4 == XmDROP_SITE_VALID)
1716 switch (flags & 0x000f)
1719 context->action = 0;
1722 context->action = GDK_ACTION_MOVE;
1725 context->action = GDK_ACTION_COPY;
1728 context->action = GDK_ACTION_LINK;
1733 context->action = 0;
1735 return GDK_FILTER_TRANSLATE;
1737 return GDK_FILTER_REMOVE;
1741 motif_dnd_filter (GdkXEvent *xev,
1745 XEvent *xevent = (XEvent *)xev;
1746 XClientMessageEvent *xce = &xevent->xclient;
1752 guint32 source_window;
1754 gint16 x_root, y_root;
1757 /* First read some fields common to all Motif DND messages */
1759 reason = xce->data.b[0];
1760 byte_order = xce->data.b[1];
1761 flags = card16_to_host (xce->data.s[1], byte_order);
1762 timestamp = card32_to_host (xce->data.l[1], byte_order);
1764 is_reply = ((reason & 0x80) != 0);
1766 switch (reason & 0x7f)
1768 case XmTOP_LEVEL_ENTER:
1769 source_window = card32_to_host (xce->data.l[2], byte_order);
1770 atom = card32_to_host (xce->data.l[3], byte_order);
1771 return motif_top_level_enter (event, flags, timestamp, source_window, atom);
1772 case XmTOP_LEVEL_LEAVE:
1773 return motif_top_level_leave (event, flags, timestamp);
1776 x_root = card16_to_host (xce->data.s[4], byte_order);
1777 y_root = card16_to_host (xce->data.s[5], byte_order);
1780 return motif_motion (event, flags, timestamp, x_root, y_root);
1782 return motif_drag_status (event, flags, timestamp);
1784 case XmDROP_SITE_ENTER:
1785 return motif_drag_status (event, flags, timestamp);
1787 case XmDROP_SITE_LEAVE:
1788 return motif_drag_status (event,
1789 XmNO_DROP_SITE << 8 | XmDROP_NOOP,
1792 x_root = card16_to_host (xce->data.s[4], byte_order);
1793 y_root = card16_to_host (xce->data.s[5], byte_order);
1794 atom = card32_to_host (xce->data.l[3], byte_order);
1795 source_window = card32_to_host (xce->data.l[4], byte_order);
1798 return motif_drop_start (event, flags, timestamp, source_window, atom, x_root, y_root);
1801 case XmOPERATION_CHANGED:
1803 return motif_operation_changed (event, flags, timestamp);
1805 return motif_drag_status (event, flags, timestamp);
1808 /* To the best of my knowledge, these next two messages are
1809 * not part of the protocol, though they are defined in
1813 case XmDRAG_DROP_FINISH:
1817 return GDK_FILTER_REMOVE;
1820 /*************************************************************
1821 ***************************** XDND **************************
1822 *************************************************************/
1824 /* Utility functions */
1829 GdkDragAction action;
1830 } xdnd_actions_table[] = {
1831 { "XdndActionCopy", GDK_NONE, GDK_ACTION_COPY },
1832 { "XdndActionMove", GDK_NONE, GDK_ACTION_MOVE },
1833 { "XdndActionLink", GDK_NONE, GDK_ACTION_LINK },
1834 { "XdndActionAsk", GDK_NONE, GDK_ACTION_ASK },
1835 { "XdndActionPrivate", GDK_NONE, GDK_ACTION_COPY },
1838 static const gint xdnd_n_actions = sizeof(xdnd_actions_table) / sizeof(xdnd_actions_table[0]);
1839 static gboolean xdnd_actions_initialized = FALSE;
1842 xdnd_initialize_actions (void)
1846 xdnd_actions_initialized = TRUE;
1847 for (i=0; i < xdnd_n_actions; i++)
1848 xdnd_actions_table[i].atom = gdk_atom_intern (xdnd_actions_table[i].name, FALSE);
1851 static GdkDragAction
1852 xdnd_action_from_atom (GdkAtom atom)
1856 if (!xdnd_actions_initialized)
1857 xdnd_initialize_actions();
1859 for (i=0; i<xdnd_n_actions; i++)
1860 if (atom == xdnd_actions_table[i].atom)
1861 return xdnd_actions_table[i].action;
1867 xdnd_action_to_atom (GdkDragAction action)
1871 if (!xdnd_actions_initialized)
1872 xdnd_initialize_actions();
1874 for (i=0; i<xdnd_n_actions; i++)
1875 if (action == xdnd_actions_table[i].action)
1876 return xdnd_actions_table[i].atom;
1881 static GdkAtom xdnd_aware_atom = GDK_NONE;
1885 static GdkFilterReturn
1886 xdnd_status_filter (GdkXEvent *xev,
1890 XEvent *xevent = (XEvent *)xev;
1891 guint32 dest_window = xevent->xclient.data.l[0];
1892 guint32 flags = xevent->xclient.data.l[1];
1893 GdkAtom action = xevent->xclient.data.l[4];
1894 GdkDragContext *context;
1897 g_message ("XdndStatus: dest_window: %#x action: %ld",
1898 dest_window, action));
1901 context = gdk_drag_context_find (TRUE, xevent->xclient.window, dest_window);
1904 GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
1905 if (private->drag_status == GDK_DRAG_STATUS_MOTION_WAIT)
1906 private->drag_status = GDK_DRAG_STATUS_DRAG;
1908 event->dnd.send_event = FALSE;
1909 event->dnd.type = GDK_DRAG_STATUS;
1910 event->dnd.context = context;
1911 gdk_drag_context_ref (context);
1913 event->dnd.time = GDK_CURRENT_TIME; /* FIXME? */
1914 if (!(action != 0) != !(flags & 1))
1917 g_warning ("Received status event with flags not corresponding to action!\n"));
1921 context->action = xdnd_action_from_atom (action);
1923 return GDK_FILTER_TRANSLATE;
1926 return GDK_FILTER_REMOVE;
1929 static GdkFilterReturn
1930 xdnd_finished_filter (GdkXEvent *xev,
1934 XEvent *xevent = (XEvent *)xev;
1935 guint32 dest_window = xevent->xclient.data.l[0];
1936 GdkDragContext *context;
1939 g_message ("XdndFinished: dest_window: %#x", dest_window));
1941 context = gdk_drag_context_find (TRUE, xevent->xclient.window, dest_window);
1944 event->dnd.type = GDK_DROP_FINISHED;
1945 event->dnd.context = context;
1946 gdk_drag_context_ref (context);
1948 return GDK_FILTER_TRANSLATE;
1951 return GDK_FILTER_REMOVE;
1955 xdnd_set_targets (GdkDragContext *context)
1957 GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
1959 GList *tmp_list = context->targets;
1961 gint n_atoms = g_list_length (context->targets);
1963 atomlist = g_new (GdkAtom, n_atoms);
1967 atomlist[i] = GPOINTER_TO_INT (tmp_list->data);
1968 tmp_list = tmp_list->next;
1972 XChangeProperty (GDK_WINDOW_XDISPLAY (context->source_window),
1973 GDK_WINDOW_XWINDOW (context->source_window),
1974 gdk_atom_intern ("XdndTypeList", FALSE),
1975 XA_ATOM, 32, PropModeReplace,
1976 (guchar *)atomlist, n_atoms);
1978 private->xdnd_targets_set = 1;
1982 xdnd_set_actions (GdkDragContext *context)
1984 GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
1990 if (!xdnd_actions_initialized)
1991 xdnd_initialize_actions();
1993 actions = context->actions;
1995 for (i=0; i<xdnd_n_actions; i++)
1997 if (actions & xdnd_actions_table[i].action)
1999 actions &= ~xdnd_actions_table[i].action;
2004 atomlist = g_new (GdkAtom, n_atoms);
2006 actions = context->actions;
2008 for (i=0; i<xdnd_n_actions; i++)
2010 if (actions & xdnd_actions_table[i].action)
2012 actions &= ~xdnd_actions_table[i].action;
2013 atomlist[n_atoms] = xdnd_actions_table[i].atom;
2018 XChangeProperty (GDK_WINDOW_XDISPLAY (context->source_window),
2019 GDK_WINDOW_XWINDOW (context->source_window),
2020 gdk_atom_intern ("XdndActionList", FALSE),
2021 XA_ATOM, 32, PropModeReplace,
2022 (guchar *)atomlist, n_atoms);
2024 private->xdnd_actions_set = 1;
2028 xdnd_send_enter (GdkDragContext *context)
2031 GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
2033 xev.xclient.type = ClientMessage;
2034 xev.xclient.message_type = gdk_atom_intern ("XdndEnter", FALSE);
2035 xev.xclient.format = 32;
2036 xev.xclient.window = GDK_WINDOW_XWINDOW (context->dest_window);
2037 xev.xclient.data.l[0] = GDK_WINDOW_XWINDOW (context->source_window);
2038 xev.xclient.data.l[1] = (3 << 24); /* version */
2039 xev.xclient.data.l[2] = 0;
2040 xev.xclient.data.l[3] = 0;
2041 xev.xclient.data.l[4] = 0;
2043 if (!private->xdnd_selection)
2044 private->xdnd_selection = gdk_atom_intern ("XdndSelection", FALSE);
2046 if (g_list_length (context->targets) > 3)
2048 if (!private->xdnd_targets_set)
2049 xdnd_set_targets (context);
2050 xev.xclient.data.l[1] |= 1;
2054 GList *tmp_list = context->targets;
2059 xev.xclient.data.l[i] = GPOINTER_TO_INT (tmp_list->data);
2060 tmp_list = tmp_list->next;
2065 if (!private->xdnd_actions_set)
2066 xdnd_set_actions (context);
2068 if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->dest_window),
2072 g_message ("Send event to %lx failed",
2073 GDK_WINDOW_XWINDOW (context->dest_window)));
2074 gdk_window_unref (context->dest_window);
2075 context->dest_window = NULL;
2080 xdnd_send_leave (GdkDragContext *context)
2084 xev.xclient.type = ClientMessage;
2085 xev.xclient.message_type = gdk_atom_intern ("XdndLeave", 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] = 0;
2091 xev.xclient.data.l[3] = 0;
2092 xev.xclient.data.l[4] = 0;
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;
2106 xdnd_send_drop (GdkDragContext *context, guint32 time)
2110 xev.xclient.type = ClientMessage;
2111 xev.xclient.message_type = gdk_atom_intern ("XdndDrop", FALSE);
2112 xev.xclient.format = 32;
2113 xev.xclient.window = GDK_WINDOW_XWINDOW (context->dest_window);
2114 xev.xclient.data.l[0] = GDK_WINDOW_XWINDOW (context->source_window);
2115 xev.xclient.data.l[1] = 0;
2116 xev.xclient.data.l[2] = time;
2117 xev.xclient.data.l[3] = 0;
2118 xev.xclient.data.l[4] = 0;
2120 if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->dest_window),
2124 g_message ("Send event to %lx failed",
2125 GDK_WINDOW_XWINDOW (context->dest_window)));
2126 gdk_window_unref (context->dest_window);
2127 context->dest_window = NULL;
2132 xdnd_send_motion (GdkDragContext *context,
2135 GdkDragAction action,
2138 GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
2141 xev.xclient.type = ClientMessage;
2142 xev.xclient.message_type = gdk_atom_intern ("XdndPosition", FALSE);
2143 xev.xclient.format = 32;
2144 xev.xclient.window = GDK_WINDOW_XWINDOW (context->dest_window);
2145 xev.xclient.data.l[0] = GDK_WINDOW_XWINDOW (context->source_window);
2146 xev.xclient.data.l[1] = 0;
2147 xev.xclient.data.l[2] = (x_root << 16) | y_root;
2148 xev.xclient.data.l[3] = time;
2149 xev.xclient.data.l[4] = xdnd_action_to_atom (action);
2151 if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->dest_window),
2155 g_message ("Send event to %lx failed",
2156 GDK_WINDOW_XWINDOW (context->dest_window)));
2157 gdk_window_unref (context->dest_window);
2158 context->dest_window = NULL;
2160 private->drag_status = GDK_DRAG_STATUS_MOTION_WAIT;
2164 xdnd_check_dest (Window win)
2166 gboolean retval = FALSE;
2169 unsigned long nitems, after;
2173 static GdkAtom xdnd_proxy_atom = GDK_NONE;
2175 gint old_warnings = gdk_error_warnings;
2177 if (!xdnd_proxy_atom)
2178 xdnd_proxy_atom = gdk_atom_intern ("XdndProxy", FALSE);
2180 if (!xdnd_aware_atom)
2181 xdnd_aware_atom = gdk_atom_intern ("XdndAware", FALSE);
2186 gdk_error_warnings = 0;
2188 XGetWindowProperty (gdk_display, win,
2190 1, False, AnyPropertyType,
2191 &type, &format, &nitems, &after,
2192 (guchar **)&proxy_data);
2194 if (!gdk_error_code)
2198 if ((format == 32) && (nitems == 1))
2200 proxy = *proxy_data;
2204 g_warning ("Invalid XdndOwner property on window %ld\n", win));
2209 XGetWindowProperty (gdk_display, proxy ? proxy : win,
2211 1, False, AnyPropertyType,
2212 &type, &format, &nitems, &after,
2213 (guchar **)&version);
2215 if (!gdk_error_code && type != None)
2217 if ((format == 32) && (nitems == 1))
2224 g_warning ("Invalid XdndAware property on window %ld\n", win));
2231 gdk_error_warnings = old_warnings;
2234 return retval ? (proxy ? proxy : win) : GDK_NONE;
2239 static GdkFilterReturn
2240 xdnd_enter_filter (GdkXEvent *xev,
2244 XEvent *xevent = (XEvent *)xev;
2245 GdkDragContext *new_context;
2250 gulong nitems, after;
2253 guint32 source_window = xevent->xclient.data.l[0];
2254 gboolean get_types = ((xevent->xclient.data.l[1] & 1) != 0);
2255 gint version = (xevent->xclient.data.l[1] & 0xff000000) >> 24;
2258 g_message ("XdndEnter: source_window: %#x, version: %#x",
2259 source_window, version));
2263 /* Old source ignore */
2264 GDK_NOTE (DND, g_message ("Ignored old XdndEnter message"));
2265 return GDK_FILTER_REMOVE;
2268 if (current_dest_drag != NULL)
2270 gdk_drag_context_unref (current_dest_drag);
2271 current_dest_drag = NULL;
2274 new_context = gdk_drag_context_new ();
2275 new_context->protocol = GDK_DRAG_PROTO_XDND;
2276 new_context->is_source = FALSE;
2278 new_context->source_window = gdk_window_lookup (source_window);
2279 if (new_context->source_window)
2280 gdk_window_ref (new_context->source_window);
2283 new_context->source_window = gdk_window_foreign_new (source_window);
2284 if (!new_context->source_window)
2286 gdk_drag_context_unref (new_context);
2287 return GDK_FILTER_REMOVE;
2290 new_context->dest_window = event->any.window;
2291 gdk_window_ref (new_context->dest_window);
2293 new_context->targets = NULL;
2296 XGetWindowProperty (GDK_WINDOW_XDISPLAY (event->any.window),
2298 gdk_atom_intern ("XdndTypeList", FALSE), 0, 65536,
2299 False, XA_ATOM, &type, &format, &nitems,
2300 &after, (guchar **)&data);
2302 if ((format != 32) || (type != XA_ATOM))
2304 gdk_drag_context_unref (new_context);
2305 return GDK_FILTER_REMOVE;
2308 for (i=0; i<nitems; i++)
2309 new_context->targets = g_list_append (new_context->targets,
2310 GUINT_TO_POINTER (data[i]));
2317 if (xevent->xclient.data.l[2+i])
2318 new_context->targets = g_list_append (new_context->targets,
2319 GUINT_TO_POINTER (xevent->xclient.data.l[2+i]));
2322 /* Get the XdndActionList, if set */
2324 XGetWindowProperty (GDK_WINDOW_XDISPLAY (event->any.window),
2326 gdk_atom_intern ("XdndActionList", FALSE), 0, 65536,
2327 False, XA_ATOM, &type, &format, &nitems,
2328 &after, (guchar **)&data);
2330 if ((format == 32) && (type == XA_ATOM))
2332 new_context->actions = 0;
2334 for (i=0; i<nitems; i++)
2335 new_context->actions |= xdnd_action_from_atom (data[i]);
2337 ((GdkDragContextPrivate *)new_context)->xdnd_have_actions = TRUE;
2339 #ifdef G_ENABLE_DEBUG
2340 if (gdk_debug_flags & GDK_DEBUG_DND)
2342 GString *action_str = g_string_new (NULL);
2343 if (new_context->actions & GDK_ACTION_MOVE)
2344 g_string_append(action_str, "MOVE ");
2345 if (new_context->actions & GDK_ACTION_COPY)
2346 g_string_append(action_str, "COPY ");
2347 if (new_context->actions & GDK_ACTION_LINK)
2348 g_string_append(action_str, "LINK ");
2349 if (new_context->actions & GDK_ACTION_ASK)
2350 g_string_append(action_str, "ASK ");
2352 g_message("\tactions = %s", action_str->str);
2353 g_string_free (action_str, TRUE);
2355 #endif /* G_ENABLE_DEBUG */
2360 #ifdef G_ENABLE_DEBUG
2361 if (gdk_debug_flags & GDK_DEBUG_DND)
2362 print_target_list (new_context->targets);
2363 #endif /* G_ENABLE_DEBUG */
2365 event->dnd.type = GDK_DRAG_ENTER;
2366 event->dnd.context = new_context;
2367 gdk_drag_context_ref (new_context);
2369 current_dest_drag = new_context;
2370 ((GdkDragContextPrivate *)new_context)->xdnd_selection =
2371 gdk_atom_intern ("XdndSelection", FALSE);
2373 return GDK_FILTER_TRANSLATE;
2376 static GdkFilterReturn
2377 xdnd_leave_filter (GdkXEvent *xev,
2381 XEvent *xevent = (XEvent *)xev;
2382 guint32 source_window = xevent->xclient.data.l[0];
2385 g_message ("XdndLeave: source_window: %#x",
2388 if ((current_dest_drag != NULL) &&
2389 (current_dest_drag->protocol == GDK_DRAG_PROTO_XDND) &&
2390 (GDK_WINDOW_XWINDOW (current_dest_drag->source_window) == source_window))
2392 event->dnd.type = GDK_DRAG_LEAVE;
2393 /* Pass ownership of context to the event */
2394 event->dnd.context = current_dest_drag;
2396 current_dest_drag = NULL;
2398 return GDK_FILTER_TRANSLATE;
2401 return GDK_FILTER_REMOVE;
2404 static GdkFilterReturn
2405 xdnd_position_filter (GdkXEvent *xev,
2409 XEvent *xevent = (XEvent *)xev;
2410 guint32 source_window = xevent->xclient.data.l[0];
2411 gint16 x_root = xevent->xclient.data.l[2] >> 16;
2412 gint16 y_root = xevent->xclient.data.l[2] & 0xffff;
2413 guint32 time = xevent->xclient.data.l[3];
2414 GdkAtom action = xevent->xclient.data.l[4];
2417 g_message ("XdndPosition: source_window: %#x position: (%d, %d) time: %d action: %ld",
2418 source_window, x_root, y_root, time, action));
2421 if ((current_dest_drag != NULL) &&
2422 (current_dest_drag->protocol == GDK_DRAG_PROTO_XDND) &&
2423 (GDK_WINDOW_XWINDOW (current_dest_drag->source_window) == source_window))
2425 event->dnd.type = GDK_DRAG_MOTION;
2426 event->dnd.context = current_dest_drag;
2427 gdk_drag_context_ref (current_dest_drag);
2429 event->dnd.time = time;
2431 current_dest_drag->suggested_action = xdnd_action_from_atom (action);
2432 if (!((GdkDragContextPrivate *)current_dest_drag)->xdnd_have_actions)
2433 current_dest_drag->actions = current_dest_drag->suggested_action;
2435 event->dnd.x_root = x_root;
2436 event->dnd.y_root = y_root;
2438 ((GdkDragContextPrivate *)current_dest_drag)->last_x = x_root;
2439 ((GdkDragContextPrivate *)current_dest_drag)->last_y = y_root;
2441 return GDK_FILTER_TRANSLATE;
2444 return GDK_FILTER_REMOVE;
2447 static GdkFilterReturn
2448 xdnd_drop_filter (GdkXEvent *xev,
2452 XEvent *xevent = (XEvent *)xev;
2453 guint32 source_window = xevent->xclient.data.l[0];
2454 guint32 time = xevent->xclient.data.l[2];
2457 g_message ("XdndDrop: source_window: %#x time: %d",
2458 source_window, time));
2460 if ((current_dest_drag != NULL) &&
2461 (current_dest_drag->protocol == GDK_DRAG_PROTO_XDND) &&
2462 (GDK_WINDOW_XWINDOW (current_dest_drag->source_window) == source_window))
2464 GdkDragContextPrivate *private;
2465 private = (GdkDragContextPrivate *)current_dest_drag;
2467 event->dnd.type = GDK_DROP_START;
2469 event->dnd.context = current_dest_drag;
2470 gdk_drag_context_ref (current_dest_drag);
2472 event->dnd.time = time;
2473 event->dnd.x_root = private->last_x;
2474 event->dnd.y_root = private->last_y;
2476 return GDK_FILTER_TRANSLATE;
2479 return GDK_FILTER_REMOVE;
2482 /*************************************************************
2483 ************************** Public API ***********************
2484 *************************************************************/
2491 gdk_add_client_message_filter (
2492 gdk_atom_intern ("_MOTIF_DRAG_AND_DROP_MESSAGE", FALSE),
2493 motif_dnd_filter, NULL);
2494 gdk_add_client_message_filter (
2495 gdk_atom_intern ("XdndEnter", FALSE),
2496 xdnd_enter_filter, NULL);
2497 gdk_add_client_message_filter (
2498 gdk_atom_intern ("XdndLeave", FALSE),
2499 xdnd_leave_filter, NULL);
2500 gdk_add_client_message_filter (
2501 gdk_atom_intern ("XdndPosition", FALSE),
2502 xdnd_position_filter, NULL);
2503 gdk_add_client_message_filter (
2504 gdk_atom_intern ("XdndStatus", FALSE),
2505 xdnd_status_filter, NULL);
2506 gdk_add_client_message_filter (
2507 gdk_atom_intern ("XdndFinished", FALSE),
2508 xdnd_finished_filter, NULL);
2509 gdk_add_client_message_filter (
2510 gdk_atom_intern ("XdndDrop", FALSE),
2511 xdnd_drop_filter, NULL);
2517 gdk_drag_do_leave (GdkDragContext *context, guint32 time)
2519 if (context->dest_window)
2521 switch (context->protocol)
2523 case GDK_DRAG_PROTO_MOTIF:
2524 motif_send_leave (context, time);
2526 case GDK_DRAG_PROTO_XDND:
2527 xdnd_send_leave (context);
2529 case GDK_DRAG_PROTO_ROOTWIN:
2530 case GDK_DRAG_PROTO_NONE:
2534 gdk_window_unref (context->dest_window);
2535 context->dest_window = NULL;
2540 gdk_drag_begin (GdkWindow *window,
2542 GdkDragAction actions)
2545 GdkDragContext *new_context;
2547 g_return_val_if_fail (window != NULL, NULL);
2549 new_context = gdk_drag_context_new ();
2550 new_context->is_source = TRUE;
2551 new_context->source_window = window;
2552 gdk_window_ref (window);
2554 tmp_list = g_list_last (targets);
2555 new_context->targets = NULL;
2558 new_context->targets = g_list_prepend (new_context->targets,
2560 tmp_list = tmp_list->prev;
2563 new_context->actions = actions;
2569 gdk_drag_get_protocol (guint32 xid,
2570 GdkDragProtocol *protocol)
2574 if ((retval = xdnd_check_dest (xid)))
2576 *protocol = GDK_DRAG_PROTO_XDND;
2577 GDK_NOTE (DND, g_message ("Entering dnd window %#x\n", xid));
2580 else if ((retval = motif_check_dest (xid)))
2582 *protocol = GDK_DRAG_PROTO_MOTIF;
2583 GDK_NOTE (DND, g_message ("Entering motif window %#x\n", xid));
2588 /* Check if this is a root window */
2590 gboolean rootwin = FALSE;
2591 gint old_warnings = gdk_error_warnings;
2594 unsigned long nitems, after;
2595 unsigned char *data;
2597 if (xid == gdk_root_window)
2604 XGetWindowProperty (gdk_display, xid,
2605 gdk_atom_intern ("ENLIGHTENMENT_DESKTOP", FALSE),
2606 0, 0, False, AnyPropertyType,
2607 &type, &format, &nitems, &after, &data);
2608 if ((gdk_error_code == 0) && type != None)
2615 /* Until I find out what window manager the next one is for,
2616 * I'm leaving it commented out. It's supported in the
2617 * xscreensaver sources, though.
2624 XGetWindowProperty (gdk_display, win,
2625 gdk_atom_intern ("__SWM_VROOT", FALSE),
2626 0, 0, False, AnyPropertyType,
2627 &type, &format, &nitems, &data);
2628 if ((gdk_error_code == 0) && type != None)
2633 gdk_error_warnings = old_warnings;
2637 *protocol = GDK_DRAG_PROTO_ROOTWIN;
2642 *protocol = GDK_DRAG_PROTO_NONE;
2647 gdk_drag_find_window (GdkDragContext *context,
2648 GdkWindow *drag_window,
2651 GdkWindow **dest_window,
2652 GdkDragProtocol *protocol)
2654 GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
2657 g_return_if_fail (context != NULL);
2659 if (!private->window_cache)
2660 private->window_cache = gdk_window_cache_new();
2662 dest = get_client_window_at_coords (private->window_cache,
2664 GDK_WINDOW_XWINDOW (drag_window) : GDK_NONE,
2667 if (private->dest_xid != dest)
2670 private->dest_xid = dest;
2672 /* Check if new destination accepts drags, and which protocol */
2674 if ((recipient = gdk_drag_get_protocol (dest, protocol)))
2676 *dest_window = gdk_window_lookup (recipient);
2678 gdk_window_ref (*dest_window);
2680 *dest_window = gdk_window_foreign_new (recipient);
2683 *dest_window = NULL;
2687 *dest_window = context->dest_window;
2689 gdk_window_ref (*dest_window);
2690 *protocol = context->protocol;
2695 gdk_drag_motion (GdkDragContext *context,
2696 GdkWindow *dest_window,
2697 GdkDragProtocol protocol,
2700 GdkDragAction action,
2703 GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
2705 g_return_val_if_fail (context != NULL, FALSE);
2707 if (context->dest_window != dest_window)
2709 GdkEvent temp_event;
2711 /* Send a leave to the last destination */
2712 gdk_drag_do_leave (context, time);
2713 private->drag_status = GDK_DRAG_STATUS_DRAG;
2715 /* Check if new destination accepts drags, and which protocol */
2719 context->dest_window = dest_window;
2720 gdk_window_ref (context->dest_window);
2721 context->protocol = protocol;
2725 case GDK_DRAG_PROTO_MOTIF:
2726 motif_send_enter (context, time);
2729 case GDK_DRAG_PROTO_XDND:
2730 xdnd_send_enter (context);
2733 case GDK_DRAG_PROTO_ROOTWIN:
2734 case GDK_DRAG_PROTO_NONE:
2737 private->old_action = action;
2738 context->suggested_action = action;
2742 context->dest_window = NULL;
2743 context->action = 0;
2746 /* Push a status event, to let the client know that
2750 temp_event.dnd.type = GDK_DRAG_STATUS;
2751 temp_event.dnd.window = context->source_window;
2752 /* We use this to signal a synthetic status. Perhaps
2753 * we should use an extra field...
2755 temp_event.dnd.send_event = TRUE;
2757 temp_event.dnd.context = context;
2758 temp_event.dnd.time = time;
2760 gdk_event_put (&temp_event);
2764 private->old_action = context->suggested_action;
2765 context->suggested_action = action;
2768 /* Send a drag-motion event */
2770 private->last_x = x_root;
2771 private->last_y = y_root;
2773 if (context->dest_window)
2775 if (private->drag_status == GDK_DRAG_STATUS_DRAG)
2777 switch (context->protocol)
2779 case GDK_DRAG_PROTO_MOTIF:
2780 motif_send_motion (context, x_root, y_root, action, time);
2783 case GDK_DRAG_PROTO_XDND:
2784 xdnd_send_motion (context, x_root, y_root, action, time);
2787 case GDK_DRAG_PROTO_ROOTWIN:
2789 GdkEvent temp_event;
2791 if (g_list_find (context->targets,
2792 GUINT_TO_POINTER (gdk_atom_intern ("application/x-rootwin-drop", FALSE))))
2793 context->action = context->suggested_action;
2795 context->action = 0;
2797 temp_event.dnd.type = GDK_DRAG_STATUS;
2798 temp_event.dnd.window = context->source_window;
2799 temp_event.dnd.send_event = FALSE;
2800 temp_event.dnd.context = context;
2801 temp_event.dnd.time = time;
2803 gdk_event_put (&temp_event);
2806 case GDK_DRAG_PROTO_NONE:
2807 g_warning ("GDK_DRAG_PROTO_NONE is not valid in gdk_drag_motion()");
2819 gdk_drag_drop (GdkDragContext *context,
2822 g_return_if_fail (context != NULL);
2824 if (context->dest_window)
2826 switch (context->protocol)
2828 case GDK_DRAG_PROTO_MOTIF:
2829 motif_send_leave (context, time);
2830 motif_send_drop (context, time);
2833 case GDK_DRAG_PROTO_XDND:
2834 xdnd_send_drop (context, time);
2837 case GDK_DRAG_PROTO_ROOTWIN:
2838 g_warning ("Drops for GDK_DRAG_PROTO_ROOTWIN must be handled internally");
2840 case GDK_DRAG_PROTO_NONE:
2841 g_warning ("GDK_DRAG_PROTO_NONE is not valid in gdk_drag_drop()");
2848 gdk_drag_abort (GdkDragContext *context,
2851 g_return_if_fail (context != NULL);
2853 gdk_drag_do_leave (context, time);
2856 /* Destination side */
2859 gdk_drag_status (GdkDragContext *context,
2860 GdkDragAction action,
2863 GdkDragContextPrivate *private;
2866 g_return_if_fail (context != NULL);
2868 private = (GdkDragContextPrivate *)context;
2870 context->action = action;
2872 if (context->protocol == GDK_DRAG_PROTO_MOTIF)
2874 xev.xclient.type = ClientMessage;
2875 xev.xclient.message_type = gdk_atom_intern ("_MOTIF_DRAG_AND_DROP_MESSAGE", FALSE);
2876 xev.xclient.format = 8;
2877 xev.xclient.window = GDK_WINDOW_XWINDOW (context->source_window);
2879 if (private->drag_status == GDK_DRAG_STATUS_ACTION_WAIT)
2881 xev.xclient.data.b[0] = XmOPERATION_CHANGED | 0x80;
2885 if ((action != 0) != (private->old_action != 0))
2888 xev.xclient.data.b[0] = XmDROP_SITE_ENTER | 0x80;
2890 xev.xclient.data.b[0] = XmDROP_SITE_LEAVE | 0x80;
2893 xev.xclient.data.b[0] = XmDRAG_MOTION | 0x80;
2896 xev.xclient.data.b[1] = local_byte_order;
2900 case GDK_ACTION_MOVE:
2901 xev.xclient.data.s[1] = XmDROP_MOVE;
2903 case GDK_ACTION_COPY:
2904 xev.xclient.data.s[1] = XmDROP_COPY;
2906 case GDK_ACTION_LINK:
2907 xev.xclient.data.s[1] = XmDROP_LINK;
2910 xev.xclient.data.s[1] = XmDROP_NOOP;
2915 xev.xclient.data.s[1] |= (XmDROP_SITE_VALID << 4);
2917 xev.xclient.data.s[1] |= (XmNO_DROP_SITE << 4);
2919 xev.xclient.data.l[1] = time;
2920 xev.xclient.data.s[4] = private->last_x;
2921 xev.xclient.data.s[5] = private->last_y;
2923 if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->source_window),
2926 g_message ("Send event to %lx failed",
2927 GDK_WINDOW_XWINDOW (context->source_window)));
2929 else if (context->protocol == GDK_DRAG_PROTO_XDND)
2931 xev.xclient.type = ClientMessage;
2932 xev.xclient.message_type = gdk_atom_intern ("XdndStatus", FALSE);
2933 xev.xclient.format = 32;
2934 xev.xclient.window = GDK_WINDOW_XWINDOW (context->source_window);
2936 xev.xclient.data.l[0] = GDK_WINDOW_XWINDOW (context->dest_window);
2937 xev.xclient.data.l[1] = (action != 0) ? (2 | 1) : 0;
2938 xev.xclient.data.l[2] = 0;
2939 xev.xclient.data.l[3] = 0;
2940 xev.xclient.data.l[4] = xdnd_action_to_atom (action);
2942 if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->source_window),
2945 g_message ("Send event to %lx failed",
2946 GDK_WINDOW_XWINDOW (context->source_window)));
2949 private->old_action = action;
2953 gdk_drop_reply (GdkDragContext *context,
2957 GdkDragContextPrivate *private;
2959 g_return_if_fail (context != NULL);
2961 private = (GdkDragContextPrivate *)context;
2963 if (context->protocol == GDK_DRAG_PROTO_MOTIF)
2967 xev.xclient.type = ClientMessage;
2968 xev.xclient.message_type = gdk_atom_intern ("_MOTIF_DRAG_AND_DROP_MESSAGE", FALSE);
2969 xev.xclient.format = 8;
2971 xev.xclient.data.b[0] = XmDROP_START | 0x80;
2972 xev.xclient.data.b[1] = local_byte_order;
2974 xev.xclient.data.s[1] = XmDROP_COPY |
2975 (XmDROP_SITE_VALID << 4) |
2976 (XmDROP_NOOP << 8) |
2979 xev.xclient.data.s[1] = XmDROP_NOOP |
2980 (XmNO_DROP_SITE << 4) |
2981 (XmDROP_NOOP << 8) |
2982 (XmDROP_CANCEL << 12);
2983 xev.xclient.data.s[2] = private->last_x;
2984 xev.xclient.data.s[3] = private->last_y;
2986 gdk_send_xevent (GDK_WINDOW_XWINDOW (context->source_window),
2992 gdk_drop_finish (GdkDragContext *context,
2996 g_return_if_fail (context != NULL);
2998 if (context->protocol == GDK_DRAG_PROTO_XDND)
3002 xev.xclient.type = ClientMessage;
3003 xev.xclient.message_type = gdk_atom_intern ("XdndFinished", FALSE);
3004 xev.xclient.format = 32;
3005 xev.xclient.window = GDK_WINDOW_XWINDOW (context->source_window);
3007 xev.xclient.data.l[0] = GDK_WINDOW_XWINDOW (context->dest_window);
3008 xev.xclient.data.l[1] = 0;
3009 xev.xclient.data.l[2] = 0;
3010 xev.xclient.data.l[3] = 0;
3011 xev.xclient.data.l[4] = 0;
3013 if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->source_window),
3016 g_message ("Send event to %lx failed",
3017 GDK_WINDOW_XWINDOW (context->source_window)));
3023 gdk_window_register_dnd (GdkWindow *window)
3025 static guint32 xdnd_version = 3;
3026 MotifDragReceiverInfo info;
3028 g_return_if_fail (window != NULL);
3030 /* Set Motif drag receiver information property */
3032 if (!motif_drag_receiver_info_atom)
3033 motif_drag_receiver_info_atom = gdk_atom_intern ("_MOTIF_DRAG_RECEIVER_INFO", FALSE);
3035 info.byte_order = local_byte_order;
3036 info.protocol_version = 0;
3037 info.protocol_style = XmDRAG_DYNAMIC;
3038 info.proxy_window = GDK_NONE;
3039 info.num_drop_sites = 0;
3040 info.total_size = sizeof(info);
3042 XChangeProperty (gdk_display, GDK_WINDOW_XWINDOW (window),
3043 motif_drag_receiver_info_atom,
3044 motif_drag_receiver_info_atom,
3051 if (!xdnd_aware_atom)
3052 xdnd_aware_atom = gdk_atom_intern ("XdndAware", FALSE);
3054 /* The property needs to be of type XA_ATOM, not XA_INTEGER. Blech */
3055 XChangeProperty (GDK_WINDOW_XDISPLAY (window),
3056 GDK_WINDOW_XWINDOW (window),
3057 xdnd_aware_atom, XA_ATOM,
3058 32, PropModeReplace,
3059 (guchar *)&xdnd_version, 1);
3062 /*************************************************************
3063 * gdk_drag_get_selection:
3064 * Returns the selection atom for the current source window
3068 *************************************************************/
3071 gdk_drag_get_selection (GdkDragContext *context)
3073 g_return_val_if_fail (context != NULL, GDK_NONE);
3075 if (context->protocol == GDK_DRAG_PROTO_MOTIF)
3076 return ((GdkDragContextPrivate *)context)->motif_selection;
3077 else if (context->protocol == GDK_DRAG_PROTO_XDND)
3078 return ((GdkDragContextPrivate *)context)->xdnd_selection;