[gnome-settings-daemon/gnome-3-12] orientation: Fix plugin on MS Surface devices



commit 1bd84fb1634e516dd4a1e94ef47ade699aa1d225
Author: Bastien Nocera <hadess hadess net>
Date:   Mon Jul 21 16:23:39 2014 +0200

    orientation: Fix plugin on MS Surface devices
    
    When plugging in the type/touch cover on a Microsoft Surface, the
    IIO sensor is unplugged, and plugged in again with a different
    sysfs path. As the accelerometer comes and goes, we need to handle this
    in the orientation plugin, and not bail out if we can't find the
    accelerometer on startup, and handle devices coming and going.

 plugins/orientation/gsd-orientation-manager.c |   69 +++++++++++++++++--------
 1 files changed, 48 insertions(+), 21 deletions(-)
---
diff --git a/plugins/orientation/gsd-orientation-manager.c b/plugins/orientation/gsd-orientation-manager.c
index 989642b..24be4e7 100644
--- a/plugins/orientation/gsd-orientation-manager.c
+++ b/plugins/orientation/gsd-orientation-manager.c
@@ -83,6 +83,7 @@ static const gchar introspection_xml[] =
 static void     gsd_orientation_manager_class_init  (GsdOrientationManagerClass *klass);
 static void     gsd_orientation_manager_init        (GsdOrientationManager      *orientation_manager);
 static void     gsd_orientation_manager_finalize    (GObject                    *object);
+static void     update_accelerometer                (GsdOrientationManager      *manager);
 
 G_DEFINE_TYPE (GsdOrientationManager, gsd_orientation_manager, G_TYPE_OBJECT)
 
@@ -260,8 +261,11 @@ client_uevent_cb (GUdevClient           *client,
         if (manager->priv->orientation_lock)
                 return;
 
-        if (g_str_equal (action, "change") == FALSE)
+        if (g_str_equal (action, "change") == FALSE) {
+                /* "add", "remove", or "move" */
+                update_accelerometer (manager);
                 return;
+        }
 
         if (g_strcmp0 (manager->priv->sysfs_path, sysfs_path) != 0)
                 return;
@@ -346,13 +350,16 @@ on_bus_gotten (GObject               *source_object,
                           (GAsyncReadyCallback) xrandr_ready_cb,
                           manager);
 
-        manager->priv->name_id = g_bus_own_name_on_connection (connection,
-                                                               GSD_ORIENTATION_DBUS_NAME,
-                                                               G_BUS_NAME_OWNER_FLAGS_NONE,
-                                                               NULL,
-                                                               NULL,
-                                                               NULL,
-                                                               NULL);
+       /* If we got the accelerometer before D-Bus was ready */
+        if (manager->priv->sysfs_path != NULL) {
+                manager->priv->name_id = g_bus_own_name_on_connection (manager->priv->connection,
+                                                                       GSD_ORIENTATION_DBUS_NAME,
+                                                                       G_BUS_NAME_OWNER_FLAGS_NONE,
+                                                                       NULL,
+                                                                       NULL,
+                                                                       NULL,
+                                                                       NULL);
+        }
 }
 
 static GUdevDevice *
@@ -394,11 +401,41 @@ get_accelerometer (GUdevClient *client)
         return ret;
 }
 
+static void
+update_accelerometer (GsdOrientationManager *manager)
+{
+        GUdevDevice *dev;
+
+        g_clear_pointer (&manager->priv->sysfs_path, g_free);
+        manager->priv->prev_orientation = ORIENTATION_UNDEFINED;
+
+        dev = get_accelerometer (manager->priv->client);
+        if (dev == NULL) {
+                if (manager->priv->name_id != 0)
+                        g_bus_unown_name (manager->priv->name_id);
+        } else {
+                if (manager->priv->connection) {
+                        manager->priv->name_id = g_bus_own_name_on_connection (manager->priv->connection,
+                                                                               GSD_ORIENTATION_DBUS_NAME,
+                                                                               G_BUS_NAME_OWNER_FLAGS_NONE,
+                                                                               NULL,
+                                                                               NULL,
+                                                                               NULL,
+                                                                               NULL);
+                }
+
+                manager->priv->sysfs_path = g_strdup (g_udev_device_get_sysfs_path (dev));
+                g_debug ("Found accelerometer at sysfs path '%s'", manager->priv->sysfs_path);
+
+                manager->priv->prev_orientation = get_orientation_from_device (dev);
+                g_object_unref (dev);
+        }
+}
+
 static gboolean
 gsd_orientation_manager_idle_cb (GsdOrientationManager *manager)
 {
         const char * const subsystems[] = { "input", NULL };
-        GUdevDevice *dev;
 
         gnome_settings_profile_start (NULL);
 
@@ -409,19 +446,9 @@ gsd_orientation_manager_idle_cb (GsdOrientationManager *manager)
                           G_CALLBACK (orientation_lock_changed_cb), manager);
 
         manager->priv->client = g_udev_client_new (subsystems);
-        dev = get_accelerometer (manager->priv->client);
-        if (dev == NULL) {
-                g_debug ("Did not find an accelerometer");
-                gnome_settings_profile_end (NULL);
-                return G_SOURCE_REMOVE;
-        }
-        manager->priv->sysfs_path = g_strdup (g_udev_device_get_sysfs_path (dev));
-        g_debug ("Found accelerometer at sysfs path '%s'", manager->priv->sysfs_path);
-
-        manager->priv->prev_orientation = get_orientation_from_device (dev);
-        g_object_unref (dev);
+        update_accelerometer (manager);
 
-        /* Start process of owning a D-Bus name */
+        /* D-Bus setup */
         g_bus_get (G_BUS_TYPE_SESSION,
                    NULL,
                    (GAsyncReadyCallback) on_bus_gotten,


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