[gnome-settings-daemon/wip/window-scales] xsettings: Add support for window-scaling



commit cd6377773dcbea45915f3b11c2e49c036b828782
Author: Alexander Larsson <alexl redhat com>
Date:   Mon Jul 1 14:14:23 2013 +0200

    xsettings: Add support for window-scaling
    
    We read the window-scale-factor gsettings and propagate to gdk, including doing
    auto-detection if the setting is 0.
    
    Additionally, we scale the old Xft.DPI setting by the window scale so that old
    applications get a decent size on very high dpi monitors, plus we report the
    unscaled dpi so that window scale aware apps (like gtk) can avoid this
    dpi scaling.

 plugins/xsettings/gsd-xsettings-manager.c |   56 ++++++++++++++++++++++++++--
 1 files changed, 52 insertions(+), 4 deletions(-)
---
diff --git a/plugins/xsettings/gsd-xsettings-manager.c b/plugins/xsettings/gsd-xsettings-manager.c
index 22edbfc..4bd1b71 100644
--- a/plugins/xsettings/gsd-xsettings-manager.c
+++ b/plugins/xsettings/gsd-xsettings-manager.c
@@ -59,6 +59,7 @@
 #define GTK_MODULES_ENABLED_KEY  "enabled-gtk-modules"
 
 #define TEXT_SCALING_FACTOR_KEY "text-scaling-factor"
+#define WINDOW_SCALING_FACTOR_KEY "window-scaling-factor"
 
 #define FONT_ANTIALIASING_KEY "antialiasing"
 #define FONT_HINTING_KEY      "hinting"
@@ -218,6 +219,8 @@
  */
 #define DPI_FALLBACK 96
 
+#define HIDPI_LIMIT 200
+
 typedef struct _TranslationEntry TranslationEntry;
 typedef void (* TranslationFunc) (GnomeXSettingsManager *manager,
                                   TranslationEntry      *trans,
@@ -378,10 +381,48 @@ get_dpi_from_gsettings (GnomeXSettingsManager *manager)
         return dpi * factor;
 }
 
+static int
+get_window_scale (GnomeXSettingsManager *manager)
+{
+       GSettings  *interface_settings;
+        int window_scale;
+        GdkRectangle rect;
+        GdkDisplay *display;
+        GdkScreen *screen;
+        int width_mm, height_mm;
+        double dpi_x, dpi_y;
+
+       interface_settings = g_hash_table_lookup (manager->priv->settings, INTERFACE_SETTINGS_SCHEMA);
+        window_scale =
+                g_settings_get_int (interface_settings, WINDOW_SCALING_FACTOR_KEY);
+        if (window_scale == 0) {
+                display = gdk_display_get_default ();
+                screen = gdk_display_get_default_screen (display);
+                gdk_screen_get_monitor_geometry (screen, 0, &rect);
+                width_mm = gdk_screen_get_monitor_width_mm (screen, 0);
+                height_mm = gdk_screen_get_monitor_height_mm (screen, 0);
+
+                window_scale = 1;
+                if (width_mm > 0 && height_mm > 0) {
+                        dpi_x = (double)rect.width / (width_mm / 25.4);
+                        dpi_y = (double)rect.height / (height_mm / 25.4);
+                        /* We don't completely trust these values so both
+                           must be high, and never pick higher ratio than
+                           2 automatically */
+                        if (dpi_x > HIDPI_LIMIT && dpi_y > HIDPI_LIMIT)
+                                window_scale = 2;
+                }
+        }
+
+        return window_scale;
+}
+
 typedef struct {
         gboolean    antialias;
         gboolean    hinting;
+        int         scaled_dpi;
         int         dpi;
+        int         window_scale;
         const char *rgba;
         const char *hintstyle;
 } GnomeXftSettings;
@@ -395,6 +436,7 @@ xft_settings_get (GnomeXSettingsManager *manager,
         GsdFontHinting hinting;
         GsdFontRgbaOrder order;
         gboolean use_rgba = FALSE;
+        double dpi;
 
         antialiasing = g_settings_get_enum (manager->priv->plugin_settings, FONT_ANTIALIASING_KEY);
         hinting = g_settings_get_enum (manager->priv->plugin_settings, FONT_HINTING_KEY);
@@ -402,7 +444,10 @@ xft_settings_get (GnomeXSettingsManager *manager,
 
         settings->antialias = (antialiasing != GSD_FONT_ANTIALIASING_MODE_NONE);
         settings->hinting = (hinting != GSD_FONT_HINTING_NONE);
-        settings->dpi = get_dpi_from_gsettings (manager) * 1024; /* Xft wants 1/1024ths of an inch */
+        settings->window_scale = get_window_scale (manager);
+        dpi = get_dpi_from_gsettings (manager);
+        settings->dpi = dpi * 1024; /* Xft wants 1/1024ths of an inch */
+        settings->scaled_dpi = dpi * settings->window_scale * 1024;
         settings->rgba = "rgb";
         settings->hintstyle = "hintfull";
 
@@ -468,7 +513,9 @@ xft_settings_set_xsettings (GnomeXSettingsManager *manager,
                 xsettings_manager_set_int (manager->priv->managers [i], "Xft/Antialias", 
settings->antialias);
                 xsettings_manager_set_int (manager->priv->managers [i], "Xft/Hinting", settings->hinting);
                 xsettings_manager_set_string (manager->priv->managers [i], "Xft/HintStyle", 
settings->hintstyle);
-                xsettings_manager_set_int (manager->priv->managers [i], "Xft/DPI", settings->dpi);
+                xsettings_manager_set_int (manager->priv->managers [i], "Gdk/WindowScalingFactor", 
settings->window_scale);
+                xsettings_manager_set_int (manager->priv->managers [i], "Gdk/UnscaledDPI", settings->dpi);
+                xsettings_manager_set_int (manager->priv->managers [i], "Xft/DPI", settings->scaled_dpi);
                 xsettings_manager_set_string (manager->priv->managers [i], "Xft/RGBA", settings->rgba);
         }
         gnome_settings_profile_end (NULL);
@@ -522,7 +569,7 @@ xft_settings_set_xresources (GnomeXftSettings *settings)
         g_debug("xft_settings_set_xresources: orig res '%s'", add_string->str);
 
         update_property (add_string, "Xft.dpi",
-                                g_ascii_dtostr (dpibuf, sizeof (dpibuf), (double) settings->dpi / 1024.0));
+                                g_ascii_dtostr (dpibuf, sizeof (dpibuf), (double) settings->scaled_dpi / 
1024.0));
         update_property (add_string, "Xft.antialias",
                                 settings->antialias ? "1" : "0");
         update_property (add_string, "Xft.hinting",
@@ -750,7 +797,8 @@ xsettings_callback (GSettings             *settings,
         guint             i;
         GVariant         *value;
 
-        if (g_str_equal (key, TEXT_SCALING_FACTOR_KEY)) {
+        if (g_str_equal (key, TEXT_SCALING_FACTOR_KEY) ||
+            g_str_equal (key, WINDOW_SCALING_FACTOR_KEY)) {
                xft_callback (NULL, key, manager);
                return;
        }


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