summaryrefslogtreecommitdiff
path: root/libmetacity/meta-theme.c
diff options
context:
space:
mode:
authorAlberts Muktupāvels <alberts.muktupavels@gmail.com>2016-02-04 00:24:08 +0200
committerAlberts Muktupāvels <alberts.muktupavels@gmail.com>2016-02-04 00:24:08 +0200
commit725a5438e72c95ce9b784c8a60a3c1a6e7bb192a (patch)
tree3cfbfd294b79278e183386361b6fd59b91d5a19c /libmetacity/meta-theme.c
parent99f79563ae5e2c777544ec59cfdbfb8e4f38c162 (diff)
downloadmetacity-725a5438e72c95ce9b784c8a60a3c1a6e7bb192a.tar.gz
theme: move get_current and set_current to libmetacity
Diffstat (limited to 'libmetacity/meta-theme.c')
-rw-r--r--libmetacity/meta-theme.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/libmetacity/meta-theme.c b/libmetacity/meta-theme.c
index ef88cdcd..66eb8549 100644
--- a/libmetacity/meta-theme.c
+++ b/libmetacity/meta-theme.c
@@ -17,6 +17,7 @@
#include "config.h"
+#include <glib/gi18n-lib.h>
#include <string.h>
#include "meta-enum-types.h"
@@ -595,3 +596,65 @@ meta_theme_draw_frame (MetaTheme *theme,
mini_icon,
icon);
}
+
+/**
+ * The current theme. (Themes are singleton.)
+ */
+static MetaTheme *meta_current_theme = NULL;
+
+MetaTheme*
+meta_theme_get_current (void)
+{
+ return meta_current_theme;
+}
+
+void
+meta_theme_set_current (const gchar *name,
+ gboolean force_reload,
+ gboolean composited,
+ const PangoFontDescription *titlebar_font)
+{
+ MetaTheme *new_theme;
+ GError *error;
+
+ g_debug ("Setting current theme to '%s'", name);
+
+ if (!force_reload && meta_current_theme)
+ {
+ gchar *theme_name;
+
+ theme_name = meta_theme_get_name (meta_current_theme);
+ if (g_strcmp0 (name, theme_name) == 0)
+ {
+ g_free (theme_name);
+ return;
+ }
+
+ g_free (theme_name);
+ }
+
+ if (name != NULL && strcmp (name, "") != 0)
+ new_theme = meta_theme_new (META_THEME_TYPE_METACITY);
+ else
+ new_theme = meta_theme_new (META_THEME_TYPE_GTK);
+
+ meta_theme_set_composited (new_theme, composited);
+ meta_theme_set_titlebar_font (new_theme, titlebar_font);
+
+ error = NULL;
+ if (!meta_theme_load (new_theme, name, &error))
+ {
+ g_warning (_("Failed to load theme '%s': %s"), name, error->message);
+ g_error_free (error);
+
+ g_object_unref (new_theme);
+ }
+ else
+ {
+ if (meta_current_theme)
+ g_object_unref (meta_current_theme);
+ meta_current_theme = new_theme;
+
+ g_debug ("New theme is '%s'", name);
+ }
+}