diff --git a/js/Makefile.am b/js/Makefile.am index e750db1ff..cfaf1048c 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 2eea063bb..1ded175f3 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 000000000..5e586300e --- /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 = + +; + +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); + }, +});