clutter/actor: Take responsibility for ::actor-{added,removed}

These signals have de facto been ClutterActor signals for some time now,
simply move them in from ClutterActor

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3384>
This commit is contained in:
Zander Brown 2023-11-07 08:54:00 +00:00
parent e1cdeb0319
commit 7113ecd86c
5 changed files with 64 additions and 113 deletions

View File

@ -104,8 +104,8 @@
* given index by using clutter_actor_get_child_at_index(). * given index by using clutter_actor_get_child_at_index().
* *
* If you need to track additions of children to a #ClutterActor, use * If you need to track additions of children to a #ClutterActor, use
* the #ClutterContainer::actor-added signal; similarly, to track removals * the #ClutterActor::actor-added signal; similarly, to track removals
* of children from a ClutterActor, use the #ClutterContainer::actor-removed * of children from a ClutterActor, use the #ClutterActor::actor-removed
* signal. * signal.
* *
* See [basic-actor.c](https://git.gnome.org/browse/clutter/tree/examples/basic-actor.c?h=clutter-1.18). * See [basic-actor.c](https://git.gnome.org/browse/clutter/tree/examples/basic-actor.c?h=clutter-1.18).
@ -537,7 +537,7 @@
#include "clutter/clutter-color-static.h" #include "clutter/clutter-color-static.h"
#include "clutter/clutter-color.h" #include "clutter/clutter-color.h"
#include "clutter/clutter-constraint-private.h" #include "clutter/clutter-constraint-private.h"
#include "clutter/clutter-container-private.h" #include "clutter/clutter-container.h"
#include "clutter/clutter-content-private.h" #include "clutter/clutter-content-private.h"
#include "clutter/clutter-debug.h" #include "clutter/clutter-debug.h"
#include "clutter/clutter-easing.h" #include "clutter/clutter-easing.h"
@ -926,6 +926,8 @@ enum
TRANSITION_STOPPED, TRANSITION_STOPPED,
STAGE_VIEWS_CHANGED, STAGE_VIEWS_CHANGED,
RESOURCE_SCALE_CHANGED, RESOURCE_SCALE_CHANGED,
ACTOR_ADDED,
ACTOR_REMOVED,
CLONED, CLONED,
DECLONED, DECLONED,
@ -4197,7 +4199,7 @@ clutter_actor_remove_child_internal (ClutterActor *self,
/* we need to emit the signal before dropping the reference */ /* we need to emit the signal before dropping the reference */
if (emit_actor_removed) if (emit_actor_removed)
_clutter_container_emit_actor_removed (CLUTTER_CONTAINER (self), child); g_signal_emit (self, actor_signals[ACTOR_REMOVED], 0, child);
if (notify_first_last) if (notify_first_last)
{ {
@ -7423,6 +7425,39 @@ clutter_actor_class_init (ClutterActorClass *klass)
NULL, NULL, NULL, NULL, NULL, NULL,
G_TYPE_NONE, 0); G_TYPE_NONE, 0);
/**
* ClutterActor::actor-added:
* @actor: the actor which received the signal
* @child: the new child that has been added to @actor
*
* The signal is emitted each time an actor
* has been added to @actor.
*/
actor_signals[ACTOR_ADDED] =
g_signal_new (I_("actor-added"),
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (ClutterActorClass, actor_added),
NULL, NULL, NULL,
G_TYPE_NONE, 1,
CLUTTER_TYPE_ACTOR);
/**
* ClutterActor::actor-removed:
* @actor: the actor which received the signal
* @child: the child that has been removed from @actor
*
* The signal is emitted each time an actor
* is removed from @actor.
*/
actor_signals[ACTOR_REMOVED] =
g_signal_new (I_("actor-removed"),
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (ClutterActorClass, actor_removed),
NULL, NULL, NULL,
G_TYPE_NONE, 1,
CLUTTER_TYPE_ACTOR);
/*< private > */ /*< private > */
actor_signals[CLONED] = actor_signals[CLONED] =
g_signal_new ("cloned", g_signal_new ("cloned",
@ -11176,7 +11211,7 @@ clutter_actor_add_child_internal (ClutterActor *self,
} }
if (emit_actor_added) if (emit_actor_added)
_clutter_container_emit_actor_added (CLUTTER_CONTAINER (self), child); g_signal_emit (self, actor_signals[ACTOR_ADDED], 0, child);
if (notify_first_last) if (notify_first_last)
{ {
@ -11203,7 +11238,7 @@ clutter_actor_add_child_internal (ClutterActor *self,
* This function will take into consideration the #ClutterActor:depth * This function will take into consideration the #ClutterActor:depth
* of @child, and will keep the list of children sorted. * of @child, and will keep the list of children sorted.
* *
* This function will emit the #ClutterContainer::actor-added signal * This function will emit the #ClutterActor::actor-added signal
* on @self. * on @self.
*/ */
void void
@ -11237,7 +11272,7 @@ clutter_actor_add_child (ClutterActor *self,
* This function will not take into consideration the #ClutterActor:depth * This function will not take into consideration the #ClutterActor:depth
* of @child. * of @child.
* *
* This function will emit the #ClutterContainer::actor-added signal * This function will emit the #ClutterActor::actor-added signal
* on @self. * on @self.
*/ */
void void
@ -11272,7 +11307,7 @@ clutter_actor_insert_child_at_index (ClutterActor *self,
* This function will not take into consideration the #ClutterActor:depth * This function will not take into consideration the #ClutterActor:depth
* of @child. * of @child.
* *
* This function will emit the #ClutterContainer::actor-added signal * This function will emit the #ClutterActor::actor-added signal
* on @self. * on @self.
*/ */
void void
@ -11311,7 +11346,7 @@ clutter_actor_insert_child_above (ClutterActor *self,
* This function will not take into consideration the #ClutterActor:depth * This function will not take into consideration the #ClutterActor:depth
* of @child. * of @child.
* *
* This function will emit the #ClutterContainer::actor-added signal * This function will emit the #ClutterActor::actor-added signal
* on @self. * on @self.
*/ */
void void
@ -11382,7 +11417,7 @@ clutter_actor_get_paint_visibility (ClutterActor *actor)
* you will have to acquire a referenced on it before calling this * you will have to acquire a referenced on it before calling this
* function. * function.
* *
* This function will emit the #ClutterContainer::actor-removed * This function will emit the #ClutterActor::actor-removed
* signal on @self. * signal on @self.
*/ */
void void

View File

@ -246,6 +246,11 @@ struct _ClutterActorClass
void (* resource_scale_changed) (ClutterActor *self); void (* resource_scale_changed) (ClutterActor *self);
float (* calculate_resource_scale) (ClutterActor *self, float (* calculate_resource_scale) (ClutterActor *self,
int phase); int phase);
void (* actor_added) (ClutterActor *self,
ClutterActor *child);
void (* actor_removed) (ClutterActor *self,
ClutterActor *child);
}; };
/** /**

View File

@ -1,33 +0,0 @@
/*
* Clutter.
*
* An OpenGL based 'interactive canvas' library.
*
* Copyright 2020 Red Hat, Inc.
*
* 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
#include "clutter/clutter-container.h"
G_BEGIN_DECLS
void _clutter_container_emit_actor_added (ClutterContainer *container,
ClutterActor *actor);
void _clutter_container_emit_actor_removed (ClutterContainer *container,
ClutterActor *actor);
G_END_DECLS

View File

@ -37,7 +37,6 @@
#include "clutter/clutter-actor-private.h" #include "clutter/clutter-actor-private.h"
#include "clutter/clutter-child-meta.h" #include "clutter/clutter-child-meta.h"
#include "clutter/clutter-container-private.h"
#include "clutter/clutter-debug.h" #include "clutter/clutter-debug.h"
#include "clutter/clutter-main.h" #include "clutter/clutter-main.h"
#include "clutter/clutter-marshal.h" #include "clutter/clutter-marshal.h"
@ -75,8 +74,6 @@
enum enum
{ {
ACTOR_ADDED,
ACTOR_REMOVED,
CHILD_NOTIFY, CHILD_NOTIFY,
LAST_SIGNAL LAST_SIGNAL
@ -121,39 +118,6 @@ clutter_container_default_init (ClutterContainerInterface *iface)
quark_child_meta = quark_child_meta =
g_quark_from_static_string ("clutter-container-child-data"); g_quark_from_static_string ("clutter-container-child-data");
/**
* ClutterContainer::actor-added:
* @container: the actor which received the signal
* @actor: the new child that has been added to @container
*
* The signal is emitted each time an actor
* has been added to @container.
*/
container_signals[ACTOR_ADDED] =
g_signal_new (I_("actor-added"),
iface_type,
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (ClutterContainerIface, actor_added),
NULL, NULL, NULL,
G_TYPE_NONE, 1,
CLUTTER_TYPE_ACTOR);
/**
* ClutterContainer::actor-removed:
* @container: the actor which received the signal
* @actor: the child that has been removed from @container
*
* The signal is emitted each time an actor
* is removed from @container.
*/
container_signals[ACTOR_REMOVED] =
g_signal_new (I_("actor-removed"),
iface_type,
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (ClutterContainerIface, actor_removed),
NULL, NULL, NULL,
G_TYPE_NONE, 1,
CLUTTER_TYPE_ACTOR);
/** /**
* ClutterContainer::child-notify: * ClutterContainer::child-notify:
* @container: the container which received the signal * @container: the container which received the signal
@ -985,23 +949,3 @@ clutter_container_child_notify (ClutterContainer *container,
child, child,
pspec); pspec);
} }
void
_clutter_container_emit_actor_added (ClutterContainer *container,
ClutterActor *actor)
{
g_return_if_fail (CLUTTER_IS_CONTAINER (container));
g_return_if_fail (CLUTTER_IS_ACTOR (actor));
g_signal_emit (container, container_signals[ACTOR_ADDED], 0, actor);
}
void
_clutter_container_emit_actor_removed (ClutterContainer *container,
ClutterActor *actor)
{
g_return_if_fail (CLUTTER_IS_CONTAINER (container));
g_return_if_fail (CLUTTER_IS_ACTOR (actor));
g_signal_emit (container, container_signals[ACTOR_REMOVED], 0, actor);
}

View File

@ -400,7 +400,7 @@ actor_remove_all (void)
} }
static void static void
actor_added (ClutterContainer *container, actor_added (ClutterActor *container,
ClutterActor *child, ClutterActor *child,
gpointer data) gpointer data)
{ {
@ -419,7 +419,7 @@ actor_added (ClutterContainer *container,
} }
static void static void
actor_removed (ClutterContainer *container, actor_removed (ClutterActor *container,
ClutterActor *child, ClutterActor *child,
gpointer data) gpointer data)
{ {