[metacity] frames: move style variants to MetaTheme
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [metacity] frames: move style variants to MetaTheme
- Date: Mon, 1 Feb 2016 14:59:47 +0000 (UTC)
commit 058c0ac5df562281900c4addf9f10011409dfd6f
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Mon Feb 1 14:33:58 2016 +0200
frames: move style variants to MetaTheme
libmetacity/meta-theme.c | 60 ++++++++++++++++++++++++++++++++++++++++
libmetacity/meta-theme.h | 6 ++++
src/ui/frames.c | 69 ++++------------------------------------------
src/ui/frames.h | 3 --
4 files changed, 72 insertions(+), 66 deletions(-)
---
diff --git a/libmetacity/meta-theme.c b/libmetacity/meta-theme.c
index f7ae68a..32e17e0 100644
--- a/libmetacity/meta-theme.c
+++ b/libmetacity/meta-theme.c
@@ -33,6 +33,8 @@ struct _MetaTheme
gboolean composited;
PangoFontDescription *titlebar_font;
+
+ GHashTable *variants;
};
enum
@@ -74,6 +76,8 @@ meta_theme_dispose (GObject *object)
g_clear_object (&theme->impl);
+ g_clear_pointer (&theme->variants, g_hash_table_destroy);
+
G_OBJECT_CLASS (meta_theme_parent_class)->dispose (object);
}
@@ -169,6 +173,10 @@ meta_theme_class_init (MetaThemeClass *theme_class)
static void
meta_theme_init (MetaTheme *theme)
{
+ theme->composited = TRUE;
+
+ theme->variants = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
+ (GDestroyNotify) meta_style_info_unref);
}
/**
@@ -200,10 +208,62 @@ meta_theme_load (MetaTheme *theme,
}
void
+meta_theme_style_invalidate (MetaTheme *theme)
+{
+ GList *variants;
+ GList *l;
+
+ variants = g_hash_table_get_keys (theme->variants);
+
+ for (l = variants; l != NULL; l = g_list_next (l))
+ {
+ gchar *variant;
+ MetaStyleInfo *style_info;
+
+ variant = g_strdup ((gchar *) l->data);
+
+ if (g_strcmp0 (variant, "default") == 0)
+ style_info = meta_style_info_new (NULL, theme->composited);
+ else
+ style_info = meta_style_info_new (variant, theme->composited);
+
+ g_hash_table_insert (theme->variants, variant, style_info);
+ }
+
+ g_list_free (variants);
+}
+
+MetaStyleInfo *
+meta_theme_get_style_info (MetaTheme *theme,
+ const gchar *variant)
+{
+ MetaStyleInfo *style_info;
+
+ if (variant == NULL)
+ variant = "default";
+
+ style_info = g_hash_table_lookup (theme->variants, variant);
+
+ if (style_info == NULL)
+ {
+ style_info = meta_style_info_new (variant, theme->composited);
+
+ g_hash_table_insert (theme->variants, g_strdup (variant), style_info);
+ }
+
+ return style_info;
+}
+
+void
meta_theme_set_composited (MetaTheme *theme,
gboolean composited)
{
+ if (theme->composited == composited)
+ return;
+
theme->composited = composited;
+
+ meta_theme_style_invalidate (theme);
}
gboolean
diff --git a/libmetacity/meta-theme.h b/libmetacity/meta-theme.h
index 64bff50..4e74907 100644
--- a/libmetacity/meta-theme.h
+++ b/libmetacity/meta-theme.h
@@ -21,6 +21,7 @@
#include <gtk/gtk.h>
#include <libmetacity/meta-frame-enums.h>
+#include <libmetacity/meta-style-info.h>
G_BEGIN_DECLS
@@ -82,6 +83,11 @@ gboolean meta_theme_load (MetaTheme
const gchar *theme_name,
GError **error);
+void meta_theme_style_invalidate (MetaTheme *theme);
+
+MetaStyleInfo *meta_theme_get_style_info (MetaTheme *theme,
+ const gchar *variant);
+
void meta_theme_set_composited (MetaTheme *theme,
gboolean composited);
diff --git a/src/ui/frames.c b/src/ui/frames.c
index da546a5..ed219a2 100644
--- a/src/ui/frames.c
+++ b/src/ui/frames.c
@@ -174,48 +174,6 @@ prefs_changed_callback (MetaPreference pref,
meta_frames_button_layout_changed (META_FRAMES (data));
}
-static MetaStyleInfo *
-meta_frames_get_theme_variant (MetaFrames *frames,
- const gchar *variant)
-{
- MetaStyleInfo *style_info;
-
- style_info = g_hash_table_lookup (frames->style_variants, variant);
- if (style_info == NULL)
- {
- MetaTheme *theme = meta_theme_get_current ();
- style_info = meta_style_info_new (variant, meta_theme_get_composited (theme));
- g_hash_table_insert (frames->style_variants, g_strdup (variant), style_info);
- }
-
- return style_info;
-}
-
-static void
-update_style_contexts (MetaFrames *frames)
-{
- MetaStyleInfo *style_info;
- GList *variants, *variant;
- MetaTheme *theme;
- gboolean composited;
-
- theme = meta_theme_get_current ();
- composited = meta_theme_get_composited (theme);
-
- if (frames->normal_style)
- meta_style_info_unref (frames->normal_style);
- frames->normal_style = meta_style_info_new (NULL, composited);
-
- variants = g_hash_table_get_keys (frames->style_variants);
- for (variant = variants; variant; variant = variants->next)
- {
- style_info = meta_style_info_new ((char *)variant->data, composited);
- g_hash_table_insert (frames->style_variants,
- g_strdup (variant->data), style_info);
- }
- g_list_free (variants);
-}
-
static void
meta_frames_init (MetaFrames *frames)
{
@@ -231,10 +189,6 @@ meta_frames_init (MetaFrames *frames)
frames->invalidate_frames = NULL;
frames->cache = g_hash_table_new (g_direct_hash, g_direct_equal);
- frames->style_variants = g_hash_table_new_full (g_str_hash, g_str_equal,
- g_free, (GDestroyNotify)meta_style_info_unref);
- update_style_contexts (frames);
-
meta_prefs_add_listener (prefs_changed_callback, frames);
}
@@ -272,18 +226,6 @@ meta_frames_destroy (GtkWidget *widget)
}
g_slist_free (winlist);
- if (frames->normal_style)
- {
- meta_style_info_unref (frames->normal_style);
- frames->normal_style = NULL;
- }
-
- if (frames->style_variants)
- {
- g_hash_table_destroy (frames->style_variants);
- frames->style_variants = NULL;
- }
-
GTK_WIDGET_CLASS (meta_frames_parent_class)->destroy (widget);
}
@@ -471,11 +413,10 @@ meta_frames_style_updated (GtkWidget *widget)
compositing_manager = meta_prefs_get_compositing_manager ();
meta_theme_set_composited (theme, compositing_manager);
+ meta_theme_style_invalidate (theme);
meta_frames_font_changed (frames);
- update_style_contexts (frames);
-
g_hash_table_foreach (frames->frames,
reattach_style_func, frames);
@@ -667,6 +608,7 @@ meta_frames_attach_style (MetaFrames *frames,
gboolean has_frame;
char *variant = NULL;
const char *variant_override;
+ MetaTheme *theme;
if (frame->style_info != NULL)
meta_style_info_unref (frame->style_info);
@@ -682,11 +624,12 @@ meta_frames_attach_style (MetaFrames *frames,
META_CORE_GET_THEME_VARIANT, &variant,
META_CORE_GET_END);
+ theme = meta_theme_get_current ();
+
if (variant == NULL || strcmp(variant, "normal") == 0)
- frame->style_info = meta_style_info_ref (frames->normal_style);
+ frame->style_info = meta_style_info_ref (meta_theme_get_style_info (theme, NULL));
else
- frame->style_info = meta_style_info_ref (meta_frames_get_theme_variant (frames,
- variant));
+ frame->style_info = meta_style_info_ref (meta_theme_get_style_info (theme, variant));
if (variant_override)
g_free (variant);
diff --git a/src/ui/frames.h b/src/ui/frames.h
index 5de2313..1109a8c 100644
--- a/src/ui/frames.h
+++ b/src/ui/frames.h
@@ -97,9 +97,6 @@ struct _MetaFrames
guint tooltip_timeout;
MetaUIFrame *last_motion_frame;
- MetaStyleInfo *normal_style;
- GHashTable *style_variants;
-
int expose_delay_count;
int invalidate_cache_timeout_id;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]