[gnome-software] gs-star-widget: Only refresh if the widget is realised



commit 8e17f641d94ee9f9e143b14ca107dfd3d971fe34
Author: Philip Withnall <withnall endlessm com>
Date:   Tue Jun 2 13:20:53 2020 +0100

    gs-star-widget: Only refresh if the widget is realised
    
    The widget is refreshed whenever any of its properties are changed,
    including at construction time. But there’s no need to actually refresh
    and implement the property changes until the widget is realised and
    drawn on screen. So defer and coalesce that work.
    
    Signed-off-by: Philip Withnall <withnall endlessm com>

 src/gs-star-widget.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
---
diff --git a/src/gs-star-widget.c b/src/gs-star-widget.c
index 32255b4e..6b3bfb08 100644
--- a/src/gs-star-widget.c
+++ b/src/gs-star-widget.c
@@ -87,6 +87,9 @@ gs_star_widget_refresh (GsStarWidget *star)
        GsStarWidgetPrivate *priv = gs_star_widget_get_instance_private (star);
        const gint rate_to_star[] = {20, 40, 60, 80, 100, -1};
 
+       if (!gtk_widget_get_realized (GTK_WIDGET (star)))
+               return;
+
        /* remove all existing widgets */
        gs_container_remove_all (GTK_CONTAINER (priv->box1));
 
@@ -209,6 +212,15 @@ gs_star_widget_destroy (GtkWidget *widget)
        GTK_WIDGET_CLASS (gs_star_widget_parent_class)->destroy (widget);
 }
 
+static void
+gs_star_widget_realize (GtkWidget *widget)
+{
+       GTK_WIDGET_CLASS (gs_star_widget_parent_class)->realize (widget);
+
+       /* Create child widgets. */
+       gs_star_widget_refresh (GS_STAR_WIDGET (widget));
+}
+
 static void
 gs_star_widget_init (GsStarWidget *star)
 {
@@ -223,6 +235,7 @@ gs_star_widget_class_init (GsStarWidgetClass *klass)
        GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
        widget_class->destroy = gs_star_widget_destroy;
+       widget_class->realize = gs_star_widget_realize;
        object_class->get_property = gs_star_widget_get_property;
        object_class->set_property = gs_star_widget_set_property;
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]