summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Müllner <fmuellner@gnome.org>2014-09-26 15:10:56 +0100
committerFlorian Müllner <fmuellner@gnome.org>2014-12-22 23:49:04 +0100
commit8dda2967982bff5b5f4ad7fcfc07fa7876c80a35 (patch)
tree553d814767d983d86341a9b7eb477db3538a2418
parentc7880d0a80be475160c8d3fe88cf4a7293097106 (diff)
downloadmutter-wip/gtk-theming.tar.gz
theme: Move the layout we save closer to GTK+'s modelwip/gtk-theming
With support for the old metacity theme format gone, there's no reason to keep storing theme information in terms of the old theme properties. Just store the padding/border information for each element directly.
-rw-r--r--src/ui/theme-private.h38
-rw-r--r--src/ui/theme.c108
2 files changed, 55 insertions, 91 deletions
diff --git a/src/ui/theme-private.h b/src/ui/theme-private.h
index 2857cb125..22608b960 100644
--- a/src/ui/theme-private.h
+++ b/src/ui/theme-private.h
@@ -53,36 +53,13 @@ typedef struct _MetaFrameGeometry MetaFrameGeometry;
**/
struct _MetaFrameLayout
{
- /** Reference count. */
int refcount;
- /** Size of left side */
- int left_width;
- /** Size of right side */
- int right_width;
- /** Size of bottom side */
- int bottom_height;
-
- /** Border of blue title region
- * \bug (blue?!)
- **/
- GtkBorder title_border;
-
- /** Extra height for inside of title region, above the font height */
- int title_vertical_pad;
-
- /** Right indent of buttons from edges of frame */
- int right_titlebar_edge;
- /** Left indent of buttons from edges of frame */
- int left_titlebar_edge;
-
- /** Width of a button; set even when we are using aspect sizing */
- int button_width;
-
- /** Height of a button; set even when we are using aspect sizing */
- int button_height;
-
- /** Space around buttons */
+ /** Border/padding of the entire frame */
+ GtkBorder frame_border;
+ /** Border/padding of the titlebar region */
+ GtkBorder titlebar_border;
+ /** Border/padding of titlebar buttons */
GtkBorder button_border;
/** Size of images in buttons */
@@ -136,10 +113,7 @@ struct _MetaFrameGeometry
GdkRectangle title_rect;
- int left_titlebar_edge;
- int right_titlebar_edge;
- int top_titlebar_edge;
- int bottom_titlebar_edge;
+ GtkBorder content_border;
/* used for a memset hack */
#define ADDRESS_OF_BUTTON_RECTS(fgeom) (((char*)(fgeom)) + G_STRUCT_OFFSET (MetaFrameGeometry, close_rect))
diff --git a/src/ui/theme.c b/src/ui/theme.c
index f39bcc6d3..db7d782c0 100644
--- a/src/ui/theme.c
+++ b/src/ui/theme.c
@@ -66,7 +66,7 @@ meta_frame_layout_new (void)
layout->titlebar_spacing = 6; /* hardcoded in GTK+ */
layout->has_title = TRUE;
- layout->title_scale = 1.0;
+ layout->title_scale = PANGO_SCALE_MEDIUM;
layout->icon_size = META_MINI_ICON_WIDTH;
return layout;
@@ -116,7 +116,7 @@ meta_frame_layout_get_borders (const MetaFrameLayout *layout,
MetaFrameType type,
MetaFrameBorders *borders)
{
- int buttons_height, title_height, draggable_borders;
+ int buttons_height, content_height, draggable_borders;
meta_frame_borders_clear (borders);
@@ -129,16 +129,15 @@ meta_frame_layout_get_borders (const MetaFrameLayout *layout,
if (!layout->has_title)
text_height = 0;
- buttons_height = layout->button_height +
+ buttons_height = layout->icon_size +
layout->button_border.top + layout->button_border.bottom;
- title_height = text_height +
- layout->title_vertical_pad +
- layout->title_border.top + layout->title_border.bottom;
+ content_height = MAX (buttons_height, text_height) +
+ layout->titlebar_border.top + layout->titlebar_border.bottom;
- borders->visible.top = MAX (buttons_height, title_height);
- borders->visible.left = layout->left_width;
- borders->visible.right = layout->right_width;
- borders->visible.bottom = layout->bottom_height;
+ borders->visible.top = layout->frame_border.top + content_height;
+ borders->visible.left = layout->frame_border.left;
+ borders->visible.right = layout->frame_border.right;
+ borders->visible.bottom = layout->frame_border.bottom;
draggable_borders = meta_prefs_get_draggable_border_width ();
@@ -297,12 +296,8 @@ meta_frame_layout_sync_with_style (MetaFrameLayout *layout,
meta_style_info_set_flags (style_info, flags);
style = style_info->styles[META_STYLE_ELEMENT_FRAME];
- get_padding_and_border (style, &border);
- scale_border (&border, layout->title_scale);
-
- layout->left_width = border.left;
- layout->right_width = border.right;
- layout->bottom_height = border.bottom;
+ get_padding_and_border (style, &layout->frame_border);
+ scale_border (&layout->frame_border, layout->title_scale);
if (layout->hide_buttons)
layout->icon_size = 0;
@@ -321,36 +316,26 @@ meta_frame_layout_sync_with_style (MetaFrameLayout *layout,
*/
layout->top_left_corner_rounded_radius = border_radius;
layout->top_right_corner_rounded_radius = border_radius;
- max_radius = MIN (layout->bottom_height, layout->left_width);
+ max_radius = MIN (layout->frame_border.bottom, layout->frame_border.left);
layout->bottom_left_corner_rounded_radius = MAX (border_radius, max_radius);
- max_radius = MIN (layout->bottom_height, layout->right_width);
+ max_radius = MIN (layout->frame_border.bottom, layout->frame_border.right);
layout->bottom_right_corner_rounded_radius = MAX (border_radius, max_radius);
- get_padding_and_border (style, &border);
- scale_border (&border, layout->title_scale);
- layout->left_titlebar_edge = border.left;
- layout->right_titlebar_edge = border.right;
- layout->title_vertical_pad = border.top;
-
- layout->button_border.top = border.top;
- layout->button_border.bottom = border.bottom;
- layout->button_border.left = 0;
- layout->button_border.right = 0;
-
- layout->button_width = layout->icon_size;
- layout->button_height = layout->icon_size;
+ get_padding_and_border (style, &layout->titlebar_border);
+ scale_border (&layout->titlebar_border, layout->title_scale);
style = style_info->styles[META_STYLE_ELEMENT_BUTTON];
- get_padding_and_border (style, &border);
- scale_border (&border, layout->title_scale);
- layout->button_width += border.left + border.right;
- layout->button_height += border.top + border.bottom;
+ get_padding_and_border (style, &layout->button_border);
+ scale_border (&layout->button_border, layout->title_scale);
style = style_info->styles[META_STYLE_ELEMENT_IMAGE];
get_padding_and_border (style, &border);
scale_border (&border, layout->title_scale);
- layout->button_width += border.left + border.right;
- layout->button_height += border.top + border.bottom;
+
+ layout->button_border.left += border.left;
+ layout->button_border.right += border.right;
+ layout->button_border.top += border.top;
+ layout->button_border.bottom += border.bottom;
}
static void
@@ -370,6 +355,7 @@ meta_frame_layout_calc_geometry (MetaFrameLayout *layout,
int button_y;
int title_right_edge;
int width, height;
+ int content_width, content_height;
int button_width, button_height;
int min_size_for_rounding;
@@ -391,6 +377,12 @@ meta_frame_layout_calc_geometry (MetaFrameLayout *layout,
fgeom->borders = borders;
+ fgeom->content_border = layout->frame_border;
+ fgeom->content_border.left += layout->titlebar_border.left;
+ fgeom->content_border.right += layout->titlebar_border.right;
+ fgeom->content_border.top += layout->titlebar_border.top;
+ fgeom->content_border.bottom += layout->titlebar_border.bottom;
+
width = client_width + borders.total.left + borders.total.right;
height = borders.total.top + borders.total.bottom;
@@ -400,13 +392,15 @@ meta_frame_layout_calc_geometry (MetaFrameLayout *layout,
fgeom->width = width;
fgeom->height = height;
- fgeom->top_titlebar_edge = layout->title_border.top;
- fgeom->bottom_titlebar_edge = layout->title_border.bottom;
- fgeom->left_titlebar_edge = layout->left_titlebar_edge;
- fgeom->right_titlebar_edge = layout->right_titlebar_edge;
+ content_width = width -
+ (fgeom->content_border.left + borders.invisible.left) -
+ (fgeom->content_border.right + borders.invisible.right);
+ content_height = borders.visible.top - fgeom->content_border.top - fgeom->content_border.bottom;
- button_width = layout->button_width;
- button_height = layout->button_height;
+ button_width = layout->icon_size +
+ layout->button_border.left + layout->button_border.right;
+ button_height = layout->icon_size +
+ layout->button_border.top + layout->button_border.bottom;
/* FIXME all this code sort of pretends that duplicate buttons
* with the same function are allowed, but that breaks the
@@ -461,9 +455,6 @@ meta_frame_layout_calc_geometry (MetaFrameLayout *layout,
while (n_left > 0 || n_right > 0)
{
int space_used_by_buttons;
- int space_available;
-
- space_available = fgeom->width - layout->left_titlebar_edge - layout->right_titlebar_edge;
space_used_by_buttons = 0;
@@ -475,7 +466,7 @@ meta_frame_layout_calc_geometry (MetaFrameLayout *layout,
space_used_by_buttons += (button_width * 0.75) * n_right_spacers;
space_used_by_buttons += layout->titlebar_spacing * MAX (n_right - 1, 0);
- if (space_used_by_buttons <= space_available)
+ if (space_used_by_buttons <= content_width)
break; /* Everything fits, bail out */
/* First try to remove separators */
@@ -539,11 +530,11 @@ meta_frame_layout_calc_geometry (MetaFrameLayout *layout,
fgeom->n_right_buttons = n_right;
/* center buttons vertically */
- button_y = (borders.visible.top -
- (button_height + layout->button_border.top + layout->button_border.bottom)) / 2 + layout->button_border.top + borders.invisible.top;
+ button_y = fgeom->content_border.top + borders.invisible.top +
+ (content_height - button_height) / 2;
/* right edge of farthest-right button */
- x = width - layout->right_titlebar_edge - borders.invisible.right;
+ x = width - fgeom->content_border.right - borders.invisible.right;
i = n_right - 1;
while (i >= 0)
@@ -572,7 +563,7 @@ meta_frame_layout_calc_geometry (MetaFrameLayout *layout,
rect->clickable.height = button_height + button_y;
if (i == n_right - 1)
- rect->clickable.width += layout->right_titlebar_edge + layout->right_width;
+ rect->clickable.width += fgeom->content_border.right;
}
else
@@ -587,12 +578,12 @@ meta_frame_layout_calc_geometry (MetaFrameLayout *layout,
}
/* save right edge of titlebar for later use */
- title_right_edge = x - layout->title_border.right;
+ title_right_edge = x;
/* Now x changes to be position from the left and we go through
* the left-side buttons
*/
- x = layout->left_titlebar_edge + borders.invisible.left;
+ x = fgeom->content_border.left + borders.invisible.left;
for (i = 0; i < n_left; i++)
{
MetaButtonSpace *rect;
@@ -630,13 +621,12 @@ meta_frame_layout_calc_geometry (MetaFrameLayout *layout,
x += (button_width * 0.75);
}
- /* We always fill as much vertical space as possible with title rect,
- * rather than centering it like the buttons
- */
- fgeom->title_rect.x = x + layout->title_border.left;
- fgeom->title_rect.y = layout->title_border.top + borders.invisible.top;
+ /* Center vertically in the available content area */
+ fgeom->title_rect.x = x;
+ fgeom->title_rect.y = fgeom->content_border.top + borders.invisible.top +
+ (content_height - text_height) / 2;
fgeom->title_rect.width = title_right_edge - fgeom->title_rect.x;
- fgeom->title_rect.height = borders.visible.top - layout->title_border.top - layout->title_border.bottom;
+ fgeom->title_rect.height = text_height;
/* Nuke title if it won't fit */
if (fgeom->title_rect.width < 0 ||