summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorAlberts Muktupāvels <alberts.muktupavels@gmail.com>2016-01-31 04:08:50 +0200
committerAlberts Muktupāvels <alberts.muktupavels@gmail.com>2016-01-31 04:08:50 +0200
commit942b171e91dcacca2df985aa33abb680d8d8815a (patch)
treefaea87a31676db6e889a9c9d6b59a56d91d16762 /src/ui
parenta494336bee2b150942f18b53f0ddce4c04d59d4c (diff)
downloadmetacity-942b171e91dcacca2df985aa33abb680d8d8815a.tar.gz
libmetacity: add meta-frame-style.[c/h]
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/theme-private.h84
-rw-r--r--src/ui/theme.c380
-rw-r--r--src/ui/theme.h34
3 files changed, 3 insertions, 495 deletions
diff --git a/src/ui/theme-private.h b/src/ui/theme-private.h
index 0fb6a02f..102f5a92 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 a6b2676e..fb24ed5b 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 96b596bb..7d1627ea 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,