[gnome-settings-daemon] xsettings: Outsource decision making regarding animations to the shell



commit 122b7cae1ce6cfd3ac952058acf7604f1901fe57
Author: Jonas Ådahl <jadahl gmail com>
Date:   Wed Oct 9 17:37:49 2019 +0200

    xsettings: Outsource decision making regarding animations to the shell
    
    Animations were disabled depending various hueristics, specifically
    whether there was a Vino session active on D-Bus, whether the desktop
    was hardware accelerated, or if a certain X11 extension was advertised
    that happens to be advertised when Xvnc is used as an X server.
    
    This logic has been moved to gnome-shell, and is exposed as a property
    on org.gnome.Shell.Introspect, except Vino sessions is not discovered
    anymore. gnome-shell has, however, means to detect whether a remote
    desktop session that wants to have animations disabled is active or not.

 plugins/xsettings/gsd-remote-display-manager.c | 289 -------------------------
 plugins/xsettings/gsd-xsettings-manager.c      | 139 ++++++++----
 plugins/xsettings/meson.build                  |   1 -
 plugins/xsettings/test.py                      |  50 -----
 4 files changed, 95 insertions(+), 384 deletions(-)
---
diff --git a/plugins/xsettings/gsd-xsettings-manager.c b/plugins/xsettings/gsd-xsettings-manager.c
index 4164de40..75744b20 100644
--- a/plugins/xsettings/gsd-xsettings-manager.c
+++ b/plugins/xsettings/gsd-xsettings-manager.c
@@ -276,7 +276,8 @@ struct _GsdXSettingsManager
 
         GsdXSettingsGtk   *gtk;
 
-        GsdRemoteDisplayManager *remote_display;
+        guint              introspect_properties_changed_id;
+        guint              shell_introspect_watch_id;
         gboolean           enable_animations;
 
         guint              display_config_watch_id;
@@ -1072,38 +1073,6 @@ setup_xsettings_managers (GsdXSettingsManager *manager)
         return TRUE;
 }
 
-static void
-force_disable_animation_changed (GObject    *gobject,
-                                 GParamSpec *pspec,
-                                 GsdXSettingsManager *manager)
-{
-        gboolean force_disable, value;
-
-        g_object_get (gobject, "force-disable-animations", &force_disable, NULL);
-        if (force_disable)
-                value = FALSE;
-        else {
-                GSettings *settings;
-
-                settings = g_hash_table_lookup (manager->settings, "org.gnome.desktop.interface");
-                value = g_settings_get_boolean (settings, "enable-animations");
-        }
-
-        manager->enable_animations = value;
-        xsettings_manager_set_int (manager->manager, "Gtk/EnableAnimations", value);
-
-        queue_notify (manager);
-        send_dbus_event (manager, GTK_SETTINGS_ENABLE_ANIMATIONS);
-}
-
-static void
-enable_animations_changed_cb (GSettings           *settings,
-                              gchar               *key,
-                              GsdXSettingsManager *manager)
-{
-        force_disable_animation_changed (G_OBJECT (manager->remote_display), NULL, manager);
-}
-
 static void
 monitors_changed (GsdXSettingsManager *manager)
 {
@@ -1134,6 +1103,69 @@ on_display_config_name_appeared_handler (GDBusConnection *connection,
         monitors_changed (manager);
 }
 
+static void
+animations_enabled_changed (GsdXSettingsManager *manager)
+{
+        g_autoptr(GError) error = NULL;
+        g_autoptr(GVariant) res = NULL;
+        g_autoptr(GVariant) animations_enabled_variant = NULL;
+        gboolean animations_enabled;
+
+        res = g_dbus_connection_call_sync (manager->dbus_connection,
+                                           "org.gnome.Shell.Introspect",
+                                           "/org/gnome/Shell/Introspect",
+                                           "org.freedesktop.DBus.Properties",
+                                           "Get",
+                                           g_variant_new ("(ss)",
+                                                          "org.gnome.Shell.Introspect",
+                                                          "AnimationsEnabled"),
+                                           NULL,
+                                           G_DBUS_CALL_FLAGS_NONE,
+                                           -1,
+                                           NULL,
+                                           &error);
+        if (!res) {
+                g_warning ("Failed to get animations-enabled state: %s",
+                           error->message);
+                return;
+        }
+
+        g_variant_get (res, "(v)", &animations_enabled_variant);
+        g_variant_get (animations_enabled_variant, "b", &animations_enabled);
+
+        if (manager->enable_animations == animations_enabled)
+                return;
+
+        manager->enable_animations = animations_enabled;
+        xsettings_manager_set_int (manager->manager, "Gtk/EnableAnimations",
+                                   animations_enabled);
+        queue_notify (manager);
+        send_dbus_event (manager, GTK_SETTINGS_ENABLE_ANIMATIONS);
+}
+
+static void
+on_introspect_properties_changed (GDBusConnection *connection,
+                                  const gchar     *sender_name,
+                                  const gchar     *object_path,
+                                  const gchar     *interface_name,
+                                  const gchar     *signal_name,
+                                  GVariant        *parameters,
+                                  gpointer         data)
+{
+        GsdXSettingsManager *manager = data;
+        animations_enabled_changed (manager);
+}
+
+static void
+on_shell_introspect_name_appeared_handler (GDBusConnection *connection,
+                                           const gchar     *name,
+                                           const gchar     *name_owner,
+                                           gpointer         data)
+{
+        GsdXSettingsManager *manager = data;
+        animations_enabled_changed (manager);
+}
+
 gboolean
 gsd_xsettings_manager_start (GsdXSettingsManager *manager,
                              GError             **error)
@@ -1153,10 +1185,6 @@ gsd_xsettings_manager_start (GsdXSettingsManager *manager,
                 return FALSE;
         }
 
-        manager->remote_display = gsd_remote_display_manager_new ();
-        g_signal_connect (G_OBJECT (manager->remote_display), "notify::force-disable-animations",
-                          G_CALLBACK (force_disable_animation_changed), manager);
-
         manager->monitors_changed_id =
                 g_dbus_connection_signal_subscribe (manager->dbus_connection,
                                                     "org.gnome.Mutter.DisplayConfig",
@@ -1177,6 +1205,26 @@ gsd_xsettings_manager_start (GsdXSettingsManager *manager,
                                                 manager,
                                                 NULL);
 
+        manager->introspect_properties_changed_id =
+                g_dbus_connection_signal_subscribe (manager->dbus_connection,
+                                                    "org.gnome.Shell.Introspect",
+                                                    "org.freedesktop.DBus.Properties",
+                                                    "PropertiesChanged",
+                                                    "/org/gnome/Shell/Introspect",
+                                                    NULL,
+                                                    G_DBUS_SIGNAL_FLAGS_NONE,
+                                                    on_introspect_properties_changed,
+                                                    manager,
+                                                    NULL);
+        manager->shell_introspect_watch_id =
+                g_bus_watch_name_on_connection (manager->dbus_connection,
+                                                "org.gnome.Shell.Introspect",
+                                                G_BUS_NAME_WATCHER_FLAGS_NONE,
+                                                on_shell_introspect_name_appeared_handler,
+                                                NULL,
+                                                manager,
+                                                NULL);
+
         manager->settings = g_hash_table_new_full (g_str_hash, g_str_equal,
                                                          NULL, (GDestroyNotify) g_object_unref);
 
@@ -1209,9 +1257,6 @@ gsd_xsettings_manager_start (GsdXSettingsManager *manager,
                 }
         }
 
-        g_signal_connect (G_OBJECT (g_hash_table_lookup (manager->settings, INTERFACE_SETTINGS_SCHEMA)), 
"changed::enable-animations",
-                          G_CALLBACK (enable_animations_changed_cb), manager);
-
         for (i = 0; i < G_N_ELEMENTS (fixed_entries); i++) {
                 FixedEntry *fixed = &fixed_entries[i];
                 (* fixed->func) (manager, fixed);
@@ -1249,9 +1294,6 @@ gsd_xsettings_manager_start (GsdXSettingsManager *manager,
                           G_CALLBACK (gtk_modules_callback), manager);
         gtk_modules_callback (manager->gtk, NULL, manager);
 
-        /* Animation settings */
-        force_disable_animation_changed (G_OBJECT (manager->remote_display), NULL, manager);
-
         /* Xft settings */
         update_xft_settings (manager);
 
@@ -1275,7 +1317,16 @@ gsd_xsettings_manager_stop (GsdXSettingsManager *manager)
 {
         g_debug ("Stopping xsettings manager");
 
-        g_clear_object (&manager->remote_display);
+        if (manager->introspect_properties_changed_id) {
+                g_dbus_connection_signal_unsubscribe (manager->dbus_connection,
+                                                      manager->introspect_properties_changed_id);
+                manager->introspect_properties_changed_id = 0;
+        }
+
+        if (manager->shell_introspect_watch_id) {
+                g_bus_unwatch_name (manager->shell_introspect_watch_id);
+                manager->shell_introspect_watch_id = 0;
+        }
 
         if (manager->monitors_changed_id) {
                 g_dbus_connection_signal_unsubscribe (manager->dbus_connection,
diff --git a/plugins/xsettings/meson.build b/plugins/xsettings/meson.build
index 1c187716..fb4ef4cf 100644
--- a/plugins/xsettings/meson.build
+++ b/plugins/xsettings/meson.build
@@ -5,7 +5,6 @@ fc_monitor = files('fc-monitor.c')
 wm_button_layout_translation = files('wm-button-layout-translation.c')
 
 sources = gsd_xsettings_gtk + fc_monitor + wm_button_layout_translation + files(
-  'gsd-remote-display-manager.c',
   'gsd-xsettings-manager.c',
   'xsettings-common.c',
   'xsettings-manager.c',
diff --git a/plugins/xsettings/test.py b/plugins/xsettings/test.py
index 79ced93b..9c1b4a09 100755
--- a/plugins/xsettings/test.py
+++ b/plugins/xsettings/test.py
@@ -160,56 +160,6 @@ class XsettingsPluginTest(gsdtestcase.GSDTestCase):
         values = sorted(str(retval).split(':'))
         self.assertEqual(values, ['canberra-gtk-module', 'pk-gtk-module'])
 
-    def test_enable_animations(self):
-        # Check that "Enable animations" is off
-        self.assertEqual(self.obj_xsettings_props.Get('org.gtk.Settings', 'EnableAnimations'),
-                dbus.Boolean(True, variant_level=1))
-
-        # Make vino appear
-        vino = self.spawn_server('org.gnome.Vino',
-                '/org/gnome/vino/screens/0',
-                'org.gnome.VinoScreen')
-
-        dbus_con = self.get_dbus()
-        obj_vino = dbus_con.get_object('org.gnome.Vino', '/org/gnome/vino/screens/0')
-        mock_vino = dbus.Interface(obj_vino, dbusmock.MOCK_IFACE)
-        mock_vino.AddProperty('', 'Connected', dbus.Boolean(False, variant_level=1))
-
-        time.sleep(0.1)
-
-        # Check animations are still enabled
-        self.assertEqual(self.obj_xsettings_props.Get('org.gtk.Settings', 'EnableAnimations'),
-                dbus.Boolean(True, variant_level=1))
-
-        # Connect a remote user
-        mock_vino.EmitSignal('org.freedesktop.DBus.Properties',
-                             'PropertiesChanged',
-                            'sa{sv}as',
-                            ['org.gnome.VinoScreen',
-                            dbus.Dictionary({'Connected': dbus.Boolean(True, variant_level=1)}, 
signature='sv'),
-                            dbus.Array([], signature='s')
-                            ])
-
-        time.sleep(0.1)
-
-        # gdbus debug output
-        # gdbus_log_write = open(os.path.join(self.workdir, 'gdbus.log'), 'wb')
-        # process = subprocess.Popen(['gdbus', 'introspect', '--session', '--dest', 'org.gnome.Vino', 
'--object-path', '/org/gnome/vino/screens/0'],
-        #         stdout=gdbus_log_write, stderr=subprocess.STDOUT)
-        # time.sleep(1)
-
-        # Check that "Enable animations" is off
-        self.assertEqual(self.obj_xsettings_props.Get('org.gtk.Settings', 'EnableAnimations'),
-                dbus.Boolean(False, variant_level=1))
-
-        vino.terminate()
-        vino.wait()
-        time.sleep(0.1)
-
-        # Check animations are back enabled
-        self.assertEqual(self.obj_xsettings_props.Get('org.gtk.Settings', 'EnableAnimations'),
-                dbus.Boolean(True, variant_level=1))
-
     def test_fontconfig_timestamp(self):
         # gdbus_log_write = open(os.path.join(self.workdir, 'gdbus.log'), 'wb')
         # process = subprocess.Popen(['gdbus', 'introspect', '--session', '--dest', 'org.gtk.Settings', 
'--object-path', '/org/gtk/Settings'],


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