[gnome-settings-daemon] xsettings: always use mutter-computed UI scaling value



commit a14690bdb46ca3da1ea8a10ebe20ccd100f46fca
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Mon Nov 26 23:39:31 2018 -0600

    xsettings: always use mutter-computed UI scaling value
    
    Mutter already computes the proper window scaling level to be used under X11,
    this logic is already present in mutter, so there's no point to change it here
    and go into the implementations details.
    So just use the 'legacy-ui-scaling-factor' key value that we can trust.

 plugins/xsettings/gsd-xsettings-manager.c | 76 ++++++++-----------------------
 1 file changed, 19 insertions(+), 57 deletions(-)
---
diff --git a/plugins/xsettings/gsd-xsettings-manager.c b/plugins/xsettings/gsd-xsettings-manager.c
index c6772dd7..72e42d86 100644
--- a/plugins/xsettings/gsd-xsettings-manager.c
+++ b/plugins/xsettings/gsd-xsettings-manager.c
@@ -83,11 +83,6 @@ static const gchar introspection_xml[] =
 "  </interface>"
 "</node>";
 
-typedef enum _DisplayLayoutMode {
-        DISPLAY_LAYOUT_MODE_LOGICAL = 1,
-        DISPLAY_LAYOUT_MODE_PHYSICAL = 2
-} DisplayLayoutMode;
-
 /* As we cannot rely on the X server giving us good DPI information, and
  * that we don't want multi-monitor screens to have different DPIs (thus
  * different text sizes), we'll hard-code the value of the DPI
@@ -578,33 +573,29 @@ get_dpi_from_gsettings (GnomeXSettingsManager *manager)
 }
 
 static gboolean
-is_layout_mode_logical (GVariantIter *properties)
+get_legacy_ui_scale (GVariantIter *properties,
+                     int          *scale)
 {
-        DisplayLayoutMode layout_mode = DISPLAY_LAYOUT_MODE_LOGICAL;
         const char *key;
         GVariant *value;
 
-        while (g_variant_iter_next (properties, "{&sv}", &key, &value)) {
-                DisplayLayoutMode layout_mode_value;
+        *scale = 0;
 
-                if (!g_str_equal (key, "layout-mode")) {
-                        g_variant_unref (value);
+        while (g_variant_iter_loop (properties, "{&sv}", &key, &value)) {
+                if (!g_str_equal (key, "legacy-ui-scaling-factor"))
                         continue;
-                }
-
-                layout_mode_value = g_variant_get_uint32 (value);
-                g_variant_unref (value);
-
-                if (layout_mode_value < DISPLAY_LAYOUT_MODE_LOGICAL ||
-                    layout_mode_value > DISPLAY_LAYOUT_MODE_PHYSICAL)
-                        g_warning ("Unknown layout mode %u", layout_mode_value);
-                else
-                        layout_mode = layout_mode_value;
 
+                *scale = g_variant_get_int32 (value);
                 break;
         }
 
-        return layout_mode == DISPLAY_LAYOUT_MODE_LOGICAL;
+        if (*scale < 1) {
+                g_warning ("Failed to get current UI legacy scaling factor");
+                *scale = 1;
+                return FALSE;
+        }
+
+        return TRUE;
 }
 
 #define MODE_FORMAT "(siiddada{sv})"
@@ -622,11 +613,9 @@ is_layout_mode_logical (GVariantIter *properties)
 static int
 get_window_scale (GnomeXSettingsManager *manager)
 {
-        GError *error = NULL;
-        GVariant *current_state;
-        GVariantIter *logical_monitors;
-        GVariant *logical_monitor_variant;
-        GVariantIter *properties;
+        g_autoptr(GError) error = NULL;
+        g_autoptr(GVariant) current_state = NULL;
+        g_autoptr(GVariantIter) properties = NULL;
         int scale = 1;
 
         current_state =
@@ -644,7 +633,6 @@ get_window_scale (GnomeXSettingsManager *manager)
         if (!current_state) {
                 g_warning ("Failed to get current display configuration state: %s",
                            error->message);
-                g_error_free (error);
                 return 1;
         }
 
@@ -652,37 +640,11 @@ get_window_scale (GnomeXSettingsManager *manager)
                        CURRENT_STATE_FORMAT,
                        NULL,
                        NULL,
-                       &logical_monitors,
+                       NULL,
                        &properties);
 
-        if (is_layout_mode_logical (properties))
-                goto out;
-
-        while (g_variant_iter_next (logical_monitors, "@"LOGICAL_MONITOR_FORMAT,
-                                    &logical_monitor_variant)) {
-                gboolean is_primary;
-                double logical_monitor_scale;
-
-                g_variant_get (logical_monitor_variant,
-                               LOGICAL_MONITOR_FORMAT,
-                               NULL, NULL,
-                               &logical_monitor_scale,
-                               NULL,
-                               &is_primary,
-                               NULL, NULL);
-
-                if (is_primary) {
-                        scale = (int) logical_monitor_scale;
-                        break;
-                }
-
-                g_variant_unref (logical_monitor_variant);
-        }
-
-out:
-        g_variant_unref (current_state);
-        g_variant_iter_free (properties);
-        g_variant_iter_free (logical_monitors);
+        if (!get_legacy_ui_scale (properties, &scale))
+                g_warning ("Failed to get current UI legacy scaling factor");
 
         return scale;
 }


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