[gnome-shell/wip/message-tray-menu: 22/25] status: Add new brightness slider widget



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

    status: Add new brightness slider widget

 js/Makefile.am             |    1 +
 js/ui/status/brightness.js |   72 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 73 insertions(+), 0 deletions(-)
---
diff --git a/js/Makefile.am b/js/Makefile.am
index a14b3f4..b4412a2 100644
--- a/js/Makefile.am
+++ b/js/Makefile.am
@@ -86,6 +86,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/lockScreenMenu.js     \
        ui/status/network.js    \
diff --git a/js/ui/status/brightness.js b/js/ui/status/brightness.js
new file mode 100644
index 0000000..501d36e
--- /dev/null
+++ b/js/ui/status/brightness.js
@@ -0,0 +1,72 @@
+// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
+
+const Clutter = imports.gi.Clutter;
+const Lang = imports.lang;
+const Gio = imports.gi.Gio;
+const St = imports.gi.St;
+const Signals = imports.signals;
+
+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='u' 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.section = new PopupMenu.PopupMenuSection();
+        this._item = new PopupMenu.PopupBaseMenuItem({ activate: false });
+
+        this._actor = new St.BoxLayout({ style_class: 'popup-slider-icon-menu-item' });
+
+        this._slider = new Slider.Slider(0);
+        this._slider.connect('value-changed', Lang.bind(this, this._sliderChanged));
+
+        this._actor.add(new St.Icon({ icon_name: 'display-brightness-symbolic', icon_size: 16 }));
+        this._actor.add(this._slider.actor, { expand: true });
+        this._actor.add(new St.Icon({ icon_name: 'display-brightness-symbolic', icon_size: 16 }));
+
+        this._item.addActor(this._actor, { span: -1, expand: true });
+        this.section.addMenuItem(this._item);
+
+        this._updateBrightness();
+    },
+
+    _updateVisibility: function() {
+        let visible = this._shouldBeVisible();
+        this.section.actor.visible = visible;
+    },
+
+    _sliderChanged: function(slider, value) {
+        let percent = value * 100;
+        this._proxy.Brightness = percent;
+    },
+
+    _updateBrightness: function() {
+        this._slider.setValue(this._proxy.Brightness);
+    },
+});
+
+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.section);
+    },
+});


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