[metacity] libmetacity: move all button releated info to MetaButtonLayout



commit 619f814293e1a19a34d3ac80cced5c9c3392570d
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Wed Aug 17 17:53:46 2016 +0300

    libmetacity: move all button releated info to MetaButtonLayout

 libmetacity/meta-button-layout-private.h |   18 +++++++----
 libmetacity/meta-button-layout.c         |   45 +++++++++++++++++----------
 libmetacity/meta-theme-gtk.c             |   27 ++++++++---------
 libmetacity/meta-theme-impl-private.h    |    3 +-
 libmetacity/meta-theme-metacity.c        |   48 ++++++++++++++---------------
 libmetacity/meta-theme.c                 |   22 +++++++++----
 libmetacity/meta-theme.h                 |    4 --
 7 files changed, 92 insertions(+), 75 deletions(-)
---
diff --git a/libmetacity/meta-button-layout-private.h b/libmetacity/meta-button-layout-private.h
index 31341a5..62c62df 100644
--- a/libmetacity/meta-button-layout-private.h
+++ b/libmetacity/meta-button-layout-private.h
@@ -26,16 +26,22 @@ G_BEGIN_DECLS
 typedef struct
 {
   /* buttons in the group on the left side */
-  MetaButtonType left_buttons[META_BUTTON_TYPE_LAST];
-  gboolean       left_buttons_has_spacer[META_BUTTON_TYPE_LAST];
+  MetaButtonType  left_buttons[META_BUTTON_TYPE_LAST];
+  gboolean        left_buttons_has_spacer[META_BUTTON_TYPE_LAST];
+  gint            n_left_buttons;
 
   /* buttons in the group on the right side */
-  MetaButtonType right_buttons[META_BUTTON_TYPE_LAST];
-  gboolean       right_buttons_has_spacer[META_BUTTON_TYPE_LAST];
+  MetaButtonType  right_buttons[META_BUTTON_TYPE_LAST];
+  gboolean        right_buttons_has_spacer[META_BUTTON_TYPE_LAST];
+  gint            n_right_buttons;
+
+  MetaButtonState button_states[META_BUTTON_TYPE_LAST];
 } MetaButtonLayout;
 
-MetaButtonLayout meta_button_layout_new (const gchar *str,
-                                         gboolean     invert);
+MetaButtonLayout *meta_button_layout_new  (const gchar      *str,
+                                           gboolean          invert);
+
+void              meta_button_layout_free (MetaButtonLayout *layout);
 
 G_END_DECLS
 
diff --git a/libmetacity/meta-button-layout.c b/libmetacity/meta-button-layout.c
index 239d949..fb92712 100644
--- a/libmetacity/meta-button-layout.c
+++ b/libmetacity/meta-button-layout.c
@@ -153,29 +153,31 @@ string_to_buttons (const gchar    *str,
   g_strfreev (buttons);
 }
 
-MetaButtonLayout
+MetaButtonLayout *
 meta_button_layout_new (const gchar *str,
                         gboolean     invert)
 {
   gchar **sides;
-  MetaButtonLayout layout;
-  MetaButtonLayout rtl_layout;
+  MetaButtonLayout *layout;
+  MetaButtonLayout *rtl_layout;
   gint i;
   gint j;
 
+  layout = g_new0 (MetaButtonLayout, 1);
+  meta_button_layout_init (layout);
+
   sides = g_strsplit (str, ":", 2);
-  meta_button_layout_init (&layout);
 
   if (sides[0] != NULL)
     {
-      string_to_buttons (sides[0], layout.left_buttons,
-                         layout.left_buttons_has_spacer);
+      string_to_buttons (sides[0], layout->left_buttons,
+                         layout->left_buttons_has_spacer);
     }
 
   if (sides[0] != NULL && sides[1] != NULL)
     {
-      string_to_buttons (sides[1], layout.right_buttons,
-                         layout.right_buttons_has_spacer);
+      string_to_buttons (sides[1], layout->right_buttons,
+                         layout->right_buttons_has_spacer);
     }
 
   g_strfreev (sides);
@@ -183,35 +185,44 @@ meta_button_layout_new (const gchar *str,
   if (!invert)
     return layout;
 
-  meta_button_layout_init (&rtl_layout);
+  rtl_layout = g_new0 (MetaButtonLayout, 1);
+  meta_button_layout_init (rtl_layout);
 
   i = 0;
-  while (rtl_layout.left_buttons[i] != META_BUTTON_TYPE_LAST)
+  while (rtl_layout->left_buttons[i] != META_BUTTON_TYPE_LAST)
     i++;
 
   for (j = 0; j < i; j++)
     {
-      rtl_layout.right_buttons[j] = layout.left_buttons[i - j - 1];
+      rtl_layout->right_buttons[j] = layout->left_buttons[i - j - 1];
 
       if (j == 0)
-        rtl_layout.right_buttons_has_spacer[i - 1] = layout.left_buttons_has_spacer[i - j - 1];
+        rtl_layout->right_buttons_has_spacer[i - 1] = layout->left_buttons_has_spacer[i - j - 1];
       else
-        rtl_layout.right_buttons_has_spacer[j - 1] = layout.left_buttons_has_spacer[i - j - 1];
+        rtl_layout->right_buttons_has_spacer[j - 1] = layout->left_buttons_has_spacer[i - j - 1];
     }
 
   i = 0;
-  while (rtl_layout.left_buttons[i] != META_BUTTON_TYPE_LAST)
+  while (rtl_layout->left_buttons[i] != META_BUTTON_TYPE_LAST)
     i++;
 
   for (j = 0; j < i; j++)
     {
-      rtl_layout.left_buttons[j] = layout.right_buttons[i - j - 1];
+      rtl_layout->left_buttons[j] = layout->right_buttons[i - j - 1];
 
       if (j == 0)
-        rtl_layout.left_buttons_has_spacer[i - 1] = layout.right_buttons_has_spacer[i - j - 1];
+        rtl_layout->left_buttons_has_spacer[i - 1] = layout->right_buttons_has_spacer[i - j - 1];
       else
-        rtl_layout.left_buttons_has_spacer[j - 1] = layout.right_buttons_has_spacer[i - j - 1];
+        rtl_layout->left_buttons_has_spacer[j - 1] = layout->right_buttons_has_spacer[i - j - 1];
     }
 
+  meta_button_layout_free (layout);
+
   return rtl_layout;
 }
+
+void
+meta_button_layout_free (MetaButtonLayout *layout)
+{
+  g_free (layout);
+}
diff --git a/libmetacity/meta-theme-gtk.c b/libmetacity/meta-theme-gtk.c
index 0b374c7..94fba18 100644
--- a/libmetacity/meta-theme-gtk.c
+++ b/libmetacity/meta-theme-gtk.c
@@ -403,16 +403,16 @@ strip_button (MetaButtonSpace *func_rects[META_BUTTON_TYPE_LAST],
 }
 
 static void
-meta_theme_gtk_calc_geometry (MetaThemeImpl          *impl,
-                              MetaFrameLayout        *layout,
-                              MetaStyleInfo          *style_info,
-                              gint                    text_height,
-                              MetaFrameFlags          flags,
-                              gint                    client_width,
-                              gint                    client_height,
-                              const MetaButtonLayout *button_layout,
-                              MetaFrameType           type,
-                              MetaFrameGeometry      *fgeom)
+meta_theme_gtk_calc_geometry (MetaThemeImpl     *impl,
+                              MetaFrameLayout   *layout,
+                              MetaStyleInfo     *style_info,
+                              gint               text_height,
+                              MetaFrameFlags     flags,
+                              gint               client_width,
+                              gint               client_height,
+                              MetaButtonLayout  *button_layout,
+                              MetaFrameType      type,
+                              MetaFrameGeometry *fgeom)
 {
   MetaFrameBorders borders;
   int i, n_left, n_right, n_left_spacers, n_right_spacers;
@@ -589,8 +589,8 @@ meta_theme_gtk_calc_geometry (MetaThemeImpl          *impl,
     }
 
   /* Save the button layout */
-  fgeom->n_left_buttons = n_left;
-  fgeom->n_right_buttons = n_right;
+  button_layout->n_left_buttons = n_left;
+  button_layout->n_right_buttons = n_right;
 
   /* center buttons vertically */
   button_y = borders.invisible.top + layout->gtk.frame_border.top * scale +
@@ -741,7 +741,6 @@ meta_theme_gtk_draw_frame (MetaThemeImpl           *impl,
                            PangoLayout             *title_layout,
                            MetaFrameFlags           flags,
                            const MetaButtonLayout  *button_layout,
-                           MetaButtonState          button_states[META_BUTTON_TYPE_LAST],
                            GdkPixbuf               *mini_icon,
                            GdkPixbuf               *icon)
 {
@@ -840,7 +839,7 @@ meta_theme_gtk_draw_frame (MetaThemeImpl           *impl,
       if (button_class)
         gtk_style_context_add_class (context, button_class);
 
-      button_state = button_states [button_type];
+      button_state = button_layout->button_states[button_type];
 
       if (button_state == META_BUTTON_STATE_PRELIGHT)
         gtk_style_context_set_state (context, state | GTK_STATE_PRELIGHT);
diff --git a/libmetacity/meta-theme-impl-private.h b/libmetacity/meta-theme-impl-private.h
index 58d4afc..77cba2c 100644
--- a/libmetacity/meta-theme-impl-private.h
+++ b/libmetacity/meta-theme-impl-private.h
@@ -56,7 +56,7 @@ struct _MetaThemeImplClass
                                     MetaFrameFlags            flags,
                                     gint                      client_width,
                                     gint                      client_height,
-                                    const MetaButtonLayout   *button_layout,
+                                    MetaButtonLayout         *button_layout,
                                     MetaFrameType             type,
                                     MetaFrameGeometry        *fgeom);
 
@@ -68,7 +68,6 @@ struct _MetaThemeImplClass
                                     PangoLayout              *title_layout,
                                     MetaFrameFlags            flags,
                                     const MetaButtonLayout   *button_layout,
-                                    MetaButtonState           button_states[META_BUTTON_TYPE_LAST],
                                     GdkPixbuf                *mini_icon,
                                     GdkPixbuf                *icon);
 };
diff --git a/libmetacity/meta-theme-metacity.c b/libmetacity/meta-theme-metacity.c
index 554e541..7d41ec2 100644
--- a/libmetacity/meta-theme-metacity.c
+++ b/libmetacity/meta-theme-metacity.c
@@ -4845,16 +4845,16 @@ strip_button (MetaButtonSpace *func_rects[META_BUTTON_TYPE_LAST],
 }
 
 static void
-meta_theme_metacity_calc_geometry (MetaThemeImpl          *impl,
-                                   MetaFrameLayout        *layout,
-                                   MetaStyleInfo          *style_info,
-                                   gint                    text_height,
-                                   MetaFrameFlags          flags,
-                                   gint                    client_width,
-                                   gint                    client_height,
-                                   const MetaButtonLayout *button_layout,
-                                   MetaFrameType           type,
-                                   MetaFrameGeometry      *fgeom)
+meta_theme_metacity_calc_geometry (MetaThemeImpl     *impl,
+                                   MetaFrameLayout   *layout,
+                                   MetaStyleInfo     *style_info,
+                                   gint               text_height,
+                                   MetaFrameFlags     flags,
+                                   gint               client_width,
+                                   gint               client_height,
+                                   MetaButtonLayout  *button_layout,
+                                   MetaFrameType      type,
+                                   MetaFrameGeometry *fgeom)
 {
   MetaFrameBorders borders;
   int i, n_left, n_right, n_left_spacers, n_right_spacers;
@@ -5090,8 +5090,8 @@ meta_theme_metacity_calc_geometry (MetaThemeImpl          *impl,
     }
 
   /* Save the button layout */
-  fgeom->n_left_buttons = n_left;
-  fgeom->n_right_buttons = n_right;
+  button_layout->n_left_buttons = n_left;
+  button_layout->n_right_buttons = n_right;
 
   /* center buttons vertically */
   button_y = (borders.visible.top -
@@ -5381,8 +5381,7 @@ static MetaButtonState
 map_button_state (MetaButtonFunction       button_function,
                   const MetaFrameGeometry *fgeom,
                   gint                     middle_bg_offset,
-                  const MetaButtonLayout  *button_layout,
-                  MetaButtonState          button_states[META_BUTTON_TYPE_LAST])
+                  const MetaButtonLayout  *button_layout)
 {
   MetaButtonType type = META_BUTTON_TYPE_LAST;
 
@@ -5426,28 +5425,28 @@ map_button_state (MetaButtonFunction       button_function,
     /* Map position buttons to the corresponding type */
     case META_BUTTON_FUNCTION_RIGHT_LEFT_BACKGROUND:
     case META_BUTTON_FUNCTION_RIGHT_SINGLE_BACKGROUND:
-      if (fgeom->n_right_buttons > 0)
+      if (button_layout->n_right_buttons > 0)
         type = button_layout->right_buttons[0];
       break;
     case META_BUTTON_FUNCTION_RIGHT_RIGHT_BACKGROUND:
-      if (fgeom->n_right_buttons > 0)
-        type = button_layout->right_buttons[fgeom->n_right_buttons - 1];
+      if (button_layout->n_right_buttons > 0)
+        type = button_layout->right_buttons[button_layout->n_right_buttons - 1];
       break;
     case META_BUTTON_FUNCTION_RIGHT_MIDDLE_BACKGROUND:
-      if (middle_bg_offset + 1 < fgeom->n_right_buttons)
+      if (middle_bg_offset + 1 < button_layout->n_right_buttons)
         type = button_layout->right_buttons[middle_bg_offset + 1];
       break;
     case META_BUTTON_FUNCTION_LEFT_LEFT_BACKGROUND:
     case META_BUTTON_FUNCTION_LEFT_SINGLE_BACKGROUND:
-      if (fgeom->n_left_buttons > 0)
+      if (button_layout->n_left_buttons > 0)
         type = button_layout->left_buttons[0];
       break;
     case META_BUTTON_FUNCTION_LEFT_RIGHT_BACKGROUND:
-      if (fgeom->n_left_buttons > 0)
-        type = button_layout->left_buttons[fgeom->n_left_buttons - 1];
+      if (button_layout->n_left_buttons > 0)
+        type = button_layout->left_buttons[button_layout->n_left_buttons - 1];
       break;
     case META_BUTTON_FUNCTION_LEFT_MIDDLE_BACKGROUND:
-      if (middle_bg_offset + 1 < fgeom->n_left_buttons)
+      if (middle_bg_offset + 1 < button_layout->n_left_buttons)
         type = button_layout->left_buttons[middle_bg_offset + 1];
       break;
     case META_BUTTON_FUNCTION_LAST:
@@ -5457,7 +5456,7 @@ map_button_state (MetaButtonFunction       button_function,
     }
 
   if (type != META_BUTTON_TYPE_LAST)
-    return button_states[type];
+    return button_layout->button_states[type];
 
   return META_BUTTON_STATE_LAST;
 }
@@ -5471,7 +5470,6 @@ meta_theme_metacity_draw_frame (MetaThemeImpl           *impl,
                                 PangoLayout             *title_layout,
                                 MetaFrameFlags           flags,
                                 const MetaButtonLayout  *button_layout,
-                                MetaButtonState          button_states[META_BUTTON_TYPE_LAST],
                                 GdkPixbuf               *mini_icon,
                                 GdkPixbuf               *icon)
 {
@@ -5705,7 +5703,7 @@ meta_theme_metacity_draw_frame (MetaThemeImpl           *impl,
               rect.height = tmp_rect.height / scale;
 
               button_state = map_button_state (j, fgeom, middle_bg_offset,
-                                               button_layout, button_states);
+                                               button_layout);
 
               op_list = meta_frame_style_get_button (style, j, button_state);
 
diff --git a/libmetacity/meta-theme.c b/libmetacity/meta-theme.c
index 4699661..efabb3f 100644
--- a/libmetacity/meta-theme.c
+++ b/libmetacity/meta-theme.c
@@ -35,7 +35,7 @@ struct _MetaTheme
   MetaThemeType         type;
   MetaThemeImpl        *impl;
 
-  MetaButtonLayout      button_layout;
+  MetaButtonLayout     *button_layout;
 
   gboolean              composited;
 
@@ -416,6 +416,12 @@ meta_theme_finalize (GObject *object)
 
   theme = META_THEME (object);
 
+  if (theme->button_layout != NULL)
+    {
+      meta_button_layout_free (theme->button_layout);
+      theme->button_layout = NULL;
+    }
+
   if (theme->titlebar_font)
     {
       pango_font_description_free (theme->titlebar_font);
@@ -558,6 +564,9 @@ meta_theme_set_button_layout (MetaTheme   *theme,
                               const gchar *button_layout,
                               gboolean     invert)
 {
+  if (theme->button_layout != NULL)
+    meta_button_layout_free (theme->button_layout);
+
   theme->button_layout = meta_button_layout_new (button_layout, invert);
 }
 
@@ -643,7 +652,7 @@ meta_theme_calc_geometry (MetaTheme         *theme,
 
   impl_class->calc_geometry (theme->impl, style->layout, style_info,
                              title_height, flags, client_width, client_height,
-                             &theme->button_layout, type, fgeom);
+                             theme->button_layout, type, fgeom);
 }
 
 void
@@ -667,7 +676,6 @@ meta_theme_draw_frame (MetaTheme           *theme,
   PangoLayout *title_layout;
   MetaFrameGeometry fgeom;
   gint i;
-  MetaButtonState button_states[META_BUTTON_TYPE_LAST];
 
   g_return_if_fail (type < META_FRAME_TYPE_LAST);
 
@@ -684,7 +692,7 @@ meta_theme_draw_frame (MetaTheme           *theme,
 
   impl_class->calc_geometry (theme->impl, style->layout, style_info,
                              title_height, flags, client_width, client_height,
-                             &theme->button_layout, type, &fgeom);
+                             theme->button_layout, type, &fgeom);
 
   for (i = 0; i < META_BUTTON_TYPE_LAST; i++)
     {
@@ -699,12 +707,12 @@ meta_theme_draw_frame (MetaTheme           *theme,
 
       g_assert (state >= META_BUTTON_STATE_NORMAL && state < META_BUTTON_STATE_LAST);
 
-      button_states[i] = state;
+      theme->button_layout->button_states[i] = state;
     }
 
   impl_class->draw_frame (theme->impl, style, style_info, cr, &fgeom,
-                          title_layout, flags, &theme->button_layout,
-                          button_states, mini_icon, icon);
+                          title_layout, flags, theme->button_layout,
+                          mini_icon, icon);
 
   g_object_unref (title_layout);
 }
diff --git a/libmetacity/meta-theme.h b/libmetacity/meta-theme.h
index 9229051..4ee1d7c 100644
--- a/libmetacity/meta-theme.h
+++ b/libmetacity/meta-theme.h
@@ -135,10 +135,6 @@ struct _MetaFrameGeometry
   GdkRectangle right_single_background;
   /* End of button rects (if changed adjust memset hack) */
 
-  /* Saved button layout */
-  int n_left_buttons;
-  int n_right_buttons;
-
   /* Round corners */
   guint top_left_corner_rounded_radius;
   guint top_right_corner_rounded_radius;


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