2013-04-23 19:26:05 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2019-01-31 09:07:06 -05:00
|
|
|
/* exported Indicator */
|
2013-04-23 19:26:05 -04:00
|
|
|
|
2019-02-08 22:21:36 -05:00
|
|
|
const { Gio, St } = imports.gi;
|
2013-04-23 19:26:05 -04:00
|
|
|
|
|
|
|
const PanelMenu = imports.ui.panelMenu;
|
|
|
|
const PopupMenu = imports.ui.popupMenu;
|
|
|
|
const Slider = imports.ui.slider;
|
|
|
|
|
2018-09-05 20:55:20 -04:00
|
|
|
const { loadInterfaceXML } = imports.misc.fileUtils;
|
|
|
|
|
2013-04-23 19:26:05 -04:00
|
|
|
const BUS_NAME = 'org.gnome.SettingsDaemon.Power';
|
|
|
|
const OBJECT_PATH = '/org/gnome/SettingsDaemon/Power';
|
|
|
|
|
2018-09-05 20:55:20 -04:00
|
|
|
const BrightnessInterface = loadInterfaceXML('org.gnome.SettingsDaemon.Power.Screen');
|
2013-04-23 19:26:05 -04:00
|
|
|
const BrightnessProxy = Gio.DBusProxy.makeProxyWrapper(BrightnessInterface);
|
|
|
|
|
2017-10-30 21:19:44 -04:00
|
|
|
var Indicator = class extends PanelMenu.SystemIndicator {
|
|
|
|
constructor() {
|
|
|
|
super('display-brightness-symbolic');
|
2013-04-23 19:26:05 -04:00
|
|
|
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);
|
2019-07-25 12:53:00 -04:00
|
|
|
this._slider.connect('notify::value', this._sliderChanged.bind(this));
|
|
|
|
this._slider.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' });
|
2019-04-12 17:00:49 -04:00
|
|
|
this._item.add(icon);
|
2019-07-25 12:53:00 -04:00
|
|
|
this._item.add(this._slider, { expand: true });
|
2019-04-12 17:00:49 -04:00
|
|
|
this._item.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
|
|
|
});
|
2019-04-12 17:00:49 -04:00
|
|
|
this._item.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
|
|
|
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-04-23 19:26:05 -04:00
|
|
|
|
2019-07-25 12:53:00 -04:00
|
|
|
_sliderChanged() {
|
|
|
|
let percent = this._slider.value * 100;
|
2013-04-23 19:26:05 -04:00
|
|
|
this._proxy.Brightness = percent;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-04-23 19:26:05 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_sync() {
|
2013-04-23 19:26:05 -04:00
|
|
|
let visible = this._proxy.Brightness >= 0;
|
2019-04-12 17:00:49 -04:00
|
|
|
this._item.visible = visible;
|
2013-04-23 19:26:05 -04:00
|
|
|
if (visible)
|
2019-07-25 11:33:00 -04:00
|
|
|
this._slider.value = this._proxy.Brightness / 100.0;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
|
|
|
};
|