[metacity] libmetacity: don't expose meta_theme_get_title_font_desc



commit 34fb409ba5162102ecda1d35f860881eb0778990
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Mon Jun 6 20:01:42 2016 +0300

    libmetacity: don't expose meta_theme_get_title_font_desc

 libmetacity/meta-theme.c           |  203 ++++++++++++++++++------------------
 libmetacity/meta-theme.h           |  112 ++++++++++----------
 src/ui/frames.c                    |   11 +--
 theme-viewer/theme-viewer-window.c |    9 +-
 4 files changed, 165 insertions(+), 170 deletions(-)
---
diff --git a/libmetacity/meta-theme.c b/libmetacity/meta-theme.c
index fc23ced..70ab57b 100644
--- a/libmetacity/meta-theme.c
+++ b/libmetacity/meta-theme.c
@@ -61,6 +61,94 @@ static GParamSpec *properties[LAST_PROP] = { NULL };
 
 G_DEFINE_TYPE (MetaTheme, meta_theme, G_TYPE_OBJECT)
 
+static MetaStyleInfo *
+meta_theme_get_style_info (MetaTheme   *theme,
+                           const gchar *variant)
+{
+  const gchar *key;
+  MetaStyleInfo *style_info;
+
+  key = variant;
+  if (variant == NULL)
+    key = "default";
+
+  style_info = g_hash_table_lookup (theme->variants, key);
+
+  if (style_info == NULL)
+    {
+      gint window_scale;
+
+      window_scale = get_window_scaling_factor ();
+      style_info = meta_style_info_new (theme->gtk_theme_name, variant,
+                                        theme->composited, window_scale);
+
+      g_hash_table_insert (theme->variants, g_strdup (key), style_info);
+    }
+
+  return style_info;
+}
+
+static void
+font_desc_apply_scale (PangoFontDescription *font_desc,
+                       MetaTheme            *theme,
+                       MetaFrameType         type,
+                       MetaFrameFlags        flags)
+{
+  gint old_size;
+  MetaFrameStyle *style;
+  gdouble scale;
+  gint new_size;
+
+  old_size = pango_font_description_get_size (font_desc);
+  style = meta_theme_get_frame_style (theme, type, flags);
+  scale = get_window_scaling_factor ();
+
+  new_size = MAX (old_size * (style->layout->title_scale / scale), 1);
+
+  pango_font_description_set_size (font_desc, new_size);
+}
+
+static PangoFontDescription *
+get_title_font_desc (MetaTheme      *theme,
+                     const gchar    *variant,
+                     MetaFrameType   type,
+                     MetaFrameFlags  flags)
+{
+  gchar *key;
+  PangoFontDescription *font_desc;
+  MetaStyleInfo *style_info;
+  GtkStyleContext *context;
+
+  key = g_strdup_printf ("%s_%d_%x", variant ? variant : "default", type, flags);
+  font_desc = g_hash_table_lookup (theme->font_descs, key);
+
+  if (font_desc != NULL)
+    {
+      g_free (key);
+      return font_desc;
+    }
+
+  style_info = meta_theme_get_style_info (theme, variant);
+  context = meta_style_info_get_style (style_info, META_STYLE_ELEMENT_TITLE);
+
+  gtk_style_context_save (context);
+  gtk_style_context_set_state (context, GTK_STATE_FLAG_NORMAL);
+
+  gtk_style_context_get (context, GTK_STATE_FLAG_NORMAL,
+                         "font", &font_desc, NULL);
+
+  gtk_style_context_restore (context);
+
+  if (theme->titlebar_font)
+    pango_font_description_merge (font_desc, theme->titlebar_font, TRUE);
+
+  font_desc_apply_scale (font_desc, theme, type, flags);
+
+  g_hash_table_insert (theme->font_descs, key, font_desc);
+
+  return font_desc;
+}
+
 static void
 ensure_pango_context (MetaTheme *theme)
 {
@@ -98,7 +186,7 @@ get_title_height (MetaTheme      *theme,
   gpointer height;
   gint title_height;
 
-  description = meta_theme_get_title_font_desc (theme, variant, type, flags);
+  description = get_title_font_desc (theme, variant, type, flags);
   g_assert (description != NULL);
 
   size = GINT_TO_POINTER (pango_font_description_get_size (description));
@@ -138,53 +226,6 @@ get_title_height (MetaTheme      *theme,
 }
 
 static void
-font_desc_apply_scale (PangoFontDescription *font_desc,
-                       MetaTheme            *theme,
-                       MetaFrameType         type,
-                       MetaFrameFlags        flags)
-{
-  gint old_size;
-  MetaFrameStyle *style;
-  gdouble scale;
-  gint new_size;
-
-  old_size = pango_font_description_get_size (font_desc);
-  style = meta_theme_get_frame_style (theme, type, flags);
-  scale = get_window_scaling_factor ();
-
-  new_size = MAX (old_size * (style->layout->title_scale / scale), 1);
-
-  pango_font_description_set_size (font_desc, new_size);
-}
-
-static MetaStyleInfo *
-meta_theme_get_style_info (MetaTheme   *theme,
-                           const gchar *variant)
-{
-  const gchar *key;
-  MetaStyleInfo *style_info;
-
-  key = variant;
-  if (variant == NULL)
-    key = "default";
-
-  style_info = g_hash_table_lookup (theme->variants, key);
-
-  if (style_info == NULL)
-    {
-      gint window_scale;
-
-      window_scale = get_window_scaling_factor ();
-      style_info = meta_style_info_new (theme->gtk_theme_name, variant,
-                                        theme->composited, window_scale);
-
-      g_hash_table_insert (theme->variants, g_strdup (key), style_info);
-    }
-
-  return style_info;
-}
-
-static void
 meta_theme_constructed (GObject *object)
 {
   MetaTheme *theme;
@@ -477,15 +518,24 @@ meta_theme_get_frame_style (MetaTheme      *theme,
 /**
  * meta_theme_create_title_layout:
  * @theme: a #MetaTheme
+ * @variant: (nullable): theme variant
+ * @type: frame type
+ * @flags: frame flags
  * @title: (nullable): text to set on the layout
  *
+ * Use this function to create #PangoLayout for use in meta_theme_draw_frame.
+ *
  * Returns: (transfer full): the new #PangoLayout
  */
 PangoLayout *
-meta_theme_create_title_layout (MetaTheme   *theme,
-                                const gchar *title)
+meta_theme_create_title_layout (MetaTheme      *theme,
+                                const gchar    *variant,
+                                MetaFrameType   type,
+                                MetaFrameFlags  flags,
+                                const gchar    *title)
 {
   PangoLayout *layout;
+  PangoFontDescription *font_desc;
 
   ensure_pango_context (theme);
 
@@ -498,57 +548,10 @@ meta_theme_create_title_layout (MetaTheme   *theme,
   pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_END);
   pango_layout_set_single_paragraph_mode (layout, TRUE);
 
-  return layout;
-}
+  font_desc = get_title_font_desc (theme, variant, type, flags);
+  pango_layout_set_font_description (layout, font_desc);
 
-/**
- * meta_theme_get_title_font_desc:
- * @theme: a #MetaTheme
- * @variant: (nullable): theme variant
- * @type: frame type
- * @flags: frame flags
- *
- * Returns: (transfer none): the #PangoFontDescription
- */
-PangoFontDescription*
-meta_theme_get_title_font_desc (MetaTheme      *theme,
-                                const gchar    *variant,
-                                MetaFrameType   type,
-                                MetaFrameFlags  flags)
-{
-  gchar *key;
-  PangoFontDescription *font_desc;
-  MetaStyleInfo *style_info;
-  GtkStyleContext *context;
-
-  key = g_strdup_printf ("%s_%d_%x", variant ? variant : "default", type, flags);
-  font_desc = g_hash_table_lookup (theme->font_descs, key);
-
-  if (font_desc != NULL)
-    {
-      g_free (key);
-      return font_desc;
-    }
-
-  style_info = meta_theme_get_style_info (theme, variant);
-  context = meta_style_info_get_style (style_info, META_STYLE_ELEMENT_TITLE);
-
-  gtk_style_context_save (context);
-  gtk_style_context_set_state (context, GTK_STATE_FLAG_NORMAL);
-
-  gtk_style_context_get (context, GTK_STATE_FLAG_NORMAL,
-                         "font", &font_desc, NULL);
-
-  gtk_style_context_restore (context);
-
-  if (theme->titlebar_font)
-    pango_font_description_merge (font_desc, theme->titlebar_font, TRUE);
-
-  font_desc_apply_scale (font_desc, theme, type, flags);
-
-  g_hash_table_insert (theme->font_descs, key, font_desc);
-
-  return font_desc;
+  return layout;
 }
 
 MetaFrameType
diff --git a/libmetacity/meta-theme.h b/libmetacity/meta-theme.h
index 4b190ae..8a36efb 100644
--- a/libmetacity/meta-theme.h
+++ b/libmetacity/meta-theme.h
@@ -145,63 +145,61 @@ struct _MetaFrameGeometry
   guint bottom_right_corner_rounded_radius;
 };
 
-GQuark                meta_theme_error_quark               (void);
-
-MetaTheme            *meta_theme_new                       (MetaThemeType                type);
-
-gboolean              meta_theme_load                      (MetaTheme                   *theme,
-                                                            const gchar                 *theme_name,
-                                                            GError                     **error);
-
-void                  meta_theme_invalidate                (MetaTheme                   *theme);
-
-void                  meta_theme_set_composited            (MetaTheme                   *theme,
-                                                            gboolean                     composited);
-
-void                  meta_theme_set_titlebar_font         (MetaTheme                   *theme,
-                                                            const PangoFontDescription  *titlebar_font);
-
-MetaFrameStyle       *meta_theme_get_frame_style           (MetaTheme                   *theme,
-                                                            MetaFrameType                type,
-                                                            MetaFrameFlags               flags);
-
-PangoLayout          *meta_theme_create_title_layout       (MetaTheme                   *theme,
-                                                            const gchar                 *title);
-
-PangoFontDescription *meta_theme_get_title_font_desc       (MetaTheme                   *theme,
-                                                            const gchar                 *variant,
-                                                            MetaFrameType                type,
-                                                            MetaFrameFlags               flags);
-
-MetaFrameType         meta_frame_type_from_string          (const gchar                 *str);
-
-void                  meta_theme_get_frame_borders         (MetaTheme                   *theme,
-                                                            const gchar                 *variant,
-                                                            MetaFrameType                type,
-                                                            MetaFrameFlags               flags,
-                                                            MetaFrameBorders            *borders);
-
-void                  meta_theme_calc_geometry             (MetaTheme                   *theme,
-                                                            const gchar                 *variant,
-                                                            MetaFrameType                type,
-                                                            MetaFrameFlags               flags,
-                                                            gint                         client_width,
-                                                            gint                         client_height,
-                                                            const MetaButtonLayout      *button_layout,
-                                                            MetaFrameGeometry           *fgeom);
-
-void                  meta_theme_draw_frame                (MetaTheme                   *theme,
-                                                            const gchar                 *variant,
-                                                            cairo_t                     *cr,
-                                                            MetaFrameType                type,
-                                                            MetaFrameFlags               flags,
-                                                            gint                         client_width,
-                                                            gint                         client_height,
-                                                            PangoLayout                 *title_layout,
-                                                            const MetaButtonLayout      *button_layout,
-                                                            MetaButtonState              
button_states[META_BUTTON_TYPE_LAST],
-                                                            GdkPixbuf                   *mini_icon,
-                                                            GdkPixbuf                   *icon);
+GQuark          meta_theme_error_quark         (void);
+
+MetaTheme      *meta_theme_new                 (MetaThemeType                type);
+
+gboolean        meta_theme_load                (MetaTheme                   *theme,
+                                                const gchar                 *theme_name,
+                                                GError                     **error);
+
+void            meta_theme_invalidate          (MetaTheme                   *theme);
+
+void            meta_theme_set_composited      (MetaTheme                   *theme,
+                                                gboolean                     composited);
+
+void            meta_theme_set_titlebar_font   (MetaTheme                   *theme,
+                                                const PangoFontDescription  *titlebar_font);
+
+MetaFrameStyle *meta_theme_get_frame_style     (MetaTheme                   *theme,
+                                                MetaFrameType                type,
+                                                MetaFrameFlags               flags);
+
+PangoLayout    *meta_theme_create_title_layout (MetaTheme                   *theme,
+                                                const gchar                 *variant,
+                                                MetaFrameType                type,
+                                                MetaFrameFlags               flags,
+                                                const gchar                 *title);
+
+MetaFrameType   meta_frame_type_from_string    (const gchar                 *str);
+
+void            meta_theme_get_frame_borders   (MetaTheme                   *theme,
+                                                const gchar                 *variant,
+                                                MetaFrameType                type,
+                                                MetaFrameFlags               flags,
+                                                MetaFrameBorders            *borders);
+
+void            meta_theme_calc_geometry       (MetaTheme                   *theme,
+                                                const gchar                 *variant,
+                                                MetaFrameType                type,
+                                                MetaFrameFlags               flags,
+                                                gint                         client_width,
+                                                gint                         client_height,
+                                                const MetaButtonLayout      *button_layout,
+                                                MetaFrameGeometry           *fgeom);
+
+void            meta_theme_draw_frame          (MetaTheme                   *theme,
+                                                const gchar                 *variant,
+                                                cairo_t                     *cr,
+                                                MetaFrameType                type,
+                                                MetaFrameFlags               flags,
+                                                gint                         client_width,
+                                                gint                         client_height,
+                                                PangoLayout                 *title_layout,
+                                                const MetaButtonLayout      *button_layout,
+                                                MetaButtonState              
button_states[META_BUTTON_TYPE_LAST],
+                                                GdkPixbuf                   *mini_icon,
+                                                GdkPixbuf                   *icon);
 
 G_END_DECLS
 
diff --git a/src/ui/frames.c b/src/ui/frames.c
index 202e1f2..88737fb 100644
--- a/src/ui/frames.c
+++ b/src/ui/frames.c
@@ -426,13 +426,10 @@ meta_frames_ensure_layout (MetaFrames  *frames,
 
   if (frame->text_layout == NULL)
     {
-      PangoFontDescription *font_desc;
-
-      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);
-
-      pango_layout_set_font_description (frame->text_layout, font_desc);
+      frame->text_layout = meta_theme_create_title_layout (theme,
+                                                           frame->theme_variant,
+                                                           type, flags,
+                                                           frame->title);
     }
 }
 
diff --git a/theme-viewer/theme-viewer-window.c b/theme-viewer/theme-viewer-window.c
index 775c368..e66f5de 100644
--- a/theme-viewer/theme-viewer-window.c
+++ b/theme-viewer/theme-viewer-window.c
@@ -235,13 +235,10 @@ static void
 update_title_layout (ThemeViewerWindow *window)
 {
   PangoLayout *layout;
-  PangoFontDescription *font_desc;
 
-  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);
-
-  pango_layout_set_font_description (layout, font_desc);
+  layout = meta_theme_create_title_layout (window->theme, window->theme_variant,
+                                           window->frame_type, window->frame_flags,
+                                           "Metacity Theme Viewer");
 
   if (window->title_layout)
     g_object_unref (window->title_layout);


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