diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 15:07:22 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 15:07:22 +0000 |
commit | f9d480cfe50ca1d7a0f0b5a2b8bb9932962bfbe7 (patch) | |
tree | ce9e8db2d4e8799780fa72ae8f1953039373e2ee /js/ui/status/brightness.js | |
parent | Initial commit. (diff) | |
download | gnome-shell-upstream.tar.xz gnome-shell-upstream.zip |
Adding upstream version 3.38.6.upstream/3.38.6upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | js/ui/status/brightness.js | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/js/ui/status/brightness.js b/js/ui/status/brightness.js new file mode 100644 index 0000000..1724788 --- /dev/null +++ b/js/ui/status/brightness.js @@ -0,0 +1,73 @@ +// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*- +/* exported Indicator */ + +const { Gio, GObject, St } = imports.gi; + +const PanelMenu = imports.ui.panelMenu; +const PopupMenu = imports.ui.popupMenu; +const Slider = imports.ui.slider; + +const { loadInterfaceXML } = imports.misc.fileUtils; + +const BUS_NAME = 'org.gnome.SettingsDaemon.Power'; +const OBJECT_PATH = '/org/gnome/SettingsDaemon/Power'; + +const BrightnessInterface = loadInterfaceXML('org.gnome.SettingsDaemon.Power.Screen'); +const BrightnessProxy = Gio.DBusProxy.makeProxyWrapper(BrightnessInterface); + +var Indicator = GObject.registerClass( +class Indicator extends PanelMenu.SystemIndicator { + _init() { + super._init(); + this._proxy = new BrightnessProxy(Gio.DBus.session, BUS_NAME, OBJECT_PATH, + (proxy, error) => { + if (error) { + log(error.message); + return; + } + + this._proxy.connect('g-properties-changed', this._sync.bind(this)); + this._sync(); + }); + + this._item = new PopupMenu.PopupBaseMenuItem({ activate: false }); + this.menu.addMenuItem(this._item); + + this._slider = new Slider.Slider(0); + this._sliderChangedId = this._slider.connect('notify::value', + this._sliderChanged.bind(this)); + this._slider.accessible_name = _("Brightness"); + + let icon = new St.Icon({ icon_name: 'display-brightness-symbolic', + style_class: 'popup-menu-icon' }); + this._item.add(icon); + this._item.add_child(this._slider); + this._item.connect('button-press-event', (actor, event) => { + return this._slider.startDragging(event); + }); + this._item.connect('key-press-event', (actor, event) => { + return this._slider.emit('key-press-event', event); + }); + this._item.connect('scroll-event', (actor, event) => { + return this._slider.emit('scroll-event', event); + }); + } + + _sliderChanged() { + let percent = this._slider.value * 100; + this._proxy.Brightness = percent; + } + + _changeSlider(value) { + this._slider.block_signal_handler(this._sliderChangedId); + this._slider.value = value; + this._slider.unblock_signal_handler(this._sliderChangedId); + } + + _sync() { + let visible = this._proxy.Brightness >= 0; + this._item.visible = visible; + if (visible) + this._changeSlider(this._proxy.Brightness / 100.0); + } +}); |