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
|
|
|
|
2023-06-08 00:52:46 -04:00
|
|
|
const Gio = imports.gi.Gio;
|
|
|
|
const GObject = imports.gi.GObject;
|
|
|
|
|
2013-04-23 19:26:05 -04:00
|
|
|
|
2022-07-29 18:41:00 -04:00
|
|
|
const {QuickSlider, SystemIndicator} = imports.ui.quickSettings;
|
2013-04-23 19:26:05 -04:00
|
|
|
|
2022-07-29 18:41:00 -04:00
|
|
|
const {loadInterfaceXML} = imports.misc.fileUtils;
|
2018-09-05 20:55:20 -04:00
|
|
|
|
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);
|
|
|
|
|
2022-07-29 18:41:00 -04:00
|
|
|
const BrightnessItem = GObject.registerClass(
|
|
|
|
class BrightnessItem extends QuickSlider {
|
2019-07-16 05:24:13 -04:00
|
|
|
_init() {
|
2022-07-29 18:41:00 -04:00
|
|
|
super._init({
|
|
|
|
iconName: 'display-brightness-symbolic',
|
|
|
|
});
|
|
|
|
|
2013-04-23 19:26:05 -04:00
|
|
|
this._proxy = new BrightnessProxy(Gio.DBus.session, BUS_NAME, OBJECT_PATH,
|
2022-07-30 07:07:31 -04:00
|
|
|
(proxy, error) => {
|
|
|
|
if (error)
|
|
|
|
console.error(error.message);
|
|
|
|
else
|
|
|
|
this._proxy.connect('g-properties-changed', () => this._sync());
|
|
|
|
this._sync();
|
|
|
|
});
|
2013-04-23 19:26:05 -04:00
|
|
|
|
2022-07-29 18:41:00 -04:00
|
|
|
this._sliderChangedId = this.slider.connect('notify::value',
|
2019-08-12 08:10:43 -04:00
|
|
|
this._sliderChanged.bind(this));
|
2022-07-29 18:41:00 -04:00
|
|
|
this.slider.accessible_name = _('Brightness');
|
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() {
|
2022-07-29 18:41:00 -04:00
|
|
|
const 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
|
|
|
|
2019-08-12 08:10:43 -04:00
|
|
|
_changeSlider(value) {
|
2022-07-29 18:41:00 -04:00
|
|
|
this.slider.block_signal_handler(this._sliderChangedId);
|
|
|
|
this.slider.value = value;
|
|
|
|
this.slider.unblock_signal_handler(this._sliderChangedId);
|
2019-08-12 08:10:43 -04:00
|
|
|
}
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_sync() {
|
2022-07-30 08:34:12 -04:00
|
|
|
const brightness = this._proxy.Brightness;
|
|
|
|
const visible = Number.isInteger(brightness) && brightness >= 0;
|
2022-07-29 18:41:00 -04:00
|
|
|
this.visible = visible;
|
2013-04-23 19:26:05 -04:00
|
|
|
if (visible)
|
2019-08-12 08:10:43 -04:00
|
|
|
this._changeSlider(this._proxy.Brightness / 100.0);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2019-07-16 05:24:13 -04:00
|
|
|
});
|
2022-07-29 18:41:00 -04:00
|
|
|
|
|
|
|
var Indicator = GObject.registerClass(
|
|
|
|
class Indicator extends SystemIndicator {
|
|
|
|
_init() {
|
|
|
|
super._init();
|
|
|
|
|
|
|
|
this.quickSettingsItems.push(new BrightnessItem());
|
|
|
|
}
|
|
|
|
});
|