[gnome-flashback] desktop: add icon size css class



commit 35fef2dc014e05dbf77a28217b3b015aa0a0fef9
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Tue Nov 12 14:44:10 2019 +0200

    desktop: add icon size css class

 gnome-flashback/libdesktop/gf-icon.c | 39 ++++++++++++++++++++++++++++++++++--
 1 file changed, 37 insertions(+), 2 deletions(-)
---
diff --git a/gnome-flashback/libdesktop/gf-icon.c b/gnome-flashback/libdesktop/gf-icon.c
index eef6423..356e0ad 100644
--- a/gnome-flashback/libdesktop/gf-icon.c
+++ b/gnome-flashback/libdesktop/gf-icon.c
@@ -36,6 +36,8 @@ struct _GfIcon
   GfIconSize  icon_size;
   guint       extra_text_width;
 
+  char       *css_class;
+
   GtkWidget  *image;
   GtkWidget  *label;
 
@@ -207,6 +209,27 @@ multi_press_pressed_cb (GtkGestureMultiPress *gesture,
     }
 }
 
+static void
+set_icon_size (GfIcon *self,
+               int     icon_size)
+{
+  GtkStyleContext *context;
+
+  self->icon_size = icon_size;
+  gtk_image_set_pixel_size (GTK_IMAGE (self->image), icon_size);
+
+  context = gtk_widget_get_style_context (GTK_WIDGET (self));
+
+  if (self->css_class != NULL)
+    {
+      gtk_style_context_remove_class (context, self->css_class);
+      g_clear_pointer (&self->css_class, g_free);
+    }
+
+  self->css_class = g_strdup_printf ("s%dpx", icon_size);
+  gtk_style_context_add_class (context, self->css_class);
+}
+
 static void
 gf_icon_constructed (GObject *object)
 {
@@ -241,6 +264,18 @@ gf_icon_dispose (GObject *object)
   G_OBJECT_CLASS (gf_icon_parent_class)->dispose (object);
 }
 
+static void
+gf_icon_finalize (GObject *object)
+{
+  GfIcon *self;
+
+  self = GF_ICON (object);
+
+  g_clear_pointer (&self->css_class, g_free);
+
+  G_OBJECT_CLASS (gf_icon_parent_class)->finalize (object);
+}
+
 static void
 gf_icon_set_property (GObject      *object,
                       guint         property_id,
@@ -264,8 +299,7 @@ gf_icon_set_property (GObject      *object,
         break;
 
       case PROP_ICON_SIZE:
-        self->icon_size = g_value_get_enum (value);
-        gtk_image_set_pixel_size (GTK_IMAGE (self->image), self->icon_size);
+        set_icon_size (self, g_value_get_enum (value));
         break;
 
       case PROP_EXTRA_TEXT_WIDTH:
@@ -361,6 +395,7 @@ gf_icon_class_init (GfIconClass *self_class)
 
   object_class->constructed = gf_icon_constructed;
   object_class->dispose = gf_icon_dispose;
+  object_class->finalize = gf_icon_finalize;
   object_class->set_property = gf_icon_set_property;
 
   widget_class->get_preferred_width = gf_icon_get_preferred_width;


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