[epiphany] Use GtkSettings 'gtk-xft-dpi' property to keep track of DPI changes



commit e576aee616245907f86c773f75f1ca4b7446f686
Author: Mario Sanchez Prada <mario endlessm com>
Date:   Wed Mar 18 14:22:35 2015 +0000

    Use GtkSettings 'gtk-xft-dpi' property to keep track of DPI changes
    
    Use that property to find the screen's resolution for font handling
    instead of gdk_screen_get_resolution(), and also connect a callback
    to notify::gtk-xft-dpi so that we can update the font size when the
    DPI value changes for the screen, and not just on startup.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=744796

 embed/ephy-embed-prefs.c |   48 +++++++++++++++++++++++++++++++++------------
 1 files changed, 35 insertions(+), 13 deletions(-)
---
diff --git a/embed/ephy-embed-prefs.c b/embed/ephy-embed-prefs.c
index dfec800..e3b91c0 100644
--- a/embed/ephy-embed-prefs.c
+++ b/embed/ephy-embed-prefs.c
@@ -416,12 +416,8 @@ webkit_pref_callback_cookie_accept_policy (GSettings *settings,
 }
 
 static void
-webkit_pref_callback_gnome_fonts (GSettings *ephy_settings,
-                                  char *key,
-                                  gpointer data)
+ephy_embed_prefs_update_font_settings (GSettings *ephy_settings, char *key)
 {
-  GSettings *settings;
-
   if (g_settings_get_boolean (ephy_settings, key)) {
     g_object_set (webkit_settings,
                   "default-font-family", "serif",
@@ -432,25 +428,31 @@ webkit_pref_callback_gnome_fonts (GSettings *ephy_settings,
                   NULL);
   } else {
     /* Sync with Epiphany values */
-    settings = ephy_settings;
-
-    webkit_pref_callback_font_size (settings, EPHY_PREFS_WEB_SERIF_FONT,
+    webkit_pref_callback_font_size (ephy_settings, EPHY_PREFS_WEB_SERIF_FONT,
                                     "default-font-size");
-    webkit_pref_callback_font_size (settings, EPHY_PREFS_WEB_MONOSPACE_FONT,
+    webkit_pref_callback_font_size (ephy_settings, EPHY_PREFS_WEB_MONOSPACE_FONT,
                                     "default-monospace-font-size");
 
-    webkit_pref_callback_font_family (settings, EPHY_PREFS_WEB_SERIF_FONT,
+    webkit_pref_callback_font_family (ephy_settings, EPHY_PREFS_WEB_SERIF_FONT,
                                       "default-font-family");
-    webkit_pref_callback_font_family (settings, EPHY_PREFS_WEB_SANS_SERIF_FONT,
+    webkit_pref_callback_font_family (ephy_settings, EPHY_PREFS_WEB_SANS_SERIF_FONT,
                                       "sans-serif-font-family");
-    webkit_pref_callback_font_family (settings, EPHY_PREFS_WEB_MONOSPACE_FONT,
+    webkit_pref_callback_font_family (ephy_settings, EPHY_PREFS_WEB_MONOSPACE_FONT,
                                       "monospace-font-family");
-    webkit_pref_callback_font_family (settings, EPHY_PREFS_WEB_SERIF_FONT,
+    webkit_pref_callback_font_family (ephy_settings, EPHY_PREFS_WEB_SERIF_FONT,
                                       "serif-font-family");
   }
 }
 
 static void
+webkit_pref_callback_gnome_fonts (GSettings *ephy_settings,
+                                  char *key,
+                                  gpointer data)
+{
+  ephy_embed_prefs_update_font_settings (ephy_settings, key);
+}
+
+static void
 webkit_pref_callback_enable_spell_checking (GSettings *settings,
                                             char *key,
                                             gpointer data)
@@ -475,6 +477,15 @@ webkit_pref_callback_enable_spell_checking (GSettings *settings,
   }
 }
 
+static void
+gtk_settings_xft_dpi_changed_cb (GtkSettings *gtk_settings,
+                                 GParamSpec *pspec,
+                                 gpointer data)
+{
+  ephy_embed_prefs_update_font_settings (ephy_settings_get (EPHY_PREFS_WEB_SCHEMA),
+                                         EPHY_PREFS_WEB_USE_GNOME_FONTS);
+}
+
 static const PrefData webkit_pref_entries[] =
   {
     /* Epiphany font settings */
@@ -534,6 +545,7 @@ static const PrefData webkit_pref_entries[] =
 static gpointer
 ephy_embed_prefs_init (gpointer user_data)
 {
+  GtkSettings *gtk_settings;
   int i;
 
   webkit_settings = webkit_settings_new_with_settings ("enable-developer-extras", TRUE,
@@ -560,6 +572,16 @@ ephy_embed_prefs_init (gpointer user_data)
     g_free (key);
   }
 
+  /* Connect to the "notify::gtk-xft-dpi" signal for GtkSettings, so that
+   * we can update the font size in real time if the screen's resolution
+   * for font handling changes (e.g. enabled "Large Text" a11y mode).
+   */
+  gtk_settings = gtk_settings_get_default ();
+  if (gtk_settings) {
+    g_signal_connect (gtk_settings, "notify::gtk-xft-dpi",
+                      G_CALLBACK (gtk_settings_xft_dpi_changed_cb), NULL);
+  }
+
   g_settings_bind (EPHY_SETTINGS_WEB,
                    EPHY_PREFS_WEB_ENABLE_JAVASCRIPT,
                    webkit_settings, ENABLE_SCRIPTS_SETTING,


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