[metacity] libmetacity: don't expose meta_theme_get_title_height



commit d9498502d337216fe4f02a9eeee333e4b2238376
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Mon Jun 6 18:51:03 2016 +0300

    libmetacity: don't expose meta_theme_get_title_height

 libmetacity/meta-theme.c           |  116 ++++++++++++++++++++++--------------
 libmetacity/meta-theme.h           |    6 --
 src/ui/frames.c                    |   80 ++++---------------------
 src/ui/frames.h                    |    3 +-
 src/ui/ui.c                        |    8 +--
 theme-viewer/theme-viewer-window.c |   17 ++----
 6 files changed, 89 insertions(+), 141 deletions(-)
---
diff --git a/libmetacity/meta-theme.c b/libmetacity/meta-theme.c
index 3f66add..fc23ced 100644
--- a/libmetacity/meta-theme.c
+++ b/libmetacity/meta-theme.c
@@ -45,6 +45,7 @@ struct _MetaTheme
   PangoContext         *context;
 
   GHashTable           *font_descs;
+  GHashTable           *title_heights;
 };
 
 enum
@@ -86,6 +87,56 @@ ensure_pango_context (MetaTheme *theme)
   theme->context = context;
 }
 
+static gint
+get_title_height (MetaTheme      *theme,
+                  const gchar    *variant,
+                  MetaFrameType   type,
+                  MetaFrameFlags  flags)
+{
+  PangoFontDescription *description;
+  gpointer size;
+  gpointer height;
+  gint title_height;
+
+  description = meta_theme_get_title_font_desc (theme, variant, type, flags);
+  g_assert (description != NULL);
+
+  size = GINT_TO_POINTER (pango_font_description_get_size (description));
+  height = g_hash_table_lookup (theme->title_heights, size);
+
+  if (height != NULL)
+    {
+      title_height = GPOINTER_TO_INT (height);
+    }
+  else
+    {
+      PangoLanguage *lang;
+      PangoFontMetrics *metrics;
+      gint ascent;
+      gint descent;
+      gint scale;
+
+      ensure_pango_context (theme);
+
+      lang = pango_context_get_language (theme->context);
+      metrics = pango_context_get_metrics (theme->context, description, lang);
+
+      ascent = pango_font_metrics_get_ascent (metrics);
+      descent = pango_font_metrics_get_descent (metrics);
+      pango_font_metrics_unref (metrics);
+
+      title_height = PANGO_PIXELS (ascent + descent);
+      scale = get_window_scaling_factor ();
+
+      title_height *= scale;
+
+      height = GINT_TO_POINTER (title_height);
+      g_hash_table_insert (theme->title_heights, size, height);
+    }
+
+  return title_height;
+}
+
 static void
 font_desc_apply_scale (PangoFontDescription *font_desc,
                        MetaTheme            *theme,
@@ -166,6 +217,7 @@ meta_theme_dispose (GObject *object)
   g_clear_object (&theme->context);
 
   g_clear_pointer (&theme->font_descs, g_hash_table_destroy);
+  g_clear_pointer (&theme->title_heights, g_hash_table_destroy);
 
   G_OBJECT_CLASS (meta_theme_parent_class)->dispose (object);
 }
@@ -247,6 +299,8 @@ meta_theme_init (MetaTheme *theme)
 
   theme->font_descs = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
                                              (GDestroyNotify) pango_font_description_free);
+
+  theme->title_heights = g_hash_table_new (NULL, NULL);
 }
 
 /**
@@ -302,6 +356,7 @@ meta_theme_invalidate (MetaTheme *theme)
   g_hash_table_remove_all (theme->variants);
   g_clear_object (&theme->context);
   g_hash_table_remove_all (theme->font_descs);
+  g_hash_table_remove_all (theme->title_heights);
 }
 
 void
@@ -325,6 +380,7 @@ meta_theme_set_titlebar_font (MetaTheme                  *theme,
   theme->titlebar_font = pango_font_description_copy (titlebar_font);
 
   g_hash_table_remove_all (theme->font_descs);
+  g_hash_table_remove_all (theme->title_heights);
 }
 
 MetaFrameStyle *
@@ -495,39 +551,6 @@ meta_theme_get_title_font_desc (MetaTheme      *theme,
   return font_desc;
 }
 
-/**
- * meta_theme_get_title_height:
- * @theme: a #MetaTheme
- * @font_desc: the font description to use when calculating title height
- *
- * Returns: the height of title
- */
-gint
-meta_theme_get_title_height (MetaTheme                  *theme,
-                             const PangoFontDescription *font_desc)
-{
-  PangoLanguage *lang;
-  PangoFontMetrics *metrics;
-  gint ascent;
-  gint descent;
-  gint title_height;
-  gint scale;
-
-  ensure_pango_context (theme);
-
-  lang = pango_context_get_language (theme->context);
-  metrics = pango_context_get_metrics (theme->context, font_desc, lang);
-
-  ascent = pango_font_metrics_get_ascent (metrics);
-  descent = pango_font_metrics_get_descent (metrics);
-  pango_font_metrics_unref (metrics);
-
-  title_height = PANGO_PIXELS (ascent + descent);
-  scale = get_window_scaling_factor ();
-
-  return title_height * scale;
-}
-
 MetaFrameType
 meta_frame_type_from_string (const gchar *str)
 {
@@ -553,13 +576,13 @@ void
 meta_theme_get_frame_borders (MetaTheme        *theme,
                               const gchar      *theme_variant,
                               MetaFrameType     type,
-                              int               text_height,
                               MetaFrameFlags    flags,
                               MetaFrameBorders *borders)
 {
   MetaFrameStyle *style;
-  MetaStyleInfo *style_info;
   MetaThemeImplClass *impl_class;
+  MetaStyleInfo *style_info;
+  gint title_height;
 
   g_return_if_fail (type < META_FRAME_TYPE_LAST);
 
@@ -571,18 +594,18 @@ meta_theme_get_frame_borders (MetaTheme        *theme,
   if (style == NULL)
     return;
 
-  style_info = meta_theme_get_style_info (theme, theme_variant);
   impl_class = META_THEME_IMPL_GET_CLASS (theme->impl);
+  style_info = meta_theme_get_style_info (theme, theme_variant);
+  title_height = get_title_height (theme, theme_variant, type, flags);
 
   impl_class->get_frame_borders (theme->impl, style->layout, style_info,
-                                 text_height, flags, type, borders);
+                                 title_height, flags, type, borders);
 }
 
 void
 meta_theme_calc_geometry (MetaTheme              *theme,
                           const gchar            *theme_variant,
                           MetaFrameType           type,
-                          gint                    text_height,
                           MetaFrameFlags          flags,
                           gint                    client_width,
                           gint                    client_height,
@@ -590,8 +613,9 @@ meta_theme_calc_geometry (MetaTheme              *theme,
                           MetaFrameGeometry      *fgeom)
 {
   MetaFrameStyle *style;
-  MetaStyleInfo *style_info;
   MetaThemeImplClass *impl_class;
+  MetaStyleInfo *style_info;
+  gint title_height;
 
   g_return_if_fail (type < META_FRAME_TYPE_LAST);
 
@@ -601,11 +625,12 @@ meta_theme_calc_geometry (MetaTheme              *theme,
   if (style == NULL)
     return;
 
-  style_info = meta_theme_get_style_info (theme, theme_variant);
   impl_class = META_THEME_IMPL_GET_CLASS (theme->impl);
+  style_info = meta_theme_get_style_info (theme, theme_variant);
+  title_height = get_title_height (theme, theme_variant, type, flags);
 
   impl_class->calc_geometry (theme->impl, style->layout, style_info,
-                             text_height, flags, client_width, client_height,
+                             title_height, flags, client_width, client_height,
                              button_layout, type, fgeom);
 }
 
@@ -618,15 +643,15 @@ meta_theme_draw_frame (MetaTheme              *theme,
                        int                     client_width,
                        int                     client_height,
                        PangoLayout            *title_layout,
-                       int                     text_height,
                        const MetaButtonLayout *button_layout,
                        MetaButtonState         button_states[META_BUTTON_TYPE_LAST],
                        GdkPixbuf              *mini_icon,
                        GdkPixbuf              *icon)
 {
   MetaFrameStyle *style;
-  MetaStyleInfo *style_info;
   MetaThemeImplClass *impl_class;
+  MetaStyleInfo *style_info;
+  gint title_height;
   MetaFrameGeometry fgeom;
 
   g_return_if_fail (type < META_FRAME_TYPE_LAST);
@@ -637,11 +662,12 @@ meta_theme_draw_frame (MetaTheme              *theme,
   if (style == NULL)
     return;
 
-  style_info = meta_theme_get_style_info (theme, theme_variant);
   impl_class = META_THEME_IMPL_GET_CLASS (theme->impl);
+  style_info = meta_theme_get_style_info (theme, theme_variant);
+  title_height = get_title_height (theme, theme_variant, type, flags);
 
   impl_class->calc_geometry (theme->impl, style->layout, style_info,
-                             text_height, flags, client_width, client_height,
+                             title_height, flags, client_width, client_height,
                              button_layout, type, &fgeom);
 
   impl_class->draw_frame (theme->impl, style, style_info, cr, &fgeom,
diff --git a/libmetacity/meta-theme.h b/libmetacity/meta-theme.h
index 69f778b..4b190ae 100644
--- a/libmetacity/meta-theme.h
+++ b/libmetacity/meta-theme.h
@@ -173,22 +173,17 @@ PangoFontDescription *meta_theme_get_title_font_desc       (MetaTheme
                                                             MetaFrameType                type,
                                                             MetaFrameFlags               flags);
 
-gint                  meta_theme_get_title_height          (MetaTheme                   *theme,
-                                                            const PangoFontDescription  *font_desc);
-
 MetaFrameType         meta_frame_type_from_string          (const gchar                 *str);
 
 void                  meta_theme_get_frame_borders         (MetaTheme                   *theme,
                                                             const gchar                 *variant,
                                                             MetaFrameType                type,
-                                                            gint                         text_height,
                                                             MetaFrameFlags               flags,
                                                             MetaFrameBorders            *borders);
 
 void                  meta_theme_calc_geometry             (MetaTheme                   *theme,
                                                             const gchar                 *variant,
                                                             MetaFrameType                type,
-                                                            gint                         text_height,
                                                             MetaFrameFlags               flags,
                                                             gint                         client_width,
                                                             gint                         client_height,
@@ -203,7 +198,6 @@ void                  meta_theme_draw_frame                (MetaTheme
                                                             gint                         client_width,
                                                             gint                         client_height,
                                                             PangoLayout                 *title_layout,
-                                                            int                          text_height,
                                                             const MetaButtonLayout      *button_layout,
                                                             MetaButtonState              
button_states[META_BUTTON_TYPE_LAST],
                                                             GdkPixbuf                   *mini_icon,
diff --git a/src/ui/frames.c b/src/ui/frames.c
index aaf03a5..202e1f2 100644
--- a/src/ui/frames.c
+++ b/src/ui/frames.c
@@ -100,8 +100,6 @@ struct _MetaFrames
 {
   GtkWindow    parent;
 
-  GHashTable  *text_heights;
-
   GHashTable  *frames;
 
   guint        tooltip_timeout;
@@ -173,8 +171,6 @@ prefs_changed_callback (MetaPreference pref,
 static void
 meta_frames_init (MetaFrames *frames)
 {
-  frames->text_heights = g_hash_table_new (NULL, NULL);
-
   frames->frames = g_hash_table_new (unsigned_long_hash, unsigned_long_equal);
 
   frames->tooltip_timeout = 0;
@@ -234,8 +230,6 @@ meta_frames_finalize (GObject *object)
 
   meta_prefs_remove_listener (prefs_changed_callback, frames);
 
-  g_hash_table_destroy (frames->text_heights);
-
   invalidate_all_caches (frames);
   if (frames->invalidate_cache_timeout_id)
     g_source_remove (frames->invalidate_cache_timeout_id);
@@ -346,12 +340,6 @@ meta_frames_font_changed (MetaFrames *frames)
 
   meta_theme_set_titlebar_font (theme, titlebar_font);
 
-  if (g_hash_table_size (frames->text_heights) > 0)
-    {
-      g_hash_table_destroy (frames->text_heights);
-      frames->text_heights = g_hash_table_new (NULL, NULL);
-    }
-
   /* Queue a draw/resize on all frames */
   g_hash_table_foreach (frames->frames,
                         queue_recalc_func, frames);
@@ -438,31 +426,12 @@ meta_frames_ensure_layout (MetaFrames  *frames,
 
   if (frame->text_layout == NULL)
     {
-      gpointer key, value;
       PangoFontDescription *font_desc;
-      int size;
 
       frame->text_layout = meta_theme_create_title_layout (theme, frame->title);
       font_desc = meta_theme_get_title_font_desc (theme, frame->theme_variant,
                                                   type, flags);
 
-      size = pango_font_description_get_size (font_desc);
-
-      if (g_hash_table_lookup_extended (frames->text_heights,
-                                        GINT_TO_POINTER (size),
-                                        &key, &value))
-        {
-          frame->text_height = GPOINTER_TO_INT (value);
-        }
-      else
-        {
-          frame->text_height = meta_theme_get_title_height (theme, font_desc);
-
-          g_hash_table_replace (frames->text_heights,
-                                GINT_TO_POINTER (size),
-                                GINT_TO_POINTER (frame->text_height));
-        }
-
       pango_layout_set_font_description (frame->text_layout, font_desc);
     }
 }
@@ -488,14 +457,8 @@ meta_frames_calc_geometry (MetaFrames        *frames,
 
   meta_prefs_get_button_layout (&button_layout);
 
-  meta_theme_calc_geometry (meta_ui_get_theme (),
-                            frame->theme_variant,
-                            type,
-                            frame->text_height,
-                            flags,
-                            width, height,
-                            &button_layout,
-                            fgeom);
+  meta_theme_calc_geometry (meta_ui_get_theme (), frame->theme_variant,
+                            type, flags, width, height, &button_layout, fgeom);
 }
 
 MetaFrames*
@@ -591,7 +554,6 @@ meta_frames_manage_window (MetaFrames *frames,
   frame->xwindow = xwindow;
   frame->cache_style = NULL;
   frame->text_layout = NULL;
-  frame->text_height = -1;
   frame->title = NULL;
   frame->expose_delayed = FALSE;
   frame->shape_applied = FALSE;
@@ -680,12 +642,8 @@ meta_ui_frame_get_borders (MetaFrames       *frames,
    * by the core move/resize code to decide on the client
    * window size
    */
-  meta_theme_get_frame_borders (meta_ui_get_theme (),
-                                frame->theme_variant,
-                                type,
-                                frame->text_height,
-                                flags,
-                                borders);
+  meta_theme_get_frame_borders (meta_ui_get_theme (), frame->theme_variant,
+                                type, flags, borders);
 }
 
 void
@@ -2172,12 +2130,8 @@ populate_cache (MetaFrames *frames,
       return;
     }
 
-  meta_theme_get_frame_borders (meta_ui_get_theme (),
-                                frame->theme_variant,
-                                frame_type,
-                                frame->text_height,
-                                frame_flags,
-                                &borders);
+  meta_theme_get_frame_borders (meta_ui_get_theme (), frame->theme_variant,
+                                frame_type, frame_flags, &borders);
 
   pixels = get_cache (frames, frame);
 
@@ -2286,10 +2240,8 @@ subtract_client_area (cairo_region_t *region,
                  META_CORE_GET_CLIENT_HEIGHT, &area.height,
                  META_CORE_GET_END);
 
-  meta_theme_get_frame_borders (meta_ui_get_theme (),
-                                frame->theme_variant,
-                                type, frame->text_height, flags,
-                                &borders);
+  meta_theme_get_frame_borders (meta_ui_get_theme (), frame->theme_variant,
+                                type, flags, &borders);
 
   area.x = borders.total.left;
   area.y = borders.total.top;
@@ -2553,19 +2505,9 @@ meta_frames_paint (MetaFrames   *frames,
 
   meta_prefs_get_button_layout (&button_layout);
 
-  meta_theme_draw_frame (meta_ui_get_theme (),
-                         frame->theme_variant,
-                         cr,
-                         type,
-                         flags,
-                         w,
-                         h,
-                         frame->text_layout,
-                         frame->text_height,
-                         &button_layout,
-                         button_states,
-                         mini_icon,
-                         icon);
+  meta_theme_draw_frame (meta_ui_get_theme (), frame->theme_variant,
+                         cr, type, flags, w, h, frame->text_layout,
+                         &button_layout, button_states, mini_icon, icon);
 }
 
 static gboolean
diff --git a/src/ui/frames.h b/src/ui/frames.h
index 30cb623..ee9c92a 100644
--- a/src/ui/frames.h
+++ b/src/ui/frames.h
@@ -70,8 +70,7 @@ struct _MetaUIFrame
   gchar *theme_variant;
   MetaFrameStyle *cache_style;
   PangoLayout *text_layout;
-  int text_height;
-  char *title; /* NULL once we have a layout */
+  gchar *title;
   guint expose_delayed : 1;
   guint shape_applied : 1;
 
diff --git a/src/ui/ui.c b/src/ui/ui.c
index 3175269..a9676c7 100644
--- a/src/ui/ui.c
+++ b/src/ui/ui.c
@@ -682,17 +682,11 @@ meta_ui_theme_get_frame_borders (MetaUI           *ui,
 {
   MetaTheme *theme;
   const gchar *theme_variant;
-  PangoFontDescription *font_desc;
-  gint text_height;
 
   theme = meta_ui_get_theme ();
   theme_variant = NULL;
 
-  font_desc = meta_theme_get_title_font_desc (theme, theme_variant, type, flags);
-  text_height = meta_theme_get_title_height (theme, font_desc);
-
-  meta_theme_get_frame_borders (theme, theme_variant, type,
-                                text_height, flags, borders);
+  meta_theme_get_frame_borders (theme, theme_variant, type, flags, borders);
 }
 
 MetaTheme *
diff --git a/theme-viewer/theme-viewer-window.c b/theme-viewer/theme-viewer-window.c
index 5ac9092..775c368 100644
--- a/theme-viewer/theme-viewer-window.c
+++ b/theme-viewer/theme-viewer-window.c
@@ -57,7 +57,6 @@ struct _ThemeViewerWindow
   MetaFrameFlags    frame_flags;
 
   PangoLayout      *title_layout;
-  gint              title_height;
 
   MetaFrameBorders  borders;
 
@@ -164,9 +163,8 @@ update_button_state (GtkWidget         *widget,
   get_client_width_and_height (widget, window, &width, &height);
 
   meta_theme_calc_geometry (window->theme, window->theme_variant,
-                            window->frame_type, window->title_height,
-                            window->frame_flags, width, height,
-                            &window->button_layout, &fgeom);
+                            window->frame_type, window->frame_flags,
+                            width, height, &window->button_layout, &fgeom);
 
   x -= PADDING;
   y -= PADDING;
@@ -238,29 +236,25 @@ update_title_layout (ThemeViewerWindow *window)
 {
   PangoLayout *layout;
   PangoFontDescription *font_desc;
-  gint height;
 
   layout = meta_theme_create_title_layout (window->theme, "Metacity Theme Viewer");
   font_desc = meta_theme_get_title_font_desc (window->theme, window->theme_variant,
                                               window->frame_type, window->frame_flags);
 
-  height = meta_theme_get_title_height (window->theme, font_desc);
-
   pango_layout_set_font_description (layout, font_desc);
 
   if (window->title_layout)
     g_object_unref (window->title_layout);
 
   window->title_layout = layout;
-  window->title_height = height;
 }
 
 static void
 update_frame_borders (ThemeViewerWindow *window)
 {
   meta_theme_get_frame_borders (window->theme, window->theme_variant,
-                                window->frame_type, window->title_height,
-                                window->frame_flags, &window->borders);
+                                window->frame_type, window->frame_flags,
+                                &window->borders);
 }
 
 static void
@@ -603,8 +597,7 @@ theme_box_draw_cb (GtkWidget         *widget,
   cairo_translate (cr, PADDING, PADDING);
   meta_theme_draw_frame (window->theme, window->theme_variant, cr,
                          window->frame_type, window->frame_flags,
-                         client_width, client_height,
-                         window->title_layout, window->title_height,
+                         client_width, client_height, window->title_layout,
                          &window->button_layout, window->button_states,
                          window->mini_icon, window->icon);
 


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