drop: Add GdkDrop:surface property

This replaces gdk_drag_context_get_dest_surface().
This commit is contained in:
Benjamin Otte 2018-05-23 18:30:14 +02:00
parent 4aedf3d003
commit 05bf87cf14
7 changed files with 66 additions and 22 deletions

View File

@ -36,6 +36,7 @@ struct _GdkDropPrivate {
GdkDevice *device;
GdkDragContext *drag;
GdkContentFormats *formats;
GdkSurface *surface;
GdkDragAction actions;
};
@ -46,6 +47,7 @@ enum {
PROP_DISPLAY,
PROP_DRAG,
PROP_FORMATS,
PROP_SURFACE,
N_PROPERTIES
};
@ -118,6 +120,8 @@ gdk_drop_set_property (GObject *gobject,
case PROP_DEVICE:
priv->device = g_value_dup_object (value);
g_assert (priv->device != NULL);
if (priv->surface)
g_assert (gdk_surface_get_display (priv->surface) == gdk_device_get_display (priv->device));
break;
case PROP_DRAG:
@ -131,6 +135,15 @@ gdk_drop_set_property (GObject *gobject,
#endif
break;
case PROP_SURFACE:
priv->surface = g_value_dup_object (value);
#ifdef DROP_SUBCLASS
g_assert (priv->surface != NULL);
if (priv->device)
g_assert (gdk_surface_get_display (priv->surface) == gdk_device_get_display (priv->device));
#endif
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
break;
@ -168,6 +181,10 @@ gdk_drop_get_property (GObject *gobject,
g_value_set_boxed (value, priv->formats);
break;
case PROP_SURFACE:
g_value_set_object (value, priv->surface);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
break;
@ -271,6 +288,22 @@ gdk_drop_class_init (GdkDropClass *klass)
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS |
G_PARAM_EXPLICIT_NOTIFY);
/**
* GdkDrop:surface:
*
* The #GdkSurface the drop happens on
*/
properties[PROP_SURFACE] =
g_param_spec_object ("surface",
"Surface",
"The surface the drop is happening on",
GDK_TYPE_SURFACE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS |
G_PARAM_EXPLICIT_NOTIFY);
g_object_class_install_properties (object_class, N_PROPERTIES, properties);
}
@ -334,6 +367,24 @@ gdk_drop_get_formats (GdkDrop *self)
return priv->formats;
}
/**
* gdk_drop_get_surface:
* @self: a #GdkDrop
*
* Returns the #GdkSurface performing the drop.
*
* Returns: (transfer none): The #GdkSurface performing the drop.
**/
GdkSurface *
gdk_drop_get_surface (GdkDrop *self)
{
GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
g_return_val_if_fail (GDK_IS_DROP (self), NULL);
return priv->surface;
}
/**
* gdk_drop_get_actions:
* @self: a #GdkDrop

View File

@ -44,6 +44,8 @@ GdkDisplay * gdk_drop_get_display (GdkDrop
GDK_AVAILABLE_IN_ALL
GdkDevice * gdk_drop_get_device (GdkDrop *self);
GDK_AVAILABLE_IN_ALL
GdkSurface * gdk_drop_get_surface (GdkDrop *self);
GDK_AVAILABLE_IN_ALL
GdkContentFormats * gdk_drop_get_formats (GdkDrop *self);
GDK_AVAILABLE_IN_ALL
GdkDragAction gdk_drop_get_actions (GdkDrop *self);

View File

@ -1269,14 +1269,12 @@ data_device_enter (void *data,
seat->pending_builder = NULL;
seat->pending_offer = NULL;
seat->drop_context = _gdk_wayland_drop_context_new (device, formats, offer);
seat->drop_context = _gdk_wayland_drop_context_new (device, formats, dest_surface, offer, serial);
dnd_owner = seat->foreign_dnd_surface;
_gdk_wayland_drag_context_set_source_surface (seat->drop_context, dnd_owner);
_gdk_wayland_drag_context_set_dest_surface (seat->drop_context,
dest_surface, serial);
_gdk_wayland_drag_context_set_coords (seat->drop_context,
wl_fixed_to_double (x),
wl_fixed_to_double (y));
@ -1305,7 +1303,6 @@ data_device_leave (void *data,
_gdk_wayland_drag_context_set_coords (seat->drop_context, -1, -1);
_gdk_wayland_drag_context_emit_event (seat->drop_context, GDK_DRAG_LEAVE,
GDK_CURRENT_TIME);
_gdk_wayland_drag_context_set_dest_surface (seat->drop_context, NULL, 0);
g_clear_object (&seat->drop_context);
}

View File

@ -117,7 +117,7 @@ _gdk_wayland_drag_context_emit_event (GdkDragContext *context,
if (context->is_source)
surface = gdk_drag_context_get_source_surface (context);
else
surface = gdk_drag_context_get_dest_surface (context);
surface = gdk_drop_get_surface (GDK_DROP (context));
event = gdk_event_new (type);
event->any.surface = g_object_ref (surface);
@ -494,7 +494,10 @@ _gdk_wayland_surface_drag_begin (GdkSurface *surface,
GdkDragContext *
_gdk_wayland_drop_context_new (GdkDevice *device,
GdkContentFormats *formats,
struct wl_data_offer *offer)
GdkSurface *surface,
struct wl_data_offer *offer,
uint32_t serial)
{
GdkWaylandDragContext *context_wayland;
GdkDragContext *context;
@ -502,10 +505,12 @@ _gdk_wayland_drop_context_new (GdkDevice *device,
context_wayland = g_object_new (GDK_TYPE_WAYLAND_DRAG_CONTEXT,
"device", device,
"formats", formats,
"surface", surface,
NULL);
context = GDK_DRAG_CONTEXT (context_wayland);
context->is_source = FALSE;
context_wayland->offer = offer;
context_wayland->serial = serial;
return context;
}
@ -532,18 +537,6 @@ _gdk_wayland_drag_context_set_source_surface (GdkDragContext *context,
context->source_surface = surface ? g_object_ref (surface) : NULL;
}
void
_gdk_wayland_drag_context_set_dest_surface (GdkDragContext *context,
GdkSurface *dest_surface,
uint32_t serial)
{
if (context->dest_surface)
g_object_unref (context->dest_surface);
context->dest_surface = dest_surface ? g_object_ref (dest_surface) : NULL;
GDK_WAYLAND_DRAG_CONTEXT (context)->serial = serial;
}
GdkDragContext *
gdk_wayland_drag_context_lookup_by_data_source (struct wl_data_source *source)
{

View File

@ -106,12 +106,11 @@ void _gdk_wayland_surface_offset_next_wl_buffer (GdkSurface *surface,
int y);
GdkDragContext * _gdk_wayland_drop_context_new (GdkDevice *device,
GdkContentFormats *formats,
struct wl_data_offer *offer);
GdkSurface *surface,
struct wl_data_offer *offer,
uint32_t serial);
void _gdk_wayland_drag_context_set_source_surface (GdkDragContext *context,
GdkSurface *surface);
void _gdk_wayland_drag_context_set_dest_surface (GdkDragContext *context,
GdkSurface *dest_surface,
uint32_t serial);
void _gdk_wayland_drag_context_emit_event (GdkDragContext *context,
GdkEventType type,
guint32 time_);

View File

@ -144,6 +144,7 @@ gdk_drop_context_new (GdkDisplay *display,
context_win32 = g_object_new (GDK_TYPE_WIN32_DROP_CONTEXT,
"device", gdk_seat_get_pointer (gdk_display_get_default_seat (display)),
"formats", formats,
"surface", dest_surface,
NULL);
context = GDK_DRAG_CONTEXT (context_win32);

View File

@ -1815,6 +1815,7 @@ xdnd_enter_filter (const XEvent *xevent,
context_x11 = g_object_new (GDK_TYPE_X11_DRAG_CONTEXT,
"device", gdk_seat_get_pointer (seat),
"formats", content_formats,
"surface", event->any.surface,
NULL);
context = (GdkDragContext *)context_x11;