1
0
Fork 0

wayland: Flatten data source object hierarchy

We have an abstract MetaWaylandDataSource and 2 subclasses for
clipboard/primary data sources. Since the abstraction provided
by the additional sublevel is arguable, push the wl_resource
field up, and leave us with just 2 objects to think about, all
of them containing a wl_resource.

https://gitlab.gnome.org/GNOME/mutter/issues/878
This commit is contained in:
Carlos Garnacho 2019-10-23 13:09:21 +02:00
parent 95eda361c1
commit c11ef6ef07
2 changed files with 107 additions and 128 deletions

View file

@ -25,16 +25,10 @@
#ifndef META_WAYLAND_DATA_DEVICE_PRIVATE_H
#define META_WAYLAND_DATA_DEVICE_PRIVATE_H
#define META_TYPE_WAYLAND_DATA_SOURCE_WAYLAND (meta_wayland_data_source_wayland_get_type ())
G_DECLARE_FINAL_TYPE (MetaWaylandDataSourceWayland,
meta_wayland_data_source_wayland,
META, WAYLAND_DATA_SOURCE_WAYLAND,
MetaWaylandDataSource);
#define META_TYPE_WAYLAND_DATA_SOURCE_PRIMARY (meta_wayland_data_source_primary_get_type ())
G_DECLARE_FINAL_TYPE (MetaWaylandDataSourcePrimary,
meta_wayland_data_source_primary,
META, WAYLAND_DATA_SOURCE_PRIMARY,
MetaWaylandDataSourceWayland);
MetaWaylandDataSource);
#endif /* META_WAYLAND_DATA_DEVICE_PRIVATE_H */

View file

@ -65,6 +65,7 @@ struct _MetaWaylandDataOffer
typedef struct _MetaWaylandDataSourcePrivate
{
struct wl_resource *resource;
MetaWaylandDataOffer *offer;
struct wl_array mime_types;
gboolean has_target;
@ -76,30 +77,21 @@ typedef struct _MetaWaylandDataSourcePrivate
guint in_ask : 1;
} MetaWaylandDataSourcePrivate;
typedef struct _MetaWaylandDataSourceWayland
{
MetaWaylandDataSource parent;
struct wl_resource *resource;
} MetaWaylandDataSourceWayland;
typedef struct _MetaWaylandDataSourcePrimary
{
MetaWaylandDataSourceWayland parent;
MetaWaylandDataSource parent;
} MetaWaylandDataSourcePrimary;
G_DEFINE_TYPE_WITH_PRIVATE (MetaWaylandDataSource, meta_wayland_data_source,
G_TYPE_OBJECT);
G_DEFINE_TYPE (MetaWaylandDataSourceWayland, meta_wayland_data_source_wayland,
META_TYPE_WAYLAND_DATA_SOURCE);
G_DEFINE_TYPE (MetaWaylandDataSourcePrimary, meta_wayland_data_source_primary,
META_TYPE_WAYLAND_DATA_SOURCE_WAYLAND);
META_TYPE_WAYLAND_DATA_SOURCE);
static void unset_selection_source (MetaWaylandDataDevice *data_device,
MetaSelectionType selection_type);
static MetaWaylandDataSource *
meta_wayland_data_source_wayland_new (struct wl_resource *resource);
meta_wayland_data_source_new (struct wl_resource *resource);
static MetaWaylandDataSource *
meta_wayland_data_source_primary_new (struct wl_resource *resource);
@ -189,6 +181,25 @@ data_offer_update_action (MetaWaylandDataOffer *offer)
}
}
static struct wl_resource *
meta_wayland_data_source_get_resource (MetaWaylandDataSource *source)
{
MetaWaylandDataSourcePrivate *priv =
meta_wayland_data_source_get_instance_private (source);
return priv->resource;
}
static void
meta_wayland_data_source_set_resource (MetaWaylandDataSource *source,
struct wl_resource *resource)
{
MetaWaylandDataSourcePrivate *priv =
meta_wayland_data_source_get_instance_private (source);
priv->resource = resource;
}
static void
meta_wayland_data_source_target (MetaWaylandDataSource *source,
const char *mime_type)
@ -659,12 +670,10 @@ data_source_set_actions (struct wl_client *client,
MetaWaylandDataSource *source = wl_resource_get_user_data (resource);
MetaWaylandDataSourcePrivate *priv =
meta_wayland_data_source_get_instance_private (source);
MetaWaylandDataSourceWayland *source_wayland =
META_WAYLAND_DATA_SOURCE_WAYLAND (source);
if (priv->actions_set)
{
wl_resource_post_error (source_wayland->resource,
wl_resource_post_error (priv->resource,
WL_DATA_SOURCE_ERROR_INVALID_ACTION_MASK,
"cannot set actions more than once");
return;
@ -672,7 +681,7 @@ data_source_set_actions (struct wl_client *client,
if (dnd_actions & ~(ALL_ACTIONS))
{
wl_resource_post_error (source_wayland->resource,
wl_resource_post_error (priv->resource,
WL_DATA_SOURCE_ERROR_INVALID_ACTION_MASK,
"invalid actions mask %x", dnd_actions);
return;
@ -680,7 +689,7 @@ data_source_set_actions (struct wl_client *client,
if (meta_wayland_data_source_get_seat (source))
{
wl_resource_post_error (source_wayland->resource,
wl_resource_post_error (priv->resource,
WL_DATA_SOURCE_ERROR_INVALID_ACTION_MASK,
"invalid action change after "
"wl_data_device.start_drag");
@ -1327,10 +1336,10 @@ meta_wayland_source_send (MetaWaylandDataSource *source,
const gchar *mime_type,
gint fd)
{
MetaWaylandDataSourceWayland *source_wayland =
META_WAYLAND_DATA_SOURCE_WAYLAND (source);
MetaWaylandDataSourcePrivate *priv =
meta_wayland_data_source_get_instance_private (source);
wl_data_source_send_send (source_wayland->resource, mime_type, fd);
wl_data_source_send_send (priv->resource, mime_type, fd);
close (fd);
}
@ -1338,43 +1347,43 @@ static void
meta_wayland_source_target (MetaWaylandDataSource *source,
const gchar *mime_type)
{
MetaWaylandDataSourceWayland *source_wayland =
META_WAYLAND_DATA_SOURCE_WAYLAND (source);
MetaWaylandDataSourcePrivate *priv =
meta_wayland_data_source_get_instance_private (source);
wl_data_source_send_target (source_wayland->resource, mime_type);
wl_data_source_send_target (priv->resource, mime_type);
}
static void
meta_wayland_source_cancel (MetaWaylandDataSource *source)
{
MetaWaylandDataSourceWayland *source_wayland =
META_WAYLAND_DATA_SOURCE_WAYLAND (source);
MetaWaylandDataSourcePrivate *priv =
meta_wayland_data_source_get_instance_private (source);
if (source_wayland->resource)
wl_data_source_send_cancelled (source_wayland->resource);
if (priv->resource)
wl_data_source_send_cancelled (priv->resource);
}
static void
meta_wayland_source_action (MetaWaylandDataSource *source,
enum wl_data_device_manager_dnd_action action)
{
MetaWaylandDataSourceWayland *source_wayland =
META_WAYLAND_DATA_SOURCE_WAYLAND (source);
MetaWaylandDataSourcePrivate *priv =
meta_wayland_data_source_get_instance_private (source);
if (wl_resource_get_version (source_wayland->resource) >=
if (wl_resource_get_version (priv->resource) >=
WL_DATA_SOURCE_ACTION_SINCE_VERSION)
wl_data_source_send_action (source_wayland->resource, action);
wl_data_source_send_action (priv->resource, action);
}
static void
meta_wayland_source_drop_performed (MetaWaylandDataSource *source)
{
MetaWaylandDataSourceWayland *source_wayland =
META_WAYLAND_DATA_SOURCE_WAYLAND (source);
MetaWaylandDataSourcePrivate *priv =
meta_wayland_data_source_get_instance_private (source);
if (wl_resource_get_version (source_wayland->resource) >=
if (wl_resource_get_version (priv->resource) >=
WL_DATA_SOURCE_DND_DROP_PERFORMED_SINCE_VERSION)
wl_data_source_send_dnd_drop_performed (source_wayland->resource);
wl_data_source_send_dnd_drop_performed (priv->resource);
}
static void
@ -1382,8 +1391,8 @@ meta_wayland_source_drag_finished (MetaWaylandDataSource *source)
{
MetaWaylandCompositor *compositor = meta_wayland_compositor_get_default ();
MetaWaylandDataDevice *data_device = &compositor->seat->data_device;
MetaWaylandDataSourceWayland *source_wayland =
META_WAYLAND_DATA_SOURCE_WAYLAND (source);
MetaWaylandDataSourcePrivate *priv =
meta_wayland_data_source_get_instance_private (source);
enum wl_data_device_manager_dnd_action action;
if (meta_wayland_source_get_in_ask (source))
@ -1392,81 +1401,15 @@ meta_wayland_source_drag_finished (MetaWaylandDataSource *source)
meta_wayland_source_action (source, action);
}
if (wl_resource_get_version (source_wayland->resource) >=
if (wl_resource_get_version (priv->resource) >=
WL_DATA_SOURCE_DND_FINISHED_SINCE_VERSION)
wl_data_source_send_dnd_finished (source_wayland->resource);
wl_data_source_send_dnd_finished (priv->resource);
unset_selection_source (data_device, META_SELECTION_DND);
}
static void
meta_wayland_source_finalize (GObject *object)
{
G_OBJECT_CLASS (meta_wayland_data_source_wayland_parent_class)->finalize (object);
}
static void
meta_wayland_data_source_wayland_init (MetaWaylandDataSourceWayland *source_wayland)
{
}
static void
meta_wayland_data_source_wayland_class_init (MetaWaylandDataSourceWaylandClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
MetaWaylandDataSourceClass *data_source_class =
META_WAYLAND_DATA_SOURCE_CLASS (klass);
object_class->finalize = meta_wayland_source_finalize;
data_source_class->send = meta_wayland_source_send;
data_source_class->target = meta_wayland_source_target;
data_source_class->cancel = meta_wayland_source_cancel;
data_source_class->action = meta_wayland_source_action;
data_source_class->drop_performed = meta_wayland_source_drop_performed;
data_source_class->drag_finished = meta_wayland_source_drag_finished;
}
static void
meta_wayland_data_source_primary_send (MetaWaylandDataSource *source,
const gchar *mime_type,
gint fd)
{
MetaWaylandDataSourceWayland *source_wayland;
source_wayland = META_WAYLAND_DATA_SOURCE_WAYLAND (source);
gtk_primary_selection_source_send_send (source_wayland->resource,
mime_type, fd);
close (fd);
}
static void
meta_wayland_data_source_primary_cancel (MetaWaylandDataSource *source)
{
MetaWaylandDataSourceWayland *source_wayland;
source_wayland = META_WAYLAND_DATA_SOURCE_WAYLAND (source);
if (source_wayland->resource)
gtk_primary_selection_source_send_cancelled (source_wayland->resource);
}
static void
meta_wayland_data_source_primary_init (MetaWaylandDataSourcePrimary *source_primary)
{
}
static void
meta_wayland_data_source_primary_class_init (MetaWaylandDataSourcePrimaryClass *klass)
{
MetaWaylandDataSourceClass *data_source_class =
META_WAYLAND_DATA_SOURCE_CLASS (klass);
data_source_class->send = meta_wayland_data_source_primary_send;
data_source_class->cancel = meta_wayland_data_source_primary_cancel;
}
static void
meta_wayland_data_source_finalize (GObject *object)
{
MetaWaylandDataSource *source = META_WAYLAND_DATA_SOURCE (object);
MetaWaylandDataSourcePrivate *priv =
@ -1495,7 +1438,49 @@ meta_wayland_data_source_class_init (MetaWaylandDataSourceClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = meta_wayland_data_source_finalize;
object_class->finalize = meta_wayland_source_finalize;
klass->send = meta_wayland_source_send;
klass->target = meta_wayland_source_target;
klass->cancel = meta_wayland_source_cancel;
klass->action = meta_wayland_source_action;
klass->drop_performed = meta_wayland_source_drop_performed;
klass->drag_finished = meta_wayland_source_drag_finished;
}
static void
meta_wayland_data_source_primary_send (MetaWaylandDataSource *source,
const gchar *mime_type,
gint fd)
{
struct wl_resource *resource = meta_wayland_data_source_get_resource (source);
gtk_primary_selection_source_send_send (resource, mime_type, fd);
close (fd);
}
static void
meta_wayland_data_source_primary_cancel (MetaWaylandDataSource *source)
{
struct wl_resource *resource = meta_wayland_data_source_get_resource (source);
if (resource)
gtk_primary_selection_source_send_cancelled (resource);
}
static void
meta_wayland_data_source_primary_init (MetaWaylandDataSourcePrimary *source_primary)
{
}
static void
meta_wayland_data_source_primary_class_init (MetaWaylandDataSourcePrimaryClass *klass)
{
MetaWaylandDataSourceClass *data_source_class =
META_WAYLAND_DATA_SOURCE_CLASS (klass);
data_source_class->send = meta_wayland_data_source_primary_send;
data_source_class->cancel = meta_wayland_data_source_primary_cancel;
}
static void
@ -1753,7 +1738,7 @@ meta_wayland_data_device_set_primary (MetaWaylandDataDevice *data_device,
{
struct wl_resource *resource;
resource = META_WAYLAND_DATA_SOURCE_WAYLAND (source)->resource;
resource = meta_wayland_data_source_get_resource (source);
if (wl_resource_get_client (resource) !=
meta_wayland_keyboard_get_focus_client (seat->keyboard))
@ -1830,9 +1815,9 @@ static const struct gtk_primary_selection_device_interface primary_device_interf
static void
destroy_data_source (struct wl_resource *resource)
{
MetaWaylandDataSourceWayland *source = wl_resource_get_user_data (resource);
MetaWaylandDataSource *source = wl_resource_get_user_data (resource);
source->resource = NULL;
meta_wayland_data_source_set_resource (source, NULL);
g_object_unref (source);
}
@ -1844,7 +1829,7 @@ create_data_source (struct wl_client *client,
source_resource = wl_resource_create (client, &wl_data_source_interface,
wl_resource_get_version (resource), id);
meta_wayland_data_source_wayland_new (source_resource);
meta_wayland_data_source_new (source_resource);
}
static void
@ -1936,9 +1921,9 @@ static const struct wl_data_device_manager_interface manager_interface = {
static void
destroy_primary_source (struct wl_resource *resource)
{
MetaWaylandDataSourceWayland *source = wl_resource_get_user_data (resource);
MetaWaylandDataSource *source = wl_resource_get_user_data (resource);
source->resource = NULL;
meta_wayland_data_source_set_resource (source, NULL);
g_object_unref (source);
}
@ -2159,29 +2144,29 @@ meta_wayland_data_source_has_mime_type (const MetaWaylandDataSource *source,
}
static MetaWaylandDataSource *
meta_wayland_data_source_wayland_new (struct wl_resource *resource)
meta_wayland_data_source_new (struct wl_resource *resource)
{
MetaWaylandDataSourceWayland *source_wayland =
g_object_new (META_TYPE_WAYLAND_DATA_SOURCE_WAYLAND, NULL);
MetaWaylandDataSource *source =
g_object_new (META_TYPE_WAYLAND_DATA_SOURCE, NULL);
source_wayland->resource = resource;
meta_wayland_data_source_set_resource (source, resource);
wl_resource_set_implementation (resource, &data_source_interface,
source_wayland, destroy_data_source);
source, destroy_data_source);
return META_WAYLAND_DATA_SOURCE (source_wayland);
return source;
}
static MetaWaylandDataSource *
meta_wayland_data_source_primary_new (struct wl_resource *resource)
{
MetaWaylandDataSourceWayland *source_primary =
MetaWaylandDataSource *source_primary =
g_object_new (META_TYPE_WAYLAND_DATA_SOURCE_PRIMARY, NULL);
source_primary->resource = resource;
meta_wayland_data_source_set_resource (source_primary, resource);
wl_resource_set_implementation (resource, &primary_source_interface,
source_primary, destroy_primary_source);
return META_WAYLAND_DATA_SOURCE (source_primary);
return source_primary;
}
gboolean