[mutter/wip/gtk-theming: 8/20] theme: Add function to fill geometry information from GTK+ theme



commit fc2954ea56c8b113acb7fd54b732664fab8ebd37
Author: Florian Müllner <fmuellner gnome org>
Date:   Sun Sep 28 03:40:17 2014 +0200

    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.

 src/ui/theme-private.h |    3 ++
 src/ui/theme.c         |   77 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 80 insertions(+), 0 deletions(-)
---
diff --git a/src/ui/theme-private.h b/src/ui/theme-private.h
index 10a12b5..0c4e9a0 100644
--- a/src/ui/theme-private.h
+++ b/src/ui/theme-private.h
@@ -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;
 
diff --git a/src/ui/theme.c b/src/ui/theme.c
index dddd3a7..58311a9 100644
--- a/src/ui/theme.c
+++ b/src/ui/theme.c
@@ -140,6 +140,7 @@ meta_frame_layout_new  (void)
   layout->titlebar_spacing = 6; /* hardcoded in GTK+ */
   layout->has_title = TRUE;
   layout->title_scale = 1.0;
+  layout->icon_size = META_MINI_ICON_WIDTH;
 
   init_border (&layout->button_border);
 
@@ -523,6 +524,82 @@ strip_button (MetaButtonSpace *func_rects[MAX_BUTTONS_PER_CORNER],
 }
 
 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;
+
+  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);
+  /* FIXME: what about bottom? */
+  layout->top_left_corner_rounded_radius = border_radius;
+  layout->top_right_corner_rounded_radius = border_radius;
+  layout->bottom_left_corner_rounded_radius = border_radius;
+  layout->bottom_right_corner_rounded_radius = border_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,
                                  MetaFrameFlags          flags,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]