[gnome-shell] system: Use iio-sensor-proxy to detect accelerometer



commit 2e77f6b34be9194f3a021a133112fee9a8010cf9
Author: Bastien Nocera <hadess hadess net>
Date:   Thu Mar 5 15:46:57 2015 +0100

    system: Use iio-sensor-proxy to detect accelerometer
    
    Instead of using gnome-settings-daemon's D-Bus interface's presence.
    iio-sensor-proxy now offers a D-Bus interface, which will exported
    "HasAccelerometer = true" when an accelerometer is present.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=749671

 js/ui/status/system.js |   47 +++++++++++++++++++++++++++++++++++------------
 1 files changed, 35 insertions(+), 12 deletions(-)
---
diff --git a/js/ui/status/system.js b/js/ui/status/system.js
index 7e3ceec..451f53a 100644
--- a/js/ui/status/system.js
+++ b/js/ui/status/system.js
@@ -24,6 +24,17 @@ const DISABLE_LOG_OUT_KEY = 'disable-log-out';
 const DISABLE_RESTART_KEY = 'disable-restart-buttons';
 const ALWAYS_SHOW_LOG_OUT_KEY = 'always-show-log-out';
 
+const SENSOR_BUS_NAME = 'net.hadess.SensorProxy';
+const SENSOR_OBJECT_PATH = '/net/hadess/SensorProxy';
+
+const SensorProxyInterface = '<node> \
+<interface name="net.hadess.SensorProxy"> \
+  <property name="HasAccelerometer" type="b" access="read"/> \
+</interface> \
+</node>';
+
+const SensorProxy = Gio.DBusProxy.makeProxyWrapper(SensorProxyInterface);
+
 const AltSwitcher = new Lang.Class({
     Name: 'AltSwitcher',
 
@@ -144,23 +155,32 @@ const Indicator = new Lang.Class({
 
         this._orientationSettings.connect('changed::orientation-lock',
                                           Lang.bind(this, this._updateOrientationLock));
-        this._orientationExists = false;
-        Gio.DBus.session.watch_name('org.gnome.SettingsDaemon.Orientation',
-                                    Gio.BusNameWatcherFlags.NONE,
-                                    Lang.bind(this, function() {
-                                        this._orientationExists = true;
-                                        this._updateOrientationLock();
-                                    }),
-                                    Lang.bind(this, function() {
-                                        this._orientationExists = false;
-                                        this._updateOrientationLock();
-                                    }));
+        Gio.DBus.system.watch_name(SENSOR_BUS_NAME,
+                                   Gio.BusNameWatcherFlags.NONE,
+                                   Lang.bind(this, this._sensorProxyAppeared),
+                                   Lang.bind(this, function() {
+                                       this._sensorProxy = null;
+                                       this._updateOrientationLock();
+                                   }));
         this._updateOrientationLock();
 
         Main.sessionMode.connect('updated', Lang.bind(this, this._sessionUpdated));
         this._sessionUpdated();
     },
 
+    _sensorProxyAppeared: function() {
+        this._sensorProxy = new SensorProxy(Gio.DBus.system, SENSOR_BUS_NAME, SENSOR_OBJECT_PATH,
+            Lang.bind(this, function(proxy, error) {
+                if (error) {
+                    log(error.message);
+                    return;
+                }
+                this._sensorProxy.connect('g-properties-changed',
+                                          Lang.bind(this, this._updateOrientationLock));
+                this._updateOrientationLock();
+            }));
+    },
+
     _updateActionsVisibility: function() {
         let visible = (this._settingsAction.visible ||
                        this._orientationLockAction.visible ||
@@ -237,7 +257,10 @@ const Indicator = new Lang.Class({
     },
 
     _updateOrientationLock: function() {
-        this._orientationLockAction.visible = this._orientationExists;
+        if (this._sensorProxy)
+            this._orientationLockAction.visible = this._sensorProxy.HasAccelerometer;
+        else
+            this._orientationLockAction.visible = false;
 
         let locked = this._orientationSettings.get_boolean('orientation-lock');
         let icon = this._orientationLockAction.child;


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