clutter/layout-meta: Become one with ClutterChildMeta

Now ClutterContainer is gone there is no reason for this split to exist,
simply merge the two types together

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3384>
This commit is contained in:
Zander Brown 2023-11-07 09:31:21 +00:00
parent db4bbf6899
commit 4bc73ba9f4
10 changed files with 162 additions and 346 deletions

View File

@ -38,7 +38,6 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterBlurEffect, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterBoxLayout, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterBrightnessContrastEffect, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterCanvas, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterChildMeta, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterClone, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterColorizeEffect, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterConstraint, g_object_unref)
@ -51,7 +50,6 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterGridLayout, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterInputDevice, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterInterval, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterKeyframeTransition, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterLayoutMeta, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterOffscreenEffect, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterPageTurnEffect, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterPanAction, g_object_unref)

View File

@ -49,7 +49,6 @@
#include "clutter/clutter-actor-private.h"
#include "clutter/clutter-animatable.h"
#include "clutter/clutter-bin-layout.h"
#include "clutter/clutter-child-meta.h"
#include "clutter/clutter-debug.h"
#include "clutter/clutter-enum-types.h"
#include "clutter/clutter-layout-meta.h"

View File

@ -1,206 +0,0 @@
/*
* Clutter.
*
* An OpenGL based 'interactive canvas' library.
*
* Authored By Matthew Allum <mallum@openedhand.com>
* Jorn Baayen <jorn@openedhand.com>
* Emmanuele Bassi <ebassi@openedhand.com>
* Tomas Frydrych <tf@openedhand.com>
* Øyvind Kolås <ok@openedhand.com>
*
* Copyright (C) 2008 OpenedHand
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* ClutterChildMeta:
*
* Base interface for container specific state for child actors.
*
* A child data is meant to be used when you need to keep track
* of information about each individual child added to a container.
*
* In order to use it you should create your own subclass of
* #ClutterChildMeta and set the #ClutterContainerIface child_meta_type
* interface member to your subclass type, like:
*
* ```c
* static void
* my_container_iface_init (ClutterContainerIface *iface)
* {
* // set the rest of the #ClutterContainer vtable
*
* container_iface->child_meta_type = MY_TYPE_CHILD_META;
* }
* ```
*
* This will automatically create a #ClutterChildMeta of type
* `MY_TYPE_CHILD_META` for every actor that is added to the container.
*
* The child data for an actor can be retrieved using the
* clutter_container_get_child_meta() function.
*
* The properties of the data and your subclass can be manipulated with
* clutter_container_child_set() and clutter_container_child_get() which
* act like g_object_set() and g_object_get().
*
* You can provide hooks for your own storage as well as control the
* instantiation by overriding the #ClutterContainerIface virtual functions
* #ClutterContainerIface.create_child_meta(), #ClutterContainerIface.destroy_child_meta(),
* and #ClutterContainerIface.get_child_meta().
*/
#include "clutter/clutter-build-config.h"
#include "clutter/clutter-child-meta.h"
#include "clutter/clutter-container.h"
#include "clutter/clutter-debug.h"
#include "clutter/clutter-private.h"
G_DEFINE_ABSTRACT_TYPE (ClutterChildMeta, clutter_child_meta, G_TYPE_OBJECT);
enum
{
PROP_0,
PROP_CONTAINER,
PROP_ACTOR,
PROP_LAST
};
static GParamSpec *obj_props[PROP_LAST];
static void
clutter_child_meta_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
ClutterChildMeta *child_meta = CLUTTER_CHILD_META (object);
switch (prop_id)
{
case PROP_CONTAINER:
child_meta->container = g_value_get_object (value);
break;
case PROP_ACTOR:
child_meta->actor = g_value_get_object (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
clutter_child_meta_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
ClutterChildMeta *child_meta = CLUTTER_CHILD_META (object);
switch (prop_id)
{
case PROP_CONTAINER:
g_value_set_object (value, child_meta->container);
break;
case PROP_ACTOR:
g_value_set_object (value, child_meta->actor);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
clutter_child_meta_class_init (ClutterChildMetaClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->set_property = clutter_child_meta_set_property;
gobject_class->get_property = clutter_child_meta_get_property;
/**
* ClutterChildMeta:container:
*
* The #ClutterContainer that created this #ClutterChildMeta.
*/
obj_props[PROP_CONTAINER] =
g_param_spec_object ("container", NULL, NULL,
CLUTTER_TYPE_ACTOR,
G_PARAM_CONSTRUCT_ONLY |
CLUTTER_PARAM_READWRITE);
/**
* ClutterChildMeta:actor:
*
* The #ClutterActor being wrapped by this #ClutterChildMeta
*/
obj_props[PROP_ACTOR] =
g_param_spec_object ("actor", NULL, NULL,
CLUTTER_TYPE_ACTOR,
G_PARAM_CONSTRUCT_ONLY |
CLUTTER_PARAM_READWRITE);
g_object_class_install_properties (gobject_class,
PROP_LAST,
obj_props);
}
static void
clutter_child_meta_init (ClutterChildMeta *self)
{
}
/**
* clutter_child_meta_get_container:
* @data: a #ClutterChildMeta
*
* Retrieves the container using @data
*
* Return value: (transfer none): a #ClutterActor
*/
ClutterActor *
clutter_child_meta_get_container (ClutterChildMeta *data)
{
g_return_val_if_fail (CLUTTER_IS_CHILD_META (data), NULL);
return data->container;
}
/**
* clutter_child_meta_get_actor:
* @data: a #ClutterChildMeta
*
* Retrieves the actor wrapped by @data
*
* Return value: (transfer none): a #ClutterActor
*/
ClutterActor *
clutter_child_meta_get_actor (ClutterChildMeta *data)
{
g_return_val_if_fail (CLUTTER_IS_CHILD_META (data), NULL);
return data->actor;
}

View File

@ -1,78 +0,0 @@
/*
* Clutter.
*
* An OpenGL based 'interactive canvas' library.
*
* Authored By Matthew Allum <mallum@openedhand.com>
* Jorn Baayen <jorn@openedhand.com>
* Emmanuele Bassi <ebassi@openedhand.com>
* Tomas Frydrych <tf@openedhand.com>
* Øyvind Kolås <ok@openedhand.com>
*
* Copyright (C) 2008 OpenedHand
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#if !defined(__CLUTTER_H_INSIDE__) && !defined(CLUTTER_COMPILATION)
#error "Only <clutter/clutter.h> can be included directly."
#endif
#include <glib-object.h>
#include "clutter/clutter-types.h"
G_BEGIN_DECLS
#define CLUTTER_TYPE_CHILD_META (clutter_child_meta_get_type ())
#define CLUTTER_CHILD_META(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_CHILD_META, ClutterChildMeta))
#define CLUTTER_CHILD_META_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CLUTTER_TYPE_CHILD_META, ClutterChildMetaClass))
#define CLUTTER_IS_CHILD_META(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLUTTER_TYPE_CHILD_META))
#define CLUTTER_IS_CHILD_META_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CLUTTER_TYPE_CHILD_META))
#define CLUTTER_CHILD_META_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CLUTTER_TYPE_CHILD_META, ClutterChildMetaClass))
typedef struct _ClutterChildMetaClass ClutterChildMetaClass;
struct _ClutterChildMeta
{
/*< private >*/
GObject parent_instance;
/*< public >*/
ClutterActor *container;
ClutterActor *actor;
};
/**
* ClutterChildMetaClass:
*
* The #ClutterChildMetaClass contains only private data
*/
struct _ClutterChildMetaClass
{
/*< private >*/
GObjectClass parent_class;
};
CLUTTER_EXPORT
GType clutter_child_meta_get_type (void) G_GNUC_CONST;
CLUTTER_EXPORT
ClutterActor * clutter_child_meta_get_container (ClutterChildMeta *data);
CLUTTER_EXPORT
ClutterActor * clutter_child_meta_get_actor (ClutterChildMeta *data);
G_END_DECLS

View File

@ -57,7 +57,6 @@
#include "clutter/clutter-actor.h"
#include "clutter/clutter-animatable.h"
#include "clutter/clutter-child-meta.h"
#include "clutter/clutter-debug.h"
#include "clutter/clutter-enum-types.h"
#include "clutter/clutter-flow-layout.h"

View File

@ -531,11 +531,7 @@ get_child_meta (ClutterLayoutManager *manager,
layout = g_object_get_qdata (G_OBJECT (actor), quark_layout_meta);
if (layout != NULL)
{
ClutterChildMeta *child = CLUTTER_CHILD_META (layout);
if (layout->manager == manager &&
CLUTTER_ACTOR (child->container) == container &&
child->actor == actor)
if (clutter_layout_meta_is_for (layout, manager, container, actor))
return layout;
/* if the LayoutMeta referenced is not attached to the

View File

@ -27,11 +27,12 @@
*
* Wrapper for actors inside a layout manager
*
* #ClutterLayoutMeta is a wrapper object created by [class@LayoutManager]
* implementations in order to store child-specific data and properties.
* [type@Clutter.LayoutMeta] is a wrapper object created by
* [class@LayoutManager] implementations in order to store child-specific data
* and properties.
*
* A #ClutterLayoutMeta wraps a [class@Actor] inside a [iface@Container]
* using a [class@LayoutManager].
* A [type@Clutter.LayoutMeta] wraps a [class@Actor] inside a container
* [class@Actor] using a [class@LayoutManager].
*/
#include "clutter/clutter-build-config.h"
@ -40,21 +41,45 @@
#include "clutter/clutter-debug.h"
#include "clutter/clutter-private.h"
G_DEFINE_ABSTRACT_TYPE (ClutterLayoutMeta,
typedef struct _ClutterLayoutMetaPrivate ClutterLayoutMetaPrivate;
struct _ClutterLayoutMetaPrivate
{
ClutterLayoutManager *manager;
ClutterActor *container;
ClutterActor *actor;
};
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (ClutterLayoutMeta,
clutter_layout_meta,
CLUTTER_TYPE_CHILD_META);
G_TYPE_OBJECT);
enum
{
PROP_0,
PROP_MANAGER,
PROP_CONTAINER,
PROP_ACTOR,
PROP_LAST
};
static GParamSpec *obj_props[PROP_LAST];
static void
clutter_layout_meta_dispose (GObject *object)
{
ClutterLayoutMeta *layout_meta = CLUTTER_LAYOUT_META (object);
ClutterLayoutMetaPrivate *priv =
clutter_layout_meta_get_instance_private (layout_meta);
g_clear_weak_pointer (&priv->manager);
g_clear_weak_pointer (&priv->container);
g_clear_weak_pointer (&priv->actor);
G_OBJECT_CLASS (clutter_layout_meta_parent_class)->dispose (object);
}
static void
clutter_layout_meta_set_property (GObject *object,
guint prop_id,
@ -62,11 +87,21 @@ clutter_layout_meta_set_property (GObject *object,
GParamSpec *pspec)
{
ClutterLayoutMeta *layout_meta = CLUTTER_LAYOUT_META (object);
ClutterLayoutMetaPrivate *priv =
clutter_layout_meta_get_instance_private (layout_meta);
switch (prop_id)
{
case PROP_MANAGER:
layout_meta->manager = g_value_get_object (value);
g_set_weak_pointer (&priv->manager, g_value_get_object (value));
break;
case PROP_CONTAINER:
g_set_weak_pointer (&priv->container, g_value_get_object (value));
break;
case PROP_ACTOR:
g_set_weak_pointer (&priv->actor, g_value_get_object (value));
break;
default:
@ -82,11 +117,21 @@ clutter_layout_meta_get_property (GObject *object,
GParamSpec *pspec)
{
ClutterLayoutMeta *layout_meta = CLUTTER_LAYOUT_META (object);
ClutterLayoutMetaPrivate *priv =
clutter_layout_meta_get_instance_private (layout_meta);
switch (prop_id)
{
case PROP_MANAGER:
g_value_set_object (value, layout_meta->manager);
g_value_set_object (value, priv->manager);
break;
case PROP_CONTAINER:
g_value_set_object (value, priv->container);
break;
case PROP_ACTOR:
g_value_set_object (value, priv->actor);
break;
default:
@ -99,22 +144,45 @@ static void
clutter_layout_meta_class_init (ClutterLayoutMetaClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GParamSpec *pspec;
gobject_class->dispose = clutter_layout_meta_dispose;
gobject_class->set_property = clutter_layout_meta_set_property;
gobject_class->get_property = clutter_layout_meta_get_property;
/**
* ClutterLayoutMeta:manager:
*
* The [class@LayoutManager] that created this #ClutterLayoutMeta.
* The [class@LayoutManager] that created this [type@Clutter.LayoutMeta].
*/
pspec = g_param_spec_object ("manager", NULL, NULL,
obj_props[PROP_MANAGER] =
g_param_spec_object ("manager", NULL, NULL,
CLUTTER_TYPE_LAYOUT_MANAGER,
G_PARAM_CONSTRUCT_ONLY |
CLUTTER_PARAM_READWRITE);
obj_props[PROP_MANAGER] = pspec;
g_object_class_install_property (gobject_class, PROP_MANAGER, pspec);
/**
* ClutterLayoutMeta:container:
*
* The [type@Clutter.Actor] containing [property@Clutter.LayoutMeta:actor]
*/
obj_props[PROP_CONTAINER] =
g_param_spec_object ("container", NULL, NULL,
CLUTTER_TYPE_ACTOR,
G_PARAM_CONSTRUCT_ONLY |
CLUTTER_PARAM_READWRITE);
/**
* ClutterLayoutMeta:actor:
*
* The [type@Clutter.Actor] being wrapped by this [type@Clutter.LayoutMeta]
*/
obj_props[PROP_ACTOR] =
g_param_spec_object ("actor", NULL, NULL,
CLUTTER_TYPE_ACTOR,
G_PARAM_CONSTRUCT_ONLY |
CLUTTER_PARAM_READWRITE);
g_object_class_install_properties (gobject_class, PROP_LAST, obj_props);
}
static void
@ -128,12 +196,72 @@ clutter_layout_meta_init (ClutterLayoutMeta *self)
*
* Retrieves the actor wrapped by @data
*
* Return value: (transfer none): a #ClutterLayoutManager
* Return value: (transfer none): a [type@Clutter.LayoutManager]
*/
ClutterLayoutManager *
clutter_layout_meta_get_manager (ClutterLayoutMeta *data)
{
ClutterLayoutMetaPrivate *priv;
g_return_val_if_fail (CLUTTER_IS_LAYOUT_META (data), NULL);
return data->manager;
priv = clutter_layout_meta_get_instance_private (data);
return priv->manager;
}
/**
* clutter_layout_meta_get_container:
* @data: a #ClutterLayoutMeta
*
* Retrieves the container using @data
*
* Return value: (transfer none): a [type@Clutter.Actor]
*/
ClutterActor *
clutter_layout_meta_get_container (ClutterLayoutMeta *data)
{
ClutterLayoutMetaPrivate *priv;
g_return_val_if_fail (CLUTTER_IS_LAYOUT_META (data), NULL);
priv = clutter_layout_meta_get_instance_private (data);
return priv->container;
}
/**
* clutter_layout_meta_get_actor:
* @data: a #ClutterLayoutMeta
*
* Retrieves the actor wrapped by @data
*
* Return value: (transfer none): a [type@Clutter.Actor]
*/
ClutterActor *
clutter_layout_meta_get_actor (ClutterLayoutMeta *data)
{
ClutterLayoutMetaPrivate *priv;
g_return_val_if_fail (CLUTTER_IS_LAYOUT_META (data), NULL);
priv = clutter_layout_meta_get_instance_private (data);
return priv->actor;
}
gboolean
clutter_layout_meta_is_for (ClutterLayoutMeta *data,
ClutterLayoutManager *manager,
ClutterActor *container,
ClutterActor *actor)
{
ClutterLayoutMetaPrivate *priv;
g_return_val_if_fail (CLUTTER_IS_LAYOUT_META (data), FALSE);
priv = clutter_layout_meta_get_instance_private (data);
return priv->manager == manager &&
priv->container == container && priv->actor == actor;
}

View File

@ -29,47 +29,30 @@
#endif
#include "clutter/clutter-types.h"
#include "clutter/clutter-child-meta.h"
#include "clutter/clutter-layout-manager.h"
G_BEGIN_DECLS
#define CLUTTER_TYPE_LAYOUT_META (clutter_layout_meta_get_type ())
#define CLUTTER_LAYOUT_META(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_LAYOUT_META, ClutterLayoutMeta))
#define CLUTTER_IS_LAYOUT_META(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLUTTER_TYPE_LAYOUT_META))
#define CLUTTER_LAYOUT_META_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CLUTTER_TYPE_LAYOUT_META, ClutterLayoutMetaClass))
#define CLUTTER_IS_LAYOUT_META_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CLUTTER_TYPE_LAYOUT_META))
#define CLUTTER_LAYOUT_META_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CLUTTER_TYPE_LAYOUT_META, ClutterLayoutMetaClass))
/* ClutterLayoutMeta is defined in clutter-types.h */
CLUTTER_EXPORT
G_DECLARE_DERIVABLE_TYPE (ClutterLayoutMeta, clutter_layout_meta, CLUTTER, LAYOUT_META, GObject)
typedef struct _ClutterLayoutMetaClass ClutterLayoutMetaClass;
struct _ClutterLayoutMeta
{
/*< private >*/
ClutterChildMeta parent_instance;
/*< public >*/
ClutterLayoutManager *manager;
};
/**
* ClutterLayoutMetaClass:
*
* The #ClutterLayoutMetaClass contains only private data and
* should never be accessed directly
*/
struct _ClutterLayoutMetaClass
{
/*< private >*/
ClutterChildMetaClass parent_class;
GObjectClass parent_class;
};
CLUTTER_EXPORT
GType clutter_layout_meta_get_type (void) G_GNUC_CONST;
ClutterActor *clutter_layout_meta_get_container (ClutterLayoutMeta *data);
CLUTTER_EXPORT
ClutterActor *clutter_layout_meta_get_actor (ClutterLayoutMeta *data);
CLUTTER_EXPORT
ClutterLayoutManager *clutter_layout_meta_get_manager (ClutterLayoutMeta *data);
CLUTTER_EXPORT
gboolean clutter_layout_meta_is_for (ClutterLayoutMeta *data,
ClutterLayoutManager *manager,
ClutterActor *container,
ClutterActor *actor);
G_END_DECLS

View File

@ -42,7 +42,6 @@
#include "clutter/clutter-box-layout.h"
#include "clutter/clutter-brightness-contrast-effect.h"
#include "clutter/clutter-canvas.h"
#include "clutter/clutter-child-meta.h"
#include "clutter/clutter-click-action.h"
#include "clutter/clutter-clone.h"
#include "clutter/clutter-color.h"

View File

@ -17,7 +17,6 @@ clutter_headers = [
'clutter-box-layout.h',
'clutter-brightness-contrast-effect.h',
'clutter-canvas.h',
'clutter-child-meta.h',
'clutter-click-action.h',
'clutter-clone.h',
'clutter-color-state.h',
@ -108,7 +107,6 @@ clutter_sources = [
'clutter-box-layout.c',
'clutter-brightness-contrast-effect.c',
'clutter-canvas.c',
'clutter-child-meta.c',
'clutter-click-action.c',
'clutter-clone.c',
'clutter-color.c',