[gnome-settings-daemon] xsettings: Remove use of the DPI settings key



commit e8d1de92493eb286c6f20f220c8868b843370d7a
Author: Bastien Nocera <hadess hadess net>
Date:   Thu Mar 3 13:15:28 2011 +0000

    xsettings: Remove use of the DPI settings key
    
    And use the text-scaling-factor key instead. This means removing a lot
    of duplicated code. The DPI is still available through the "gtk-xft-dpi"
    GtkSettings property for applications that need it.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=643704

 ...ings-daemon.plugins.xsettings.gschema.xml.in.in |    5 -
 .../a11y-keyboard/gsd-a11y-preferences-dialog.c    |  112 +++-----------------
 plugins/media-keys/gsd-media-keys-manager.c        |   78 +-------------
 plugins/xsettings/gsd-xsettings-manager.c          |   23 +++--
 4 files changed, 34 insertions(+), 184 deletions(-)
---
diff --git a/data/org.gnome.settings-daemon.plugins.xsettings.gschema.xml.in.in b/data/org.gnome.settings-daemon.plugins.xsettings.gschema.xml.in.in
index 8bf9c2a..8cece8e 100644
--- a/data/org.gnome.settings-daemon.plugins.xsettings.gschema.xml.in.in
+++ b/data/org.gnome.settings-daemon.plugins.xsettings.gschema.xml.in.in
@@ -10,11 +10,6 @@
       <_summary>Antialiasing</_summary>
       <_description>The type of antialiasing to use when rendering fonts. Possible values are: "none" for no antialiasing, "grayscale" for standard grayscale antialiasing, and "rgba" for subpixel antialiasing (LCD screens only).</_description>
     </key>
-    <key name="dpi" type="d">
-      <default>0.0</default>
-      <_summary>DPI</_summary>
-      <_description>The resolution used for converting font sizes to pixel sizes, in dots per inch. 0.0 DPI means that the X server's DPI will be used.</_description>
-    </key>
     <key name="hinting" enum="org.gnome.settings-daemon.GsdFontHinting">
       <default>'medium'</default>
       <_summary>Hinting</_summary>
diff --git a/plugins/a11y-keyboard/gsd-a11y-preferences-dialog.c b/plugins/a11y-keyboard/gsd-a11y-preferences-dialog.c
index 2d9f3e7..ab5e9db 100644
--- a/plugins/a11y-keyboard/gsd-a11y-preferences-dialog.c
+++ b/plugins/a11y-keyboard/gsd-a11y-preferences-dialog.c
@@ -47,6 +47,7 @@
 #define GTKBUILDER_UI_FILE "gsd-a11y-preferences-dialog.ui"
 
 #define INTERFACE_SCHEMA          "org.gnome.desktop.interface"
+#define KEY_TEXT_SCALING_FACTOR   "text-scaling-factor"
 
 #define KEYBOARD_A11Y_SCHEMA      "org.gnome.desktop.a11y.keyboard"
 #define KEY_STICKY_KEYS_ENABLED   "stickykeys-enable"
@@ -58,25 +59,9 @@
 #define KEY_AT_SCREEN_MAGNIFIER_ENABLED "screen-magnifier-enabled"
 #define KEY_AT_SCREEN_READER_ENABLED    "screen-reader-enabled"
 
-#define FONT_RENDER_DIR        "org.gnome.desktop.font-rendering"
-#define KEY_FONT_DPI           "dpi"
-/* X servers sometimes lie about the screen's physical dimensions, so we cannot
- * compute an accurate DPI value.  When this happens, the user gets fonts that
- * are too huge or too tiny.  So, we see what the server returns:  if it reports
- * something outside of the range [DPI_LOW_REASONABLE_VALUE,
- * DPI_HIGH_REASONABLE_VALUE], then we assume that it is lying and we use
- * DPI_FALLBACK instead.
- *
- * See get_dpi_from_gconf_or_server() below, and also
- * https://bugzilla.novell.com/show_bug.cgi?id=217790
- */
-#define DPI_LOW_REASONABLE_VALUE 50
-#define DPI_HIGH_REASONABLE_VALUE 500
-
 #define DPI_FACTOR_LARGE   1.25
 #define DPI_FACTOR_LARGER  1.5
 #define DPI_FACTOR_LARGEST 2.0
-#define DPI_DEFAULT        96
 
 #define KEY_GTK_THEME          "gtk-theme"
 #define KEY_METACITY_THEME     "/apps/metacity/general/theme"
@@ -174,97 +159,30 @@ on_response (GsdA11yPreferencesDialog *dialog,
         }
 }
 
-static double
-dpi_from_pixels_and_mm (int pixels,
-                        int mm)
-{
-        double dpi;
-
-        if (mm >= 1) {
-                dpi = pixels / (mm / 25.4);
-        } else {
-                dpi = 0;
-        }
-
-        return dpi;
-}
-
-static double
-get_dpi_from_x_server (void)
-{
-        GdkScreen *screen;
-        double     dpi;
-
-        screen = gdk_screen_get_default ();
-        if (screen != NULL) {
-                double width_dpi;
-                double height_dpi;
-
-                width_dpi = dpi_from_pixels_and_mm (gdk_screen_get_width (screen),
-                                                    gdk_screen_get_width_mm (screen));
-                height_dpi = dpi_from_pixels_and_mm (gdk_screen_get_height (screen),
-                                                     gdk_screen_get_height_mm (screen));
-                if (width_dpi < DPI_LOW_REASONABLE_VALUE
-                    || width_dpi > DPI_HIGH_REASONABLE_VALUE
-                    || height_dpi < DPI_LOW_REASONABLE_VALUE
-                    || height_dpi > DPI_HIGH_REASONABLE_VALUE) {
-                        dpi = DPI_DEFAULT;
-                } else {
-                        dpi = (width_dpi + height_dpi) / 2.0;
-                }
-        } else {
-                /* Huh!?  No screen? */
-                dpi = DPI_DEFAULT;
-        }
-
-        return dpi;
-}
-
 static gboolean
-config_get_large_print (gboolean *is_writable)
+config_get_large_print (GsdA11yPreferencesDialog *dialog,
+			gboolean                 *is_writable)
 {
         gboolean     ret;
-        GSettings   *settings;
-        gdouble      x_dpi;
-        gdouble      u_dpi;
-
-        settings = g_settings_new ("org.gnome.desktop.font-rendering");
-        u_dpi = g_settings_get_double (settings, KEY_FONT_DPI);
-        x_dpi = get_dpi_from_x_server ();
-
-        g_object_unref (settings);
+        gdouble      factor;
 
-        g_debug ("GsdA11yPreferences: got x-dpi=%f user-dpi=%f", x_dpi, u_dpi);
+        factor = g_settings_get_double (dialog->priv->interface_settings, KEY_TEXT_SCALING_FACTOR);
 
-        ret = (((double)DPI_FACTOR_LARGE * x_dpi) < u_dpi);
+        ret = (factor > 1.0);
 
-        *is_writable = TRUE; /* FIXME */
+        *is_writable = g_settings_is_writable (dialog->priv->interface_settings, KEY_TEXT_SCALING_FACTOR);
 
         return ret;
 }
 
 static void
-config_set_large_print (gboolean enabled)
+config_set_large_print (GsdA11yPreferencesDialog *dialog,
+			gboolean                  enabled)
 {
-        GSettings *settings;
-
-        settings = g_settings_new ("org.gnome.desktop.font-rendering");
-
-        if (enabled) {
-                gdouble x_dpi;
-                gdouble u_dpi;
-
-                x_dpi = get_dpi_from_x_server ();
-                u_dpi = (double)DPI_FACTOR_LARGER * x_dpi;
-
-                g_debug ("GsdA11yPreferences: setting x-dpi=%f user-dpi=%f", x_dpi, u_dpi);
-
-                g_settings_set_double (settings, KEY_FONT_DPI, u_dpi);
-        } else {
-                g_settings_reset (settings, KEY_FONT_DPI);
-        }
-
-        g_object_unref (settings);
+        if (enabled)
+                g_settings_set_double (dialog->priv->interface_settings, KEY_TEXT_SCALING_FACTOR, DPI_FACTOR_LARGER);
+        else
+                g_settings_reset (dialog->priv->interface_settings, KEY_TEXT_SCALING_FACTOR);
 }
 
 static gboolean
@@ -361,7 +279,7 @@ static void
 on_large_print_checkbutton_toggled (GtkToggleButton          *button,
                                     GsdA11yPreferencesDialog *dialog)
 {
-        config_set_large_print (gtk_toggle_button_get_active (button));
+        config_set_large_print (dialog, gtk_toggle_button_get_active (button));
 }
 
 static void
@@ -484,7 +402,7 @@ setup_dialog (GsdA11yPreferencesDialog *dialog,
                           "toggled",
                           G_CALLBACK (on_large_print_checkbutton_toggled),
                           NULL);
-        enabled = config_get_large_print (&is_writable);
+        enabled = config_get_large_print (dialog, &is_writable);
         ui_set_large_print (dialog, enabled);
         if (! is_writable) {
                 gtk_widget_set_sensitive (widget, FALSE);
diff --git a/plugins/media-keys/gsd-media-keys-manager.c b/plugins/media-keys/gsd-media-keys-manager.c
index 60fdd1a..356a97e 100644
--- a/plugins/media-keys/gsd-media-keys-manager.c
+++ b/plugins/media-keys/gsd-media-keys-manager.c
@@ -1086,71 +1086,10 @@ do_on_screen_keyboard_action (GsdMediaKeysManager *manager)
         do_toggle_accessibility_key ("screen-keyboard-enabled");
 }
 
-/* The following two functions taken from gsd-a11y-preferences-dialog.c
- *
- * Copyright (C)  2008 William Jon McCann <jmccann redhat com>
- *
- * Licensed under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- */
-/* X servers sometimes lie about the screen's physical dimensions, so we cannot
- * compute an accurate DPI value.  When this happens, the user gets fonts that
- * are too huge or too tiny.  So, we see what the server returns:  if it reports
- * something outside of the range [DPI_LOW_REASONABLE_VALUE,
- * DPI_HIGH_REASONABLE_VALUE], then we assume that it is lying and we use
- * DPI_FALLBACK instead.
- *
- * See get_dpi_from_x_server() below, and also
- * https://bugzilla.novell.com/show_bug.cgi?id=217790
- */
-#define DPI_LOW_REASONABLE_VALUE 50
-#define DPI_HIGH_REASONABLE_VALUE 500
-#define DPI_DEFAULT        96
-
-static gdouble
-dpi_from_pixels_and_mm (gint pixels,
-			gint mm)
-{
-	if (mm >= 1)
-		return pixels / (mm / 25.4);
-	else
-		return 0;
-}
-
-static gdouble
-get_dpi_from_x_server (GdkScreen *screen)
-{
-	gdouble dpi;
-
-	if (screen) {
-		gdouble width_dpi, height_dpi;
-
-		width_dpi = dpi_from_pixels_and_mm (gdk_screen_get_width (screen),
-						    gdk_screen_get_width_mm (screen));
-		height_dpi = dpi_from_pixels_and_mm (gdk_screen_get_height (screen),
-						     gdk_screen_get_height_mm (screen));
-
-		if (width_dpi < DPI_LOW_REASONABLE_VALUE
-		    || width_dpi > DPI_HIGH_REASONABLE_VALUE
-		    || height_dpi < DPI_LOW_REASONABLE_VALUE
-		    || height_dpi > DPI_HIGH_REASONABLE_VALUE) {
-			dpi = DPI_DEFAULT;
-		} else {
-			dpi = (width_dpi + height_dpi) / 2.0;
-		}
-	} else {
-		dpi = DPI_DEFAULT;
-	}
-
-	return dpi;
-}
-
 static void
 do_text_size_action (GsdMediaKeysManager *manager,
 		     MediaKeyType         type)
 {
-	GSettings *font_settings;
 	gdouble x_dpi, u_dpi;
 	gdouble factor, best, distance;
 	guint i;
@@ -1163,17 +1102,8 @@ do_text_size_action (GsdMediaKeysManager *manager,
 		1.5
 	};
 
-	font_settings = g_settings_new (SETTINGS_XSETTINGS_DIR);
-
 	/* Figure out the current DPI scaling factor */
-	u_dpi = g_settings_get_double (font_settings, "dpi");
-	x_dpi = get_dpi_from_x_server (manager->priv->current_screen);
-	if (u_dpi == 0.0)
-		factor = 1.0;
-	else
-		factor = u_dpi / x_dpi;
-
-	/* Increasing text size means increasing the DPI */
+	factor = g_settings_get_double (manager->priv->interface_settings, "text-scaling-factor");
 	factor += (type == INCREASE_TEXT_KEY ? 0.25 : -0.25);
 
 	/* Try to find a matching value */
@@ -1189,11 +1119,9 @@ do_text_size_action (GsdMediaKeysManager *manager,
 	}
 
 	if (best == 1.0)
-		g_settings_reset (font_settings, "dpi");
+		g_settings_reset (manager->priv->interface_settings, "text-scaling-factor");
 	else
-		g_settings_set_double (font_settings, "dpi", best);
-
-	g_object_unref (font_settings);
+		g_settings_set_double (manager->priv->interface_settings, "text-scaling-factor", best);
 }
 
 static void
diff --git a/plugins/xsettings/gsd-xsettings-manager.c b/plugins/xsettings/gsd-xsettings-manager.c
index a471cf4..594e821 100644
--- a/plugins/xsettings/gsd-xsettings-manager.c
+++ b/plugins/xsettings/gsd-xsettings-manager.c
@@ -56,10 +56,11 @@
 #define GTK_MODULES_DISABLED_KEY "disabled-gtk-modules"
 #define GTK_MODULES_ENABLED_KEY  "enabled-gtk-modules"
 
+#define TEXT_SCALING_FACTOR_KEY "text-scaling-factor"
+
 #define FONT_ANTIALIASING_KEY "antialiasing"
 #define FONT_HINTING_KEY      "hinting"
 #define FONT_RGBA_ORDER_KEY   "rgba-order"
-#define FONT_DPI_KEY          "dpi"
 
 /* X servers sometimes lie about the screen's physical dimensions, so we cannot
  * compute an accurate DPI value.  When this happens, the user gets fonts that
@@ -261,15 +262,18 @@ get_dpi_from_x_server (void)
 }
 
 static double
-get_dpi_from_gsettings_or_x_server (GnomeXSettingsManager *manager)
+get_dpi_from_gsettings (GnomeXSettingsManager *manager)
 {
+	GSettings  *interface_settings;
         double      dpi;
+        double      factor;
 
-        dpi = g_settings_get_double (manager->priv->plugin_settings, FONT_DPI_KEY);
-        if (dpi == 0.0)
-                dpi = get_dpi_from_x_server ();
+	interface_settings = g_hash_table_lookup (manager->priv->settings, INTERFACE_SETTINGS_SCHEMA);
+        factor = g_settings_get_double (interface_settings, TEXT_SCALING_FACTOR_KEY);
 
-        return dpi;
+	dpi = get_dpi_from_x_server ();
+
+        return dpi * factor;
 }
 
 typedef struct {
@@ -292,7 +296,7 @@ xft_settings_get (GnomeXSettingsManager *manager,
 
         antialiasing = g_settings_get_enum (manager->priv->plugin_settings, FONT_ANTIALIASING_KEY);
         hinting = g_settings_get_enum (manager->priv->plugin_settings, FONT_HINTING_KEY);
-        dpi = get_dpi_from_gsettings_or_x_server (manager);
+        dpi = get_dpi_from_gsettings (manager);
 
         settings->antialias = (antialiasing != GSD_FONT_ANTIALIASING_MODE_NONE);
         settings->hinting = (hinting != GSD_FONT_HINTING_NONE);
@@ -575,6 +579,11 @@ xsettings_callback (GSettings             *settings,
         guint             i;
         GVariant         *value;
 
+        if (g_str_equal (key, TEXT_SCALING_FACTOR_KEY)) {
+        	xft_callback (NULL, key, manager);
+        	return;
+	}
+
         trans = find_translation_entry (settings, key);
         if (trans == NULL) {
                 return;



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