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 | |
parent | 348379bdb230b61599a6de2ef1eff9e0c55d7737 (diff) | |
download | metacity-efb9fe070f375910ed8b7a82a280875d3ecada70.tar.gz |
theme: move MetaTheme to libmetacity and GObjectize it
24 files changed, 495 insertions, 351 deletions
diff --git a/configure.ac b/configure.ac index 3e29fa21..b08b36c1 100644 --- a/configure.ac +++ b/configure.ac @@ -58,6 +58,12 @@ LT_INIT LT_LIB_M dnl ************************************************************************** +dnl Check for required programs +dnl ************************************************************************** + +AC_PATH_PROG([GLIB_MKENUMS], [glib-mkenums]) + +dnl ************************************************************************** dnl Check for required packages dnl ************************************************************************** diff --git a/libmetacity/Makefile.am b/libmetacity/Makefile.am index bbf8de14..4db4a2f3 100644 --- a/libmetacity/Makefile.am +++ b/libmetacity/Makefile.am @@ -36,11 +36,12 @@ libmetacity_la_SOURCES = \ meta-theme.c \ meta-theme.h \ meta-theme-gtk.c \ - meta-theme-gtk.h \ + meta-theme-gtk-private.h \ meta-theme-impl.c \ - meta-theme-impl.h \ + meta-theme-impl-private.h \ meta-theme-metacity.c \ - meta-theme-metacity.h \ + meta-theme-metacity-private.h \ + $(BUILT_SOURCES) \ $(NULL) libmetacity_la_CPPFLAGS = \ @@ -73,6 +74,7 @@ libmetacity_include_HEADERS = \ meta-color-spec.h \ meta-draw-op.h \ meta-draw-spec.h \ + meta-enum-types.h \ meta-frame-borders.h \ meta-frame-enums.h \ meta-frame-layout.h \ @@ -81,9 +83,32 @@ libmetacity_include_HEADERS = \ meta-gradient-spec.h \ meta-style-info.h \ meta-theme.h \ - meta-theme-gtk.h \ - meta-theme-impl.h \ - meta-theme-metacity.h \ + $(NULL) + +ENUM_TYPES = \ + meta-theme.h \ + $(NULL) + +meta-enum-types.c: meta-enum-types.c.in meta-enum-types.h $(ENUM_TYPES) + $(AM_V_GEN) $(GLIB_MKENUMS) --template meta-enum-types.c.in $(ENUM_TYPES) > meta-enum-types.c.tmp \ + meta-enum-types.c.tmp && mv meta-enum-types.c.tmp meta-enum-types.c + +meta-enum-types.h: meta-enum-types.h.in $(ENUM_TYPES) + $(AM_V_GEN) $(GLIB_MKENUMS) --template meta-enum-types.h.in $(ENUM_TYPES) > meta-enum-types.h.tmp \ + meta-enum-types.h.tmp && mv meta-enum-types.h.tmp meta-enum-types.h + +BUILT_SOURCES = \ + meta-enum-types.c \ + meta-enum-types.h \ + $(NULL) + +EXTRA_DIST = \ + meta-enum-types.c.in \ + meta-enum-types.h.in \ + $(NULL) + +CLEANFILES = \ + $(BUILT_SOURCES) \ $(NULL) -include $(top_srcdir)/git.mk diff --git a/libmetacity/meta-draw-spec.c b/libmetacity/meta-draw-spec.c index f9b1a089..716c8acc 100644 --- a/libmetacity/meta-draw-spec.c +++ b/libmetacity/meta-draw-spec.c @@ -23,6 +23,7 @@ #include "meta-draw-spec.h" #include "meta-theme.h" +#include "meta-theme-metacity-private.h" typedef enum { diff --git a/libmetacity/meta-draw-spec.h b/libmetacity/meta-draw-spec.h index 5f7dfddc..a17d9a04 100644 --- a/libmetacity/meta-draw-spec.h +++ b/libmetacity/meta-draw-spec.h @@ -20,11 +20,11 @@ #define META_DRAW_SPEC_H #include <gdk/gdk.h> -#include <libmetacity/meta-theme-metacity.h> G_BEGIN_DECLS typedef struct _MetaDrawSpec MetaDrawSpec; +typedef struct _MetaThemeMetacity MetaThemeMetacity; typedef struct _MetaPositionExprEnv MetaPositionExprEnv; struct _MetaPositionExprEnv diff --git a/libmetacity/meta-enum-types.c.in b/libmetacity/meta-enum-types.c.in new file mode 100644 index 00000000..49f3441c --- /dev/null +++ b/libmetacity/meta-enum-types.c.in @@ -0,0 +1,42 @@ +/*** BEGIN file-header ***/ +#include "config.h" + +#include "meta-enum-types.h" +/*** END file-header ***/ + +/*** BEGIN file-production ***/ +#include "@filename@" +/*** END file-production ***/ + +/*** BEGIN value-header ***/ + +GType +@enum_name@_get_type (void) +{ + static volatile gsize g_enum_type_id; + static const G@Type@Value values[] = + { +/*** END value-header ***/ + +/*** BEGIN value-production ***/ + { @VALUENAME@, "@VALUENAME@", "@valuenick@" }, +/*** END value-production ***/ + +/*** BEGIN value-tail ***/ + { 0, NULL, NULL } + }; + + if (g_once_init_enter (&g_enum_type_id)) + { + const gchar *string; + GType id; + + string = g_intern_static_string ("@EnumName@"); + id = g_@type@_register_static (string, values); + + g_once_init_leave (&g_enum_type_id, id); + } + + return g_enum_type_id; +} +/*** END value-tail ***/ diff --git a/libmetacity/meta-enum-types.h.in b/libmetacity/meta-enum-types.h.in new file mode 100644 index 00000000..ce4fd1f2 --- /dev/null +++ b/libmetacity/meta-enum-types.h.in @@ -0,0 +1,21 @@ +/*** BEGIN file-header ***/ +#ifndef META_ENUM_TYPES_H +#define META_ENUM_TYPES_H + +#include <glib-object.h> + +G_BEGIN_DECLS + +/*** END file-header ***/ + +/*** BEGIN value-header ***/ +GType @enum_name@_get_type (void) G_GNUC_CONST; +#define @ENUMPREFIX@_TYPE_@ENUMSHORT@ (@enum_name@_get_type()) + +/*** END value-header ***/ + +/*** BEGIN file-tail ***/ +G_END_DECLS + +#endif +/*** END file-tail ***/ diff --git a/libmetacity/meta-frame-flags.h b/libmetacity/meta-frame-flags.h deleted file mode 100644 index e943d882..00000000 --- a/libmetacity/meta-frame-flags.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2001 Havoc Pennington - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef META_FRAME_FLAGS_H -#define META_FRAME_FLAGS_H - -#include <glib.h> - -G_BEGIN_DECLS - -typedef enum -{ - META_FRAME_ALLOWS_DELETE = 1 << 0, - META_FRAME_ALLOWS_MENU = 1 << 1, - META_FRAME_ALLOWS_APPMENU = 1 << 2, - META_FRAME_ALLOWS_MINIMIZE = 1 << 3, - META_FRAME_ALLOWS_MAXIMIZE = 1 << 4, - META_FRAME_ALLOWS_VERTICAL_RESIZE = 1 << 5, - META_FRAME_ALLOWS_HORIZONTAL_RESIZE = 1 << 6, - META_FRAME_HAS_FOCUS = 1 << 7, - META_FRAME_SHADED = 1 << 8, - META_FRAME_STUCK = 1 << 9, - META_FRAME_MAXIMIZED = 1 << 10, - META_FRAME_ALLOWS_SHADE = 1 << 11, - META_FRAME_ALLOWS_MOVE = 1 << 12, - META_FRAME_FULLSCREEN = 1 << 13, - META_FRAME_IS_FLASHING = 1 << 14, - META_FRAME_ABOVE = 1 << 15, - META_FRAME_TILED_LEFT = 1 << 16, - META_FRAME_TILED_RIGHT = 1 << 17 -} MetaFrameFlags; - -G_END_DECLS - -#endif diff --git a/libmetacity/meta-frame-style.c b/libmetacity/meta-frame-style.c index ccbb094c..0df2d4f1 100644 --- a/libmetacity/meta-frame-style.c +++ b/libmetacity/meta-frame-style.c @@ -22,6 +22,7 @@ #include "meta-frame-style.h" #include "meta-theme.h" +#include "meta-theme-metacity-private.h" static const char* meta_frame_state_to_string (MetaFrameState state) diff --git a/libmetacity/meta-style-info.c b/libmetacity/meta-style-info.c index d2c00926..5eb102bb 100644 --- a/libmetacity/meta-style-info.c +++ b/libmetacity/meta-style-info.c @@ -18,7 +18,7 @@ #include "config.h" -#include "meta-frame-flags.h" +#include "meta-frame-enums.h" #include "meta-style-info.h" static void diff --git a/libmetacity/meta-theme-gtk.h b/libmetacity/meta-theme-gtk-private.h index 11e5bfe3..284deeb3 100644 --- a/libmetacity/meta-theme-gtk.h +++ b/libmetacity/meta-theme-gtk-private.h @@ -15,10 +15,10 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef META_THEME_GTK_H -#define META_THEME_GTK_H +#ifndef META_THEME_GTK_PRIVATE_H +#define META_THEME_GTK_PRIVATE_H -#include "meta-theme-impl.h" +#include "meta-theme-impl-private.h" G_BEGIN_DECLS diff --git a/libmetacity/meta-theme-gtk.c b/libmetacity/meta-theme-gtk.c index 1e6b1307..57f00f07 100644 --- a/libmetacity/meta-theme-gtk.c +++ b/libmetacity/meta-theme-gtk.c @@ -20,7 +20,7 @@ #include <gtk/gtk.h> #include "meta-frame-style.h" -#include "meta-theme-gtk.h" +#include "meta-theme-gtk-private.h" #include "meta-theme.h" struct _MetaThemeGtk @@ -122,6 +122,22 @@ meta_theme_gtk_load (MetaThemeImpl *impl, return TRUE; } +static gchar * +meta_theme_gtk_get_name (MetaThemeImpl *impl) +{ + GtkSettings *settings; + gchar *name; + + settings = gtk_settings_get_default (); + + if (settings == NULL) + return NULL; + + g_object_get (settings, "gtk-theme-name", &name, NULL); + + return name; +} + static void meta_theme_gtk_class_init (MetaThemeGtkClass *gtk_class) { @@ -130,6 +146,7 @@ meta_theme_gtk_class_init (MetaThemeGtkClass *gtk_class) impl_class = META_THEME_IMPL_CLASS (gtk_class); impl_class->load = meta_theme_gtk_load; + impl_class->get_name = meta_theme_gtk_get_name; } static void diff --git a/libmetacity/meta-theme-impl.h b/libmetacity/meta-theme-impl-private.h index 2096de8f..ec83bc44 100644 --- a/libmetacity/meta-theme-impl.h +++ b/libmetacity/meta-theme-impl-private.h @@ -15,15 +15,15 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef META_THEME_IMPL_H -#define META_THEME_IMPL_H +#ifndef META_THEME_IMPL_PRIVATE_H +#define META_THEME_IMPL_PRIVATE_H #include <glib-object.h> -#include <libmetacity/meta-frame-enums.h> -G_BEGIN_DECLS +#include "meta-frame-enums.h" +#include "meta-frame-style.h" -typedef struct _MetaFrameStyleSet MetaFrameStyleSet; +G_BEGIN_DECLS #define META_TYPE_THEME_IMPL meta_theme_impl_get_type () G_DECLARE_DERIVABLE_TYPE (MetaThemeImpl, meta_theme_impl, @@ -33,14 +33,12 @@ struct _MetaThemeImplClass { GObjectClass parent_class; - gboolean (* load) (MetaThemeImpl *impl, - const gchar *name, - GError **error); -}; + gboolean (* load) (MetaThemeImpl *impl, + const gchar *name, + GError **error); -gboolean meta_theme_impl_load (MetaThemeImpl *impl, - const gchar *name, - GError **error); + gchar * (* get_name) (MetaThemeImpl *impl); +}; void meta_theme_impl_add_style_set (MetaThemeImpl *impl, MetaFrameType type, diff --git a/libmetacity/meta-theme-impl.c b/libmetacity/meta-theme-impl.c index a6670bc6..6bf87f34 100644 --- a/libmetacity/meta-theme-impl.c +++ b/libmetacity/meta-theme-impl.c @@ -20,7 +20,7 @@ #include <glib/gi18n.h> #include "meta-frame-style.h" -#include "meta-theme-impl.h" +#include "meta-theme-impl-private.h" #include "meta-theme.h" typedef struct @@ -53,7 +53,7 @@ meta_theme_impl_dispose (GObject *object) } static gboolean -meta_theme_real_impl_load (MetaThemeImpl *impl, +meta_theme_impl_real_load (MetaThemeImpl *impl, const gchar *name, GError **error) { @@ -66,6 +66,12 @@ meta_theme_real_impl_load (MetaThemeImpl *impl, return FALSE; } +static gchar * +meta_theme_impl_real_get_name (MetaThemeImpl *impl) +{ + return NULL; +} + static void meta_theme_impl_class_init (MetaThemeImplClass *impl_class) { @@ -75,7 +81,8 @@ meta_theme_impl_class_init (MetaThemeImplClass *impl_class) object_class->dispose = meta_theme_impl_dispose; - impl_class->load = meta_theme_real_impl_load; + impl_class->load = meta_theme_impl_real_load; + impl_class->get_name = meta_theme_impl_real_get_name; } static void @@ -83,14 +90,6 @@ meta_theme_impl_init (MetaThemeImpl *impl) { } -gboolean -meta_theme_impl_load (MetaThemeImpl *impl, - const gchar *name, - GError **error) -{ - return META_THEME_IMPL_GET_CLASS (impl)->load (impl, name, error); -} - void meta_theme_impl_add_style_set (MetaThemeImpl *impl, MetaFrameType type, diff --git a/libmetacity/meta-theme-metacity.h b/libmetacity/meta-theme-metacity-private.h index 94625d8a..08fe5460 100644 --- a/libmetacity/meta-theme-metacity.h +++ b/libmetacity/meta-theme-metacity-private.h @@ -16,11 +16,11 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef META_THEME_METACITY_H -#define META_THEME_METACITY_H +#ifndef META_THEME_METACITY_PRIVATE_H +#define META_THEME_METACITY_PRIVATE_H -#include <libmetacity/meta-button-enums.h> -#include "meta-theme-impl.h" +#include "meta-button-enums.h" +#include "meta-theme-impl-private.h" G_BEGIN_DECLS @@ -53,10 +53,6 @@ MetaFrameStyle *meta_theme_metacity_lookup_style (MetaThemeMetacity * MetaFrameStyleSet *meta_theme_metacity_lookup_style_set (MetaThemeMetacity *metacity, const gchar *name); -const gchar *meta_theme_metacity_get_name (MetaThemeMetacity *metacity); - -const gchar *meta_theme_metacity_get_readable_name (MetaThemeMetacity *metacity); - gboolean meta_theme_metacity_allows_shade_stick_above_buttons (MetaThemeMetacity *metacity); guint meta_theme_metacity_earliest_version_with_button (MetaButtonType type); diff --git a/libmetacity/meta-theme-metacity.c b/libmetacity/meta-theme-metacity.c index 3c3cbe43..914b585c 100644 --- a/libmetacity/meta-theme-metacity.c +++ b/libmetacity/meta-theme-metacity.c @@ -25,7 +25,7 @@ #include "meta-frame-layout.h" #include "meta-frame-style.h" #include "meta-theme.h" -#include "meta-theme-metacity.h" +#include "meta-theme-metacity-private.h" /* We were intending to put the version number * in the subdirectory name, but we ended up @@ -4617,6 +4617,16 @@ out: return retval; } +static gchar * +meta_theme_metacity_get_name (MetaThemeImpl *impl) +{ + MetaThemeMetacity *metacity; + + metacity = META_THEME_METACITY (impl); + + return g_strdup (metacity->name); +} + static void meta_theme_metacity_class_init (MetaThemeMetacityClass *metacity_class) { @@ -4630,6 +4640,7 @@ meta_theme_metacity_class_init (MetaThemeMetacityClass *metacity_class) object_class->finalize = meta_theme_metacity_finalize; impl_class->load = meta_theme_metacity_load; + impl_class->get_name = meta_theme_metacity_get_name; } static void @@ -4721,18 +4732,6 @@ meta_theme_metacity_lookup_style_set (MetaThemeMetacity *metacity, return g_hash_table_lookup (metacity->style_sets, name); } -const gchar * -meta_theme_metacity_get_name (MetaThemeMetacity *metacity) -{ - return metacity->name; -} - -const gchar * -meta_theme_metacity_get_readable_name (MetaThemeMetacity *metacity) -{ - return metacity->readable_name; -} - gboolean meta_theme_metacity_allows_shade_stick_above_buttons (MetaThemeMetacity *metacity) { diff --git a/libmetacity/meta-theme.c b/libmetacity/meta-theme.c index 39f500f2..f7ae68a7 100644 --- a/libmetacity/meta-theme.c +++ b/libmetacity/meta-theme.c @@ -17,7 +17,159 @@ #include "config.h" +#include "meta-enum-types.h" #include "meta-theme.h" +#include "meta-theme-gtk-private.h" +#include "meta-theme-impl-private.h" +#include "meta-theme-metacity-private.h" + +struct _MetaTheme +{ + GObject parent; + + MetaThemeType type; + MetaThemeImpl *impl; + + gboolean composited; + + PangoFontDescription *titlebar_font; +}; + +enum +{ + PROP_0, + + PROP_TYPE, + + LAST_PROP +}; + +static GParamSpec *theme_properties[LAST_PROP] = { NULL }; + +G_DEFINE_TYPE (MetaTheme, meta_theme, G_TYPE_OBJECT) + +static void +meta_theme_constructed (GObject *object) +{ + MetaTheme *theme; + + G_OBJECT_CLASS (meta_theme_parent_class)->constructed (object); + + theme = META_THEME (object); + + if (theme->type == META_THEME_TYPE_GTK) + theme->impl = g_object_new (META_TYPE_THEME_GTK, NULL); + else if (theme->type == META_THEME_TYPE_METACITY) + theme->impl = g_object_new (META_TYPE_THEME_METACITY, NULL); + else + g_assert_not_reached (); +} + +static void +meta_theme_dispose (GObject *object) +{ + MetaTheme *theme; + + theme = META_THEME (object); + + g_clear_object (&theme->impl); + + G_OBJECT_CLASS (meta_theme_parent_class)->dispose (object); +} + +static void +meta_theme_finalize (GObject *object) +{ + MetaTheme *theme; + + theme = META_THEME (object); + + if (theme->titlebar_font) + { + pango_font_description_free (theme->titlebar_font); + theme->titlebar_font = NULL; + } + + G_OBJECT_CLASS (meta_theme_parent_class)->finalize (object); +} + +static void +meta_theme_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + MetaTheme *theme; + + theme = META_THEME (object); + + switch (property_id) + { + case PROP_TYPE: + g_value_set_enum (value, theme->type); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +meta_theme_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + MetaTheme *theme; + + theme = META_THEME (object); + + switch (property_id) + { + case PROP_TYPE: + theme->type = g_value_get_enum (value); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +meta_theme_install_properties (GObjectClass *object_class) +{ + theme_properties[PROP_TYPE] = + g_param_spec_enum ("type", "type", "type", + META_TYPE_THEME_TYPE, META_THEME_TYPE_GTK, + G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE | + G_PARAM_STATIC_STRINGS); + + g_object_class_install_properties (object_class, LAST_PROP, + theme_properties); +} + +static void +meta_theme_class_init (MetaThemeClass *theme_class) +{ + GObjectClass *object_class; + + object_class = G_OBJECT_CLASS (theme_class); + + object_class->constructed = meta_theme_constructed; + object_class->dispose = meta_theme_dispose; + object_class->finalize = meta_theme_finalize; + object_class->get_property = meta_theme_get_property; + object_class->set_property = meta_theme_set_property; + + meta_theme_install_properties (object_class); +} + +static void +meta_theme_init (MetaTheme *theme) +{ +} /** * meta_theme_error_quark: @@ -31,3 +183,77 @@ meta_theme_error_quark (void) { return g_quark_from_static_string ("meta-theme-error-quark"); } + +MetaTheme * +meta_theme_new (MetaThemeType type) +{ + return g_object_new (META_TYPE_THEME, "type", type, NULL); +} + +gboolean +meta_theme_load (MetaTheme *theme, + const gchar *name, + GError **error) +{ + return META_THEME_IMPL_GET_CLASS (theme->impl)->load (theme->impl, name, + error); +} + +void +meta_theme_set_composited (MetaTheme *theme, + gboolean composited) +{ + theme->composited = composited; +} + +gboolean +meta_theme_get_composited (MetaTheme *theme) +{ + return theme->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); +} + +const PangoFontDescription * +meta_theme_get_titlebar_font (MetaTheme *theme) +{ + return theme->titlebar_font; +} + +MetaThemeType +meta_theme_get_theme_type (MetaTheme *theme) +{ + return theme->type; +} + +gchar * +meta_theme_get_name (MetaTheme *theme) +{ + return META_THEME_IMPL_GET_CLASS (theme->impl)->get_name (theme->impl); +} + +MetaFrameStyleSet * +meta_theme_get_style_set (MetaTheme *theme, + MetaFrameType type) +{ + return meta_theme_impl_get_style_set (theme->impl, type); +} + +gboolean +meta_theme_allows_shade_stick_above_buttons (MetaTheme *theme) +{ + MetaThemeMetacity *metacity; + + if (theme->type != META_THEME_TYPE_METACITY) + return TRUE; + + metacity = META_THEME_METACITY (theme->impl); + + return meta_theme_metacity_allows_shade_stick_above_buttons (metacity); +} diff --git a/libmetacity/meta-theme.h b/libmetacity/meta-theme.h index d6977c28..64bff507 100644 --- a/libmetacity/meta-theme.h +++ b/libmetacity/meta-theme.h @@ -19,10 +19,16 @@ #ifndef META_THEME_H #define META_THEME_H -#include <glib.h> +#include <gtk/gtk.h> +#include <libmetacity/meta-frame-enums.h> G_BEGIN_DECLS +typedef struct _MetaFrameStyleSet MetaFrameStyleSet; + +#define META_TYPE_THEME meta_theme_get_type () +G_DECLARE_FINAL_TYPE (MetaTheme, meta_theme, META, THEME, GObject) + /** * META_THEME_ERROR: * @@ -68,7 +74,32 @@ typedef enum META_THEME_TYPE_METACITY, } MetaThemeType; -GQuark meta_theme_error_quark (void); +GQuark meta_theme_error_quark (void); + +MetaTheme *meta_theme_new (MetaThemeType type); + +gboolean meta_theme_load (MetaTheme *theme, + const gchar *theme_name, + GError **error); + +void meta_theme_set_composited (MetaTheme *theme, + gboolean composited); + +gboolean meta_theme_get_composited (MetaTheme *theme); + +void meta_theme_set_titlebar_font (MetaTheme *theme, + const PangoFontDescription *titlebar_font); + +const PangoFontDescription *meta_theme_get_titlebar_font (MetaTheme *theme); + +MetaThemeType meta_theme_get_theme_type (MetaTheme *theme); + +gchar *meta_theme_get_name (MetaTheme *theme); + +MetaFrameStyleSet *meta_theme_get_style_set (MetaTheme *theme, + MetaFrameType type); + +gboolean meta_theme_allows_shade_stick_above_buttons (MetaTheme *theme); G_END_DECLS 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; |