* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
+#include "config.h"
#include <X11/Xlib.h>
#include <X11/Xatom.h>
+#include <X11/extensions/shape.h>
+
#include <string.h>
#include "gdk.h" /* For gdk_flush() */
#include "gdkinternals.h"
#include "gdkscreen-x11.h"
#include "gdkdisplay-x11.h"
+#include "gdkalias.h"
typedef struct _GdkDragContextPrivateX11 GdkDragContextPrivateX11;
guint32 xid;
gint x, y, width, height;
gboolean mapped;
+ gboolean shape_selected;
+ gboolean shape_valid;
+ GdkRegion *shape;
} GdkCacheChild;
typedef struct {
GdkDragContext context;
Atom motif_selection;
- Atom xdnd_selection;
guint ref_count;
guint16 last_x; /* Coordinates from last event */
Window drop_xid; /* The (non-proxied) window that is receiving drops */
guint xdnd_targets_set : 1; /* Whether we've already set XdndTypeList */
guint xdnd_actions_set : 1; /* Whether we've already set XdndActionList */
- guint xdnd_have_actions : 1; /* Whether an XdndActionList was provided */
+ guint xdnd_have_actions : 1; /* Whether an XdndActionList was provided */
guint motif_targets_set : 1; /* Whether we've already set motif initiator info */
guint drag_status : 4; /* current status of drag */
+
+ guint drop_failed : 1; /* Whether the drop was unsuccessful */
+ guint version; /* Xdnd protocol version */
GSList *window_caches;
};
GdkWindow *window,
gboolean add_filter);
-static void gdk_drag_context_init (GdkDragContext *dragcontext);
-static void gdk_drag_context_class_init (GdkDragContextClass *klass);
static void gdk_drag_context_finalize (GObject *object);
-static gpointer parent_class = NULL;
static GList *contexts;
-const static struct {
+static const struct {
const char *atom_name;
GdkFilterFunc func;
} xdnd_filters[] = {
{ "XdndDrop", xdnd_drop_filter },
};
-GType
-gdk_drag_context_get_type (void)
-{
- static GType object_type = 0;
-
- if (!object_type)
- {
- static const GTypeInfo object_info =
- {
- sizeof (GdkDragContextClass),
- (GBaseInitFunc) NULL,
- (GBaseFinalizeFunc) NULL,
- (GClassInitFunc) gdk_drag_context_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (GdkDragContext),
- 0, /* n_preallocs */
- (GInstanceInitFunc) gdk_drag_context_init,
- };
-
- object_type = g_type_register_static (G_TYPE_OBJECT,
- "GdkDragContext",
- &object_info, 0);
- }
-
- return object_type;
-}
+G_DEFINE_TYPE (GdkDragContext, gdk_drag_context, G_TYPE_OBJECT)
static void
gdk_drag_context_init (GdkDragContext *dragcontext)
{
GdkDragContextPrivateX11 *private;
- private = g_new0 (GdkDragContextPrivateX11, 1);
-
+ private = G_TYPE_INSTANCE_GET_PRIVATE (dragcontext,
+ GDK_TYPE_DRAG_CONTEXT,
+ GdkDragContextPrivateX11);
+
dragcontext->windowing_data = private;
contexts = g_list_prepend (contexts, dragcontext);
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
- parent_class = g_type_class_peek_parent (klass);
-
object_class->finalize = gdk_drag_context_finalize;
+
+ g_type_class_add_private (object_class, sizeof (GdkDragContextPrivateX11));
}
static void
contexts = g_list_remove (contexts, context);
- g_free (private);
-
- G_OBJECT_CLASS (parent_class)->finalize (object);
+ G_OBJECT_CLASS (gdk_drag_context_parent_class)->finalize (object);
}
/* Drag Contexts */
* Return value: the newly created #GdkDragContext.
**/
GdkDragContext *
-gdk_drag_context_new (void)
+gdk_drag_context_new (void)
{
- return g_object_new (gdk_drag_context_get_type (), NULL);
+ return g_object_new (GDK_TYPE_DRAG_CONTEXT, NULL);
}
/**
* gdk_drag_context_ref:
* @context: a #GdkDragContext.
- *
+ *
* Deprecated function; use g_object_ref() instead.
+ *
+ * Deprecated: 2.2: Use g_object_ref() instead.
**/
void
gdk_drag_context_ref (GdkDragContext *context)
/**
* gdk_drag_context_unref:
* @context: a #GdkDragContext.
- *
+ *
* Deprecated function; use g_object_unref() instead.
+ *
+ * Deprecated: 2.2: Use g_object_unref() instead.
**/
void
gdk_drag_context_unref (GdkDragContext *context)
return NULL;
}
+static void
+precache_target_list (GdkDragContext *context)
+{
+ if (context->targets)
+ {
+ GPtrArray *targets = g_ptr_array_new ();
+ GList *tmp_list;
+ int i;
+
+ for (tmp_list = context->targets; tmp_list; tmp_list = tmp_list->next)
+ g_ptr_array_add (targets, gdk_atom_name (GDK_POINTER_TO_ATOM (tmp_list->data)));
+
+ _gdk_x11_precache_atoms (GDK_WINDOW_DISPLAY (context->source_window),
+ (const gchar **)targets->pdata,
+ targets->len);
+
+ for (i =0; i < targets->len; i++)
+ g_free (targets->pdata[i]);
+
+ g_ptr_array_free (targets, TRUE);
+ }
+}
+
/* Utility functions */
+static void
+free_cache_child (GdkCacheChild *child,
+ GdkDisplay *display)
+{
+ if (child->shape)
+ gdk_region_destroy (child->shape);
+
+ if (child->shape_selected && display)
+ {
+ GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
+
+ XShapeSelectInput (display_x11->xdisplay, child->xid, 0);
+ }
+
+ g_free (child);
+}
+
static void
gdk_window_cache_add (GdkWindowCache *cache,
guint32 xid,
child->width = width;
child->height = height;
child->mapped = mapped;
+ child->shape_selected = FALSE;
+ child->shape_valid = FALSE;
+ child->shape = NULL;
cache->children = g_list_prepend (cache->children, child);
g_hash_table_insert (cache->child_hash, GUINT_TO_POINTER (xid),
cache->children);
}
+static GdkFilterReturn
+gdk_window_cache_shape_filter (GdkXEvent *xev,
+ GdkEvent *event,
+ gpointer data)
+{
+ XEvent *xevent = (XEvent *)xev;
+ GdkWindowCache *cache = data;
+
+ GdkDisplayX11 *display = GDK_DISPLAY_X11 (gdk_screen_get_display (cache->screen));
+
+ if (display->have_shapes &&
+ xevent->type == display->shape_event_base + ShapeNotify)
+ {
+ XShapeEvent *xse = (XShapeEvent*)xevent;
+ GList *node;
+
+ node = g_hash_table_lookup (cache->child_hash,
+ GUINT_TO_POINTER (xse->window));
+ if (node)
+ {
+ GdkCacheChild *child = node->data;
+ child->shape_valid = FALSE;
+ if (child->shape)
+ {
+ gdk_region_destroy (child->shape);
+ child->shape = NULL;
+ }
+ }
+
+ return GDK_FILTER_REMOVE;
+ }
+
+ return GDK_FILTER_CONTINUE;
+}
+
static GdkFilterReturn
gdk_window_cache_filter (GdkXEvent *xev,
GdkEvent *event,
GUINT_TO_POINTER (xdwe->window));
if (node)
{
+ GdkCacheChild *child = node->data;
+
g_hash_table_remove (cache->child_hash,
GUINT_TO_POINTER (xdwe->window));
cache->children = g_list_remove_link (cache->children, node);
- g_free (node->data);
+ /* window is destroyed, no need to disable ShapeNotify */
+ free_cache_child (child, NULL);
g_list_free_1 (node);
}
break;
node = g_hash_table_lookup (cache->child_hash,
GUINT_TO_POINTER (xume->window));
- if (node)
+ if (node)
{
GdkCacheChild *child = node->data;
child->mapped = FALSE;
XGetWindowAttributes (xdisplay, GDK_WINDOW_XWINDOW (root_window), &xwa);
result->old_event_mask = xwa.your_event_mask;
+
+ if (G_UNLIKELY (!GDK_DISPLAY_X11 (GDK_SCREEN_X11 (screen)->display)->trusted_client))
+ {
+ GList *toplevel_windows, *list;
+ GdkWindow *window;
+ gint x, y, width, height;
+
+ toplevel_windows = gdk_screen_get_toplevel_windows (screen);
+ for (list = toplevel_windows; list; list = list->next) {
+ window = GDK_WINDOW (list->data);
+ gdk_window_get_geometry (window, &x, &y, &width, &height, NULL);
+ gdk_window_cache_add (result, GDK_WINDOW_XID (window),
+ x, y, width, height,
+ gdk_window_is_visible (window));
+ }
+ g_list_free (toplevel_windows);
+ return result;
+ }
+
XSelectInput (xdisplay, GDK_WINDOW_XWINDOW (root_window),
result->old_event_mask | SubstructureNotifyMask);
gdk_window_add_filter (root_window, gdk_window_cache_filter, result);
+ gdk_window_add_filter (NULL, gdk_window_cache_shape_filter, result);
if (!_gdk_x11_get_window_child_info (gdk_screen_get_display (screen),
GDK_WINDOW_XWINDOW (root_window),
- FALSE, &children, &nchildren))
+ FALSE, NULL,
+ &children, &nchildren))
return result;
for (i = 0; i < nchildren ; i++)
gdk_window_cache_destroy (GdkWindowCache *cache)
{
GdkWindow *root_window = gdk_screen_get_root_window (cache->screen);
-
- XSelectInput (GDK_WINDOW_XDISPLAY (root_window),
+
+ XSelectInput (GDK_WINDOW_XDISPLAY (root_window),
GDK_WINDOW_XWINDOW (root_window),
cache->old_event_mask);
gdk_window_remove_filter (root_window, gdk_window_cache_filter, cache);
+ gdk_window_remove_filter (NULL, gdk_window_cache_shape_filter, cache);
+
+ gdk_error_trap_push ();
+
+ g_list_foreach (cache->children, (GFunc)free_cache_child,
+ gdk_screen_get_display (cache->screen));
+
+ gdk_flush ();
+ gdk_error_trap_pop ();
- g_list_foreach (cache->children, (GFunc)g_free, NULL);
g_list_free (cache->children);
g_hash_table_destroy (cache->child_hash);
}
static gboolean
-window_has_wm_state (GdkDisplay *display,
- Window win)
+is_pointer_within_shape (GdkDisplay *display,
+ GdkCacheChild *child,
+ gint x_pos,
+ gint y_pos)
{
- Atom type = None;
- int format;
- unsigned long nitems, after;
- unsigned char *data;
-
- if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY(display), win,
- gdk_x11_get_xatom_by_name_for_display (display, "WM_STATE"),
- 0, 0, False, AnyPropertyType,
- &type, &format, &nitems, &after, &data) != Success)
- return FALSE;
-
- if (type != None)
+ if (!child->shape_selected)
+ {
+ GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
+
+ XShapeSelectInput (display_x11->xdisplay, child->xid, ShapeNotifyMask);
+ child->shape_selected = TRUE;
+ }
+ if (!child->shape_valid)
{
- XFree (data);
- return TRUE;
+ GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
+ GdkRegion *input_shape;
+
+ child->shape = _xwindow_get_shape (display_x11->xdisplay,
+ child->xid, ShapeBounding);
+#ifdef ShapeInput
+ input_shape = _xwindow_get_shape (display_x11->xdisplay,
+ child->xid, ShapeInput);
+ if (child->shape && input_shape)
+ {
+ gdk_region_intersect (child->shape, input_shape);
+ gdk_region_destroy (input_shape);
+ }
+ else if (input_shape)
+ {
+ child->shape = input_shape;
+ }
+#endif
+
+ child->shape_valid = TRUE;
}
- return FALSE;
+ return child->shape == NULL ||
+ gdk_region_point_in (child->shape, x_pos, y_pos);
}
static Window
get_client_window_at_coords_recurse (GdkDisplay *display,
Window win,
+ gboolean is_toplevel,
gint x,
gint y)
{
unsigned int nchildren;
int i;
gboolean found_child = FALSE;
- GdkChildInfoX11 child;
+ GdkChildInfoX11 child = { 0, };
+ gboolean has_wm_state = FALSE;
if (!_gdk_x11_get_window_child_info (display, win, TRUE,
+ is_toplevel? &has_wm_state : NULL,
&children, &nchildren))
return None;
+ if (has_wm_state)
+ {
+ g_free (children);
+
+ return win;
+ }
+
for (i = nchildren - 1; (i >= 0) && !found_child; i--)
{
GdkChildInfoX11 *cur_child = &children[i];
if (child.has_wm_state)
return child.window;
else
- return get_client_window_at_coords_recurse (display, child.window, x, y);
+ return get_client_window_at_coords_recurse (display, child.window, FALSE, x, y);
}
else
return None;
GdkCacheChild *child = tmp_list->data;
if ((child->xid != ignore) && (child->mapped))
- {
- if ((x_root >= child->x) && (x_root < child->x + child->width) &&
- (y_root >= child->y) && (y_root < child->y + child->height))
- {
- if (window_has_wm_state (gdk_screen_get_display (cache->screen), child->xid))
- retval = child->xid;
- else
- retval = get_client_window_at_coords_recurse (gdk_screen_get_display (cache->screen),
- child->xid,
- x_root - child->x,
- y_root - child->y);
- if (!retval)
- retval = child->xid;
- }
-
- }
+ {
+ if ((x_root >= child->x) && (x_root < child->x + child->width) &&
+ (y_root >= child->y) && (y_root < child->y + child->height))
+ {
+ GdkDisplay *display = gdk_screen_get_display (cache->screen);
+
+ if (!is_pointer_within_shape (display, child,
+ x_root - child->x,
+ y_root - child->y))
+ {
+ tmp_list = tmp_list->next;
+ continue;
+ }
+
+ retval = get_client_window_at_coords_recurse (display,
+ child->xid, TRUE,
+ x_root - child->x,
+ y_root - child->y);
+ if (!retval)
+ retval = child->xid;
+ }
+ }
tmp_list = tmp_list->next;
}
XCreateWindow (persistant_xdisplay,
RootWindow (persistant_xdisplay, 0),
-100, -100, 10, 10, 0, 0,
- InputOnly, CopyFromParent,
+ InputOnly, (Visual *)CopyFromParent,
(CWOverrideRedirect | CWEventMask), &attr);
GDK_NOTE (DND,
if (motif_find_drag_window (display, FALSE))
{
+ guchar *data;
MotifTargetTableHeader *header = NULL;
guchar *target_bytes = NULL;
guchar *p;
0, (sizeof(MotifTargetTableHeader)+3)/4, FALSE,
motif_drag_targets_atom,
&type, &format, &nitems, &bytes_after,
- (guchar **)&header);
+ &data);
if (gdk_error_trap_pop () || (format != 8) || (nitems < sizeof (MotifTargetTableHeader)))
goto error;
+ header = (MotifTargetTableHeader *)data;
+
header->n_lists = card16_to_host (header->n_lists, header->byte_order);
header->total_size = card32_to_host (header->total_size, header->byte_order);
Window win)
{
gboolean retval = FALSE;
+ guchar *data;
MotifDragReceiverInfo *info;
Atom type = None;
int format;
motif_drag_receiver_info_atom,
0, (sizeof(*info)+3)/4, False, AnyPropertyType,
&type, &format, &nitems, &after,
- (guchar **)&info);
+ &data);
if (gdk_error_trap_pop() == 0)
{
if (type != None)
{
+ info = (MotifDragReceiverInfo *)data;
+
if ((format == 8) && (nitems == sizeof(*info)))
{
if ((info->protocol_version == 0) &&
GdkDisplay *display = GDK_DRAWABLE_DISPLAY (context->source_window);
XEvent xev;
+ if (!G_LIKELY (GDK_DISPLAY_X11 (display)->trusted_client))
+ return; /* Motif Dnd requires getting properties on the root window */
+
xev.xclient.type = ClientMessage;
xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_MOTIF_DRAG_AND_DROP_MESSAGE");
xev.xclient.format = 8;
gint format;
gulong nitems;
gulong bytes_after;
+ guchar *data;
MotifDragInitiatorInfo *initiator_info;
GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
0, sizeof(*initiator_info), FALSE,
gdk_x11_get_xatom_by_name_for_display (display, "_MOTIF_DRAG_INITIATOR_INFO"),
&type, &format, &nitems, &bytes_after,
- (guchar **)&initiator_info);
+ &data);
if (gdk_error_trap_pop () || (format != 8) || (nitems != sizeof (MotifDragInitiatorInfo)) || (bytes_after != 0))
{
return FALSE;
}
+ initiator_info = (MotifDragInitiatorInfo *)data;
+
motif_read_target_table (display);
initiator_info->targets_index =
event->dnd.x_root = x_root;
event->dnd.y_root = y_root;
+ gdk_x11_window_set_user_time (event->any.window, timestamp);
+
g_object_ref (new_context);
display_x11->current_dest_drag = new_context;
/* Utility functions */
static struct {
- gchar *name;
+ const gchar *name;
GdkAtom atom;
GdkDragAction action;
} xdnd_actions_table[] = {
xdnd_actions_initialized = TRUE;
for (i=0; i < xdnd_n_actions; i++)
- xdnd_actions_table[i].atom = gdk_atom_intern (xdnd_actions_table[i].name, FALSE);
+ xdnd_actions_table[i].atom = gdk_atom_intern_static_string (xdnd_actions_table[i].name);
}
static GdkDragAction
xdnd_action_from_atom (GdkDisplay *display,
Atom xatom)
{
- GdkAtom atom = gdk_x11_xatom_to_atom_for_display (display, xatom);
+ GdkAtom atom;
gint i;
+ if (xatom == None)
+ return 0;
+
+ atom = gdk_x11_xatom_to_atom_for_display (display, xatom);
+
if (!xdnd_actions_initialized)
xdnd_initialize_actions();
XEvent *xevent = (XEvent *)xev;
guint32 dest_window = xevent->xclient.data.l[0];
GdkDragContext *context;
+ GdkDragContextPrivateX11 *private;
if (!event->any.window ||
gdk_window_get_window_type (event->any.window) == GDK_WINDOW_FOREIGN)
if (context)
{
+ private = PRIVATE_DATA (context);
+ if (private->version == 5)
+ private->drop_failed = xevent->xclient.data.l[1] == 0;
+
event->dnd.type = GDK_DROP_FINISHED;
event->dnd.context = context;
g_object_ref (context);
+ event->dnd.time = GDK_CURRENT_TIME; /* FIXME? */
+
return GDK_FILTER_TRANSLATE;
}
g_free (atomlist);
- private->xdnd_actions_set = 1;
+ private->xdnd_actions_set = TRUE;
private->xdnd_actions = context->actions;
}
static void
-send_xevent_async_cb (Window window,
- gboolean success,
- gpointer data)
+send_client_message_async_cb (Window window,
+ gboolean success,
+ gpointer data)
{
GdkDragContext *context = data;
GDK_NOTE (DND,
}
static void
-send_xevent_async (GdkDragContext *context,
- Window window,
- gboolean propagate,
- glong event_mask,
- XEvent *event_send)
+send_client_message_async (GdkDragContext *context,
+ Window window,
+ gboolean propagate,
+ glong event_mask,
+ XClientMessageEvent *event_send)
{
GdkDisplay *display = gdk_drag_context_get_display (context);
g_object_ref (context);
- _gdk_x11_send_xevent_async (display, window,
- propagate, event_mask, event_send,
- send_xevent_async_cb, context);
+ _gdk_x11_send_client_message_async (display, window,
+ propagate, event_mask, event_send,
+ send_client_message_async_cb, context);
}
static gboolean
Window xwindow;
glong event_mask;
+ g_assert (event_send->xany.type == ClientMessage);
+
/* We short-circuit messages to ourselves */
- if (gdk_window_get_window_type (window) != GDK_WINDOW_FOREIGN &&
- event_send->xany.type == ClientMessage)
+ if (gdk_window_get_window_type (window) != GDK_WINDOW_FOREIGN)
{
gint i;
temp_event.any.window = window;
if ((*xdnd_filters[i].func) (event_send, &temp_event, NULL) == GDK_FILTER_TRANSLATE)
- gdk_event_put (&temp_event);
+ {
+ gdk_event_put (&temp_event);
+ g_object_unref (temp_event.dnd.context);
+ }
return TRUE;
}
else
event_mask = 0;
- send_xevent_async (context, xwindow, propagate, event_mask, event_send);
+ send_client_message_async (context, xwindow, propagate, event_mask,
+ &event_send->xclient);
return TRUE;
}
private->drop_xid :
GDK_DRAWABLE_XID (context->dest_window);
xev.xclient.data.l[0] = GDK_DRAWABLE_XID (context->source_window);
- xev.xclient.data.l[1] = (3 << 24); /* version */
+ xev.xclient.data.l[1] = (private->version << 24); /* version */
xev.xclient.data.l[2] = 0;
xev.xclient.data.l[3] = 0;
xev.xclient.data.l[4] = 0;
- if (!private->xdnd_selection)
- private->xdnd_selection = gdk_x11_get_xatom_by_name_for_display (display, "XdndSelection");
-
+ GDK_NOTE(DND,
+ g_message ("Sending enter source window %#lx XDND protocol version %d\n",
+ GDK_DRAWABLE_XID (context->source_window), private->version));
if (g_list_length (context->targets) > 3)
{
if (!private->xdnd_targets_set)
static guint32
xdnd_check_dest (GdkDisplay *display,
- Window win)
+ Window win,
+ guint *xdnd_version)
{
gboolean retval = FALSE;
Atom type = None;
int format;
unsigned long nitems, after;
+ guchar *data;
Atom *version;
Window *proxy_data;
Window proxy;
xdnd_proxy_atom, 0,
1, False, AnyPropertyType,
&type, &format, &nitems, &after,
- (guchar **)&proxy_data) == Success)
+ &data) == Success)
{
if (type != None)
{
+ proxy_data = (Window *)data;
+
if ((format == 32) && (nitems == 1))
{
proxy = *proxy_data;
}
else
GDK_NOTE (DND,
- g_warning ("Invalid XdndOwner "
+ g_warning ("Invalid XdndProxy "
"property on window %ld\n", win));
XFree (proxy_data);
xdnd_aware_atom, 0,
1, False, AnyPropertyType,
&type, &format, &nitems, &after,
- (guchar **)&version) == Success) &&
+ &data) == Success) &&
type != None)
{
+ version = (Atom *)data;
+
if ((format == 32) && (nitems == 1))
{
if (*version >= 3)
retval = TRUE;
+ if (xdnd_version)
+ *xdnd_version = *version;
}
else
GDK_NOTE (DND,
- g_warning ("Invalid XdndAware property on window %ld\n", win));
+ g_warning ("Invalid XdndAware "
+ "property on window %ld\n", win));
XFree (version);
}
Atom type;
int format;
gulong nitems, after;
- Atom *data;
+ guchar *data;
+ Atom *atoms;
gint i;
-
- /* Get the XdndActionList, if set */
-
- gdk_error_trap_push ();
- if (XGetWindowProperty (GDK_DRAWABLE_XDISPLAY (context->source_window),
- GDK_DRAWABLE_XID (context->source_window),
- gdk_x11_get_xatom_by_name_for_display (display, "XdndActionList"),
- 0, 65536,
- False, XA_ATOM, &type, &format, &nitems,
- &after, (guchar **)&data) == Success &&
- type == XA_ATOM)
- {
- context->actions = 0;
-
- for (i=0; i<nitems; i++)
- context->actions |= xdnd_action_from_atom (display, data[i]);
+ PRIVATE_DATA (context)->xdnd_have_actions = FALSE;
- (PRIVATE_DATA (context))->xdnd_have_actions = TRUE;
-
-#ifdef G_ENABLE_DEBUG
- if (_gdk_debug_flags & GDK_DEBUG_DND)
+ if (gdk_window_get_window_type (context->source_window) == GDK_WINDOW_FOREIGN)
+ {
+ /* Get the XdndActionList, if set */
+
+ gdk_error_trap_push ();
+
+ if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display),
+ GDK_DRAWABLE_XID (context->source_window),
+ gdk_x11_get_xatom_by_name_for_display (display, "XdndActionList"),
+ 0, 65536,
+ False, XA_ATOM, &type, &format, &nitems,
+ &after, &data) == Success &&
+ type == XA_ATOM)
{
- GString *action_str = g_string_new (NULL);
- if (context->actions & GDK_ACTION_MOVE)
- g_string_append(action_str, "MOVE ");
- if (context->actions & GDK_ACTION_COPY)
- g_string_append(action_str, "COPY ");
- if (context->actions & GDK_ACTION_LINK)
- g_string_append(action_str, "LINK ");
- if (context->actions & GDK_ACTION_ASK)
- g_string_append(action_str, "ASK ");
+ atoms = (Atom *)data;
- g_message("Xdnd actions = %s", action_str->str);
- g_string_free (action_str, TRUE);
- }
+ context->actions = 0;
+
+ for (i=0; i<nitems; i++)
+ context->actions |= xdnd_action_from_atom (display, atoms[i]);
+
+ PRIVATE_DATA (context)->xdnd_have_actions = TRUE;
+
+#ifdef G_ENABLE_DEBUG
+ if (_gdk_debug_flags & GDK_DEBUG_DND)
+ {
+ GString *action_str = g_string_new (NULL);
+ if (context->actions & GDK_ACTION_MOVE)
+ g_string_append(action_str, "MOVE ");
+ if (context->actions & GDK_ACTION_COPY)
+ g_string_append(action_str, "COPY ");
+ if (context->actions & GDK_ACTION_LINK)
+ g_string_append(action_str, "LINK ");
+ if (context->actions & GDK_ACTION_ASK)
+ g_string_append(action_str, "ASK ");
+
+ g_message("Xdnd actions = %s", action_str->str);
+ g_string_free (action_str, TRUE);
+ }
#endif /* G_ENABLE_DEBUG */
+
+ }
- XFree(data);
+ if (data)
+ XFree (data);
+
+ gdk_error_trap_pop ();
}
+ else
+ {
+ /* Local drag
+ */
+ GdkDragContext *source_context;
- gdk_error_trap_pop ();
+ source_context = gdk_drag_context_find (display, TRUE,
+ GDK_DRAWABLE_XID (context->source_window),
+ GDK_DRAWABLE_XID (context->dest_window));
+
+ if (source_context)
+ {
+ context->actions = source_context->actions;
+ PRIVATE_DATA (context)->xdnd_have_actions = TRUE;
+ }
+ }
}
/* We have to make sure that the XdndActionList we keep internally
GdkWindow *window,
gboolean add_filter)
{
- gdk_error_trap_push ();
-
- if (!GDK_WINDOW_DESTROYED (window))
+ if (!GDK_WINDOW_DESTROYED (window) &&
+ gdk_window_get_window_type (window) == GDK_WINDOW_FOREIGN)
{
+ gdk_error_trap_push ();
+
if (add_filter)
{
gdk_window_set_events (window,
gdk_window_get_events (window) |
GDK_PROPERTY_CHANGE_MASK);
gdk_window_add_filter (window, xdnd_source_window_filter, context);
-
}
else
{
* INCR selection transactions).
*/
}
+
+ gdk_display_sync (gdk_drawable_get_display (window));
+ gdk_error_trap_pop ();
}
+}
+
+static void
+base_precache_atoms (GdkDisplay *display)
+{
+ GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
- gdk_display_sync (gdk_drawable_get_display (window));
- gdk_error_trap_pop ();
+ if (!display_x11->base_dnd_atoms_precached)
+ {
+ static const char *const precache_atoms[] = {
+ "ENLIGHTENMENT_DESKTOP",
+ "WM_STATE",
+ "XdndAware",
+ "XdndProxy",
+ "_MOTIF_DRAG_RECEIVER_INFO"
+ };
+
+ _gdk_x11_precache_atoms (display,
+ precache_atoms, G_N_ELEMENTS (precache_atoms));
+
+ display_x11->base_dnd_atoms_precached = TRUE;
+ }
+}
+
+static void
+xdnd_precache_atoms (GdkDisplay *display)
+{
+ GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
+
+ if (!display_x11->xdnd_atoms_precached)
+ {
+ static const char *const precache_atoms[] = {
+ "XdndActionAsk",
+ "XdndActionCopy",
+ "XdndActionLink",
+ "XdndActionList",
+ "XdndActionMove",
+ "XdndActionPrivate",
+ "XdndDrop",
+ "XdndEnter",
+ "XdndFinished",
+ "XdndLeave",
+ "XdndPosition",
+ "XdndSelection",
+ "XdndStatus",
+ "XdndTypeList"
+ };
+
+ _gdk_x11_precache_atoms (display,
+ precache_atoms, G_N_ELEMENTS (precache_atoms));
+
+ display_x11->xdnd_atoms_precached = TRUE;
+ }
}
static GdkFilterReturn
Atom type;
int format;
gulong nitems, after;
- Atom *data;
+ guchar *data;
+ Atom *atoms;
guint32 source_window;
gboolean get_types;
display = GDK_DRAWABLE_DISPLAY (event->any.window);
display_x11 = GDK_DISPLAY_X11 (display);
+ xdnd_precache_atoms (display);
+
GDK_NOTE (DND,
g_message ("XdndEnter: source_window: %#x, version: %#x",
source_window, version));
- if (version != 3)
+ if (version < 3)
{
/* Old source ignore */
GDK_NOTE (DND, g_message ("Ignored old XdndEnter message"));
new_context = gdk_drag_context_new ();
new_context->protocol = GDK_DRAG_PROTO_XDND;
- new_context->is_source = FALSE;
+ PRIVATE_DATA(new_context)->version = version;
new_context->source_window = gdk_window_lookup_for_display (display, source_window);
if (new_context->source_window)
gdk_x11_get_xatom_by_name_for_display (display, "XdndTypeList"),
0, 65536,
False, XA_ATOM, &type, &format, &nitems,
- &after, (guchar **)&data);
+ &after, &data);
if (gdk_error_trap_pop () || (format != 32) || (type != XA_ATOM))
{
g_object_unref (new_context);
+
+ if (data)
+ XFree (data);
+
return GDK_FILTER_REMOVE;
}
+ atoms = (Atom *)data;
+
for (i=0; i<nitems; i++)
new_context->targets =
g_list_append (new_context->targets,
GDK_ATOM_TO_POINTER (gdk_x11_xatom_to_atom_for_display (display,
- data[i])));
+ atoms[i])));
- XFree(data);
+ XFree(atoms);
}
else
{
display_x11->current_dest_drag = new_context;
- (PRIVATE_DATA (new_context))->xdnd_selection =
- gdk_x11_get_xatom_by_name_for_display (display, "XdndSelection");
return GDK_FILTER_TRANSLATE;
}
{
XEvent *xevent = (XEvent *)xev;
guint32 source_window = xevent->xclient.data.l[0];
+ GdkDisplay *display;
GdkDisplayX11 *display_x11;
if (!event->any.window ||
g_message ("XdndLeave: source_window: %#x",
source_window));
- display_x11 = GDK_DISPLAY_X11 (GDK_DRAWABLE_DISPLAY (event->any.window));
+ display = GDK_DRAWABLE_DISPLAY (event->any.window);
+ display_x11 = GDK_DISPLAY_X11 (display);
+
+ xdnd_precache_atoms (display);
if ((display_x11->current_dest_drag != NULL) &&
(display_x11->current_dest_drag->protocol == GDK_DRAG_PROTO_XDND) &&
display = GDK_DRAWABLE_DISPLAY (event->any.window);
display_x11 = GDK_DISPLAY_X11 (display);
+ xdnd_precache_atoms (display);
+
if ((display_x11->current_dest_drag != NULL) &&
(display_x11->current_dest_drag->protocol == GDK_DRAG_PROTO_XDND) &&
(GDK_DRAWABLE_XID (display_x11->current_dest_drag->source_window) == source_window))
XEvent *xevent = (XEvent *)xev;
guint32 source_window = xevent->xclient.data.l[0];
guint32 time = xevent->xclient.data.l[2];
+ GdkDisplay *display;
GdkDisplayX11 *display_x11;
if (!event->any.window ||
g_message ("XdndDrop: source_window: %#x time: %d",
source_window, time));
- display_x11 = GDK_DISPLAY_X11 (GDK_DRAWABLE_DISPLAY (event->any.window));
+ display = GDK_DRAWABLE_DISPLAY (event->any.window);
+ display_x11 = GDK_DISPLAY_X11 (display);
+
+ xdnd_precache_atoms (display);
if ((display_x11->current_dest_drag != NULL) &&
(display_x11->current_dest_drag->protocol == GDK_DRAG_PROTO_XDND) &&
event->dnd.time = time;
event->dnd.x_root = private->last_x;
event->dnd.y_root = private->last_y;
+
+ gdk_x11_window_set_user_time (event->any.window, time);
return GDK_FILTER_TRANSLATE;
}
gdk_display_add_client_message_filter (
display,
- gdk_atom_intern ("_MOTIF_DRAG_AND_DROP_MESSAGE", FALSE),
+ gdk_atom_intern_static_string ("_MOTIF_DRAG_AND_DROP_MESSAGE"),
motif_dnd_filter, NULL);
for (i = 0; i < G_N_ELEMENTS (xdnd_filters); i++)
{
gdk_display_add_client_message_filter (
display,
- gdk_atom_intern (xdnd_filters[i].atom_name, FALSE),
+ gdk_atom_intern_static_string (xdnd_filters[i].atom_name),
xdnd_filters[i].func, NULL);
}
}
GdkDragContext *new_context;
g_return_val_if_fail (window != NULL, NULL);
+ g_return_val_if_fail (GDK_WINDOW_IS_X11 (window), NULL);
new_context = gdk_drag_context_new ();
new_context->is_source = TRUE;
g_object_ref (window);
new_context->targets = g_list_copy (targets);
+ precache_target_list (new_context);
+
new_context->actions = 0;
return new_context;
}
-/**
- * gdk_drag_get_protocol_for_display:
- * @display: the #GdkDisplay where the destination window resides
- * @xid: the X id of the destination window.
- * @protocol: location where the supported DND protocol is returned.
- * @returns: the X id of the window where the drop should happen. This
- * may be @xid or the X id of a proxy window, or None if @xid doesn't
- * support Drag and Drop.
- *
- * Finds out the DND protocol supported by a window.
- *
- * Since: 2.2
- */
-guint32
-gdk_drag_get_protocol_for_display (GdkDisplay *display,
- guint32 xid,
- GdkDragProtocol *protocol)
+static GdkNativeWindow
+_gdk_drag_get_protocol_for_display (GdkDisplay *display,
+ GdkNativeWindow xid,
+ GdkDragProtocol *protocol,
+ guint *version)
+
{
- guint32 retval;
+ GdkWindow *window;
+ GdkNativeWindow retval;
g_return_val_if_fail (GDK_IS_DISPLAY (display), None);
-
- if ((retval = xdnd_check_dest (display, xid)))
+
+ base_precache_atoms (display);
+
+ /* Check for a local drag
+ */
+ window = gdk_window_lookup_for_display (display, xid);
+ if (window &&
+ gdk_window_get_window_type (window) != GDK_WINDOW_FOREIGN)
+ {
+ if (g_object_get_data (G_OBJECT (window), "gdk-dnd-registered") != NULL)
+ {
+ *protocol = GDK_DRAG_PROTO_XDND;
+ *version = 5;
+ xdnd_precache_atoms (display);
+ GDK_NOTE (DND, g_message ("Entering local Xdnd window %#x\n", xid));
+ return xid;
+ }
+ else if (_gdk_x11_display_is_root_window (display, (Window) xid))
+ {
+ *protocol = GDK_DRAG_PROTO_ROOTWIN;
+ GDK_NOTE (DND, g_message ("Entering root window\n"));
+ return xid;
+ }
+ }
+ else if ((retval = xdnd_check_dest (display, xid, version)))
{
*protocol = GDK_DRAG_PROTO_XDND;
- GDK_NOTE (DND, g_message ("Entering dnd window %#x\n", xid));
+ xdnd_precache_atoms (display);
+ GDK_NOTE (DND, g_message ("Entering Xdnd window %#x\n", xid));
return retval;
}
else if ((retval = motif_check_dest (display, xid)))
0, 0, False, AnyPropertyType,
&type, &format, &nitems, &data) &&
type != None)
- rootwin = TRUE;
+ {
+ XFree (data);
+ rootwin = TRUE;
+ }
}
#endif
if (rootwin)
{
+ GDK_NOTE (DND, g_message ("Entering root window\n"));
*protocol = GDK_DRAG_PROTO_ROOTWIN;
return xid;
}
}
*protocol = GDK_DRAG_PROTO_NONE;
- return None;
+
+ return 0; /* a.k.a. None */
+}
+
+/**
+ * gdk_drag_get_protocol_for_display:
+ * @display: the #GdkDisplay where the destination window resides
+ * @xid: the windowing system id of the destination window.
+ * @protocol: location where the supported DND protocol is returned.
+ * @returns: the windowing system id of the window where the drop should happen. This
+ * may be @xid or the id of a proxy window, or zero if @xid doesn't
+ * support Drag and Drop.
+ *
+ * Finds out the DND protocol supported by a window.
+ *
+ * Since: 2.2
+ */
+GdkNativeWindow
+gdk_drag_get_protocol_for_display (GdkDisplay *display,
+ GdkNativeWindow xid,
+ GdkDragProtocol *protocol)
+{
+ return _gdk_drag_get_protocol_for_display (display, xid, protocol, NULL);
}
static GdkWindowCache *
* @screen: the screen where the destination window is sought.
* @x_root: the x position of the pointer in root coordinates.
* @y_root: the y position of the pointer in root coordinates.
- * @dest_window: location to store the destination window in.
- * @protocol: location to store the DND protocol in.
- *
+ * @dest_window: (out): location to store the destination window in.
+ * @protocol: (out): location to store the DND protocol in.
+ *
* Finds the destination window and DND protocol to use at the
- * given pointer position.
+ * given pointer position.
*
* This function is called by the drag source to obtain the
* @dest_window and @protocol parameters for gdk_drag_motion().
window_cache = drag_context_find_window_cache (context, screen);
dest = get_client_window_at_coords (window_cache,
- drag_window ?
+ drag_window && GDK_WINDOW_IS_X11 (drag_window) ?
GDK_DRAWABLE_XID (drag_window) : None,
x_root, y_root);
* two are passed explicitely, the third implicitly through
* protocol->dest_xid.
*/
- if ((recipient = gdk_drag_get_protocol_for_display (display, dest, protocol)))
+ if ((recipient = _gdk_drag_get_protocol_for_display (display, dest,
+ protocol, &private->version)))
{
*dest_window = gdk_window_lookup_for_display (display, recipient);
if (*dest_window)
GdkDragContextPrivateX11 *private = PRIVATE_DATA (context);
g_return_val_if_fail (context != NULL, FALSE);
+ g_return_val_if_fail (dest_window == NULL || GDK_WINDOW_IS_X11 (dest_window), FALSE);
- /* When we have a Xdnd target, make sure our XdndActionList
- * matches the current actions;
- */
private->old_actions = context->actions;
context->actions = possible_actions;
- if ((protocol == GDK_DRAG_PROTO_XDND) &&
- (!private->xdnd_actions_set ||
- private->xdnd_actions != possible_actions))
- xdnd_set_actions (context);
+ if (private->old_actions != possible_actions)
+ private->xdnd_actions_set = FALSE;
+
+ if (protocol == GDK_DRAG_PROTO_XDND && private->version == 0)
+ {
+ /* This ugly hack is necessary since GTK+ doesn't know about
+ * the XDND protocol version, and in particular doesn't know
+ * that gdk_drag_find_window_for_screen() has the side-effect
+ * of setting private->version, and therefore sometimes call
+ * gdk_drag_motion() without a prior call to
+ * gdk_drag_find_window_for_screen(). This happens, e.g.
+ * when GTK+ is proxying DND events to embedded windows.
+ */
+ if (dest_window)
+ {
+ GdkDisplay *display = GDK_WINDOW_DISPLAY (dest_window);
+
+ xdnd_check_dest (display,
+ GDK_DRAWABLE_XID (dest_window),
+ &private->version);
+ }
+ }
+
+ /* When we have a Xdnd target, make sure our XdndActionList
+ * matches the current actions;
+ */
+ if (protocol == GDK_DRAG_PROTO_XDND && !private->xdnd_actions_set)
+ {
+ if (dest_window)
+ {
+ if (gdk_window_get_window_type (dest_window) == GDK_WINDOW_FOREIGN)
+ xdnd_set_actions (context);
+ else if (context->dest_window == dest_window)
+ {
+ GdkDisplay *display = GDK_WINDOW_DISPLAY (dest_window);
+ GdkDragContext *dest_context;
+
+ dest_context = gdk_drag_context_find (display, FALSE,
+ GDK_DRAWABLE_XID (context->source_window),
+ GDK_DRAWABLE_XID (dest_window));
+
+ if (dest_context)
+ {
+ dest_context->actions = context->actions;
+ PRIVATE_DATA (dest_context)->xdnd_have_actions = TRUE;
+ }
+ }
+ }
+ }
if (context->dest_window != dest_window)
{
/* GTK+ traditionally has used application/x-rootwin-drop,
* but the XDND spec specifies x-rootwindow-drop.
*/
- GdkAtom target1 = gdk_atom_intern ("application/x-rootwindow-drop", FALSE);
- GdkAtom target2 = gdk_atom_intern ("application/x-rootwin-drop", FALSE);
+ GdkAtom target1 = gdk_atom_intern_static_string ("application/x-rootwindow-drop");
+ GdkAtom target2 = gdk_atom_intern_static_string ("application/x-rootwin-drop");
if (g_list_find (context->targets,
GDK_ATOM_TO_POINTER (target1)) ||
xev.xclient.window = GDK_DRAWABLE_XID (context->source_window);
xev.xclient.data.l[0] = GDK_DRAWABLE_XID (context->dest_window);
- xev.xclient.data.l[1] = 0;
- xev.xclient.data.l[2] = 0;
+ if (success)
+ {
+ xev.xclient.data.l[1] = 1;
+ xev.xclient.data.l[2] = xdnd_action_to_atom (display,
+ context->action);
+ }
+ else
+ {
+ xev.xclient.data.l[1] = 0;
+ xev.xclient.data.l[2] = None;
+ }
xev.xclient.data.l[3] = 0;
xev.xclient.data.l[4] = 0;
void
gdk_window_register_dnd (GdkWindow *window)
{
- static gulong xdnd_version = 3;
+ static const gulong xdnd_version = 5;
MotifDragReceiverInfo info;
Atom motif_drag_receiver_info_atom;
GdkDisplay *display = gdk_drawable_get_display (window);
g_return_if_fail (window != NULL);
- if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (window), "gdk-dnd-registered")))
+ base_precache_atoms (display);
+
+ if (g_object_get_data (G_OBJECT (window), "gdk-dnd-registered") != NULL)
return;
else
g_object_set_data (G_OBJECT (window), "gdk-dnd-registered", GINT_TO_POINTER (TRUE));
motif_drag_receiver_info_atom = gdk_x11_get_xatom_by_name_for_display (display,
"_MOTIF_DRAG_RECEIVER_INFO");
+ /* initialize to zero to avoid writing uninitialized data to socket */
+ memset(&info, 0, sizeof(info));
info.byte_order = local_byte_order;
info.protocol_version = 0;
info.protocol_style = XmDRAG_DYNAMIC;
return gdk_x11_xatom_to_atom_for_display (GDK_DRAWABLE_DISPLAY (context->source_window),
(PRIVATE_DATA (context))->motif_selection);
else if (context->protocol == GDK_DRAG_PROTO_XDND)
- return gdk_x11_xatom_to_atom_for_display (GDK_DRAWABLE_DISPLAY (context->source_window),
- (PRIVATE_DATA (context))->xdnd_selection);
+ return gdk_atom_intern_static_string ("XdndSelection");
else
return GDK_NONE;
}
+/**
+ * gdk_drag_drop_succeeded:
+ * @context: a #GdkDragContext
+ *
+ * Returns whether the dropped data has been successfully
+ * transferred. This function is intended to be used while
+ * handling a %GDK_DROP_FINISHED event, its return value is
+ * meaningless at other times.
+ *
+ * Return value: %TRUE if the drop was successful.
+ *
+ * Since: 2.6
+ **/
+gboolean
+gdk_drag_drop_succeeded (GdkDragContext *context)
+{
+ GdkDragContextPrivateX11 *private;
+
+ g_return_val_if_fail (context != NULL, FALSE);
+
+ private = PRIVATE_DATA (context);
+
+ return !private->drop_failed;
+}
+
+#define __GDK_DND_X11_C__
+#include "gdkaliasdef.c"