mirror of
https://github.com/brl/mutter.git
synced 2024-12-23 03:22:04 +00:00
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. https://bugzilla.gnome.org/show_bug.cgi?id=741917
This commit is contained in:
parent
d5e6177900
commit
662dd6a289
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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,
|
||||
@ -648,7 +647,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,
|
||||
@ -1560,7 +1559,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);
|
||||
|
||||
@ -1751,7 +1750,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,
|
||||
|
@ -4573,23 +4573,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++)
|
||||
{
|
||||
@ -4650,8 +4646,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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
11
src/ui/ui.c
11
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
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user