2013-04-23 23:26:05 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2019-01-31 14:07:06 +00:00
|
|
|
/* exported Indicator */
|
2013-04-23 23:26:05 +00:00
|
|
|
|
2019-08-12 12:10:43 +00:00
|
|
|
const { Gio, GObject, St } = imports.gi;
|
2013-04-23 23:26:05 +00:00
|
|
|
|
|
|
|
const PanelMenu = imports.ui.panelMenu;
|
|
|
|
const PopupMenu = imports.ui.popupMenu;
|
|
|
|
const Slider = imports.ui.slider;
|
|
|
|
|
2018-09-06 00:55:20 +00:00
|
|
|
const { loadInterfaceXML } = imports.misc.fileUtils;
|
|
|
|
|
2013-04-23 23:26:05 +00:00
|
|
|
const BUS_NAME = 'org.gnome.SettingsDaemon.Power';
|
|
|
|
const OBJECT_PATH = '/org/gnome/SettingsDaemon/Power';
|
|
|
|
|
2018-09-06 00:55:20 +00:00
|
|
|
const BrightnessInterface = loadInterfaceXML('org.gnome.SettingsDaemon.Power.Screen');
|
2013-04-23 23:26:05 +00:00
|
|
|
const BrightnessProxy = Gio.DBusProxy.makeProxyWrapper(BrightnessInterface);
|
|
|
|
|
2019-10-28 18:35:33 +00:00
|
|
|
var Indicator = GObject.registerClass(
|
|
|
|
class Indicator extends PanelMenu.SystemIndicator {
|
2019-07-16 09:24:13 +00:00
|
|
|
_init() {
|
|
|
|
super._init();
|
2013-04-23 23:26:05 +00:00
|
|
|
this._proxy = new BrightnessProxy(Gio.DBus.session, BUS_NAME, OBJECT_PATH,
|
2017-10-31 00:38:18 +00:00
|
|
|
(proxy, error) => {
|
2013-04-23 23:26:05 +00:00
|
|
|
if (error) {
|
|
|
|
log(error.message);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-02 00:27:35 +00:00
|
|
|
this._proxy.connect('g-properties-changed', this._sync.bind(this));
|
2013-04-23 23:26:05 +00:00
|
|
|
this._sync();
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2013-04-23 23:26:05 +00:00
|
|
|
|
|
|
|
this._item = new PopupMenu.PopupBaseMenuItem({ activate: false });
|
|
|
|
this.menu.addMenuItem(this._item);
|
|
|
|
|
|
|
|
this._slider = new Slider.Slider(0);
|
2019-08-12 12:10:43 +00:00
|
|
|
this._sliderChangedId = this._slider.connect('notify::value',
|
|
|
|
this._sliderChanged.bind(this));
|
2019-07-25 16:53:00 +00:00
|
|
|
this._slider.accessible_name = _("Brightness");
|
2013-04-23 23:26:05 +00:00
|
|
|
|
2020-03-29 21:51:13 +00:00
|
|
|
const icon = new St.Icon({
|
|
|
|
icon_name: 'display-brightness-symbolic',
|
|
|
|
style_class: 'popup-menu-icon',
|
|
|
|
});
|
2019-04-12 21:00:49 +00:00
|
|
|
this._item.add(icon);
|
2019-10-21 18:44:00 +00:00
|
|
|
this._item.add_child(this._slider);
|
2019-04-12 21:00:49 +00:00
|
|
|
this._item.connect('button-press-event', (actor, event) => {
|
2013-11-29 18:17:34 +00:00
|
|
|
return this._slider.startDragging(event);
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2019-04-12 21:00:49 +00:00
|
|
|
this._item.connect('key-press-event', (actor, event) => {
|
2019-09-10 05:42:48 +00:00
|
|
|
return this._slider.emit('key-press-event', event);
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2020-05-16 13:04:32 +00:00
|
|
|
this._item.connect('scroll-event', (actor, event) => {
|
|
|
|
return this._slider.emit('scroll-event', event);
|
|
|
|
});
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-04-23 23:26:05 +00:00
|
|
|
|
2019-07-25 16:53:00 +00:00
|
|
|
_sliderChanged() {
|
|
|
|
let percent = this._slider.value * 100;
|
2013-04-23 23:26:05 +00:00
|
|
|
this._proxy.Brightness = percent;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-04-23 23:26:05 +00:00
|
|
|
|
2019-08-12 12:10:43 +00:00
|
|
|
_changeSlider(value) {
|
2019-10-30 17:11:56 +00:00
|
|
|
this._slider.block_signal_handler(this._sliderChangedId);
|
2019-08-12 12:10:43 +00:00
|
|
|
this._slider.value = value;
|
2019-10-30 17:11:56 +00:00
|
|
|
this._slider.unblock_signal_handler(this._sliderChangedId);
|
2019-08-12 12:10:43 +00:00
|
|
|
}
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_sync() {
|
2013-04-23 23:26:05 +00:00
|
|
|
let visible = this._proxy.Brightness >= 0;
|
2019-04-12 21:00:49 +00:00
|
|
|
this._item.visible = visible;
|
2013-04-23 23:26:05 +00:00
|
|
|
if (visible)
|
2019-08-12 12:10:43 +00:00
|
|
|
this._changeSlider(this._proxy.Brightness / 100.0);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2019-07-16 09:24:13 +00:00
|
|
|
});
|