[gnome-shell] status: Add new brightness slider widget



commit cb09ae5cc0fc377550d8e9d123db60ea6a2aee14
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Tue Apr 23 19:26:05 2013 -0400

    status: Add new brightness slider widget
    
    This is a simple slider that shows the current brightness of the
    screen, and offers a way to change it.
    
    This is a part of the new system status design, see
    https://wiki.gnome.org/GnomeShell/Design/Guidelines/SystemStatus/
    for design details.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=705845

 js/Makefile.am             |    1 +
 js/ui/panel.js             |    2 +
 js/ui/status/brightness.js |   63 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 66 insertions(+), 0 deletions(-)
---
diff --git a/js/Makefile.am b/js/Makefile.am
index e750db1..cfaf104 100644
--- a/js/Makefile.am
+++ b/js/Makefile.am
@@ -89,6 +89,7 @@ nobase_dist_js_DATA =         \
        ui/searchDisplay.js     \
        ui/shellDBus.js         \
        ui/status/accessibility.js      \
+       ui/status/brightness.js \
        ui/status/keyboard.js   \
        ui/status/network.js    \
        ui/status/power.js      \
diff --git a/js/ui/panel.js b/js/ui/panel.js
index 2eea063..1ded175 100644
--- a/js/ui/panel.js
+++ b/js/ui/panel.js
@@ -855,6 +855,7 @@ const AggregateMenu = new Lang.Class({
         this._power = new imports.ui.status.power.Indicator();
         this._rfkill = new imports.ui.status.rfkill.Indicator();
         this._volume = new imports.ui.status.volume.Indicator();
+        this._brightness = new imports.ui.status.brightness.Indicator();
         this._system = new imports.ui.status.system.Indicator();
 
         this._indicators.add_child(this._network.indicators);
@@ -867,6 +868,7 @@ const AggregateMenu = new Lang.Class({
                                                   y_align: Clutter.ActorAlign.CENTER }));
 
         this.menu.addMenuItem(this._volume.menu);
+        this.menu.addMenuItem(this._brightness.menu);
         this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
         this.menu.addMenuItem(this._network.menu);
         this.menu.addMenuItem(this._bluetooth.menu);
diff --git a/js/ui/status/brightness.js b/js/ui/status/brightness.js
new file mode 100644
index 0000000..5e58630
--- /dev/null
+++ b/js/ui/status/brightness.js
@@ -0,0 +1,63 @@
+// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
+
+const Lang = imports.lang;
+const Gio = imports.gi.Gio;
+const St = imports.gi.St;
+
+const PanelMenu = imports.ui.panelMenu;
+const PopupMenu = imports.ui.popupMenu;
+const Slider = imports.ui.slider;
+
+const BUS_NAME = 'org.gnome.SettingsDaemon.Power';
+const OBJECT_PATH = '/org/gnome/SettingsDaemon/Power';
+
+const BrightnessInterface = <interface name="org.gnome.SettingsDaemon.Power.Screen">
+<property name='Brightness' type='i' access='readwrite'/>
+</interface>;
+
+const BrightnessProxy = Gio.DBusProxy.makeProxyWrapper(BrightnessInterface);
+
+const Indicator = new Lang.Class({
+    Name: 'BrightnessIndicator',
+    Extends: PanelMenu.SystemIndicator,
+
+    _init: function() {
+        this.parent('display-brightness-symbolic');
+        this._proxy = new BrightnessProxy(Gio.DBus.session, BUS_NAME, OBJECT_PATH,
+                                          Lang.bind(this, function(proxy, error) {
+                                              if (error) {
+                                                  log(error.message);
+                                                  return;
+                                              }
+
+                                              this._proxy.connect('g-properties-changed', Lang.bind(this, 
this._sync));
+                                              this._sync();
+                                          }));
+
+        this._item = new PopupMenu.PopupBaseMenuItem({ activate: false });
+        this.menu.addMenuItem(this._item);
+
+        this._slider = new Slider.Slider(0);
+        this._slider.connect('value-changed', Lang.bind(this, this._sliderChanged));
+
+        let icon = new St.Icon({ icon_name: 'display-brightness-symbolic',
+                                 style_class: 'popup-menu-icon' });
+        this._item.actor.add(icon);
+        this._item.actor.add(this._slider.actor, { expand: true });
+        this._item.actor.connect('button-press-event', Lang.bind(this, function(actor, event) {
+            this._slider.startDragging(event);
+        }));
+    },
+
+    _sliderChanged: function(slider, value) {
+        let percent = value * 100;
+        this._proxy.Brightness = percent;
+    },
+
+    _sync: function() {
+        let visible = this._proxy.Brightness >= 0;
+        this._item.actor.visible = visible;
+        if (visible)
+            this._slider.setValue(this._proxy.Brightness / 100.0);
+    },
+});


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