From 76e5e22dacb3e8d0a4ac2af50e7962c25842afb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Wed, 9 Feb 2022 15:17:46 +0100 Subject: [PATCH] st: Add static setters Even where properties can only be set via g_object_set(), separate setters help with code organization and consistency with other properties. Part-of: --- src/st/st-adjustment.c | 29 +++++++++++++++++++++-------- src/st/st-scroll-bar.c | 31 ++++++++++++++++++++++--------- src/st/st-scroll-view.c | 20 +++++++++++++++++++- src/st/st-theme-context.c | 25 +++++++++++++++---------- 4 files changed, 77 insertions(+), 28 deletions(-) diff --git a/src/st/st-adjustment.c b/src/st/st-adjustment.c index 5235cb235..28ab78e41 100644 --- a/src/st/st-adjustment.c +++ b/src/st/st-adjustment.c @@ -202,6 +202,26 @@ actor_destroyed (gpointer user_data, g_object_notify_by_pspec (G_OBJECT (adj), props[PROP_ACTOR]); } +static void +st_adjustment_set_actor (StAdjustment *adj, + ClutterActor *actor) +{ + StAdjustmentPrivate *priv; + + priv = st_adjustment_get_instance_private (adj); + + if (priv->actor == actor) + return; + + if (priv->actor) + g_object_weak_unref (G_OBJECT (priv->actor), actor_destroyed, adj); + priv->actor = actor; + if (priv->actor) + g_object_weak_ref (G_OBJECT (priv->actor), actor_destroyed, adj); + + g_object_notify_by_pspec (G_OBJECT (adj), props[PROP_ACTOR]); +} + static void st_adjustment_set_property (GObject *gobject, guint prop_id, @@ -209,18 +229,11 @@ st_adjustment_set_property (GObject *gobject, GParamSpec *pspec) { StAdjustment *adj = ST_ADJUSTMENT (gobject); - StAdjustmentPrivate *priv; - - priv = st_adjustment_get_instance_private (ST_ADJUSTMENT (gobject)); switch (prop_id) { case PROP_ACTOR: - if (priv->actor) - g_object_weak_unref (G_OBJECT (priv->actor), actor_destroyed, adj); - priv->actor = g_value_get_object (value); - if (priv->actor) - g_object_weak_ref (G_OBJECT (priv->actor), actor_destroyed, adj); + st_adjustment_set_actor (adj, g_value_get_object (value)); break; case PROP_LOWER: diff --git a/src/st/st-scroll-bar.c b/src/st/st-scroll-bar.c index 479751130..19fe26b5d 100644 --- a/src/st/st-scroll-bar.c +++ b/src/st/st-scroll-bar.c @@ -103,6 +103,27 @@ handle_button_press_event_cb (ClutterActor *actor, static void stop_scrolling (StScrollBar *bar); +static void +st_scroll_bar_set_vertical (StScrollBar *bar, + gboolean vertical) +{ + StScrollBarPrivate *priv = ST_SCROLL_BAR_PRIVATE (bar); + + if (priv->vertical == vertical) + return; + + priv->vertical = vertical; + + if (priv->vertical) + clutter_actor_set_name (CLUTTER_ACTOR (priv->handle), + "vhandle"); + else + clutter_actor_set_name (CLUTTER_ACTOR (priv->handle), + "hhandle"); + clutter_actor_queue_relayout (CLUTTER_ACTOR (bar)); + g_object_notify_by_pspec (G_OBJECT (bar), props[PROP_VERTICAL]); +} + static void st_scroll_bar_get_property (GObject *gobject, guint prop_id, @@ -134,7 +155,6 @@ st_scroll_bar_set_property (GObject *gobject, GParamSpec *pspec) { StScrollBar *bar = ST_SCROLL_BAR (gobject); - StScrollBarPrivate *priv = st_scroll_bar_get_instance_private (bar); switch (prop_id) { @@ -143,14 +163,7 @@ st_scroll_bar_set_property (GObject *gobject, break; case PROP_VERTICAL: - priv->vertical = g_value_get_boolean (value); - if (priv->vertical) - clutter_actor_set_name (CLUTTER_ACTOR (priv->handle), - "vhandle"); - else - clutter_actor_set_name (CLUTTER_ACTOR (priv->handle), - "hhandle"); - clutter_actor_queue_relayout ((ClutterActor*) gobject); + st_scroll_bar_set_vertical (bar, g_value_get_boolean (value)); break; default: diff --git a/src/st/st-scroll-view.c b/src/st/st-scroll-view.c index 132abd5a4..453542449 100644 --- a/src/st/st-scroll-view.c +++ b/src/st/st-scroll-view.c @@ -210,6 +210,23 @@ st_scroll_view_update_fade_effect (StScrollView *scroll, clutter_actor_queue_redraw (CLUTTER_ACTOR (scroll)); } +static void +st_scroll_view_set_content_padding (StScrollView *scroll, + ClutterMargin *content_padding) +{ + StScrollViewPrivate *priv = ST_SCROLL_VIEW (scroll)->priv; + + if (priv->content_padding.left == content_padding->left && + priv->content_padding.right == content_padding->right && + priv->content_padding.top == content_padding->top && + priv->content_padding.bottom == content_padding->bottom) + return; + + priv->content_padding = *content_padding; + + g_object_notify_by_pspec (G_OBJECT (scroll), props[PROP_CONTENT_PADDING]); +} + static void st_scroll_view_set_property (GObject *object, guint property_id, @@ -240,7 +257,8 @@ st_scroll_view_set_property (GObject *object, g_value_get_enum (value)); break; case PROP_CONTENT_PADDING: - priv->content_padding = * (ClutterMargin *) g_value_get_boxed (value); + st_scroll_view_set_content_padding (self, + (ClutterMargin *)g_value_get_boxed (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); diff --git a/src/st/st-theme-context.c b/src/st/st-theme-context.c index b363b8136..17acd1a10 100644 --- a/src/st/st-theme-context.c +++ b/src/st/st-theme-context.c @@ -77,6 +77,19 @@ static void st_theme_context_get_property (GObject *object, GValue *value, GParamSpec *pspec); +static void +st_theme_context_set_scale_factor (StThemeContext *context, + int scale_factor) +{ + if (scale_factor == context->scale_factor) + return; + + context->scale_factor = scale_factor; + g_object_notify (G_OBJECT (context), "scale-factor"); + st_theme_context_changed (context); +} + + static void st_theme_context_finalize (GObject *object) { @@ -179,16 +192,8 @@ st_theme_context_set_property (GObject *object, switch (prop_id) { case PROP_SCALE_FACTOR: - { - int scale_factor = g_value_get_int (value); - if (scale_factor != context->scale_factor) - { - context->scale_factor = scale_factor; - st_theme_context_changed (context); - } - - break; - } + st_theme_context_set_scale_factor (context, g_value_get_int (value)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break;