[metacity] theme: move style_sets_by_type to MetaThemeImpl



commit fdb06ae5150413912295505300b8a7c5dbc226eb
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Sun Jan 31 05:25:05 2016 +0200

    theme: move style_sets_by_type to MetaThemeImpl

 libmetacity/meta-theme-impl.c |   58 ++++++++++++++++++++++++++++++++++++++++-
 libmetacity/meta-theme-impl.h |   10 +++++++
 src/ui/theme-parser.c         |   18 +++----------
 src/ui/theme-private.h        |    2 -
 src/ui/theme.c                |   16 ++++-------
 5 files changed, 77 insertions(+), 27 deletions(-)
---
diff --git a/libmetacity/meta-theme-impl.c b/libmetacity/meta-theme-impl.c
index 67de193..66a5552 100644
--- a/libmetacity/meta-theme-impl.c
+++ b/libmetacity/meta-theme-impl.c
@@ -17,16 +17,72 @@
 
 #include "config.h"
 
+#include "meta-frame-style.h"
 #include "meta-theme-impl.h"
 
-G_DEFINE_TYPE (MetaThemeImpl, meta_theme_impl, G_TYPE_OBJECT)
+typedef struct
+{
+  MetaFrameStyleSet *style_sets_by_type[META_FRAME_TYPE_LAST];
+} MetaThemeImplPrivate;
+
+G_DEFINE_TYPE_WITH_PRIVATE (MetaThemeImpl, meta_theme_impl, G_TYPE_OBJECT)
+
+static void
+meta_theme_impl_dispose (GObject *object)
+{
+  MetaThemeImpl *impl;
+  MetaThemeImplPrivate *priv;
+  gint i;
+
+  impl = META_THEME_IMPL (object);
+  priv = meta_theme_impl_get_instance_private (impl);
+
+  for (i = 0; i < META_FRAME_TYPE_LAST; i++)
+    {
+      if (priv->style_sets_by_type[i])
+        {
+          meta_frame_style_set_unref (priv->style_sets_by_type[i]);
+          priv->style_sets_by_type[i] = NULL;
+        }
+    }
+
+  G_OBJECT_CLASS (meta_theme_impl_parent_class)->dispose (object);
+}
 
 static void
 meta_theme_impl_class_init (MetaThemeImplClass *impl_class)
 {
+  GObjectClass *object_class;
+
+  object_class = G_OBJECT_CLASS (impl_class);
+
+  object_class->dispose = meta_theme_impl_dispose;
 }
 
 static void
 meta_theme_impl_init (MetaThemeImpl *impl)
 {
 }
+
+void
+meta_theme_impl_add_style_set (MetaThemeImpl     *impl,
+                               MetaFrameType      type,
+                               MetaFrameStyleSet *style_set)
+{
+  MetaThemeImplPrivate *priv;
+
+  priv = meta_theme_impl_get_instance_private (impl);
+
+  priv->style_sets_by_type[type] = style_set;
+}
+
+MetaFrameStyleSet *
+meta_theme_impl_get_style_set (MetaThemeImpl *impl,
+                               MetaFrameType  type)
+{
+  MetaThemeImplPrivate *priv;
+
+  priv = meta_theme_impl_get_instance_private (impl);
+
+  return priv->style_sets_by_type[type];
+}
diff --git a/libmetacity/meta-theme-impl.h b/libmetacity/meta-theme-impl.h
index 6268df2..9e03fe0 100644
--- a/libmetacity/meta-theme-impl.h
+++ b/libmetacity/meta-theme-impl.h
@@ -19,9 +19,12 @@
 #define META_THEME_IMPL_H
 
 #include <glib-object.h>
+#include <libmetacity/meta-frame-enums.h>
 
 G_BEGIN_DECLS
 
+typedef struct _MetaFrameStyleSet MetaFrameStyleSet;
+
 #define META_TYPE_THEME_IMPL meta_theme_impl_get_type ()
 G_DECLARE_DERIVABLE_TYPE (MetaThemeImpl, meta_theme_impl,
                           META, THEME_IMPL, GObject)
@@ -31,6 +34,13 @@ struct _MetaThemeImplClass
   GObjectClass parent_class;
 };
 
+void               meta_theme_impl_add_style_set (MetaThemeImpl     *impl,
+                                                  MetaFrameType      type,
+                                                  MetaFrameStyleSet *style_set);
+
+MetaFrameStyleSet *meta_theme_impl_get_style_set (MetaThemeImpl     *impl,
+                                                  MetaFrameType      type);
+
 G_END_DECLS
 
 #endif
diff --git a/src/ui/theme-parser.c b/src/ui/theme-parser.c
index 9f02dac..dd4b0bd 100644
--- a/src/ui/theme-parser.c
+++ b/src/ui/theme-parser.c
@@ -1179,7 +1179,7 @@ parse_toplevel_element (GMarkupParseContext  *context,
           return;
         }
 
-      if (info->theme->style_sets_by_type[type] != NULL)
+      if (meta_theme_impl_get_style_set (info->theme->impl, type) != NULL)
         {
           set_error (error, context, G_MARKUP_ERROR, G_MARKUP_ERROR_PARSE,
                      _("Window type \"%s\" has already been assigned a style set"),
@@ -1188,7 +1188,7 @@ parse_toplevel_element (GMarkupParseContext  *context,
         }
 
       meta_frame_style_set_ref (style_set);
-      info->theme->style_sets_by_type[type] = style_set;
+      meta_theme_impl_add_style_set (info->theme->impl, type, style_set);
 
       push_state (info, STATE_WINDOW);
     }
@@ -3672,7 +3672,8 @@ meta_theme_validate (MetaTheme *theme,
     }
 
   for (i = 0; i < (int)META_FRAME_TYPE_LAST; i++)
-    if (i != (int)META_FRAME_TYPE_ATTACHED && theme->style_sets_by_type[i] == NULL)
+    if (i != (int)META_FRAME_TYPE_ATTACHED &&
+        meta_theme_impl_get_style_set (theme->impl, i) == NULL)
       {
         g_set_error (error, META_THEME_ERROR, META_THEME_ERROR_FAILED,
                      _("No frame style set for window type \"%s\" in theme \"%s\", add a <window type=\"%s\" 
style_set=\"whatever\"/> element"),
@@ -4123,8 +4124,6 @@ theme_error_is_fatal (GError *error)
 static void
 clear_theme (MetaTheme *theme)
 {
-  gint i;
-
   g_free (theme->name);
   theme->name = NULL;
 
@@ -4157,15 +4156,6 @@ clear_theme (MetaTheme *theme)
 
   g_hash_table_remove_all (theme->images_by_filename);
 
-  for (i = 0; i < META_FRAME_TYPE_LAST; i++)
-    {
-      if (theme->style_sets_by_type[i] == NULL)
-        continue;
-
-      meta_frame_style_set_unref (theme->style_sets_by_type[i]);
-      theme->style_sets_by_type[i] = NULL;
-    }
-
   g_clear_object (&theme->impl);
   theme->impl = g_object_new (META_TYPE_THEME_METACITY, NULL);
 }
diff --git a/src/ui/theme-private.h b/src/ui/theme-private.h
index f0e6a62..9d547f8 100644
--- a/src/ui/theme-private.h
+++ b/src/ui/theme-private.h
@@ -66,8 +66,6 @@ struct _MetaTheme
 
   GHashTable *images_by_filename;
 
-  MetaFrameStyleSet *style_sets_by_type[META_FRAME_TYPE_LAST];
-
   MetaThemeImpl *impl;
 };
 
diff --git a/src/ui/theme.c b/src/ui/theme.c
index 112c149..56ef014 100644
--- a/src/ui/theme.c
+++ b/src/ui/theme.c
@@ -1715,7 +1715,8 @@ theme_set_current_gtk (const gchar                *name,
         }
 
       meta_frame_style_unref (style);
-      meta_current_theme->style_sets_by_type[frame_type] = style_set;
+      meta_theme_impl_add_style_set (meta_current_theme->impl,
+                                     frame_type, style_set);
     }
 }
 
@@ -1764,8 +1765,6 @@ meta_theme_new (MetaThemeType type)
 void
 meta_theme_free (MetaTheme *theme)
 {
-  int i;
-
   g_return_if_fail (theme != NULL);
 
   g_free (theme->name);
@@ -1782,10 +1781,6 @@ meta_theme_free (MetaTheme *theme)
 
   g_hash_table_destroy (theme->images_by_filename);
 
-  for (i = 0; i < META_FRAME_TYPE_LAST; i++)
-    if (theme->style_sets_by_type[i])
-      meta_frame_style_set_unref (theme->style_sets_by_type[i]);
-
   g_clear_object (&theme->impl);
 
   DEBUG_FILL_STRUCT (theme);
@@ -1818,16 +1813,17 @@ theme_get_style (MetaTheme     *theme,
   MetaFrameStyle *style;
   MetaFrameStyleSet *style_set;
 
-  style_set = theme->style_sets_by_type[type];
+  style_set = meta_theme_impl_get_style_set (theme->impl, type);
 
   if (style_set == NULL && type == META_FRAME_TYPE_ATTACHED)
-    style_set = theme->style_sets_by_type[META_FRAME_TYPE_BORDER];
+    style_set = meta_theme_impl_get_style_set (theme->impl, META_FRAME_TYPE_BORDER);
 
   /* Right now the parser forces a style set for all other types,
    * but this fallback code is here in case I take that out.
    */
   if (style_set == NULL)
-    style_set = theme->style_sets_by_type[META_FRAME_TYPE_NORMAL];
+    style_set = meta_theme_impl_get_style_set (theme->impl, META_FRAME_TYPE_NORMAL);
+
   if (style_set == NULL)
     return NULL;
 


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