[metacity] libmetacity: use load vfunc to load GTK+ theme



commit 0482b5ded736042867fe1e2703900b49551a9a1a
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Sun Jan 31 06:51:06 2016 +0200

    libmetacity: use load vfunc to load GTK+ theme

 libmetacity/meta-theme-gtk.c |  101 ++++++++++++++++++++++++++++++++++++++++++
 src/ui/theme.c               |   65 +--------------------------
 2 files changed, 102 insertions(+), 64 deletions(-)
---
diff --git a/libmetacity/meta-theme-gtk.c b/libmetacity/meta-theme-gtk.c
index 4bde7b6..1e6b130 100644
--- a/libmetacity/meta-theme-gtk.c
+++ b/libmetacity/meta-theme-gtk.c
@@ -17,7 +17,11 @@
 
 #include "config.h"
 
+#include <gtk/gtk.h>
+
+#include "meta-frame-style.h"
 #include "meta-theme-gtk.h"
+#include "meta-theme.h"
 
 struct _MetaThemeGtk
 {
@@ -26,9 +30,106 @@ struct _MetaThemeGtk
 
 G_DEFINE_TYPE (MetaThemeGtk, meta_theme_gtk, META_TYPE_THEME_IMPL)
 
+static gboolean
+meta_theme_gtk_load (MetaThemeImpl  *impl,
+                     const gchar    *name,
+                     GError        **error)
+{
+  GtkSettings *settings;
+  MetaFrameType type;
+
+  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+  settings = gtk_settings_get_default ();
+
+  if (settings == NULL)
+    return FALSE;
+
+  g_object_set (settings, "gtk-theme-name", name, NULL);
+
+  for (type = 0; type < META_FRAME_TYPE_LAST; type++)
+    {
+      MetaFrameStyleSet *style_set;
+      MetaFrameStyle *style;
+      gint i;
+      gint j;
+
+      style_set = meta_frame_style_set_new (NULL);
+
+      style = meta_frame_style_new (NULL);
+      style->layout = meta_frame_layout_new ();
+
+      switch (type)
+        {
+          case META_FRAME_TYPE_NORMAL:
+            break;
+
+          case META_FRAME_TYPE_DIALOG:
+          case META_FRAME_TYPE_MODAL_DIALOG:
+          case META_FRAME_TYPE_ATTACHED:
+            style->layout->hide_buttons = TRUE;
+            break;
+
+          case META_FRAME_TYPE_MENU:
+          case META_FRAME_TYPE_UTILITY:
+            style->layout->title_scale = PANGO_SCALE_SMALL;
+            break;
+
+          case META_FRAME_TYPE_BORDER:
+            style->layout->has_title = FALSE;
+            style->layout->hide_buttons = TRUE;
+            break;
+
+          case META_FRAME_TYPE_LAST:
+          default:
+            g_assert_not_reached ();
+        }
+
+      for (i = 0; i < META_FRAME_FOCUS_LAST; i++)
+        {
+          for (j = 0; j < META_FRAME_RESIZE_LAST; j++)
+            {
+              meta_frame_style_ref (style);
+              style_set->normal_styles[j][i] = style;
+
+              meta_frame_style_ref (style);
+              style_set->shaded_styles[j][i] = style;
+            }
+
+          meta_frame_style_ref (style);
+          style_set->maximized_styles[i] = style;
+
+          meta_frame_style_ref (style);
+          style_set->tiled_left_styles[i] = style;
+
+          meta_frame_style_ref (style);
+          style_set->tiled_right_styles[i] = style;
+
+          meta_frame_style_ref (style);
+          style_set->maximized_and_shaded_styles[i] = style;
+
+          meta_frame_style_ref (style);
+          style_set->tiled_left_and_shaded_styles[i] = style;
+
+          meta_frame_style_ref (style);
+          style_set->tiled_right_and_shaded_styles[i] = style;
+        }
+
+      meta_frame_style_unref (style);
+      meta_theme_impl_add_style_set (impl, type, style_set);
+    }
+
+  return TRUE;
+}
+
 static void
 meta_theme_gtk_class_init (MetaThemeGtkClass *gtk_class)
 {
+  MetaThemeImplClass *impl_class;
+
+  impl_class = META_THEME_IMPL_CLASS (gtk_class);
+
+  impl_class->load = meta_theme_gtk_load;
 }
 
 static void
diff --git a/src/ui/theme.c b/src/ui/theme.c
index 56ef014..ede31d0 100644
--- a/src/ui/theme.c
+++ b/src/ui/theme.c
@@ -1640,8 +1640,6 @@ theme_set_current_gtk (const gchar                *name,
                        gboolean                    composited,
                        const PangoFontDescription *titlebar_font)
 {
-  int i, j, frame_type;
-
   meta_topic (META_DEBUG_THEMES, "Setting current theme to \"%s\"\n", name);
 
   if (!force_reload && meta_current_theme)
@@ -1656,68 +1654,7 @@ theme_set_current_gtk (const gchar                *name,
   meta_current_theme->composited = composited;
   meta_current_theme->titlebar_font = pango_font_description_copy (titlebar_font);
 
-  for (frame_type = 0; frame_type < META_FRAME_TYPE_LAST; frame_type++)
-    {
-      MetaFrameStyleSet *style_set = meta_frame_style_set_new (NULL);
-      MetaFrameStyle *style = meta_frame_style_new (NULL);
-
-      style->layout = meta_frame_layout_new ();
-
-      switch (frame_type)
-        {
-          case META_FRAME_TYPE_NORMAL:
-            break;
-          case META_FRAME_TYPE_DIALOG:
-          case META_FRAME_TYPE_MODAL_DIALOG:
-          case META_FRAME_TYPE_ATTACHED:
-            style->layout->hide_buttons = TRUE;
-            break;
-          case META_FRAME_TYPE_MENU:
-          case META_FRAME_TYPE_UTILITY:
-            style->layout->title_scale = PANGO_SCALE_SMALL;
-            break;
-          case META_FRAME_TYPE_BORDER:
-            style->layout->has_title = FALSE;
-            style->layout->hide_buttons = TRUE;
-            break;
-          default:
-            g_assert_not_reached ();
-        }
-
-      for (i = 0; i < META_FRAME_FOCUS_LAST; i++)
-        {
-          for (j = 0; j < META_FRAME_RESIZE_LAST; j++)
-            {
-              meta_frame_style_ref (style);
-              style_set->normal_styles[j][i] = style;
-
-              meta_frame_style_ref (style);
-              style_set->shaded_styles[j][i] = style;
-            }
-
-          meta_frame_style_ref (style);
-          style_set->maximized_styles[i] = style;
-
-          meta_frame_style_ref (style);
-          style_set->tiled_left_styles[i] = style;
-
-          meta_frame_style_ref (style);
-          style_set->tiled_right_styles[i] = style;
-
-          meta_frame_style_ref (style);
-          style_set->maximized_and_shaded_styles[i] = style;
-
-          meta_frame_style_ref (style);
-          style_set->tiled_left_and_shaded_styles[i] = style;
-
-          meta_frame_style_ref (style);
-          style_set->tiled_right_and_shaded_styles[i] = style;
-        }
-
-      meta_frame_style_unref (style);
-      meta_theme_impl_add_style_set (meta_current_theme->impl,
-                                     frame_type, style_set);
-    }
+  meta_theme_impl_load (meta_current_theme->impl, name, NULL);
 }
 
 void


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