theme: Add function to fill geometry information from GTK+ theme

We want to eventually pick up all theme information from GTK+ instead
of our own theme format; to prepare for this, add another helper method
to fill in geometry information from the GTK+ theme.

https://bugzilla.gnome.org/show_bug.cgi?id=741917
This commit is contained in:
Florian Müllner 2014-09-28 03:40:17 +02:00 committed by Jasper St. Pierre
parent bc9547f29e
commit fb1459062f
2 changed files with 86 additions and 0 deletions

View File

@ -181,6 +181,9 @@ struct _MetaFrameLayout
/** Space around buttons */
GtkBorder button_border;
/** Size of images in buttons */
guint icon_size;
/** Space between titlebar elements */
guint titlebar_spacing;

View File

@ -143,6 +143,7 @@ meta_frame_layout_new (void)
layout->titlebar_spacing = 6;
layout->has_title = TRUE;
layout->title_scale = 1.0;
layout->icon_size = META_MINI_ICON_WIDTH;
init_border (&layout->button_border);
@ -525,6 +526,88 @@ strip_button (MetaButtonSpace *func_rects[MAX_BUTTONS_PER_CORNER],
return FALSE; /* did not strip anything */
}
static void
get_padding_and_border (GtkStyleContext *style,
GtkBorder *border)
{
GtkBorder tmp;
GtkStateFlags state = gtk_style_context_get_state (style);
gtk_style_context_get_border (style, state, border);
gtk_style_context_get_padding (style, state, &tmp);
border->left += tmp.left;
border->top += tmp.top;
border->right += tmp.right;
border->bottom += tmp.bottom;
}
static void
meta_frame_layout_sync_with_style (MetaFrameLayout *layout,
MetaStyleInfo *style_info,
MetaFrameFlags flags)
{
GtkStyleContext *style;
GtkBorder border;
int border_radius, max_radius;
meta_style_info_set_flags (style_info, flags);
layout->button_sizing = META_BUTTON_SIZING_FIXED;
style = style_info->styles[META_STYLE_ELEMENT_FRAME];
get_padding_and_border (style, &border);
layout->left_width = border.left;
layout->right_width = border.right;
layout->bottom_height = border.bottom;
if (layout->hide_buttons)
layout->icon_size = 0;
if (!layout->has_title && layout->hide_buttons)
return; /* border-only - be done */
style = style_info->styles[META_STYLE_ELEMENT_TITLEBAR];
gtk_style_context_get (style, gtk_style_context_get_state (style),
"border-radius", &border_radius,
NULL);
/* GTK+ currently does not allow us to look up radii of individual
* corners; however we don't clip the client area, so with the
* current trend of using small/no visible frame borders, most
* themes should work fine with this.
*/
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);
layout->bottom_left_corner_rounded_radius = MAX (border_radius, max_radius);
max_radius = MIN (layout->bottom_height, layout->right_width);
layout->bottom_right_corner_rounded_radius = MAX (border_radius, max_radius);
get_padding_and_border (style, &border);
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;
style = style_info->styles[META_STYLE_ELEMENT_BUTTON];
get_padding_and_border (style, &border);
layout->button_width += border.left + border.right;
layout->button_height += border.top + border.bottom;
style = style_info->styles[META_STYLE_ELEMENT_IMAGE];
get_padding_and_border (style, &border);
layout->button_width += border.left + border.right;
layout->button_height += border.top + border.bottom;
}
static void
meta_frame_layout_calc_geometry (const MetaFrameLayout *layout,
int text_height,