Blob Blame History Raw
From 2e03d94682524ccc0e511e14b97364c68cd7f105 Mon Sep 17 00:00:00 2001
From: Ray Strode <rstrode@redhat.com>
Date: Thu, 6 Sep 2018 10:58:11 -0400
Subject: [PATCH] xsettings: don't complain at start up when fetching window
 scale

g-s-d tries to get the window scale from mutter at startup before
mutter is running.

It then posts a warning to the log when it fails to talk to mutter.

This commit circumvents the warning by tracking mutter's lifetime,
and avoiding calls into it before its running.
---
 plugins/xsettings/gsd-xsettings-manager.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/plugins/xsettings/gsd-xsettings-manager.c b/plugins/xsettings/gsd-xsettings-manager.c
index eb55b8b7..f6406a95 100644
--- a/plugins/xsettings/gsd-xsettings-manager.c
+++ b/plugins/xsettings/gsd-xsettings-manager.c
@@ -259,60 +259,61 @@ typedef struct _FixedEntry FixedEntry;
 typedef void (* FixedFunc) (GnomeXSettingsManager *manager,
                             FixedEntry            *fixed);
 typedef union {
         const char *str;
         int num;
 } FixedEntryValue;
 
 struct _FixedEntry {
         const char     *xsetting_name;
         FixedFunc       func;
         FixedEntryValue val;
 };
 
 struct GnomeXSettingsManagerPrivate
 {
         guint              start_idle_id;
         XSettingsManager  *manager;
         GHashTable        *settings;
 
         GSettings         *plugin_settings;
         FcMonitor         *fontconfig_monitor;
         gint64             fontconfig_timestamp;
 
         GsdXSettingsGtk   *gtk;
 
         GsdRemoteDisplayManager *remote_display;
         gboolean           enable_animations;
 
         guint              display_config_watch_id;
         guint              monitors_changed_id;
+        gboolean           have_display_config;
 
         guint              shell_name_watch_id;
         gboolean           have_shell;
 
         guint              notify_idle_id;
 
         GDBusNodeInfo     *introspection_data;
         GDBusConnection   *dbus_connection;
         guint              gtk_settings_name_id;
 };
 
 #define GSD_XSETTINGS_ERROR gsd_xsettings_error_quark ()
 
 enum {
         GSD_XSETTINGS_ERROR_INIT
 };
 
 static void     gnome_xsettings_manager_class_init  (GnomeXSettingsManagerClass *klass);
 static void     gnome_xsettings_manager_init        (GnomeXSettingsManager      *xsettings_manager);
 static void     gnome_xsettings_manager_finalize    (GObject                  *object);
 
 static void     register_manager_dbus               (GnomeXSettingsManager *manager);
 
 G_DEFINE_TYPE (GnomeXSettingsManager, gnome_xsettings_manager, G_TYPE_OBJECT)
 
 static gpointer manager_object = NULL;
 
 static GQuark
 gsd_xsettings_error_quark (void)
 {
@@ -601,60 +602,65 @@ is_layout_mode_logical (GVariantIter *properties)
                         layout_mode = layout_mode_value;
 
                 break;
         }
 
         return layout_mode == DISPLAY_LAYOUT_MODE_LOGICAL;
 }
 
 #define MODE_FORMAT "(siiddada{sv})"
 #define MODES_FORMAT "a" MODE_FORMAT
 
 #define MONITOR_SPEC_FORMAT "(ssss)"
 #define MONITOR_FORMAT "(" MONITOR_SPEC_FORMAT MODES_FORMAT "a{sv})"
 #define MONITORS_FORMAT "a" MONITOR_FORMAT
 
 #define LOGICAL_MONITOR_FORMAT "(iiduba" MONITOR_SPEC_FORMAT "a{sv})"
 #define LOGICAL_MONITORS_FORMAT "a" LOGICAL_MONITOR_FORMAT
 
 #define CURRENT_STATE_FORMAT "(u" MONITORS_FORMAT LOGICAL_MONITORS_FORMAT "a{sv})"
 
 static int
 get_window_scale (GnomeXSettingsManager *manager)
 {
         GError *error = NULL;
         GVariant *current_state;
         GVariantIter *logical_monitors;
         GVariant *logical_monitor_variant;
         GVariantIter *properties;
         int scale = 1;
 
+        if (!manager->priv->have_display_config) {
+                g_debug("Window scale requested when mutter isn't running, falling back to scale 1");
+                return 1;
+        }
+
         current_state =
                 g_dbus_connection_call_sync (manager->priv->dbus_connection,
                                              "org.gnome.Mutter.DisplayConfig",
                                              "/org/gnome/Mutter/DisplayConfig",
                                              "org.gnome.Mutter.DisplayConfig",
                                              "GetCurrentState",
                                              NULL,
                                              NULL,
                                              G_DBUS_CALL_FLAGS_NO_AUTO_START,
                                              -1,
                                              NULL,
                                              &error);
         if (!current_state) {
                 g_warning ("Failed to get current display configuration state: %s",
                            error->message);
                 g_error_free (error);
                 return 1;
         }
 
         g_variant_get (current_state,
                        CURRENT_STATE_FORMAT,
                        NULL,
                        NULL,
                        &logical_monitors,
                        &properties);
 
         if (is_layout_mode_logical (properties))
                 goto out;
 
         while (g_variant_iter_next (logical_monitors, "@"LOGICAL_MONITOR_FORMAT,
@@ -1184,103 +1190,116 @@ enable_animations_changed_cb (GSettings             *settings,
         force_disable_animation_changed (G_OBJECT (manager->priv->remote_display), NULL, manager);
 }
 
 static void
 monitors_changed (GnomeXSettingsManager *manager)
 {
         update_xft_settings (manager);
         queue_notify (manager);
 }
 
 static void
 on_monitors_changed (GDBusConnection *connection,
                      const gchar     *sender_name,
                      const gchar     *object_path,
                      const gchar     *interface_name,
                      const gchar     *signal_name,
                      GVariant        *parameters,
                      gpointer         data)
 {
         GnomeXSettingsManager *manager = data;
         monitors_changed (manager);
 }
 
 static void
 on_display_config_name_appeared_handler (GDBusConnection *connection,
                                          const gchar     *name,
                                          const gchar     *name_owner,
                                          gpointer         data)
 {
         GnomeXSettingsManager *manager = data;
+
+        manager->priv->have_display_config = TRUE;
+        monitors_changed (manager);
+}
+
+static void
+on_display_config_name_disappeared_handler (GDBusConnection *connection,
+                                            const gchar     *name,
+                                            gpointer         data)
+{
+        GnomeXSettingsManager *manager = data;
+
+        manager->priv->have_display_config = FALSE;
         monitors_changed (manager);
 }
 
 gboolean
 gnome_xsettings_manager_start (GnomeXSettingsManager *manager,
                                GError               **error)
 {
         GVariant    *overrides;
         guint        i;
         GList       *list, *l;
         const char  *session;
 
         g_debug ("Starting xsettings manager");
         gnome_settings_profile_start (NULL);
 
         if (!setup_xsettings_managers (manager)) {
                 g_set_error (error, GSD_XSETTINGS_ERROR,
                              GSD_XSETTINGS_ERROR_INIT,
                              "Could not initialize xsettings manager.");
                 return FALSE;
         }
 
         manager->priv->remote_display = gsd_remote_display_manager_new ();
         g_signal_connect (G_OBJECT (manager->priv->remote_display), "notify::force-disable-animations",
                           G_CALLBACK (force_disable_animation_changed), manager);
 
         manager->priv->monitors_changed_id =
                 g_dbus_connection_signal_subscribe (manager->priv->dbus_connection,
                                                     "org.gnome.Mutter.DisplayConfig",
                                                     "org.gnome.Mutter.DisplayConfig",
                                                     "MonitorsChanged",
                                                     "/org/gnome/Mutter/DisplayConfig",
                                                     NULL,
                                                     G_DBUS_SIGNAL_FLAGS_NONE,
                                                     on_monitors_changed,
                                                     manager,
                                                     NULL);
         manager->priv->display_config_watch_id =
                 g_bus_watch_name_on_connection (manager->priv->dbus_connection,
                                                 "org.gnome.Mutter.DisplayConfig",
                                                 G_BUS_NAME_WATCHER_FLAGS_NONE,
                                                 on_display_config_name_appeared_handler,
-                                                NULL,
+                                                on_display_config_name_disappeared_handler,
                                                 manager,
                                                 NULL);
 
         manager->priv->settings = g_hash_table_new_full (g_str_hash, g_str_equal,
                                                          NULL, (GDestroyNotify) g_object_unref);
 
         g_hash_table_insert (manager->priv->settings,
                              MOUSE_SETTINGS_SCHEMA, g_settings_new (MOUSE_SETTINGS_SCHEMA));
         g_hash_table_insert (manager->priv->settings,
                              BACKGROUND_SETTINGS_SCHEMA, g_settings_new (BACKGROUND_SETTINGS_SCHEMA));
         g_hash_table_insert (manager->priv->settings,
                              INTERFACE_SETTINGS_SCHEMA, g_settings_new (INTERFACE_SETTINGS_SCHEMA));
         g_hash_table_insert (manager->priv->settings,
                              SOUND_SETTINGS_SCHEMA, g_settings_new (SOUND_SETTINGS_SCHEMA));
         g_hash_table_insert (manager->priv->settings,
                              PRIVACY_SETTINGS_SCHEMA, g_settings_new (PRIVACY_SETTINGS_SCHEMA));
         g_hash_table_insert (manager->priv->settings,
                              WM_SETTINGS_SCHEMA, g_settings_new (WM_SETTINGS_SCHEMA));
         g_hash_table_insert (manager->priv->settings,
                              A11Y_SCHEMA, g_settings_new (A11Y_SCHEMA));
 
         session = g_getenv ("XDG_CURRENT_DESKTOP");
         if (session && strstr (session, "GNOME-Classic")) {
                 GSettingsSchema *schema;
 
                 schema = g_settings_schema_source_lookup (g_settings_schema_source_get_default (),
                                                   CLASSIC_WM_SETTINGS_SCHEMA, FALSE);
                 if (schema) {
                         g_hash_table_insert (manager->priv->settings,
                                              CLASSIC_WM_SETTINGS_SCHEMA,
-- 
2.19.0.rc1