[metacity] libmetacity: add meta-frame-style.[c/h]
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [metacity] libmetacity: add meta-frame-style.[c/h]
- Date: Sun, 31 Jan 2016 05:25:35 +0000 (UTC)
commit 942b171e91dcacca2df985aa33abb680d8d8815a
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Sun Jan 31 04:08:50 2016 +0200
libmetacity: add meta-frame-style.[c/h]
libmetacity/Makefile.am | 5 +
libmetacity/meta-button-enums.h | 60 ++++++
libmetacity/meta-frame-style.c | 403 +++++++++++++++++++++++++++++++++++++++
libmetacity/meta-frame-style.h | 121 ++++++++++++
po/POTFILES.in | 1 +
src/ui/theme-private.h | 84 +--------
src/ui/theme.c | 380 +------------------------------------
src/ui/theme.h | 34 +----
8 files changed, 593 insertions(+), 495 deletions(-)
---
diff --git a/libmetacity/Makefile.am b/libmetacity/Makefile.am
index d44fb00..cc0b7eb 100644
--- a/libmetacity/Makefile.am
+++ b/libmetacity/Makefile.am
@@ -3,6 +3,7 @@ NULL =
lib_LTLIBRARIES = libmetacity.la
libmetacity_la_SOURCES = \
+ meta-button-enums.h \
meta-button-function.c \
meta-button-function.h \
meta-button-layout.c \
@@ -21,6 +22,8 @@ libmetacity_la_SOURCES = \
meta-frame-enums.h \
meta-frame-layout.c \
meta-frame-layout.h \
+ meta-frame-style.c \
+ meta-frame-style.h \
meta-gradient.c \
meta-gradient.h \
meta-gradient-private.h \
@@ -62,6 +65,7 @@ libmetacity_la_LIBADD = \
libmetacity_includedir = $(includedir)/metacity/libmetacity
libmetacity_include_HEADERS = \
+ meta-button-enums.h \
meta-button-function.h \
meta-button-layout.h \
meta-color.h \
@@ -71,6 +75,7 @@ libmetacity_include_HEADERS = \
meta-frame-borders.h \
meta-frame-enums.h \
meta-frame-layout.h \
+ meta-frame-style.h \
meta-gradient.h \
meta-gradient-spec.h \
meta-style-info.h \
diff --git a/libmetacity/meta-button-enums.h b/libmetacity/meta-button-enums.h
new file mode 100644
index 0000000..dd133cb
--- /dev/null
+++ b/libmetacity/meta-button-enums.h
@@ -0,0 +1,60 @@
+/*
+ * 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_BUTTON_ENUMS_H
+#define META_BUTTON_ENUMS_H
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+typedef enum
+{
+ META_BUTTON_STATE_NORMAL,
+ META_BUTTON_STATE_PRESSED,
+ META_BUTTON_STATE_PRELIGHT,
+ META_BUTTON_STATE_LAST
+} MetaButtonState;
+
+typedef enum
+{
+ /* Ordered so that background is drawn first */
+ META_BUTTON_TYPE_LEFT_LEFT_BACKGROUND,
+ META_BUTTON_TYPE_LEFT_MIDDLE_BACKGROUND,
+ META_BUTTON_TYPE_LEFT_RIGHT_BACKGROUND,
+ META_BUTTON_TYPE_LEFT_SINGLE_BACKGROUND,
+ META_BUTTON_TYPE_RIGHT_LEFT_BACKGROUND,
+ META_BUTTON_TYPE_RIGHT_MIDDLE_BACKGROUND,
+ META_BUTTON_TYPE_RIGHT_RIGHT_BACKGROUND,
+ META_BUTTON_TYPE_RIGHT_SINGLE_BACKGROUND,
+ META_BUTTON_TYPE_CLOSE,
+ META_BUTTON_TYPE_MAXIMIZE,
+ META_BUTTON_TYPE_MINIMIZE,
+ META_BUTTON_TYPE_MENU,
+ META_BUTTON_TYPE_APPMENU,
+ META_BUTTON_TYPE_SHADE,
+ META_BUTTON_TYPE_ABOVE,
+ META_BUTTON_TYPE_STICK,
+ META_BUTTON_TYPE_UNSHADE,
+ META_BUTTON_TYPE_UNABOVE,
+ META_BUTTON_TYPE_UNSTICK,
+ META_BUTTON_TYPE_LAST
+} MetaButtonType;
+
+G_END_DECLS
+
+#endif
diff --git a/libmetacity/meta-frame-style.c b/libmetacity/meta-frame-style.c
new file mode 100644
index 0000000..2e96dbe
--- /dev/null
+++ b/libmetacity/meta-frame-style.c
@@ -0,0 +1,403 @@
+/*
+ * Copyright (C) 2001 Havoc Pennington
+ * Copyright (C) 2016 Alberts Muktupāvels
+ *
+ * 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/>.
+ */
+
+#include "config.h"
+
+#include <glib/gi18n-lib.h>
+
+#include "meta-frame-style.h"
+#include "meta-theme.h"
+
+static const char*
+meta_frame_state_to_string (MetaFrameState state)
+{
+ switch (state)
+ {
+ case META_FRAME_STATE_NORMAL:
+ return "normal";
+ case META_FRAME_STATE_MAXIMIZED:
+ return "maximized";
+ case META_FRAME_STATE_TILED_LEFT:
+ return "tiled_left";
+ case META_FRAME_STATE_TILED_RIGHT:
+ return "tiled_right";
+ case META_FRAME_STATE_SHADED:
+ return "shaded";
+ case META_FRAME_STATE_MAXIMIZED_AND_SHADED:
+ return "maximized_and_shaded";
+ case META_FRAME_STATE_TILED_LEFT_AND_SHADED:
+ return "tiled_left_and_shaded";
+ case META_FRAME_STATE_TILED_RIGHT_AND_SHADED:
+ return "tiled_right_and_shaded";
+ case META_FRAME_STATE_LAST:
+ break;
+ default:
+ break;
+ }
+
+ return "<unknown>";
+}
+
+static const char*
+meta_frame_resize_to_string (MetaFrameResize resize)
+{
+ switch (resize)
+ {
+ case META_FRAME_RESIZE_NONE:
+ return "none";
+ case META_FRAME_RESIZE_VERTICAL:
+ return "vertical";
+ case META_FRAME_RESIZE_HORIZONTAL:
+ return "horizontal";
+ case META_FRAME_RESIZE_BOTH:
+ return "both";
+ case META_FRAME_RESIZE_LAST:
+ break;
+ default:
+ break;
+ }
+
+ return "<unknown>";
+}
+
+static const char*
+meta_frame_focus_to_string (MetaFrameFocus focus)
+{
+ switch (focus)
+ {
+ case META_FRAME_FOCUS_NO:
+ return "no";
+ case META_FRAME_FOCUS_YES:
+ return "yes";
+ case META_FRAME_FOCUS_LAST:
+ break;
+ default:
+ break;
+ }
+
+ return "<unknown>";
+}
+
+static void
+free_button_ops (MetaDrawOpList *op_lists[META_BUTTON_TYPE_LAST][META_BUTTON_STATE_LAST])
+{
+ int i, j;
+
+ for (i = 0; i < META_BUTTON_TYPE_LAST; i++)
+ {
+ for (j = 0; j < META_BUTTON_STATE_LAST; j++)
+ {
+ if (op_lists[i][j])
+ meta_draw_op_list_unref (op_lists[i][j]);
+ }
+ }
+}
+
+static void
+free_focus_styles (MetaFrameStyle *focus_styles[META_FRAME_FOCUS_LAST])
+{
+ int i;
+
+ for (i = 0; i < META_FRAME_FOCUS_LAST; i++)
+ {
+ if (focus_styles[i])
+ meta_frame_style_unref (focus_styles[i]);
+ }
+}
+
+static gboolean
+check_state (MetaFrameStyleSet *style_set,
+ MetaFrameState state,
+ GError **error)
+{
+ int i;
+
+ for (i = 0; i < META_FRAME_FOCUS_LAST; i++)
+ {
+ if (meta_frame_style_set_get_style (style_set, state,
+ META_FRAME_RESIZE_NONE, i) == NULL)
+ {
+ /* Translators: This error occurs when a <frame> tag is missing
+ * in theme XML. The "<frame ...>" is intended as a noun phrase,
+ * and the "missing" qualifies it. You should translate "whatever".
+ */
+ g_set_error (error, META_THEME_ERROR, META_THEME_ERROR_FAILED,
+ _("Missing <frame state='%s' resize='%s' focus='%s' style='whatever' />"),
+ meta_frame_state_to_string (state),
+ meta_frame_resize_to_string (META_FRAME_RESIZE_NONE),
+ meta_frame_focus_to_string (i));
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+}
+
+/**
+ * Constructor for a MetaFrameStyle.
+ *
+ * \param parent The parent style. Data not filled in here will be
+ * looked for in the parent style, and in its parent
+ * style, and so on.
+ *
+ * \return The newly-constructed style.
+ */
+MetaFrameStyle *
+meta_frame_style_new (MetaFrameStyle *parent)
+{
+ MetaFrameStyle *style;
+
+ style = g_new0 (MetaFrameStyle, 1);
+
+ style->refcount = 1;
+
+ /* Default alpha is fully opaque */
+ style->window_background_alpha = 255;
+
+ style->parent = parent;
+ if (parent)
+ meta_frame_style_ref (parent);
+
+ return style;
+}
+
+/**
+ * Increases the reference count of a frame style.
+ * If the style is NULL, this is a no-op.
+ *
+ * \param style The style.
+ */
+void
+meta_frame_style_ref (MetaFrameStyle *style)
+{
+ g_return_if_fail (style != NULL);
+
+ style->refcount += 1;
+}
+
+void
+meta_frame_style_unref (MetaFrameStyle *style)
+{
+ g_return_if_fail (style != NULL);
+ g_return_if_fail (style->refcount > 0);
+
+ style->refcount -= 1;
+
+ if (style->refcount == 0)
+ {
+ int i;
+
+ free_button_ops (style->buttons);
+
+ for (i = 0; i < META_FRAME_PIECE_LAST; i++)
+ if (style->pieces[i])
+ meta_draw_op_list_unref (style->pieces[i]);
+
+ if (style->layout)
+ meta_frame_layout_unref (style->layout);
+
+ if (style->window_background_color)
+ meta_color_spec_free (style->window_background_color);
+
+ /* we hold a reference to any parent style */
+ if (style->parent)
+ meta_frame_style_unref (style->parent);
+
+ g_free (style);
+ }
+}
+
+void
+meta_frame_style_apply_scale (const MetaFrameStyle *style,
+ PangoFontDescription *font_desc)
+{
+ int size = pango_font_description_get_size (font_desc);
+ double scale = style->layout->title_scale;
+
+ pango_font_description_set_size (font_desc, MAX (size * scale, 1));
+}
+
+MetaFrameStyleSet *
+meta_frame_style_set_new (MetaFrameStyleSet *parent)
+{
+ MetaFrameStyleSet *style_set;
+
+ style_set = g_new0 (MetaFrameStyleSet, 1);
+
+ style_set->parent = parent;
+ if (parent)
+ meta_frame_style_set_ref (parent);
+
+ style_set->refcount = 1;
+
+ return style_set;
+}
+
+void
+meta_frame_style_set_ref (MetaFrameStyleSet *style_set)
+{
+ g_return_if_fail (style_set != NULL);
+
+ style_set->refcount += 1;
+}
+
+void
+meta_frame_style_set_unref (MetaFrameStyleSet *style_set)
+{
+ g_return_if_fail (style_set != NULL);
+ g_return_if_fail (style_set->refcount > 0);
+
+ style_set->refcount -= 1;
+
+ if (style_set->refcount == 0)
+ {
+ int i;
+
+ for (i = 0; i < META_FRAME_RESIZE_LAST; i++)
+ {
+ free_focus_styles (style_set->normal_styles[i]);
+ free_focus_styles (style_set->shaded_styles[i]);
+ }
+
+ free_focus_styles (style_set->maximized_styles);
+ free_focus_styles (style_set->tiled_left_styles);
+ free_focus_styles (style_set->tiled_right_styles);
+ free_focus_styles (style_set->maximized_and_shaded_styles);
+ free_focus_styles (style_set->tiled_left_and_shaded_styles);
+ free_focus_styles (style_set->tiled_right_and_shaded_styles);
+
+ if (style_set->parent)
+ meta_frame_style_set_unref (style_set->parent);
+
+ g_free (style_set);
+ }
+}
+
+gboolean
+meta_frame_style_set_validate (MetaFrameStyleSet *style_set,
+ GError **error)
+{
+ int i, j;
+
+ g_return_val_if_fail (style_set != NULL, FALSE);
+
+ for (i = 0; i < META_FRAME_RESIZE_LAST; i++)
+ for (j = 0; j < META_FRAME_FOCUS_LAST; j++)
+ if (meta_frame_style_set_get_style (style_set,META_FRAME_STATE_NORMAL,
+ i, j) == NULL)
+ {
+ g_set_error (error, META_THEME_ERROR, META_THEME_ERROR_FAILED,
+ _("Missing <frame state='%s' resize='%s' focus='%s' style='whatever' />"),
+ meta_frame_state_to_string (META_FRAME_STATE_NORMAL),
+ meta_frame_resize_to_string (i),
+ meta_frame_focus_to_string (j));
+
+ return FALSE;
+ }
+
+ if (!check_state (style_set, META_FRAME_STATE_SHADED, error))
+ return FALSE;
+
+ if (!check_state (style_set, META_FRAME_STATE_MAXIMIZED, error))
+ return FALSE;
+
+ if (!check_state (style_set, META_FRAME_STATE_MAXIMIZED_AND_SHADED, error))
+ return FALSE;
+
+ return TRUE;
+}
+
+MetaFrameStyle *
+meta_frame_style_set_get_style (MetaFrameStyleSet *style_set,
+ MetaFrameState state,
+ MetaFrameResize resize,
+ MetaFrameFocus focus)
+{
+ MetaFrameStyle *style;
+
+ style = NULL;
+
+ if (state == META_FRAME_STATE_NORMAL || state == META_FRAME_STATE_SHADED)
+ {
+ if (state == META_FRAME_STATE_SHADED)
+ style = style_set->shaded_styles[resize][focus];
+ else
+ style = style_set->normal_styles[resize][focus];
+
+ /* Try parent if we failed here */
+ if (style == NULL && style_set->parent)
+ style = meta_frame_style_set_get_style (style_set->parent, state, resize, focus);
+
+ /* Allow people to omit the vert/horz/none resize modes */
+ if (style == NULL && resize != META_FRAME_RESIZE_BOTH)
+ style = meta_frame_style_set_get_style (style_set, state, META_FRAME_RESIZE_BOTH, focus);
+ }
+ else
+ {
+ MetaFrameStyle **styles;
+
+ styles = NULL;
+
+ switch (state)
+ {
+ case META_FRAME_STATE_MAXIMIZED:
+ styles = style_set->maximized_styles;
+ break;
+ case META_FRAME_STATE_TILED_LEFT:
+ styles = style_set->tiled_left_styles;
+ break;
+ case META_FRAME_STATE_TILED_RIGHT:
+ styles = style_set->tiled_right_styles;
+ break;
+ case META_FRAME_STATE_MAXIMIZED_AND_SHADED:
+ styles = style_set->maximized_and_shaded_styles;
+ break;
+ case META_FRAME_STATE_TILED_LEFT_AND_SHADED:
+ styles = style_set->tiled_left_and_shaded_styles;
+ break;
+ case META_FRAME_STATE_TILED_RIGHT_AND_SHADED:
+ styles = style_set->tiled_right_and_shaded_styles;
+ break;
+ case META_FRAME_STATE_NORMAL:
+ case META_FRAME_STATE_SHADED:
+ case META_FRAME_STATE_LAST:
+ default:
+ g_assert_not_reached ();
+ break;
+ }
+
+ style = styles[focus];
+
+ /* Tiled states are optional, try falling back to non-tiled states */
+ if (style == NULL)
+ {
+ if (state == META_FRAME_STATE_TILED_LEFT ||
+ state == META_FRAME_STATE_TILED_RIGHT)
+ style = meta_frame_style_set_get_style (style_set, META_FRAME_STATE_NORMAL, resize, focus);
+ else if (state == META_FRAME_STATE_TILED_LEFT_AND_SHADED ||
+ state == META_FRAME_STATE_TILED_RIGHT_AND_SHADED)
+ style = meta_frame_style_set_get_style (style_set, META_FRAME_STATE_SHADED, resize, focus);
+ }
+
+ /* Try parent if we failed here */
+ if (style == NULL && style_set->parent)
+ style = meta_frame_style_set_get_style (style_set->parent, state, resize, focus);
+ }
+
+ return style;
+}
diff --git a/libmetacity/meta-frame-style.h b/libmetacity/meta-frame-style.h
new file mode 100644
index 0000000..06f8079
--- /dev/null
+++ b/libmetacity/meta-frame-style.h
@@ -0,0 +1,121 @@
+/*
+ * Copyright (C) 2001 Havoc Pennington
+ * Copyright (C) 2016 Alberts Muktupāvels
+ *
+ * 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_STYLE_H
+#define META_FRAME_STYLE_H
+
+#include <libmetacity/meta-button-enums.h>
+#include <libmetacity/meta-color-spec.h>
+#include <libmetacity/meta-draw-op.h>
+#include <libmetacity/meta-frame-enums.h>
+#include <libmetacity/meta-frame-layout.h>
+
+G_BEGIN_DECLS
+
+typedef struct _MetaFrameStyle MetaFrameStyle;
+typedef struct _MetaFrameStyleSet MetaFrameStyleSet;
+
+/**
+ * How to draw a frame in a particular state (say, a focussed, non-maximised,
+ * resizable frame). This corresponds closely to the <frame_style> tag
+ * in a theme file.
+ */
+struct _MetaFrameStyle
+{
+ /** Reference count. */
+ int refcount;
+ /**
+ * Parent style.
+ * Settings which are unspecified here will be taken from there.
+ */
+ MetaFrameStyle *parent;
+ /** Operations for drawing each kind of button in each state. */
+ MetaDrawOpList *buttons[META_BUTTON_TYPE_LAST][META_BUTTON_STATE_LAST];
+ /** Operations for drawing each piece of the frame. */
+ MetaDrawOpList *pieces[META_FRAME_PIECE_LAST];
+ /**
+ * Details such as the height and width of each edge, the corner rounding,
+ * and the aspect ratio of the buttons.
+ */
+ MetaFrameLayout *layout;
+ /**
+ * Background colour of the window. Only present in theme formats
+ * 2 and above. Can be NULL to use the standard GTK theme engine.
+ */
+ MetaColorSpec *window_background_color;
+ /**
+ * Transparency of the window background. 0=transparent; 255=opaque.
+ */
+ guint8 window_background_alpha;
+};
+
+/**
+ * How to draw frames at different times: when it's maximised or not, shaded
+ * or not, when it's focussed or not, and (for non-maximised windows), when
+ * it can be horizontally or vertically resized, both, or neither.
+ * Not all window types actually get a frame.
+ *
+ * A theme contains one of these objects for each type of window (each
+ * MetaFrameType), that is, normal, dialogue (modal and non-modal), etc.
+ *
+ * This corresponds closely to the <frame_style_set> tag in a theme file.
+ */
+struct _MetaFrameStyleSet
+{
+ int refcount;
+ MetaFrameStyleSet *parent;
+ MetaFrameStyle *normal_styles[META_FRAME_RESIZE_LAST][META_FRAME_FOCUS_LAST];
+ MetaFrameStyle *maximized_styles[META_FRAME_FOCUS_LAST];
+ MetaFrameStyle *tiled_left_styles[META_FRAME_FOCUS_LAST];
+ MetaFrameStyle *tiled_right_styles[META_FRAME_FOCUS_LAST];
+ MetaFrameStyle *shaded_styles[META_FRAME_RESIZE_LAST][META_FRAME_FOCUS_LAST];
+ MetaFrameStyle *maximized_and_shaded_styles[META_FRAME_FOCUS_LAST];
+ MetaFrameStyle *tiled_left_and_shaded_styles[META_FRAME_FOCUS_LAST];
+ MetaFrameStyle *tiled_right_and_shaded_styles[META_FRAME_FOCUS_LAST];
+};
+
+MetaFrameStyle *meta_frame_style_new (MetaFrameStyle *parent);
+
+void meta_frame_style_ref (MetaFrameStyle *style);
+
+void meta_frame_style_unref (MetaFrameStyle *style);
+
+void meta_frame_style_apply_scale (const MetaFrameStyle *style,
+ PangoFontDescription *font_desc);
+
+gboolean meta_frame_style_validate (MetaFrameStyle *style,
+ guint current_theme_version,
+ GError **error);
+
+MetaFrameStyleSet *meta_frame_style_set_new (MetaFrameStyleSet *parent);
+
+void meta_frame_style_set_ref (MetaFrameStyleSet *style_set);
+
+void meta_frame_style_set_unref (MetaFrameStyleSet *style_set);
+
+gboolean meta_frame_style_set_validate (MetaFrameStyleSet *style_set,
+ GError **error);
+
+MetaFrameStyle *meta_frame_style_set_get_style (MetaFrameStyleSet *style_set,
+ MetaFrameState state,
+ MetaFrameResize resize,
+ MetaFrameFocus focus);
+
+G_END_DECLS
+
+#endif
diff --git a/po/POTFILES.in b/po/POTFILES.in
index c549c11..5143346 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -4,6 +4,7 @@ libmetacity/meta-color-spec.c
libmetacity/meta-draw-op.c
libmetacity/meta-draw-spec.c
libmetacity/meta-frame-layout.c
+libmetacity/meta-frame-style.c
libmetacity/meta-gradient-spec.c
libmetacity/meta-theme-metacity.c
src/50-metacity-navigation.xml.in
diff --git a/src/ui/theme-private.h b/src/ui/theme-private.h
index 0fb6a02..102f5a9 100644
--- a/src/ui/theme-private.h
+++ b/src/ui/theme-private.h
@@ -18,77 +18,13 @@
#ifndef META_THEME_PRIVATE_H
#define META_THEME_PRIVATE_H
-#include <libmetacity/meta-color-spec.h>
-#include <libmetacity/meta-draw-op.h>
-#include <libmetacity/meta-frame-layout.h>
+#include <libmetacity/meta-frame-style.h>
#include <libmetacity/meta-theme-impl.h>
#include "theme.h"
G_BEGIN_DECLS
-typedef struct _MetaFrameStyle MetaFrameStyle;
-typedef struct _MetaFrameStyleSet MetaFrameStyleSet;
-
-/**
- * How to draw a frame in a particular state (say, a focussed, non-maximised,
- * resizable frame). This corresponds closely to the <frame_style> tag
- * in a theme file.
- */
-struct _MetaFrameStyle
-{
- /** Reference count. */
- int refcount;
- /**
- * Parent style.
- * Settings which are unspecified here will be taken from there.
- */
- MetaFrameStyle *parent;
- /** Operations for drawing each kind of button in each state. */
- MetaDrawOpList *buttons[META_BUTTON_TYPE_LAST][META_BUTTON_STATE_LAST];
- /** Operations for drawing each piece of the frame. */
- MetaDrawOpList *pieces[META_FRAME_PIECE_LAST];
- /**
- * Details such as the height and width of each edge, the corner rounding,
- * and the aspect ratio of the buttons.
- */
- MetaFrameLayout *layout;
- /**
- * Background colour of the window. Only present in theme formats
- * 2 and above. Can be NULL to use the standard GTK theme engine.
- */
- MetaColorSpec *window_background_color;
- /**
- * Transparency of the window background. 0=transparent; 255=opaque.
- */
- guint8 window_background_alpha;
-};
-
-/**
- * How to draw frames at different times: when it's maximised or not, shaded
- * or not, when it's focussed or not, and (for non-maximised windows), when
- * it can be horizontally or vertically resized, both, or neither.
- * Not all window types actually get a frame.
- *
- * A theme contains one of these objects for each type of window (each
- * MetaFrameType), that is, normal, dialogue (modal and non-modal), etc.
- *
- * This corresponds closely to the <frame_style_set> tag in a theme file.
- */
-struct _MetaFrameStyleSet
-{
- int refcount;
- MetaFrameStyleSet *parent;
- MetaFrameStyle *normal_styles[META_FRAME_RESIZE_LAST][META_FRAME_FOCUS_LAST];
- MetaFrameStyle *maximized_styles[META_FRAME_FOCUS_LAST];
- MetaFrameStyle *tiled_left_styles[META_FRAME_FOCUS_LAST];
- MetaFrameStyle *tiled_right_styles[META_FRAME_FOCUS_LAST];
- MetaFrameStyle *shaded_styles[META_FRAME_RESIZE_LAST][META_FRAME_FOCUS_LAST];
- MetaFrameStyle *maximized_and_shaded_styles[META_FRAME_FOCUS_LAST];
- MetaFrameStyle *tiled_left_and_shaded_styles[META_FRAME_FOCUS_LAST];
- MetaFrameStyle *tiled_right_and_shaded_styles[META_FRAME_FOCUS_LAST];
-};
-
/**
* A theme. This is a singleton class which groups all settings from a theme
* on disk together.
@@ -137,24 +73,6 @@ struct _MetaTheme
MetaThemeImpl *impl;
};
-MetaFrameStyle *meta_frame_style_new (MetaFrameStyle *parent);
-void meta_frame_style_ref (MetaFrameStyle *style);
-void meta_frame_style_unref (MetaFrameStyle *style);
-
-void meta_frame_style_apply_scale (const MetaFrameStyle *style,
- PangoFontDescription *font_desc);
-
-gboolean meta_frame_style_validate (MetaFrameStyle *style,
- guint
current_theme_version,
- GError **error);
-
-MetaFrameStyleSet *meta_frame_style_set_new (MetaFrameStyleSet *parent);
-void meta_frame_style_set_ref (MetaFrameStyleSet *style_set);
-void meta_frame_style_set_unref (MetaFrameStyleSet *style_set);
-
-gboolean meta_frame_style_set_validate (MetaFrameStyleSet *style_set,
- GError **error);
-
MetaFrameStyle *meta_theme_get_frame_style (MetaTheme *theme,
MetaFrameType type,
MetaFrameFlags flags);
diff --git a/src/ui/theme.c b/src/ui/theme.c
index a6b2676..fb24ed5 100644
--- a/src/ui/theme.c
+++ b/src/ui/theme.c
@@ -842,92 +842,6 @@ meta_frame_layout_calc_geometry (MetaFrameLayout *layout,
fgeom->bottom_right_corner_rounded_radius = layout->bottom_right_corner_rounded_radius;
}
-/**
- * Constructor for a MetaFrameStyle.
- *
- * \param parent The parent style. Data not filled in here will be
- * looked for in the parent style, and in its parent
- * style, and so on.
- *
- * \return The newly-constructed style.
- */
-MetaFrameStyle*
-meta_frame_style_new (MetaFrameStyle *parent)
-{
- MetaFrameStyle *style;
-
- style = g_new0 (MetaFrameStyle, 1);
-
- style->refcount = 1;
-
- /* Default alpha is fully opaque */
- style->window_background_alpha = 255;
-
- style->parent = parent;
- if (parent)
- meta_frame_style_ref (parent);
-
- return style;
-}
-
-/**
- * Increases the reference count of a frame style.
- * If the style is NULL, this is a no-op.
- *
- * \param style The style.
- */
-void
-meta_frame_style_ref (MetaFrameStyle *style)
-{
- g_return_if_fail (style != NULL);
-
- style->refcount += 1;
-}
-
-static void
-free_button_ops (MetaDrawOpList *op_lists[META_BUTTON_TYPE_LAST][META_BUTTON_STATE_LAST])
-{
- int i, j;
-
- for (i = 0; i < META_BUTTON_TYPE_LAST; i++)
- for (j = 0; j < META_BUTTON_STATE_LAST; j++)
- if (op_lists[i][j])
- meta_draw_op_list_unref (op_lists[i][j]);
-}
-
-void
-meta_frame_style_unref (MetaFrameStyle *style)
-{
- g_return_if_fail (style != NULL);
- g_return_if_fail (style->refcount > 0);
-
- style->refcount -= 1;
-
- if (style->refcount == 0)
- {
- int i;
-
- free_button_ops (style->buttons);
-
- for (i = 0; i < META_FRAME_PIECE_LAST; i++)
- if (style->pieces[i])
- meta_draw_op_list_unref (style->pieces[i]);
-
- if (style->layout)
- meta_frame_layout_unref (style->layout);
-
- if (style->window_background_color)
- meta_color_spec_free (style->window_background_color);
-
- /* we hold a reference to any parent style */
- if (style->parent)
- meta_frame_style_unref (style->parent);
-
- DEBUG_FILL_STRUCT (style);
- g_free (style);
- }
-}
-
static MetaButtonState
map_button_state (MetaButtonType button_type,
const MetaFrameGeometry *fgeom,
@@ -1040,15 +954,6 @@ get_button (MetaFrameStyle *style,
return op_list;
}
-void
-meta_frame_style_apply_scale (const MetaFrameStyle *style,
- PangoFontDescription *font_desc)
-{
- int size = pango_font_description_get_size (font_desc);
- pango_font_description_set_size (font_desc,
- MAX (size * style->layout->title_scale, 1));
-}
-
static const char*
meta_button_type_to_string (MetaButtonType type)
{
@@ -1682,289 +1587,6 @@ meta_frame_style_draw_with_style_gtk (MetaFrameStyle *frame_style,
}
}
-MetaFrameStyleSet*
-meta_frame_style_set_new (MetaFrameStyleSet *parent)
-{
- MetaFrameStyleSet *style_set;
-
- style_set = g_new0 (MetaFrameStyleSet, 1);
-
- style_set->parent = parent;
- if (parent)
- meta_frame_style_set_ref (parent);
-
- style_set->refcount = 1;
-
- return style_set;
-}
-
-static void
-free_focus_styles (MetaFrameStyle *focus_styles[META_FRAME_FOCUS_LAST])
-{
- int i;
-
- for (i = 0; i < META_FRAME_FOCUS_LAST; i++)
- if (focus_styles[i])
- meta_frame_style_unref (focus_styles[i]);
-}
-
-void
-meta_frame_style_set_ref (MetaFrameStyleSet *style_set)
-{
- g_return_if_fail (style_set != NULL);
-
- style_set->refcount += 1;
-}
-
-void
-meta_frame_style_set_unref (MetaFrameStyleSet *style_set)
-{
- g_return_if_fail (style_set != NULL);
- g_return_if_fail (style_set->refcount > 0);
-
- style_set->refcount -= 1;
-
- if (style_set->refcount == 0)
- {
- int i;
-
- for (i = 0; i < META_FRAME_RESIZE_LAST; i++)
- {
- free_focus_styles (style_set->normal_styles[i]);
- free_focus_styles (style_set->shaded_styles[i]);
- }
-
- free_focus_styles (style_set->maximized_styles);
- free_focus_styles (style_set->tiled_left_styles);
- free_focus_styles (style_set->tiled_right_styles);
- free_focus_styles (style_set->maximized_and_shaded_styles);
- free_focus_styles (style_set->tiled_left_and_shaded_styles);
- free_focus_styles (style_set->tiled_right_and_shaded_styles);
-
- if (style_set->parent)
- meta_frame_style_set_unref (style_set->parent);
-
- DEBUG_FILL_STRUCT (style_set);
- g_free (style_set);
- }
-}
-
-
-static MetaFrameStyle*
-get_style (MetaFrameStyleSet *style_set,
- MetaFrameState state,
- MetaFrameResize resize,
- MetaFrameFocus focus)
-{
- MetaFrameStyle *style;
-
- style = NULL;
-
- if (state == META_FRAME_STATE_NORMAL || state == META_FRAME_STATE_SHADED)
- {
- if (state == META_FRAME_STATE_SHADED)
- style = style_set->shaded_styles[resize][focus];
- else
- style = style_set->normal_styles[resize][focus];
-
- /* Try parent if we failed here */
- if (style == NULL && style_set->parent)
- style = get_style (style_set->parent, state, resize, focus);
-
- /* Allow people to omit the vert/horz/none resize modes */
- if (style == NULL &&
- resize != META_FRAME_RESIZE_BOTH)
- style = get_style (style_set, state, META_FRAME_RESIZE_BOTH, focus);
- }
- else
- {
- MetaFrameStyle **styles;
-
- styles = NULL;
-
- switch (state)
- {
- case META_FRAME_STATE_MAXIMIZED:
- styles = style_set->maximized_styles;
- break;
- case META_FRAME_STATE_TILED_LEFT:
- styles = style_set->tiled_left_styles;
- break;
- case META_FRAME_STATE_TILED_RIGHT:
- styles = style_set->tiled_right_styles;
- break;
- case META_FRAME_STATE_MAXIMIZED_AND_SHADED:
- styles = style_set->maximized_and_shaded_styles;
- break;
- case META_FRAME_STATE_TILED_LEFT_AND_SHADED:
- styles = style_set->tiled_left_and_shaded_styles;
- break;
- case META_FRAME_STATE_TILED_RIGHT_AND_SHADED:
- styles = style_set->tiled_right_and_shaded_styles;
- break;
- case META_FRAME_STATE_NORMAL:
- case META_FRAME_STATE_SHADED:
- case META_FRAME_STATE_LAST:
- default:
- g_assert_not_reached ();
- break;
- }
-
- style = styles[focus];
-
- /* Tiled states are optional, try falling back to non-tiled states */
- if (style == NULL)
- {
- if (state == META_FRAME_STATE_TILED_LEFT ||
- state == META_FRAME_STATE_TILED_RIGHT)
- style = get_style (style_set, META_FRAME_STATE_NORMAL,
- resize, focus);
- else if (state == META_FRAME_STATE_TILED_LEFT_AND_SHADED ||
- state == META_FRAME_STATE_TILED_RIGHT_AND_SHADED)
- style = get_style (style_set, META_FRAME_STATE_SHADED,
- resize, focus);
- }
-
- /* Try parent if we failed here */
- if (style == NULL && style_set->parent)
- style = get_style (style_set->parent, state, resize, focus);
- }
-
- return style;
-}
-
-static const char*
-meta_frame_state_to_string (MetaFrameState state)
-{
- switch (state)
- {
- case META_FRAME_STATE_NORMAL:
- return "normal";
- case META_FRAME_STATE_MAXIMIZED:
- return "maximized";
- case META_FRAME_STATE_TILED_LEFT:
- return "tiled_left";
- case META_FRAME_STATE_TILED_RIGHT:
- return "tiled_right";
- case META_FRAME_STATE_SHADED:
- return "shaded";
- case META_FRAME_STATE_MAXIMIZED_AND_SHADED:
- return "maximized_and_shaded";
- case META_FRAME_STATE_TILED_LEFT_AND_SHADED:
- return "tiled_left_and_shaded";
- case META_FRAME_STATE_TILED_RIGHT_AND_SHADED:
- return "tiled_right_and_shaded";
- case META_FRAME_STATE_LAST:
- break;
- default:
- break;
- }
-
- return "<unknown>";
-}
-
-static const char*
-meta_frame_resize_to_string (MetaFrameResize resize)
-{
- switch (resize)
- {
- case META_FRAME_RESIZE_NONE:
- return "none";
- case META_FRAME_RESIZE_VERTICAL:
- return "vertical";
- case META_FRAME_RESIZE_HORIZONTAL:
- return "horizontal";
- case META_FRAME_RESIZE_BOTH:
- return "both";
- case META_FRAME_RESIZE_LAST:
- break;
- default:
- break;
- }
-
- return "<unknown>";
-}
-
-static const char*
-meta_frame_focus_to_string (MetaFrameFocus focus)
-{
- switch (focus)
- {
- case META_FRAME_FOCUS_NO:
- return "no";
- case META_FRAME_FOCUS_YES:
- return "yes";
- case META_FRAME_FOCUS_LAST:
- break;
- default:
- break;
- }
-
- return "<unknown>";
-}
-
-static gboolean
-check_state (MetaFrameStyleSet *style_set,
- MetaFrameState state,
- GError **error)
-{
- int i;
-
- for (i = 0; i < META_FRAME_FOCUS_LAST; i++)
- {
- if (get_style (style_set, state,
- META_FRAME_RESIZE_NONE, i) == NULL)
- {
- /* Translators: This error occurs when a <frame> tag is missing
- * in theme XML. The "<frame ...>" is intended as a noun phrase,
- * and the "missing" qualifies it. You should translate "whatever".
- */
- g_set_error (error, META_THEME_ERROR,
- META_THEME_ERROR_FAILED,
- _("Missing <frame state=\"%s\" resize=\"%s\" focus=\"%s\" style=\"whatever\"/>"),
- meta_frame_state_to_string (state),
- meta_frame_resize_to_string (META_FRAME_RESIZE_NONE),
- meta_frame_focus_to_string (i));
- return FALSE;
- }
- }
-
- return TRUE;
-}
-
-gboolean
-meta_frame_style_set_validate (MetaFrameStyleSet *style_set,
- GError **error)
-{
- int i, j;
-
- g_return_val_if_fail (style_set != NULL, FALSE);
-
- for (i = 0; i < META_FRAME_RESIZE_LAST; i++)
- for (j = 0; j < META_FRAME_FOCUS_LAST; j++)
- if (get_style (style_set, META_FRAME_STATE_NORMAL, i, j) == NULL)
- {
- g_set_error (error, META_THEME_ERROR,
- META_THEME_ERROR_FAILED,
- _("Missing <frame state=\"%s\" resize=\"%s\" focus=\"%s\" style=\"whatever\"/>"),
- meta_frame_state_to_string (META_FRAME_STATE_NORMAL),
- meta_frame_resize_to_string (i),
- meta_frame_focus_to_string (j));
- return FALSE;
- }
-
- if (!check_state (style_set, META_FRAME_STATE_SHADED, error))
- return FALSE;
-
- if (!check_state (style_set, META_FRAME_STATE_MAXIMIZED, error))
- return FALSE;
-
- if (!check_state (style_set, META_FRAME_STATE_MAXIMIZED_AND_SHADED, error))
- return FALSE;
-
- return TRUE;
-}
-
MetaTheme*
meta_theme_get_current (void)
{
@@ -2282,7 +1904,7 @@ theme_get_style (MetaTheme *theme,
else
focus = META_FRAME_FOCUS_NO;
- style = get_style (style_set, state, resize, focus);
+ style = meta_frame_style_set_get_style (style_set, state, resize, focus);
return style;
}
diff --git a/src/ui/theme.h b/src/ui/theme.h
index 96b596b..7d1627e 100644
--- a/src/ui/theme.h
+++ b/src/ui/theme.h
@@ -23,6 +23,7 @@
#define THEME_H
#include <gtk/gtk.h>
+#include <libmetacity/meta-button-enums.h>
#include <libmetacity/meta-button-layout.h>
#include <libmetacity/meta-frame-borders.h>
#include <libmetacity/meta-frame-enums.h>
@@ -105,39 +106,6 @@ struct _MetaFrameGeometry
guint bottom_right_corner_rounded_radius;
};
-typedef enum
-{
- META_BUTTON_STATE_NORMAL,
- META_BUTTON_STATE_PRESSED,
- META_BUTTON_STATE_PRELIGHT,
- META_BUTTON_STATE_LAST
-} MetaButtonState;
-
-typedef enum
-{
- /* Ordered so that background is drawn first */
- META_BUTTON_TYPE_LEFT_LEFT_BACKGROUND,
- META_BUTTON_TYPE_LEFT_MIDDLE_BACKGROUND,
- META_BUTTON_TYPE_LEFT_RIGHT_BACKGROUND,
- META_BUTTON_TYPE_LEFT_SINGLE_BACKGROUND,
- META_BUTTON_TYPE_RIGHT_LEFT_BACKGROUND,
- META_BUTTON_TYPE_RIGHT_MIDDLE_BACKGROUND,
- META_BUTTON_TYPE_RIGHT_RIGHT_BACKGROUND,
- META_BUTTON_TYPE_RIGHT_SINGLE_BACKGROUND,
- META_BUTTON_TYPE_CLOSE,
- META_BUTTON_TYPE_MAXIMIZE,
- META_BUTTON_TYPE_MINIMIZE,
- META_BUTTON_TYPE_MENU,
- META_BUTTON_TYPE_APPMENU,
- META_BUTTON_TYPE_SHADE,
- META_BUTTON_TYPE_ABOVE,
- META_BUTTON_TYPE_STICK,
- META_BUTTON_TYPE_UNSHADE,
- META_BUTTON_TYPE_UNABOVE,
- META_BUTTON_TYPE_UNSTICK,
- META_BUTTON_TYPE_LAST
-} MetaButtonType;
-
MetaTheme* meta_theme_get_current (void);
void meta_theme_set_current (const char *name,
gboolean force_reload,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]