[mutter/wip/gtk-theming: 15/20] theme: Use a singleton theme
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter/wip/gtk-theming: 15/20] theme: Use a singleton theme
- Date: Mon, 22 Dec 2014 23:26:01 +0000 (UTC)
commit 307bddb822350be2b8b645b8275c14a25765e000
Author: Florian Müllner <fmuellner gnome org>
Date: Fri Sep 26 00:26:01 2014 +0200
theme: Use a singleton theme
Different themes don't make sense when we are always using the current
GTK+ theme for everything, so adapt the MetaTheme API to use a singleton.
src/core/main.c | 38 --------------------------------------
src/meta/theme.h | 3 +--
src/ui/frames.c | 11 +++++------
src/ui/theme.c | 21 +++++++++------------
src/ui/ui.c | 11 ++---------
src/ui/ui.h | 1 -
6 files changed, 17 insertions(+), 68 deletions(-)
---
diff --git a/src/core/main.c b/src/core/main.c
index 8184f56..3189f84 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -431,42 +431,6 @@ meta_run (void)
meta_prefs_init ();
meta_prefs_add_listener (prefs_changed_callback, NULL);
- meta_ui_set_current_theme (meta_prefs_get_theme ());
-
- /* Try to find some theme that'll work if the theme preference
- * doesn't exist. First try Simple (the default theme) then just
- * try anything in the themes directory.
- */
- if (!meta_ui_have_a_theme ())
- meta_ui_set_current_theme ("Simple");
-
- if (!meta_ui_have_a_theme ())
- {
- const char *dir_entry = NULL;
- GError *err = NULL;
- GDir *themes_dir = NULL;
-
- if (!(themes_dir = g_dir_open (MUTTER_DATADIR"/themes", 0, &err)))
- {
- meta_fatal (_("Failed to scan themes directory: %s\n"), err->message);
- g_error_free (err);
- }
- else
- {
- while (((dir_entry = g_dir_read_name (themes_dir)) != NULL) &&
- (!meta_ui_have_a_theme ()))
- {
- meta_ui_set_current_theme (dir_entry);
- }
-
- g_dir_close (themes_dir);
- }
- }
-
- if (!meta_ui_have_a_theme ())
- meta_fatal (_("Could not find a theme! Be sure %s exists and contains the usual themes.\n"),
- MUTTER_DATADIR"/themes");
-
if (!meta_display_open ())
meta_exit (META_EXIT_ERROR);
@@ -513,9 +477,7 @@ prefs_changed_callback (MetaPreference pref,
{
switch (pref)
{
- case META_PREF_THEME:
case META_PREF_DRAGGABLE_BORDER_WIDTH:
- meta_ui_set_current_theme (meta_prefs_get_theme ());
meta_display_retheme_all ();
break;
diff --git a/src/meta/theme.h b/src/meta/theme.h
index b8d34f4..7394d7c 100644
--- a/src/meta/theme.h
+++ b/src/meta/theme.h
@@ -30,8 +30,7 @@
*/
typedef struct _MetaTheme MetaTheme;
-MetaTheme* meta_theme_get_current (void);
-void meta_theme_set_current (const char *name);
+MetaTheme* meta_theme_get_default (void);
MetaTheme* meta_theme_new (void);
void meta_theme_free (MetaTheme *theme);
diff --git a/src/ui/frames.c b/src/ui/frames.c
index 81b263b..af75a68 100644
--- a/src/ui/frames.c
+++ b/src/ui/frames.c
@@ -395,8 +395,7 @@ meta_frames_ensure_layout (MetaFrames *frames,
META_CORE_GET_FRAME_TYPE, &type,
META_CORE_GET_END);
- style = meta_theme_get_frame_style (meta_theme_get_current (),
- type, flags);
+ style = meta_theme_get_frame_style (meta_theme_get_default (), type, flags);
if (style != frame->cache_style)
{
@@ -480,7 +479,7 @@ meta_frames_calc_geometry (MetaFrames *frames,
meta_prefs_get_button_layout (&button_layout);
- meta_theme_calc_geometry (meta_theme_get_current (),
+ meta_theme_calc_geometry (meta_theme_get_default (),
frame->style_info,
type,
frame->text_height,
@@ -649,7 +648,7 @@ meta_ui_frame_get_borders (MetaFrames *frames,
* by the core move/resize code to decide on the client
* window size
*/
- meta_theme_get_frame_borders (meta_theme_get_current (),
+ meta_theme_get_frame_borders (meta_theme_get_default (),
frame->style_info,
type,
frame->text_height,
@@ -1561,7 +1560,7 @@ get_visible_frame_border_region (MetaUIFrame *frame)
META_CORE_GET_FRAME_RECT, &frame_rect,
META_CORE_GET_END);
- meta_theme_get_frame_borders (meta_theme_get_current (), frame->style_info,
+ meta_theme_get_frame_borders (meta_theme_get_default (), frame->style_info,
type, frame->text_height, flags,
&borders);
@@ -1752,7 +1751,7 @@ meta_frames_paint (MetaFrames *frames,
meta_prefs_get_button_layout (&button_layout);
- meta_theme_draw_frame (meta_theme_get_current (),
+ meta_theme_draw_frame (meta_theme_get_default (),
frame->style_info,
cr,
type,
diff --git a/src/ui/theme.c b/src/ui/theme.c
index 91bd73e..75ea94c 100644
--- a/src/ui/theme.c
+++ b/src/ui/theme.c
@@ -4575,23 +4575,19 @@ meta_frame_style_set_validate (MetaFrameStyleSet *style_set,
}
/**
- * meta_theme_get_current: (skip)
+ * meta_theme_get_default: (skip)
*
*/
MetaTheme*
-meta_theme_get_current (void)
-{
- return meta_current_theme;
-}
-
-void
-meta_theme_set_current (const char *name)
+meta_theme_get_default (void)
{
+ static MetaTheme *theme = NULL;
int i, j, frame_type;
- if (meta_current_theme)
- return;
- meta_current_theme = meta_theme_new ();
+ if (theme)
+ return theme;
+
+ theme = meta_theme_new ();
for (frame_type = 0; frame_type < META_FRAME_TYPE_LAST; frame_type++)
{
@@ -4652,8 +4648,9 @@ meta_theme_set_current (const char *name)
}
meta_frame_style_unref (style);
- meta_current_theme->style_sets_by_type[frame_type] = style_set;
+ theme->style_sets_by_type[frame_type] = style_set;
}
+ return theme;
}
/**
diff --git a/src/ui/ui.c b/src/ui/ui.c
index 8e1fba6..1f1f4c7 100644
--- a/src/ui/ui.c
+++ b/src/ui/ui.c
@@ -599,7 +599,7 @@ meta_ui_theme_get_frame_borders (MetaUI *ui,
text_height = meta_pango_font_desc_get_text_height (font_desc, context);
- meta_theme_get_frame_borders (meta_theme_get_current (),
+ meta_theme_get_frame_borders (meta_theme_get_default (),
style_info, type, text_height, flags,
borders);
@@ -615,17 +615,10 @@ meta_ui_theme_get_frame_borders (MetaUI *ui,
meta_style_info_unref (style_info);
}
-void
-meta_ui_set_current_theme (const char *name)
-{
- meta_theme_set_current (name);
- meta_invalidate_default_icons ();
-}
-
gboolean
meta_ui_have_a_theme (void)
{
- return meta_theme_get_current () != NULL;
+ return meta_theme_get_default () != NULL;
}
gboolean
diff --git a/src/ui/ui.h b/src/ui/ui.h
index 6003389..8e460fe 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -111,7 +111,6 @@ GdkPixbuf* meta_gdk_pixbuf_get_from_pixmap (Pixmap xpixmap,
gboolean meta_ui_window_should_not_cause_focus (Display *xdisplay,
Window xwindow);
-void meta_ui_set_current_theme (const char *name);
gboolean meta_ui_have_a_theme (void);
gboolean meta_ui_window_is_widget (MetaUI *ui,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]