[gnome-shell/wip/aggregate-menu: 4/17] status: Add new brightness slider widget



commit 6238d0437f0abb55e56e4b0a4b70c4c75b6996e1
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.

 js/Makefile.am             |    1 +
 js/ui/panel.js             |    2 +
 js/ui/status/brightness.js |   67 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 70 insertions(+), 0 deletions(-)
---
diff --git a/js/Makefile.am b/js/Makefile.am
index c8d6eea..5e5add4 100644
--- a/js/Makefile.am
+++ b/js/Makefile.am
@@ -88,6 +88,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 bfcdd97..4e9a7c5 100644
--- a/js/ui/panel.js
+++ b/js/ui/panel.js
@@ -860,6 +860,7 @@ const AggregateMenu = new Lang.Class({
         this._bluetooth = new imports.ui.status.bluetooth.Indicator();
         this._power = new imports.ui.status.power.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);
@@ -870,6 +871,7 @@ const AggregateMenu = new Lang.Class({
         this._indicators.add_child(new St.Label({ text: '\u25BE' }));
 
         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..c784ad1
--- /dev/null
+++ b/js/ui/status/brightness.js
@@ -0,0 +1,67 @@
+// -*- 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 BrightnessSlider = new Lang.Class({
+    Name: 'BrightnessSlider',
+
+    _init: function(proxy) {
+        this._proxy = proxy;
+        this._proxy.connect('g-properties-changed', Lang.bind(this, this._updateBrightness));
+
+        this.item = new PopupMenu.PopupBaseMenuItem({ activate: false });
+
+        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.addActor(icon, { align: St.Align.MIDDLE });
+        this.item.addActor(this._slider.actor, { expand: true });
+
+        this.item.actor.connect('button-press-event', Lang.bind(this, function(actor, event) {
+            this._slider.startDragging(event);
+        }));
+
+        this._updateBrightness();
+    },
+
+    _sliderChanged: function(slider, value) {
+        let percent = value * 100;
+        this._proxy.Brightness = percent;
+    },
+
+    _updateBrightness: function() {
+        let visible = this._proxy.Brightness >= 0;
+        this.item.actor.visible = visible;
+        if (visible)
+            this._slider.setValue(this._proxy.Brightness / 100.0);
+    },
+});
+
+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);
+        this._brightnessSlider = new BrightnessSlider(this._proxy);
+        this.menu.addMenuItem(this._brightnessSlider.item);
+    },
+});


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