#include "gdkinternals.h"
#include "gdkscreen-x11.h"
#include "gdkdisplay-x11.h"
+#include "gdkalias.h"
typedef struct _GdkDragContextPrivateX11 GdkDragContextPrivateX11;
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
event->dnd.context = context;
g_object_ref (context);
+ event->dnd.time = GDK_CURRENT_TIME; /* FIXME? */
+
return GDK_FILTER_TRANSLATE;
}
static guint32
xdnd_check_dest (GdkDisplay *display,
Window win,
- gint *xdnd_version)
+ 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;
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)
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;
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);
}
}
_gdk_drag_get_protocol_for_display (GdkDisplay *display,
guint32 xid,
GdkDragProtocol *protocol,
- gint *version)
+ guint *version)
{
GdkWindow *window;
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, version)))
+ 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;
}
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.data.l[0] = GDK_DRAWABLE_XID (context->dest_window);
if (success)
{
- g_print ("sending back success status; version %d\n",
- PRIVATE_DATA (context)->version);
xev.xclient.data.l[1] = 1;
xev.xclient.data.l[2] = xdnd_action_to_atom (display,
context->action);
void
gdk_window_register_dnd (GdkWindow *window)
{
- static gulong xdnd_version = 5;
+ 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;
}
return !private->drop_failed;
}
+
+#define __GDK_DND_X11_C__
+#include "gdkaliasdef.c"