summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlberts Muktupāvels <alberts.muktupavels@gmail.com>2017-04-02 18:58:06 +0300
committerAlberts Muktupāvels <alberts.muktupavels@gmail.com>2017-04-02 18:58:06 +0300
commit8547f41b2cf90b2829904248ccf786dc3e106b37 (patch)
treeeeac0fc600e26c84c8692683dd47e21713093494
parent2a7e7be6e28a25e85b31519ca88656e81705a0b4 (diff)
downloadmetacity-8547f41b2cf90b2829904248ccf786dc3e106b37.tar.gz
libmetacity: add meta_theme_set_scale
-rw-r--r--libmetacity/meta-theme-impl.c14
-rw-r--r--libmetacity/meta-theme.c48
-rw-r--r--libmetacity/meta-theme.h3
-rw-r--r--src/ui/ui.c3
4 files changed, 44 insertions, 24 deletions
diff --git a/libmetacity/meta-theme-impl.c b/libmetacity/meta-theme-impl.c
index dbd91aa3..cee3c755 100644
--- a/libmetacity/meta-theme-impl.c
+++ b/libmetacity/meta-theme-impl.c
@@ -120,23 +120,11 @@ meta_theme_impl_set_scale (MetaThemeImpl *impl,
gint
meta_theme_impl_get_scale (MetaThemeImpl *impl)
{
- GValue value = G_VALUE_INIT;
MetaThemeImplPrivate *priv;
- GdkScreen *screen;
priv = meta_theme_impl_get_instance_private (impl);
- if (priv->scale != 0)
- return priv->scale;
-
- screen = gdk_screen_get_default ();
-
- g_value_init (&value, G_TYPE_INT);
-
- if (gdk_screen_get_setting (screen, "gdk-window-scaling-factor", &value))
- return g_value_get_int (&value);
- else
- return 1;
+ return priv->scale;
}
void
diff --git a/libmetacity/meta-theme.c b/libmetacity/meta-theme.c
index 7d90ae7b..02b29fa9 100644
--- a/libmetacity/meta-theme.c
+++ b/libmetacity/meta-theme.c
@@ -44,6 +44,7 @@ struct _MetaTheme
MetaButtonLayout *button_layout;
gboolean composited;
+ gint scale;
PangoFontDescription *titlebar_font;
@@ -83,6 +84,20 @@ update_composited_func (gpointer key,
meta_style_info_set_composited (style_info, theme->composited);
}
+static void
+update_scale_func (gpointer key,
+ gpointer value,
+ gpointer user_data)
+{
+ MetaTheme *theme;
+ MetaStyleInfo *style_info;
+
+ theme = META_THEME (user_data);
+ style_info = META_STYLE_INFO (value);
+
+ meta_style_info_set_scale (style_info, theme->scale);
+}
+
static MetaStyleInfo *
get_style_info (MetaTheme *theme,
const gchar *variant)
@@ -98,11 +113,8 @@ get_style_info (MetaTheme *theme,
if (style_info == NULL)
{
- gint scale;
-
- scale = meta_theme_impl_get_scale (theme->impl);
style_info = meta_style_info_new (theme->gtk_theme_name, variant,
- theme->composited, scale);
+ theme->composited, theme->scale);
g_hash_table_insert (theme->variants, g_strdup (key), style_info);
}
@@ -209,14 +221,12 @@ font_desc_apply_scale (PangoFontDescription *font_desc,
{
gint old_size;
MetaFrameStyle *style;
- gdouble scale;
gint new_size;
old_size = pango_font_description_get_size (font_desc);
style = get_frame_style (theme, type, flags);
- scale = meta_theme_impl_get_scale (theme->impl);
- new_size = MAX (old_size * (style->layout->title_scale / scale), 1);
+ new_size = MAX (old_size * (style->layout->title_scale / theme->scale), 1);
pango_font_description_set_size (font_desc, new_size);
}
@@ -315,7 +325,6 @@ get_title_height (MetaTheme *theme,
PangoFontMetrics *metrics;
gint ascent;
gint descent;
- gint scale;
ensure_pango_context (theme);
@@ -327,9 +336,7 @@ get_title_height (MetaTheme *theme,
pango_font_metrics_unref (metrics);
title_height = PANGO_PIXELS (ascent + descent);
- scale = meta_theme_impl_get_scale (theme->impl);
-
- title_height *= scale;
+ title_height *= theme->scale;
height = GINT_TO_POINTER (title_height);
g_hash_table_insert (theme->title_heights, size, height);
@@ -436,6 +443,7 @@ meta_theme_constructed (GObject *object)
g_assert_not_reached ();
meta_theme_impl_set_composited (theme->impl, theme->composited);
+ meta_theme_impl_set_scale (theme->impl, theme->scale);
button_layout = "appmenu:minimize,maximize,close";
meta_theme_set_button_layout (theme, button_layout, FALSE);
@@ -592,6 +600,7 @@ static void
meta_theme_init (MetaTheme *theme)
{
theme->composited = TRUE;
+ theme->scale = 1;
theme->variants = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, g_object_unref);
@@ -799,6 +808,23 @@ meta_theme_set_composited (MetaTheme *theme,
}
void
+meta_theme_set_scale (MetaTheme *theme,
+ gint scale)
+{
+ if (theme->scale == scale)
+ return;
+
+ theme->scale = scale;
+
+ meta_theme_impl_set_scale (theme->impl, scale);
+ g_hash_table_foreach (theme->variants, update_scale_func, theme);
+
+ g_clear_object (&theme->context);
+ g_hash_table_remove_all (theme->font_descs);
+ g_hash_table_remove_all (theme->title_heights);
+}
+
+void
meta_theme_set_titlebar_font (MetaTheme *theme,
const PangoFontDescription *titlebar_font)
{
diff --git a/libmetacity/meta-theme.h b/libmetacity/meta-theme.h
index 6cc136a4..c544bd3e 100644
--- a/libmetacity/meta-theme.h
+++ b/libmetacity/meta-theme.h
@@ -122,6 +122,9 @@ MetaButton **meta_theme_get_buttons (MetaTheme *theme)
void meta_theme_set_composited (MetaTheme *theme,
gboolean composited);
+void meta_theme_set_scale (MetaTheme *theme,
+ gint scale);
+
void meta_theme_set_titlebar_font (MetaTheme *theme,
const PangoFontDescription *titlebar_font);
diff --git a/src/ui/ui.c b/src/ui/ui.c
index 18e22873..f2b9b059 100644
--- a/src/ui/ui.c
+++ b/src/ui/ui.c
@@ -112,6 +112,8 @@ notify_gtk_xft_dpi_cb (GtkSettings *settings,
{
ui->scale = get_window_scaling_factor (ui);
ui->dpi = get_xft_dpi (ui);
+
+ meta_theme_set_scale (ui->theme, ui->scale);
}
void
@@ -820,6 +822,7 @@ load_theme (MetaUI *ui,
theme = meta_theme_new (theme_type);
meta_theme_set_composited (theme, ui->composited);
+ meta_theme_set_scale (theme, ui->scale);
titlebar_font = meta_prefs_get_titlebar_font ();
meta_theme_set_titlebar_font (theme, titlebar_font);