[metacity] theme: Add function to fill geometry information from GTK+ theme



commit 49c5ca16afec5c8813830dae449004f5522a57c0
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.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=741917
    
    NOTE: Updated for metacity.

 src/ui/theme.c |   87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/ui/theme.h |    3 ++
 2 files changed, 90 insertions(+), 0 deletions(-)
---
diff --git a/src/ui/theme.c b/src/ui/theme.c
index 5ead095..6dcd8b3 100644
--- a/src/ui/theme.c
+++ b/src/ui/theme.c
@@ -244,6 +244,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);
 
@@ -624,6 +625,92 @@ 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, max_radius;
+
+  /* We don't want GTK+ info for metacity theme */
+  if (meta_prefs_get_theme ())
+    return;
+
+  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,
                                  MetaFrameFlags          flags,
diff --git a/src/ui/theme.h b/src/ui/theme.h
index b7225ca..86469e1 100644
--- a/src/ui/theme.h
+++ b/src/ui/theme.h
@@ -136,6 +136,9 @@ struct _MetaFrameLayout
   /** Space around buttons */
   GtkBorder button_border;
 
+  /** Size of images in buttons */
+  guint icon_size;
+
   /** Space between titlebar elements */
   guint titlebar_spacing;
 


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