[mutter/gnome-3-34] wayland: Flatten data source object hierarchy
- From: Robert Mader <rmader src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter/gnome-3-34] wayland: Flatten data source object hierarchy
- Date: Fri, 31 Jan 2020 14:26:54 +0000 (UTC)
commit 4cc5b85c5dc699b37ab8248ce5c5f17cf3697d44
Author: Carlos Garnacho <carlosg gnome org>
Date: Wed Oct 23 13:09:21 2019 +0200
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
(cherry picked from commit c11ef6ef079eeaa8024c8703bbe432356d06388a)
src/wayland/meta-wayland-data-device-private.h | 8 +-
src/wayland/meta-wayland-data-device.c | 197 ++++++++++++-------------
2 files changed, 92 insertions(+), 113 deletions(-)
---
diff --git a/src/wayland/meta-wayland-data-device-private.h b/src/wayland/meta-wayland-data-device-private.h
index 5e651300d..a6a373f69 100644
--- a/src/wayland/meta-wayland-data-device-private.h
+++ b/src/wayland/meta-wayland-data-device-private.h
@@ -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 */
diff --git a/src/wayland/meta-wayland-data-device.c b/src/wayland/meta-wayland-data-device.c
index dee474eef..ec5295d3b 100644
--- a/src/wayland/meta-wayland-data-device.c
+++ b/src/wayland/meta-wayland-data-device.c
@@ -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");
@@ -1323,10 +1332,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);
}
@@ -1334,43 +1343,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
@@ -1378,8 +1387,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))
@@ -1388,9 +1397,9 @@ 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);
}
@@ -1398,29 +1407,41 @@ meta_wayland_source_drag_finished (MetaWaylandDataSource *source)
static void
meta_wayland_source_finalize (GObject *object)
{
- G_OBJECT_CLASS (meta_wayland_data_source_wayland_parent_class)->finalize (object);
+ MetaWaylandDataSource *source = META_WAYLAND_DATA_SOURCE (object);
+ MetaWaylandDataSourcePrivate *priv =
+ meta_wayland_data_source_get_instance_private (source);
+ char **pos;
+
+ wl_array_for_each (pos, &priv->mime_types)
+ g_free (*pos);
+ wl_array_release (&priv->mime_types);
+
+ G_OBJECT_CLASS (meta_wayland_data_source_parent_class)->finalize (object);
}
static void
-meta_wayland_data_source_wayland_init (MetaWaylandDataSourceWayland *source_wayland)
+meta_wayland_data_source_init (MetaWaylandDataSource *source)
{
+ MetaWaylandDataSourcePrivate *priv =
+ meta_wayland_data_source_get_instance_private (source);
+
+ wl_array_init (&priv->mime_types);
+ priv->current_dnd_action = -1;
}
static void
-meta_wayland_data_source_wayland_class_init (MetaWaylandDataSourceWaylandClass *klass)
+meta_wayland_data_source_class_init (MetaWaylandDataSourceClass *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;
+ 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
@@ -1428,22 +1449,19 @@ meta_wayland_data_source_primary_send (MetaWaylandDataSource *source,
const gchar *mime_type,
gint fd)
{
- MetaWaylandDataSourceWayland *source_wayland;
+ struct wl_resource *resource = meta_wayland_data_source_get_resource (source);
- source_wayland = META_WAYLAND_DATA_SOURCE_WAYLAND (source);
- gtk_primary_selection_source_send_send (source_wayland->resource,
- mime_type, fd);
+ gtk_primary_selection_source_send_send (resource, mime_type, fd);
close (fd);
}
static void
meta_wayland_data_source_primary_cancel (MetaWaylandDataSource *source)
{
- MetaWaylandDataSourceWayland *source_wayland;
+ struct wl_resource *resource = meta_wayland_data_source_get_resource (source);
- source_wayland = META_WAYLAND_DATA_SOURCE_WAYLAND (source);
- if (source_wayland->resource)
- gtk_primary_selection_source_send_cancelled (source_wayland->resource);
+ if (resource)
+ gtk_primary_selection_source_send_cancelled (resource);
}
static void
@@ -1461,39 +1479,6 @@ meta_wayland_data_source_primary_class_init (MetaWaylandDataSourcePrimaryClass *
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 =
- meta_wayland_data_source_get_instance_private (source);
- char **pos;
-
- wl_array_for_each (pos, &priv->mime_types)
- g_free (*pos);
- wl_array_release (&priv->mime_types);
-
- G_OBJECT_CLASS (meta_wayland_data_source_parent_class)->finalize (object);
-}
-
-static void
-meta_wayland_data_source_init (MetaWaylandDataSource *source)
-{
- MetaWaylandDataSourcePrivate *priv =
- meta_wayland_data_source_get_instance_private (source);
-
- wl_array_init (&priv->mime_types);
- priv->current_dnd_action = -1;
-}
-
-static void
-meta_wayland_data_source_class_init (MetaWaylandDataSourceClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->finalize = meta_wayland_data_source_finalize;
-}
-
static void
meta_wayland_drag_dest_focus_in (MetaWaylandDataDevice *data_device,
MetaWaylandSurface *surface,
@@ -1760,7 +1745,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))
@@ -1835,9 +1820,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);
}
@@ -1849,7 +1834,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
@@ -1941,9 +1926,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);
}
@@ -2161,29 +2146,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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]