diff options
author | Alberts Muktupāvels <alberts.muktupavels@gmail.com> | 2016-01-31 23:39:47 +0200 |
---|---|---|
committer | Alberts Muktupāvels <alberts.muktupavels@gmail.com> | 2016-01-31 23:46:58 +0200 |
commit | efb9fe070f375910ed8b7a82a280875d3ecada70 (patch) | |
tree | 1b5eafa1229ef330d1feb2a2b04e0e41a454e0ae /src | |
parent | 348379bdb230b61599a6de2ef1eff9e0c55d7737 (diff) | |
download | metacity-efb9fe070f375910ed8b7a82a280875d3ecada70.tar.gz |
theme: move MetaTheme to libmetacity and GObjectize it
Diffstat (limited to 'src')
-rw-r--r-- | src/ui/frames.c | 13 | ||||
-rw-r--r-- | src/ui/preview-widget.c | 3 | ||||
-rw-r--r-- | src/ui/theme-private.h | 18 | ||||
-rw-r--r-- | src/ui/theme-viewer.c | 56 | ||||
-rw-r--r-- | src/ui/theme.c | 211 | ||||
-rw-r--r-- | src/ui/theme.h | 14 | ||||
-rw-r--r-- | src/ui/ui.c | 4 |
7 files changed, 75 insertions, 244 deletions
diff --git a/src/ui/frames.c b/src/ui/frames.c index 30c47237..da546a56 100644 --- a/src/ui/frames.c +++ b/src/ui/frames.c @@ -183,7 +183,8 @@ meta_frames_get_theme_variant (MetaFrames *frames, style_info = g_hash_table_lookup (frames->style_variants, variant); if (style_info == NULL) { - style_info = meta_style_info_new (variant, meta_theme_get_current ()->composited); + 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); } @@ -196,17 +197,19 @@ 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, theme->composited); + 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, theme->composited); + style_info = meta_style_info_new ((char *)variant->data, composited); g_hash_table_insert (frames->style_variants, g_strdup (variant->data), style_info); } @@ -532,7 +535,7 @@ meta_frames_ensure_layout (MetaFrames *frames, current = meta_theme_get_current (); - if (current->is_gtk_theme == FALSE) + if (meta_theme_get_theme_type (current) == META_THEME_TYPE_METACITY) { double scale; @@ -2634,7 +2637,7 @@ meta_frames_draw (GtkWidget *widget, current = meta_theme_get_current (); - if (current->is_gtk_theme == FALSE) + if (meta_theme_get_theme_type (current) == META_THEME_TYPE_METACITY) { MetaFrameGeometry fgeom; diff --git a/src/ui/preview-widget.c b/src/ui/preview-widget.c index 64df2faf..17ad228c 100644 --- a/src/ui/preview-widget.c +++ b/src/ui/preview-widget.c @@ -261,10 +261,11 @@ static void meta_preview_realize (GtkWidget *widget) { MetaPreview *preview = META_PREVIEW (widget); + gboolean composited = meta_theme_get_composited (preview->theme); GTK_WIDGET_CLASS (meta_preview_parent_class)->realize (widget); - preview->style_info = meta_style_info_new (NULL, preview->theme->composited); + preview->style_info = meta_style_info_new (NULL, composited); } #define NO_CHILD_WIDTH 80 diff --git a/src/ui/theme-private.h b/src/ui/theme-private.h index acaa1315..19af8f9f 100644 --- a/src/ui/theme-private.h +++ b/src/ui/theme-private.h @@ -19,29 +19,11 @@ #define META_THEME_PRIVATE_H #include <libmetacity/meta-frame-style.h> -#include <libmetacity/meta-theme-impl.h> #include "theme.h" G_BEGIN_DECLS -/** - * A theme. This is a singleton class which groups all settings from a theme - * on disk together. - * - * \bug It is rather useless to keep the metadata fields in core, I think. - */ -struct _MetaTheme -{ - gboolean is_gtk_theme; - - gboolean composited; - - PangoFontDescription *titlebar_font; - - MetaThemeImpl *impl; -}; - MetaFrameStyle *meta_theme_get_frame_style (MetaTheme *theme, MetaFrameType type, MetaFrameFlags flags); diff --git a/src/ui/theme-viewer.c b/src/ui/theme-viewer.c index 32eae2ad..bf98405f 100644 --- a/src/ui/theme-viewer.c +++ b/src/ui/theme-viewer.c @@ -839,32 +839,6 @@ benchmark_summary (void) return label; } -static const gchar * -theme_get_name (MetaTheme *theme) -{ - MetaThemeImpl *impl; - - impl = theme->impl; - - if (META_IS_THEME_METACITY (impl)) - return meta_theme_metacity_get_name (META_THEME_METACITY (impl)); - - return NULL; -} - -static const gchar * -theme_get_readable_name (MetaTheme *theme) -{ - MetaThemeImpl *impl; - - impl = theme->impl; - - if (META_IS_THEME_METACITY (impl)) - return meta_theme_metacity_get_readable_name (META_THEME_METACITY (impl)); - - return NULL; -} - int main (int argc, char **argv) { @@ -877,6 +851,7 @@ main (int argc, char **argv) clock_t start, end; GtkWidget *notebook; int i; + gchar *theme_name; bindtextdomain (GETTEXT_PACKAGE, METACITY_LOCALEDIR); textdomain(GETTEXT_PACKAGE); @@ -904,7 +879,7 @@ main (int argc, char **argv) { g_printerr (_("Usage: metacity-theme-viewer [THEMENAME]\n")); - meta_theme_free (global_theme); + g_object_unref (global_theme); exit (1); } @@ -915,12 +890,13 @@ main (int argc, char **argv) g_printerr (_("Error loading theme: %s\n"), err->message); g_error_free (err); - meta_theme_free (global_theme); + g_object_unref (global_theme); exit (1); } - g_print (_("Loaded theme '%s' in %g seconds\n"), - theme_get_name (global_theme), + theme_name = meta_theme_get_name (global_theme); + + g_print (_("Loaded theme '%s' in %g seconds\n"), theme_name, (end - start) / (double) CLOCKS_PER_SEC); run_theme_benchmark (); @@ -928,27 +904,15 @@ main (int argc, char **argv) window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size (GTK_WINDOW (window), 350, 350); - if (g_strcmp0 (theme_get_name (global_theme), theme_get_readable_name (global_theme)) == 0) - gtk_window_set_title (GTK_WINDOW (window), theme_get_name (global_theme)); - else - { - /* The theme directory name is different from the name the theme - * gives itself within its file. Display both, directory name first. - */ - gchar *title = g_strconcat (theme_get_name (global_theme), " - ", - theme_get_readable_name (global_theme), - NULL); - - gtk_window_set_title (GTK_WINDOW (window), title); - g_free (title); - } + gtk_window_set_title (GTK_WINDOW (window), theme_name); + g_free (theme_name); g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (gtk_main_quit), NULL); gtk_widget_realize (window); - style_info = meta_style_info_new (NULL, global_theme->composited); + style_info = meta_style_info_new (NULL, meta_theme_get_composited (global_theme)); gtk_style_context_get (style_info->styles[META_STYLE_ELEMENT_DECORATION], GTK_STATE_FLAG_NORMAL, "font", &font_desc, NULL); meta_style_info_unref (style_info); @@ -1075,7 +1039,7 @@ run_theme_benchmark (void) widget = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_widget_realize (widget); - style_info = meta_style_info_new (NULL, global_theme->composited); + style_info = meta_style_info_new (NULL, meta_theme_get_composited (global_theme)); meta_theme_get_frame_borders (global_theme, style_info, diff --git a/src/ui/theme.c b/src/ui/theme.c index 39c3025b..000bd4c6 100644 --- a/src/ui/theme.c +++ b/src/ui/theme.c @@ -55,16 +55,12 @@ #include "util.h" #include <gtk/gtk.h> #include <libmetacity/meta-color.h> -#include <libmetacity/meta-theme-gtk.h> -#include <libmetacity/meta-theme-metacity.h> #include <string.h> #include <stdlib.h> #define __USE_XOPEN #include <stdarg.h> #include <math.h> -#define DEBUG_FILL_STRUCT(s) memset ((s), 0xef, sizeof (*(s))) - /** * The current theme. (Themes are singleton.) */ @@ -102,7 +98,7 @@ meta_frame_layout_get_borders (MetaTheme *theme, borders->visible.right = layout->right_width; borders->visible.bottom = layout->bottom_height; - if (theme->is_gtk_theme == TRUE) + if (meta_theme_get_theme_type (theme) != META_THEME_TYPE_METACITY) { borders->invisible.left = layout->invisible_border.left; borders->invisible.right = layout->invisible_border.right; @@ -174,13 +170,9 @@ rect_for_function (MetaFrameGeometry *fgeom, MetaButtonFunction function, MetaTheme *theme) { - if (META_IS_THEME_METACITY (theme->impl)) + if (meta_theme_get_theme_type (theme) == META_THEME_TYPE_METACITY) { - MetaThemeMetacity *metacity; - - metacity = META_THEME_METACITY (theme->impl); - - if (meta_theme_metacity_allows_shade_stick_above_buttons (metacity)) + if (meta_theme_allows_shade_stick_above_buttons (theme)) { switch (function) { @@ -445,7 +437,7 @@ meta_frame_layout_sync_with_style (MetaFrameLayout *layout, int border_radius, max_radius; /* We don't want GTK+ info for metacity theme */ - if (theme->is_gtk_theme == FALSE) + if (meta_theme_get_theme_type (theme) == META_THEME_TYPE_METACITY) return; meta_style_info_set_flags (style_info, flags); @@ -461,7 +453,7 @@ meta_frame_layout_sync_with_style (MetaFrameLayout *layout, layout->top_height = border.top; layout->bottom_height = border.bottom; - if (theme->composited) + if (meta_theme_get_composited (theme)) get_margin (style, &layout->invisible_border); else { @@ -481,7 +473,7 @@ meta_frame_layout_sync_with_style (MetaFrameLayout *layout, style = style_info->styles[META_STYLE_ELEMENT_TITLEBAR]; - if (theme->composited) + if (meta_theme_get_composited (theme)) { gtk_style_context_get (style, gtk_style_context_get_state (style), "border-radius", &border_radius, @@ -689,7 +681,7 @@ meta_frame_layout_calc_geometry (MetaFrameLayout *layout, space_used_by_buttons += button_width * n_left; space_used_by_buttons += (button_width * 0.75) * n_left_spacers; - if (theme->is_gtk_theme == FALSE) + if (meta_theme_get_theme_type (theme) == META_THEME_TYPE_METACITY) { space_used_by_buttons += layout->button_border.left * n_left; space_used_by_buttons += layout->button_border.right * n_left; @@ -699,7 +691,7 @@ meta_frame_layout_calc_geometry (MetaFrameLayout *layout, space_used_by_buttons += button_width * n_right; space_used_by_buttons += (button_width * 0.75) * n_right_spacers; - if (theme->is_gtk_theme == FALSE) + if (meta_theme_get_theme_type (theme) == META_THEME_TYPE_METACITY) { space_used_by_buttons += layout->button_border.left * n_right; space_used_by_buttons += layout->button_border.right * n_right; @@ -802,7 +794,7 @@ meta_frame_layout_calc_geometry (MetaFrameLayout *layout, break; rect = right_func_rects[i]; - if (theme->is_gtk_theme == FALSE) + if (meta_theme_get_theme_type (theme) == META_THEME_TYPE_METACITY) rect->visible.x = x - layout->button_border.right - button_width; else rect->visible.x = x - button_width; @@ -824,7 +816,7 @@ meta_frame_layout_calc_geometry (MetaFrameLayout *layout, if (i == n_right - 1) { - if (theme->is_gtk_theme == FALSE) + if (meta_theme_get_theme_type (theme) == META_THEME_TYPE_METACITY) rect->clickable.width += layout->right_titlebar_edge + layout->right_width + layout->button_border.right; else rect->clickable.width += layout->right_titlebar_edge + layout->right_width; @@ -836,7 +828,7 @@ meta_frame_layout_calc_geometry (MetaFrameLayout *layout, *(right_bg_rects[i]) = rect->visible; - if (theme->is_gtk_theme == FALSE) + if (meta_theme_get_theme_type (theme) == META_THEME_TYPE_METACITY) x = rect->visible.x - layout->button_border.left; else { @@ -862,7 +854,7 @@ meta_frame_layout_calc_geometry (MetaFrameLayout *layout, rect = left_func_rects[i]; - if (theme->is_gtk_theme == FALSE) + if (meta_theme_get_theme_type (theme) == META_THEME_TYPE_METACITY) rect->visible.x = x + layout->button_border.left; else rect->visible.x = x; @@ -880,7 +872,7 @@ meta_frame_layout_calc_geometry (MetaFrameLayout *layout, else g_memmove (&(rect->clickable), &(rect->visible), sizeof(rect->clickable)); - if (theme->is_gtk_theme == FALSE) + if (meta_theme_get_theme_type (theme) == META_THEME_TYPE_METACITY) x = rect->visible.x + rect->visible.width + layout->button_border.right; else { @@ -1526,156 +1518,57 @@ meta_theme_get_current (void) return meta_current_theme; } -static const gchar * -theme_get_name (MetaTheme *theme) +void +meta_theme_set_current (const gchar *name, + gboolean force_reload, + gboolean composited, + const PangoFontDescription *titlebar_font) { - MetaThemeImpl *impl; - - impl = theme->impl; + MetaTheme *new_theme; + GError *error; - if (META_IS_THEME_METACITY (impl)) - return meta_theme_metacity_get_name (META_THEME_METACITY (impl)); + g_debug ("Setting current theme to '%s'", name); - return NULL; -} + if (!force_reload && meta_current_theme) + { + gchar *theme_name; -static void -theme_set_current_metacity (const gchar *name, - gboolean force_reload, - gboolean composited, - const PangoFontDescription *titlebar_font) -{ - MetaTheme *new_theme; - GError *err; + theme_name = meta_theme_get_name (meta_current_theme); + if (g_strcmp0 (name, theme_name) == 0) + { + g_free (theme_name); + return; + } - meta_topic (META_DEBUG_THEMES, "Setting current theme to \"%s\"\n", name); + g_free (theme_name); + } - if (!force_reload && meta_current_theme && - g_strcmp0 (name, theme_get_name (meta_current_theme)) == 0) - return; + 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); - new_theme = meta_theme_new (META_THEME_TYPE_METACITY); + meta_theme_set_composited (new_theme, composited); + meta_theme_set_titlebar_font (new_theme, titlebar_font); - err = NULL; - if (!meta_theme_load (new_theme, name, &err)) + error = NULL; + if (!meta_theme_load (new_theme, name, &error)) { - g_warning (_("Failed to load theme '%s': %s"), name, err->message); - g_error_free (err); + g_warning (_("Failed to load theme '%s': %s"), name, error->message); + g_error_free (error); - meta_theme_free (new_theme); + g_object_unref (new_theme); } else { - new_theme->is_gtk_theme = FALSE; - new_theme->composited = composited; - new_theme->titlebar_font = pango_font_description_copy (titlebar_font); - if (meta_current_theme) - meta_theme_free (meta_current_theme); - + g_object_unref (meta_current_theme); meta_current_theme = new_theme; - meta_topic (META_DEBUG_THEMES, "New theme is '%s'\n", - theme_get_name (meta_current_theme)); + g_debug ("New theme is '%s'", name); } } -static void -theme_set_current_gtk (const gchar *name, - gboolean force_reload, - gboolean composited, - const PangoFontDescription *titlebar_font) -{ - meta_topic (META_DEBUG_THEMES, "Setting current theme to \"%s\"\n", name); - - if (!force_reload && meta_current_theme) - return; - - if (force_reload && meta_current_theme) - meta_theme_free (meta_current_theme); - - meta_current_theme = meta_theme_new (META_THEME_TYPE_GTK); - - meta_current_theme->is_gtk_theme = TRUE; - meta_current_theme->composited = composited; - meta_current_theme->titlebar_font = pango_font_description_copy (titlebar_font); - - meta_theme_load (meta_current_theme, name, NULL); -} - -void -meta_theme_set_current (const gchar *name, - gboolean force_reload, - gboolean composited, - const PangoFontDescription *titlebar_font) -{ - if (name != NULL && strcmp (name, "") != 0) - { - theme_set_current_metacity (name, force_reload, composited, titlebar_font); - } - else - { - theme_set_current_gtk (name, force_reload, composited, titlebar_font); - } -} - -MetaTheme* -meta_theme_new (MetaThemeType type) -{ - MetaTheme *theme; - - theme = g_new0 (MetaTheme, 1); - - theme->is_gtk_theme = FALSE; - theme->composited = TRUE; - - if (type == META_THEME_TYPE_GTK) - theme->impl = g_object_new (META_TYPE_THEME_GTK, NULL); - else if (type == META_THEME_TYPE_METACITY) - theme->impl = g_object_new (META_TYPE_THEME_METACITY, NULL); - else - g_assert_not_reached (); - - return theme; -} - -void -meta_theme_free (MetaTheme *theme) -{ - g_return_if_fail (theme != NULL); - - if (theme->titlebar_font) - pango_font_description_free (theme->titlebar_font); - - g_clear_object (&theme->impl); - - DEBUG_FILL_STRUCT (theme); - g_free (theme); -} - -gboolean -meta_theme_load (MetaTheme *theme, - const gchar *name, - GError **err) -{ - return meta_theme_impl_load (theme->impl, name, err); -} - -void -meta_theme_set_composited (MetaTheme *theme, - gboolean composited) -{ - theme->composited = composited; -} - -void -meta_theme_set_titlebar_font (MetaTheme *theme, - const PangoFontDescription *titlebar_font) -{ - pango_font_description_free (theme->titlebar_font); - theme->titlebar_font = pango_font_description_copy (titlebar_font); -} - static MetaFrameStyle* theme_get_style (MetaTheme *theme, MetaFrameType type, @@ -1687,16 +1580,16 @@ theme_get_style (MetaTheme *theme, MetaFrameStyle *style; MetaFrameStyleSet *style_set; - style_set = meta_theme_impl_get_style_set (theme->impl, type); + style_set = meta_theme_get_style_set (theme, type); if (style_set == NULL && type == META_FRAME_TYPE_ATTACHED) - style_set = meta_theme_impl_get_style_set (theme->impl, META_FRAME_TYPE_BORDER); + style_set = meta_theme_get_style_set (theme, META_FRAME_TYPE_BORDER); /* Right now the parser forces a style set for all other types, * but this fallback code is here in case I take that out. */ if (style_set == NULL) - style_set = meta_theme_impl_get_style_set (theme->impl, META_FRAME_TYPE_NORMAL); + style_set = meta_theme_get_style_set (theme, META_FRAME_TYPE_NORMAL); if (style_set == NULL) return NULL; @@ -1803,6 +1696,7 @@ meta_style_info_create_font_desc (MetaTheme *theme, { GtkStyleContext *context; PangoFontDescription *font_desc; + const PangoFontDescription *titlebar_font; context = style_info->styles[META_STYLE_ELEMENT_TITLE]; @@ -1814,8 +1708,9 @@ meta_style_info_create_font_desc (MetaTheme *theme, gtk_style_context_restore (context); - if (theme->titlebar_font) - pango_font_description_merge (font_desc, theme->titlebar_font, TRUE); + titlebar_font = meta_theme_get_titlebar_font (theme); + if (titlebar_font) + pango_font_description_merge (font_desc, titlebar_font, TRUE); return font_desc; } @@ -1856,7 +1751,7 @@ meta_theme_draw_frame (MetaTheme *theme, &fgeom, theme); - if (theme->is_gtk_theme == FALSE) + if (meta_theme_get_theme_type (theme) == META_THEME_TYPE_METACITY) { meta_frame_style_draw_with_style (style, style_info, diff --git a/src/ui/theme.h b/src/ui/theme.h index 7d1627ea..50f19275 100644 --- a/src/ui/theme.h +++ b/src/ui/theme.h @@ -32,7 +32,6 @@ typedef struct _MetaButtonSpace MetaButtonSpace; typedef struct _MetaFrameGeometry MetaFrameGeometry; -typedef struct _MetaTheme MetaTheme; /** * The computed size of a button (really just a way of tying its @@ -112,19 +111,6 @@ void meta_theme_set_current (const char *name, gboolean composited, const PangoFontDescription *titlebar_font); -MetaTheme* meta_theme_new (MetaThemeType type); -void meta_theme_free (MetaTheme *theme); - -gboolean meta_theme_load (MetaTheme *theme, - const gchar *theme_name, - GError **err); - -void meta_theme_set_composited (MetaTheme *theme, - gboolean composited); - -void meta_theme_set_titlebar_font (MetaTheme *theme, - const PangoFontDescription *titlebar_font); - double meta_theme_get_title_scale (MetaTheme *theme, MetaFrameType type, MetaFrameFlags flags); diff --git a/src/ui/ui.c b/src/ui/ui.c index 4a8e3da1..5d8f8486 100644 --- a/src/ui/ui.c +++ b/src/ui/ui.c @@ -678,14 +678,14 @@ meta_ui_theme_get_frame_borders (MetaUI *ui, MetaTheme *current; current = meta_theme_get_current (); - style_info = meta_style_info_new (NULL, current->composited); + style_info = meta_style_info_new (NULL, meta_theme_get_composited (current)); context = gtk_widget_get_pango_context (GTK_WIDGET (ui->frames)); font_desc = meta_prefs_get_titlebar_font (); if (!font_desc) { - if (current->is_gtk_theme == FALSE) + if (meta_theme_get_theme_type (current) == META_THEME_TYPE_METACITY) { GtkStyleContext *style; GtkWidgetPath *widget_path; |