forked from AuroraMiddleware/gtk
dnd: Make GdkDragContext::device a (construct-only) property
Also remove gdk_drag_context_set_device() and insist on backends using the property.
This commit is contained in:
parent
a86359af2b
commit
4aaeb7de19
@ -84,7 +84,7 @@ gdk_broadway_drag_context_finalize (GObject *object)
|
||||
/* Drag Contexts */
|
||||
|
||||
GdkDragContext *
|
||||
_gdk_broadway_surface_drag_begin (GdkSurface *surface,
|
||||
_gdk_broadway_surface_drag_begin (GdkSurface *surface,
|
||||
GdkDevice *device,
|
||||
GdkContentProvider *content,
|
||||
GdkDragAction actions,
|
||||
@ -97,7 +97,7 @@ _gdk_broadway_surface_drag_begin (GdkSurface *surface,
|
||||
g_return_val_if_fail (GDK_SURFACE_IS_BROADWAY (surface), NULL);
|
||||
|
||||
new_context = g_object_new (GDK_TYPE_BROADWAY_DRAG_CONTEXT,
|
||||
"display", gdk_surface_get_display (surface),
|
||||
"device", device,
|
||||
"content", content,
|
||||
NULL);
|
||||
|
||||
|
56
gdk/gdkdnd.c
56
gdk/gdkdnd.c
@ -51,6 +51,7 @@ static struct {
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_CONTENT,
|
||||
PROP_DEVICE,
|
||||
PROP_DISPLAY,
|
||||
PROP_FORMATS,
|
||||
N_PROPERTIES
|
||||
@ -202,30 +203,6 @@ gdk_drag_context_get_dest_surface (GdkDragContext *context)
|
||||
return context->dest_surface;
|
||||
}
|
||||
|
||||
/**
|
||||
* gdk_drag_context_set_device:
|
||||
* @context: a #GdkDragContext
|
||||
* @device: a #GdkDevice
|
||||
*
|
||||
* Associates a #GdkDevice to @context, so all Drag and Drop events
|
||||
* for @context are emitted as if they came from this device.
|
||||
*/
|
||||
void
|
||||
gdk_drag_context_set_device (GdkDragContext *context,
|
||||
GdkDevice *device)
|
||||
{
|
||||
g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
|
||||
g_return_if_fail (GDK_IS_DEVICE (device));
|
||||
|
||||
if (context->device)
|
||||
g_object_unref (context->device);
|
||||
|
||||
context->device = device;
|
||||
|
||||
if (context->device)
|
||||
g_object_ref (context->device);
|
||||
}
|
||||
|
||||
/**
|
||||
* gdk_drag_context_get_device:
|
||||
* @context: a #GdkDragContext
|
||||
@ -266,9 +243,10 @@ gdk_drag_context_set_property (GObject *gobject,
|
||||
context->formats = gdk_content_provider_ref_formats (context->content);
|
||||
break;
|
||||
|
||||
case PROP_DISPLAY:
|
||||
context->display = g_value_get_object (value);
|
||||
g_assert (context->display != NULL);
|
||||
case PROP_DEVICE:
|
||||
context->device = g_value_dup_object (value);
|
||||
g_assert (context->device != NULL);
|
||||
context->display = gdk_device_get_display (context->device);
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -291,6 +269,10 @@ gdk_drag_context_get_property (GObject *gobject,
|
||||
g_value_set_object (value, context->content);
|
||||
break;
|
||||
|
||||
case PROP_DEVICE:
|
||||
g_value_set_object (value, context->device);
|
||||
break;
|
||||
|
||||
case PROP_DISPLAY:
|
||||
g_value_set_object (value, context->display);
|
||||
break;
|
||||
@ -383,6 +365,21 @@ gdk_drag_context_class_init (GdkDragContextClass *klass)
|
||||
G_PARAM_STATIC_STRINGS |
|
||||
G_PARAM_EXPLICIT_NOTIFY);
|
||||
|
||||
/**
|
||||
* GdkDragContext:display:
|
||||
*
|
||||
* The #GdkDevice that is performing the drag.
|
||||
*/
|
||||
properties[PROP_DEVICE] =
|
||||
g_param_spec_object ("device",
|
||||
"Device",
|
||||
"The device performing the drag",
|
||||
GDK_TYPE_DEVICE,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS |
|
||||
G_PARAM_EXPLICIT_NOTIFY);
|
||||
|
||||
/**
|
||||
* GdkDragContext:display:
|
||||
*
|
||||
@ -391,10 +388,9 @@ gdk_drag_context_class_init (GdkDragContextClass *klass)
|
||||
properties[PROP_DISPLAY] =
|
||||
g_param_spec_object ("display",
|
||||
"Display",
|
||||
"Display owning this clipboard",
|
||||
"Display this drag belongs to",
|
||||
GDK_TYPE_DISPLAY,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_READABLE |
|
||||
G_PARAM_STATIC_STRINGS |
|
||||
G_PARAM_EXPLICIT_NOTIFY);
|
||||
|
||||
|
@ -102,8 +102,6 @@ struct _GdkDragContext {
|
||||
guint drop_done : 1; /* Whether gdk_drag_drop_done() was performed */
|
||||
};
|
||||
|
||||
void gdk_drag_context_set_device (GdkDragContext *context,
|
||||
GdkDevice *device);
|
||||
void gdk_drag_context_set_cursor (GdkDragContext *context,
|
||||
GdkCursor *cursor);
|
||||
void gdk_drag_context_cancel (GdkDragContext *context,
|
||||
|
@ -584,16 +584,13 @@ update_context_from_dragging_info (id <NSDraggingInfo> sender)
|
||||
if (current_context)
|
||||
g_object_unref (current_context);
|
||||
|
||||
current_context = g_object_new (GDK_TYPE_QUARTZ_DRAG_CONTEXT, NULL);
|
||||
current_context = g_object_new (GDK_TYPE_QUARTZ_DRAG_CONTEXT,
|
||||
"device", gdk_seat_get_pointer (gdk_display_get_default_seat (current_context->display)),
|
||||
NULL);
|
||||
update_context_from_dragging_info (sender);
|
||||
|
||||
window = [[self contentView] gdkSurface];
|
||||
|
||||
current_context->display = gdk_surface_get_display (window);
|
||||
|
||||
gdk_drag_context_set_device (current_context,
|
||||
gdk_seat_get_pointer (gdk_display_get_default_seat (current_context->display)));
|
||||
|
||||
event = gdk_event_new (GDK_DRAG_ENTER);
|
||||
event->dnd.window = g_object_ref (window);
|
||||
event->dnd.send_event = FALSE;
|
||||
|
@ -44,7 +44,7 @@ _gdk_quartz_surface_drag_begin (GdkSurface *window,
|
||||
|
||||
/* Create fake context */
|
||||
_gdk_quartz_drag_source_context = g_object_new (GDK_TYPE_QUARTZ_DRAG_CONTEXT,
|
||||
"display", display,
|
||||
"device", device,
|
||||
NULL);
|
||||
_gdk_quartz_drag_source_context->is_source = TRUE;
|
||||
|
||||
@ -53,8 +53,6 @@ _gdk_quartz_surface_drag_begin (GdkSurface *window,
|
||||
|
||||
_gdk_quartz_drag_source_context->targets = targets;
|
||||
|
||||
gdk_drag_context_set_device (_gdk_quartz_drag_source_context, device);
|
||||
|
||||
return _gdk_quartz_drag_source_context;
|
||||
}
|
||||
|
||||
|
@ -1078,6 +1078,7 @@ data_device_enter (void *data,
|
||||
{
|
||||
GdkWaylandSeat *seat = data;
|
||||
GdkSurface *dest_surface, *dnd_owner;
|
||||
GdkDevice *device;
|
||||
|
||||
dest_surface = wl_surface_get_user_data (surface);
|
||||
|
||||
@ -1093,12 +1094,17 @@ data_device_enter (void *data,
|
||||
seat->pointer_info.surface_x = wl_fixed_to_double (x);
|
||||
seat->pointer_info.surface_y = wl_fixed_to_double (y);
|
||||
|
||||
seat->drop_context = _gdk_wayland_drop_context_new (seat->display,
|
||||
seat->data_device);
|
||||
if (seat->master_pointer)
|
||||
gdk_drag_context_set_device (seat->drop_context, seat->master_pointer);
|
||||
device = seat->master_pointer;
|
||||
else if (seat->touch_master)
|
||||
gdk_drag_context_set_device (seat->drop_context, seat->touch_master);
|
||||
device = seat->touch_master;
|
||||
else
|
||||
{
|
||||
g_warning ("No device for DND enter, ignoring.");
|
||||
return;
|
||||
}
|
||||
seat->drop_context = _gdk_wayland_drop_context_new (device,
|
||||
seat->data_device);
|
||||
|
||||
gdk_wayland_drop_context_update_targets (seat->drop_context);
|
||||
|
||||
|
@ -494,15 +494,13 @@ _gdk_wayland_surface_drag_begin (GdkSurface *surface,
|
||||
display_wayland = GDK_WAYLAND_DISPLAY (gdk_device_get_display (device));
|
||||
|
||||
context_wayland = g_object_new (GDK_TYPE_WAYLAND_DRAG_CONTEXT,
|
||||
"display", display_wayland,
|
||||
"device", device,
|
||||
"content", content,
|
||||
NULL);
|
||||
context = GDK_DRAG_CONTEXT (context_wayland);
|
||||
context->source_surface = g_object_ref (surface);
|
||||
context->is_source = TRUE;
|
||||
|
||||
gdk_drag_context_set_device (context, device);
|
||||
|
||||
context_wayland->dnd_surface = create_dnd_surface (gdk_surface_get_display (surface));
|
||||
context_wayland->dnd_wl_surface = gdk_wayland_surface_get_wl_surface (context_wayland->dnd_surface);
|
||||
context_wayland->data_source =
|
||||
@ -534,14 +532,14 @@ _gdk_wayland_surface_drag_begin (GdkSurface *surface,
|
||||
|
||||
|
||||
GdkDragContext *
|
||||
_gdk_wayland_drop_context_new (GdkDisplay *display,
|
||||
_gdk_wayland_drop_context_new (GdkDevice *device,
|
||||
struct wl_data_device *data_device)
|
||||
{
|
||||
GdkWaylandDragContext *context_wayland;
|
||||
GdkDragContext *context;
|
||||
|
||||
context_wayland = g_object_new (GDK_TYPE_WAYLAND_DRAG_CONTEXT,
|
||||
"display", display,
|
||||
"device", device,
|
||||
NULL);
|
||||
context = GDK_DRAG_CONTEXT (context_wayland);
|
||||
context->is_source = FALSE;
|
||||
|
@ -104,7 +104,7 @@ GdkDragContext *_gdk_wayland_surface_drag_begin (GdkSurface *surface,
|
||||
void _gdk_wayland_surface_offset_next_wl_buffer (GdkSurface *surface,
|
||||
int x,
|
||||
int y);
|
||||
GdkDragContext * _gdk_wayland_drop_context_new (GdkDisplay *display,
|
||||
GdkDragContext * _gdk_wayland_drop_context_new (GdkDevice *device,
|
||||
struct wl_data_device *data_device);
|
||||
void _gdk_wayland_drag_context_set_source_surface (GdkDragContext *context,
|
||||
GdkSurface *surface);
|
||||
|
@ -248,11 +248,10 @@ gdk_drag_context_new (GdkDisplay *display,
|
||||
GdkDragContext *context;
|
||||
|
||||
context_win32 = g_object_new (GDK_TYPE_WIN32_DRAG_CONTEXT,
|
||||
"display", display,
|
||||
"device", device ? device : gdk_seat_get_pointer (gdk_display_get_default_seat (display)),
|
||||
NULL);
|
||||
context = GDK_DRAG_CONTEXT(context_win32);
|
||||
|
||||
gdk_drag_context_set_device (context, device ? device : gdk_seat_get_pointer (gdk_display_get_default_seat (display)));
|
||||
|
||||
if (win32_display->has_fixed_scale)
|
||||
context_win32->scale = win32_display->surface_scale;
|
||||
|
@ -811,14 +811,12 @@ gdk_drag_context_new (GdkDisplay *display,
|
||||
GdkDragContext *context;
|
||||
|
||||
context_win32 = g_object_new (GDK_TYPE_WIN32_DRAG_CONTEXT,
|
||||
"display", display,
|
||||
"device", device ? device : gdk_seat_get_pointer (gdk_display_get_default_seat (display)),
|
||||
"content", content,
|
||||
NULL);
|
||||
|
||||
context = GDK_DRAG_CONTEXT (context_win32);
|
||||
|
||||
gdk_drag_context_set_device (context, device ? device : gdk_seat_get_pointer (gdk_display_get_default_seat (display)));
|
||||
|
||||
if (win32_display->has_fixed_scale)
|
||||
context_win32->scale = win32_display->surface_scale;
|
||||
else
|
||||
|
@ -141,13 +141,11 @@ gdk_drop_context_new (GdkDisplay *display,
|
||||
GdkDragContext *context;
|
||||
|
||||
context_win32 = g_object_new (GDK_TYPE_WIN32_DROP_CONTEXT,
|
||||
"display", display,
|
||||
"device", gdk_seat_get_pointer (gdk_display_get_default_seat (display)),
|
||||
NULL);
|
||||
|
||||
context = GDK_DRAG_CONTEXT (context_win32);
|
||||
|
||||
gdk_drag_context_set_device (context, gdk_seat_get_pointer (gdk_display_get_default_seat (display)));
|
||||
|
||||
if (win32_display->has_fixed_scale)
|
||||
context_win32->scale = win32_display->surface_scale;
|
||||
else
|
||||
|
@ -1776,8 +1776,9 @@ xdnd_enter_filter (const XEvent *xevent,
|
||||
display_x11->current_dest_drag = NULL;
|
||||
}
|
||||
|
||||
seat = gdk_display_get_default_seat (display);
|
||||
context_x11 = g_object_new (GDK_TYPE_X11_DRAG_CONTEXT,
|
||||
"display", display,
|
||||
"device", gdk_seat_get_pointer (seat),
|
||||
NULL);
|
||||
context = (GdkDragContext *)context_x11;
|
||||
|
||||
@ -1785,8 +1786,6 @@ xdnd_enter_filter (const XEvent *xevent,
|
||||
context_x11->version = version;
|
||||
|
||||
/* FIXME: Should extend DnD protocol to have device info */
|
||||
seat = gdk_display_get_default_seat (display);
|
||||
gdk_drag_context_set_device (context, gdk_seat_get_pointer (seat));
|
||||
|
||||
context->source_surface = gdk_x11_surface_foreign_new_for_display (display, source_surface);
|
||||
if (!context->source_surface)
|
||||
@ -2957,7 +2956,7 @@ _gdk_x11_surface_drag_begin (GdkSurface *surface,
|
||||
display = gdk_surface_get_display (surface);
|
||||
|
||||
context = (GdkDragContext *) g_object_new (GDK_TYPE_X11_DRAG_CONTEXT,
|
||||
"display", display,
|
||||
"device", device,
|
||||
"content", content,
|
||||
NULL);
|
||||
x11_context = GDK_X11_DRAG_CONTEXT (context);
|
||||
@ -2968,7 +2967,6 @@ _gdk_x11_surface_drag_begin (GdkSurface *surface,
|
||||
|
||||
precache_target_list (context);
|
||||
|
||||
gdk_drag_context_set_device (context, device);
|
||||
gdk_device_get_position (device, &x_root, &y_root);
|
||||
x_root += dx;
|
||||
y_root += dy;
|
||||
|
@ -411,7 +411,7 @@ test_type (gconstpointer data)
|
||||
else if (g_str_equal (g_type_name (type), "GdkClipboard"))
|
||||
instance = g_object_new (type, "display", display, NULL);
|
||||
else if (g_str_equal (g_type_name (type), "GdkDragContext"))
|
||||
instance = g_object_new (type, "display", display, NULL);
|
||||
instance = g_object_new (type, "device", gdk_seat_get_pointer (gdk_display_get_default_seat (gdk_display_get_default ())), NULL);
|
||||
else
|
||||
instance = g_object_new (type, NULL);
|
||||
|
||||
|
@ -52,11 +52,12 @@ test_finalize_object (gconstpointer data)
|
||||
GType test_type = GPOINTER_TO_SIZE (data);
|
||||
GObject *object;
|
||||
|
||||
if (g_str_equal (g_type_name (test_type), "GdkClipboard") ||
|
||||
g_str_equal (g_type_name (test_type), "GdkDragContext"))
|
||||
if (g_str_equal (g_type_name (test_type), "GdkClipboard"))
|
||||
object = g_object_new (test_type, "display", gdk_display_get_default (), NULL);
|
||||
else if (g_str_equal (g_type_name (test_type), "GdkDragContext"))
|
||||
object = g_object_new (test_type, "device", gdk_seat_get_pointer (gdk_display_get_default_seat (gdk_display_get_default ())), NULL);
|
||||
else
|
||||
object = g_object_new (test_type, NULL);
|
||||
object = g_object_new (test_type, NULL);
|
||||
g_assert (G_IS_OBJECT (object));
|
||||
|
||||
/* Make sure we have the only reference */
|
||||
|
Loading…
Reference in New Issue
Block a user