#include "gdkinternals.h"
#include "gdkscreen-x11.h"
#include "gdkdisplay-x11.h"
+#include "gdkalias.h"
typedef struct _GdkDragContextPrivateX11 GdkDragContextPrivateX11;
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);
}
/**
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);
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,
return None;
if (has_wm_state)
- return win;
+ {
+ g_free (children);
+
+ return win;
+ }
for (i = nchildren - 1; (i >= 0) && !found_child; i--)
{
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
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;
}
if ((*xdnd_filters[i].func) (event_send, &temp_event, NULL) == GDK_FILTER_TRANSLATE)
{
gdk_event_put (&temp_event);
- g_object_unref (tmp_event.dnd.context);
+ g_object_unref (temp_event.dnd.context);
}
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;
+ 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;
gdk_x11_get_xatom_by_name_for_display (display, "XdndActionList"),
0, 65536,
False, XA_ATOM, &type, &format, &nitems,
- &after, (guchar **)&data) == Success &&
+ &after, &data) == Success &&
type == XA_ATOM)
{
+ atoms = (Atom *)data;
+
context->actions = 0;
for (i=0; i<nitems; i++)
- context->actions |= xdnd_action_from_atom (display, data[i]);
+ context->actions |= xdnd_action_from_atom (display, atoms[i]);
PRIVATE_DATA (context)->xdnd_have_actions = TRUE;
}
#endif /* G_ENABLE_DEBUG */
- XFree(data);
}
+
+ if (data)
+ XFree (data);
gdk_error_trap_pop ();
}
Atom type;
int format;
gulong nitems, after;
- Atom *data;
+ guchar *data;
+ Atom *atoms;
guint32 source_window;
gboolean get_types;
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
{
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);
}
}
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 guint32
+_gdk_drag_get_protocol_for_display (GdkDisplay *display,
+ guint32 xid,
+ GdkDragProtocol *protocol,
+ guint *version)
+
{
GdkWindow *window;
guint32 retval;
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
- return None;
+ 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;
+ }
}
-
- if ((retval = xdnd_check_dest (display, xid)))
+ else if ((retval = xdnd_check_dest (display, xid, version)))
{
*protocol = GDK_DRAG_PROTO_XDND;
xdnd_precache_atoms (display);
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;
}
return None;
}
+/**
+ * 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)
+{
+ return _gdk_drag_get_protocol_for_display (display, xid, protocol, NULL);
+}
+
static GdkWindowCache *
drag_context_find_window_cache (GdkDragContext *context,
GdkScreen *screen)
* 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)
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;
*/
/* 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);
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_atom_intern ("XdndSelection", FALSE);
+ return gdk_atom_intern_static_string ("XdndSelection");
else
return GDK_NONE;
}
+/**
+ * gdk_drag_drop_succeeded:
+ * @context: a #GdkDragContext
+ *
+ * Returns wether 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"