st: Use g_object_notify_by_pspec() where possible

It's slightly more efficient not having to do property lookups. While
that is unlikely to be a concern for the properties in question, it's
still good practice and makes the code base a bit more consistent.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2168>
This commit is contained in:
Florian Müllner 2022-02-09 15:22:42 +01:00 committed by Marge Bot
parent 76e5e22dac
commit bfb52aaf9d
3 changed files with 50 additions and 31 deletions

View File

@ -60,8 +60,12 @@ enum {
PROP_VERTICAL, PROP_VERTICAL,
PROP_PACK_START, PROP_PACK_START,
N_PROPS
}; };
static GParamSpec *props[N_PROPS] = { NULL, };
struct _StBoxLayoutPrivate struct _StBoxLayoutPrivate
{ {
StAdjustment *hadjustment; StAdjustment *hadjustment;
@ -169,7 +173,6 @@ st_box_layout_class_init (StBoxLayoutClass *klass)
{ {
GObjectClass *object_class = G_OBJECT_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass);
StWidgetClass *widget_class = ST_WIDGET_CLASS (klass); StWidgetClass *widget_class = ST_WIDGET_CLASS (klass);
GParamSpec *pspec;
object_class->get_property = st_box_layout_get_property; object_class->get_property = st_box_layout_get_property;
object_class->set_property = st_box_layout_set_property; object_class->set_property = st_box_layout_set_property;
@ -182,13 +185,13 @@ st_box_layout_class_init (StBoxLayoutClass *klass)
* A convenience property for the #ClutterBoxLayout:vertical property of the * A convenience property for the #ClutterBoxLayout:vertical property of the
* internal layout for #StBoxLayout. * internal layout for #StBoxLayout.
*/ */
pspec = g_param_spec_boolean ("vertical", props[PROP_VERTICAL] =
"Vertical", g_param_spec_boolean ("vertical",
"Whether the layout should be vertical, rather" "Vertical",
"than horizontal", "Whether the layout should be vertical, rather"
FALSE, "than horizontal",
ST_PARAM_READWRITE); FALSE,
g_object_class_install_property (object_class, PROP_VERTICAL, pspec); ST_PARAM_READWRITE);
/** /**
* StBoxLayout:pack-start: * StBoxLayout:pack-start:
@ -196,12 +199,14 @@ st_box_layout_class_init (StBoxLayoutClass *klass)
* A convenience property for the #ClutterBoxLayout:pack-start property of the * A convenience property for the #ClutterBoxLayout:pack-start property of the
* internal layout for #StBoxLayout. * internal layout for #StBoxLayout.
*/ */
pspec = g_param_spec_boolean ("pack-start", props[PROP_PACK_START] =
"Pack Start", g_param_spec_boolean ("pack-start",
"Whether to pack items at the start of the box", "Pack Start",
FALSE, "Whether to pack items at the start of the box",
ST_PARAM_READWRITE | G_PARAM_DEPRECATED); FALSE,
g_object_class_install_property (object_class, PROP_PACK_START, pspec); ST_PARAM_READWRITE | G_PARAM_DEPRECATED);
g_object_class_install_properties (object_class, N_PROPS, props);
} }
static void static void
@ -250,7 +255,7 @@ st_box_layout_set_vertical (StBoxLayout *box,
if (clutter_box_layout_get_orientation (CLUTTER_BOX_LAYOUT (layout)) != orientation) if (clutter_box_layout_get_orientation (CLUTTER_BOX_LAYOUT (layout)) != orientation)
{ {
clutter_box_layout_set_orientation (CLUTTER_BOX_LAYOUT (layout), orientation); clutter_box_layout_set_orientation (CLUTTER_BOX_LAYOUT (layout), orientation);
g_object_notify (G_OBJECT (box), "vertical"); g_object_notify_by_pspec (G_OBJECT (box), props[PROP_VERTICAL]);
} }
} }

View File

@ -46,9 +46,13 @@ struct _StThemeContext {
enum enum
{ {
PROP_0, PROP_0,
PROP_SCALE_FACTOR PROP_SCALE_FACTOR,
N_PROPS
}; };
static GParamSpec *props[N_PROPS] = { NULL, };
enum enum
{ {
CHANGED, CHANGED,
@ -85,7 +89,7 @@ st_theme_context_set_scale_factor (StThemeContext *context,
return; return;
context->scale_factor = scale_factor; context->scale_factor = scale_factor;
g_object_notify (G_OBJECT (context), "scale-factor"); g_object_notify_by_pspec (G_OBJECT (context), props[PROP_SCALE_FACTOR]);
st_theme_context_changed (context); st_theme_context_changed (context);
} }
@ -133,13 +137,14 @@ st_theme_context_class_init (StThemeContextClass *klass)
* *
* The scaling factor used for HiDPI scaling. * The scaling factor used for HiDPI scaling.
*/ */
g_object_class_install_property (object_class, props[PROP_SCALE_FACTOR] =
PROP_SCALE_FACTOR, g_param_spec_int ("scale-factor",
g_param_spec_int ("scale-factor", "Scale factor",
"Scale factor", "Integer scale factor used for HiDPI scaling",
"Integer scale factor used for HiDPI scaling", 0, G_MAXINT, 1,
0, G_MAXINT, 1, ST_PARAM_READWRITE);
ST_PARAM_READWRITE));
g_object_class_install_properties (object_class, N_PROPS, props);
/** /**
* StThemeContext::changed: * StThemeContext::changed:

View File

@ -55,11 +55,18 @@ static void st_viewport_scrollable_interface_init (StScrollableInterface *iface)
enum { enum {
PROP_0, PROP_0,
PROP_CLIP_TO_VIEW, PROP_CLIP_TO_VIEW,
N_PROPS,
/* StScrollable */
PROP_HADJUST, PROP_HADJUST,
PROP_VADJUST PROP_VADJUST
}; };
static GParamSpec *props[N_PROPS] = { NULL, };
typedef struct typedef struct
{ {
StAdjustment *hadjustment; StAdjustment *hadjustment;
@ -177,6 +184,7 @@ st_viewport_set_clip_to_view (StViewport *viewport,
{ {
priv->clip_to_view = clip_to_view; priv->clip_to_view = clip_to_view;
clutter_actor_queue_redraw (CLUTTER_ACTOR (viewport)); clutter_actor_queue_redraw (CLUTTER_ACTOR (viewport));
g_object_notify_by_pspec (G_OBJECT (viewport), props[PROP_CLIP_TO_VIEW]);
} }
} }
@ -588,13 +596,12 @@ st_viewport_class_init (StViewportClass *klass)
actor_class->get_paint_volume = st_viewport_get_paint_volume; actor_class->get_paint_volume = st_viewport_get_paint_volume;
actor_class->pick = st_viewport_pick; actor_class->pick = st_viewport_pick;
g_object_class_install_property (object_class, props[PROP_CLIP_TO_VIEW] =
PROP_CLIP_TO_VIEW, g_param_spec_boolean ("clip-to-view",
g_param_spec_boolean ("clip-to-view", "Clip to view",
"Clip to view", "Clip to view",
"Clip to view", TRUE,
TRUE, ST_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
ST_PARAM_READWRITE));
/* StScrollable properties */ /* StScrollable properties */
g_object_class_override_property (object_class, g_object_class_override_property (object_class,
@ -604,6 +611,8 @@ st_viewport_class_init (StViewportClass *klass)
g_object_class_override_property (object_class, g_object_class_override_property (object_class,
PROP_VADJUST, PROP_VADJUST,
"vadjustment"); "vadjustment");
g_object_class_install_properties (object_class, N_PROPS, props);
} }
static void static void