summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Chimento <philip@endlessm.com>2015-09-18 17:12:33 -0700
committerPhilip Chimento <philip@endlessm.com>2015-09-21 11:31:06 -0700
commitef0813bc6d013efde371a8e621316930b07d5f79 (patch)
tree1c5a52623aaa13e61bcde0f6cf29c5066acd58ca
parented4eaf4092236ee030e8eae68de66c3ded8bb12d (diff)
Don't do unnecessary font scaling
Turns out that we removed and added a CSS provider on every size allocate even when it had the same style content. This bug was exposed by using Adwaita's spinner theming because the animation caused too many relayouts. Instead, only change the CSS provider if the calculated font scaling factor has actually changed. This should improve performance by quite a bit. [endlessm/eos-sdk#3634]
-rw-r--r--endless/eoswindow.c63
1 files changed, 36 insertions, 27 deletions
diff --git a/endless/eoswindow.c b/endless/eoswindow.c
index 3080ad6..2a24de2 100644
--- a/endless/eoswindow.c
+++ b/endless/eoswindow.c
@@ -482,44 +482,53 @@ eos_window_finalize (GObject *object)
G_OBJECT_CLASS (eos_window_parent_class)->finalize (object);
}
-/* Updates the base font size depending on the window size. */
static void
-eos_window_size_allocate (GtkWidget *window, GtkAllocation *allocation)
+eos_window_font_scale (EosWindow *self,
+ gint allocated_height)
{
- EosWindow *self = EOS_WINDOW (window);
EosWindowPrivate *priv = eos_window_get_instance_private (self);
- if (priv->font_scaling_active)
- {
- GtkStyleProvider *provider = GTK_STYLE_PROVIDER (priv->font_size_provider);
- priv->font_scaling_calculated_font_size = (gdouble) priv->font_scaling_default_size *
- ((gdouble) allocation->height / (gdouble) priv->font_scaling_default_window_size);
+ if (!priv->font_scaling_active)
+ return;
- if (priv->font_scaling_calculated_font_size < priv->font_scaling_min_font_size)
- priv->font_scaling_calculated_font_size = priv->font_scaling_min_font_size;
+ GtkStyleProvider *provider = GTK_STYLE_PROVIDER (priv->font_size_provider);
+ gdouble new_size = priv->font_scaling_default_size *
+ ((gdouble) allocated_height / priv->font_scaling_default_window_size);
- GError *error = NULL;
+ new_size = MIN (new_size, priv->font_scaling_min_font_size);
- /* A float will only have one decimal point when printed as a string.
- * The decimal point can be represented as a comma or period when using
- * either Imperial or metric units. However, the CSS parser only recognizes
- * periods as valid decimal points. Therefore, we convert the float to a
- * string using a period as the decimal point. */
- gchar font_size_float_str [G_ASCII_DTOSTR_BUF_SIZE];
- g_ascii_dtostr (font_size_float_str, G_ASCII_DTOSTR_BUF_SIZE, priv->font_scaling_calculated_font_size);
+ if (new_size == priv->font_scaling_calculated_font_size)
+ return;
- gchar *font_size_css = g_strdup_printf (FONT_SIZE_TEMPLATE, font_size_float_str);
- GdkScreen *screen = gdk_screen_get_default ();
+ priv->font_scaling_calculated_font_size = new_size;
- gtk_style_context_remove_provider_for_screen (screen, provider);
- gtk_css_provider_load_from_data (GTK_CSS_PROVIDER (provider),
- font_size_css, -1, &error);
- gtk_style_context_add_provider_for_screen (screen, provider,
- GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+ /* A float will only have one decimal point when printed as a string. The
+ * decimal point can be represented as a comma or period when using either
+ * Imperial or metric units. However, the CSS parser only recognizes periods
+ * as valid decimal points. Therefore, we convert the float to a string using
+ * a period as the decimal point. */
+ gchar font_size_float_str[G_ASCII_DTOSTR_BUF_SIZE];
+ g_ascii_dtostr (font_size_float_str, G_ASCII_DTOSTR_BUF_SIZE,
+ priv->font_scaling_calculated_font_size);
- g_free(font_size_css);
- }
+ gchar *font_size_css = g_strdup_printf (FONT_SIZE_TEMPLATE,
+ font_size_float_str);
+ GdkScreen *screen = gdk_screen_get_default ();
+ gtk_style_context_remove_provider_for_screen (screen, provider);
+ gtk_css_provider_load_from_data (GTK_CSS_PROVIDER (provider), font_size_css,
+ -1, NULL); /* ignore error */
+ gtk_style_context_add_provider_for_screen (screen, provider,
+ GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+
+ g_free (font_size_css);
+}
+
+/* Updates the base font size depending on the window size. */
+static void
+eos_window_size_allocate (GtkWidget *window, GtkAllocation *allocation)
+{
+ eos_window_font_scale (EOS_WINDOW (window), allocation->height);
GTK_WIDGET_CLASS (eos_window_parent_class)->size_allocate (window, allocation);
}