2013-04-23 19:26:05 -04:00
|
|
|
// -*- 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';
|
|
|
|
|
2013-10-24 17:51:58 -04:00
|
|
|
const BrightnessInterface = '<node> \
|
|
|
|
<interface name="org.gnome.SettingsDaemon.Power.Screen"> \
|
|
|
|
<property name="Brightness" type="i" access="readwrite"/> \
|
|
|
|
</interface> \
|
|
|
|
</node>';
|
2013-04-23 19:26:05 -04:00
|
|
|
|
|
|
|
const BrightnessProxy = Gio.DBusProxy.makeProxyWrapper(BrightnessInterface);
|
|
|
|
|
2017-07-18 13:41:25 -04:00
|
|
|
var Indicator = new Lang.Class({
|
2013-04-23 19:26:05 -04:00
|
|
|
Name: 'BrightnessIndicator',
|
|
|
|
Extends: PanelMenu.SystemIndicator,
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_init() {
|
2013-04-23 19:26:05 -04:00
|
|
|
this.parent('display-brightness-symbolic');
|
|
|
|
this._proxy = new BrightnessProxy(Gio.DBus.session, BUS_NAME, OBJECT_PATH,
|
2017-10-30 20:38:18 -04:00
|
|
|
(proxy, error) => {
|
2013-04-23 19:26:05 -04:00
|
|
|
if (error) {
|
|
|
|
log(error.message);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-01 19:27:35 -05:00
|
|
|
this._proxy.connect('g-properties-changed', this._sync.bind(this));
|
2013-04-23 19:26:05 -04:00
|
|
|
this._sync();
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2013-04-23 19:26:05 -04:00
|
|
|
|
|
|
|
this._item = new PopupMenu.PopupBaseMenuItem({ activate: false });
|
|
|
|
this.menu.addMenuItem(this._item);
|
|
|
|
|
|
|
|
this._slider = new Slider.Slider(0);
|
2017-12-01 19:27:35 -05:00
|
|
|
this._slider.connect('value-changed', this._sliderChanged.bind(this));
|
2013-08-21 12:24:30 -04:00
|
|
|
this._slider.actor.accessible_name = _("Brightness");
|
2013-04-23 19:26:05 -04:00
|
|
|
|
|
|
|
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 });
|
2017-10-30 20:38:18 -04:00
|
|
|
this._item.actor.connect('button-press-event', (actor, event) => {
|
2013-11-29 13:17:34 -05:00
|
|
|
return this._slider.startDragging(event);
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
|
|
|
this._item.actor.connect('key-press-event', (actor, event) => {
|
2013-08-22 07:15:00 -04:00
|
|
|
return this._slider.onKeyPressEvent(actor, event);
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2013-08-22 07:15:00 -04:00
|
|
|
|
2013-04-23 19:26:05 -04:00
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_sliderChanged(slider, value) {
|
2013-04-23 19:26:05 -04:00
|
|
|
let percent = value * 100;
|
|
|
|
this._proxy.Brightness = percent;
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_sync() {
|
2013-04-23 19:26:05 -04:00
|
|
|
let visible = this._proxy.Brightness >= 0;
|
|
|
|
this._item.actor.visible = visible;
|
|
|
|
if (visible)
|
|
|
|
this._slider.setValue(this._proxy.Brightness / 100.0);
|
|
|
|
},
|
|
|
|
});
|