[gnome-settings-daemon] orientation: Add support for orientation lock



commit ba973e905c01570a41935b1515c11197074ee92b
Author: Bastien Nocera <hadess hadess net>
Date:   Fri Jun 3 15:00:57 2011 +0100

    orientation: Add support for orientation lock
    
    Whether the orientation lock is enabled or disabled will
    be available through the "orientation-lock" GSettings key.
    
    The shell will simply toggle it on/off.

 ...e.settings-daemon.peripherals.gschema.xml.in.in |    7 ++
 plugins/orientation/gsd-orientation-manager.c      |   63 ++++++++++++++++++-
 2 files changed, 66 insertions(+), 4 deletions(-)
---
diff --git a/data/org.gnome.settings-daemon.peripherals.gschema.xml.in.in b/data/org.gnome.settings-daemon.peripherals.gschema.xml.in.in
index 1ea534f..5063ecf 100644
--- a/data/org.gnome.settings-daemon.peripherals.gschema.xml.in.in
+++ b/data/org.gnome.settings-daemon.peripherals.gschema.xml.in.in
@@ -4,6 +4,7 @@
     <child name="touchpad" schema="org.gnome.settings-daemon.peripherals.touchpad"/>
     <child name="keyboard" schema="org.gnome.settings-daemon.peripherals.keyboard"/>
     <child name="mouse" schema="org.gnome.settings-daemon.peripherals.mouse"/>
+    <child name="touchscreen" schema="org.gnome.settings-daemon.peripherals.touchscreen"/>
     <child name="input-devices" schema="org.gnome.settings-daemon.peripherals.input-devices"/>
   </schema>
   <schema gettext-domain="@GETTEXT_PACKAGE@" id="org.gnome.settings-daemon.peripherals.smartcard" path="/org/gnome/settings-daemon/peripherals/smartcard/">
@@ -132,6 +133,12 @@
       <_description>Enables middle mouse button emulation through simultaneous left and right button click.</_description>
     </key>
   </schema>
+  <schema gettext-domain="@GETTEXT_PACKAGE@" id="org.gnome.settings-daemon.peripherals.touchscreen" path="/org/gnome/settings-daemon/peripherals/touchscreen/">
+    <key name="orientation-lock" type="b">
+      <default>false</default>
+      <_summary>Whether the tablet's orientation is locked, or rotated automatically.</_summary>
+    </key>
+  </schema>
   <schema gettext-domain="@GETTEXT_PACKAGE@" id="org.gnome.settings-daemon.peripherals.input-devices" path="/org/gnome/settings-daemon/peripherals/input-devices/">
     <key name="hotplug-command" type="s">
       <default>''</default>
diff --git a/plugins/orientation/gsd-orientation-manager.c b/plugins/orientation/gsd-orientation-manager.c
index 88af63b..d9716e5 100644
--- a/plugins/orientation/gsd-orientation-manager.c
+++ b/plugins/orientation/gsd-orientation-manager.c
@@ -43,11 +43,19 @@
 struct GsdOrientationManagerPrivate
 {
         guint start_idle_id;
+
+        /* Accelerometer */
         char *sysfs_path;
         int device_id;
+
+        /* Notifications */
         GUdevClient *client;
+        GSettings *settings;
+        gboolean orientation_lock;
+
         OrientationUp prev_orientation;
         int prev_x, prev_y, prev_z;
+
         guint orient_timeout_id;
         guint num_checks;
 };
@@ -56,6 +64,9 @@ struct GsdOrientationManagerPrivate
  * to check for changes */
 #define MAX_CHECKS 5
 
+#define CONF_SCHEMA "org.gnome.settings-daemon.peripherals.touchscreen"
+#define ORIENTATION_LOCK_KEY "orientation-lock"
+
 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);
@@ -181,6 +192,20 @@ update_current_orientation (GsdOrientationManager *manager,
         return TRUE;
 }
 
+static void
+do_rotation (GsdOrientationManager *manager)
+{
+        GnomeRRRotation rotation;
+
+        if (manager->priv->orientation_lock) {
+                g_debug ("Orientation changed, but we are locked");
+                return;
+        }
+
+        rotation = orientation_to_rotation (manager->priv->prev_orientation);
+        /* FIXME: call into XRandR plugin */
+}
+
 static gboolean
 check_value_change_cb (GsdOrientationManager *manager)
 {
@@ -200,10 +225,7 @@ check_value_change_cb (GsdOrientationManager *manager)
 
                 /* We have updated values */
                 if (update_current_orientation (manager, x, y, z)) {
-                        GnomeRRRotation rotation;
-
-                        rotation = orientation_to_rotation (manager->priv->prev_orientation);
-                        /* FIXME: call into XRandR plugin */
+                        do_rotation (manager);
                 }
 
                 set_device_enabled (manager->priv->device_id, FALSE);
@@ -235,6 +257,9 @@ client_uevent_cb (GUdevClient           *client,
         sysfs_path = g_udev_device_get_sysfs_path (device);
         g_debug ("Received uevent '%s' from '%s'", action, sysfs_path);
 
+        if (manager->priv->orientation_lock)
+                return;
+
         if (g_str_equal (action, "change") == FALSE)
                 return;
 
@@ -286,6 +311,26 @@ get_sysfs_path (GsdOrientationManager *manager,
         return sysfs_path;
 }
 
+static void
+orientation_lock_changed_cb (GSettings             *settings,
+                             gchar                 *key,
+                             GsdOrientationManager *manager)
+{
+        gboolean new;
+
+        new = g_settings_get_boolean (settings, key);
+        if (new == manager->priv->orientation_lock)
+                return;
+
+        manager->priv->orientation_lock = new;
+
+        if (new == FALSE) {
+                /* Handle the rotations that could have occurred while
+                 * we were locked */
+                do_rotation (manager);
+        }
+}
+
 static gboolean
 gsd_orientation_manager_idle_cb (GsdOrientationManager *manager)
 {
@@ -294,6 +339,11 @@ gsd_orientation_manager_idle_cb (GsdOrientationManager *manager)
 
         gnome_settings_profile_start (NULL);
 
+        manager->priv->settings = g_settings_new (ORIENTATION_LOCK_KEY);
+        manager->priv->orientation_lock = g_settings_get_boolean (manager->priv->settings, ORIENTATION_LOCK_KEY);
+        g_signal_connect (G_OBJECT (manager->priv->settings), "changed::orientation-lock",
+                          G_CALLBACK (orientation_lock_changed_cb), manager);
+
         if (!accelerometer_is_present (&device_node,
                                        &manager->priv->device_id)) {
                 g_debug ("Did not find an accelerometer");
@@ -348,6 +398,11 @@ gsd_orientation_manager_stop (GsdOrientationManager *manager)
                 p->orient_timeout_id = 0;
         }
 
+        if (p->settings) {
+                g_object_unref (p->settings);
+                p->settings = NULL;
+        }
+
         if (p->sysfs_path) {
                 g_free (p->sysfs_path);
                 p->sysfs_path = NULL;



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