61 lines
2.2 KiB
JavaScript
61 lines
2.2 KiB
JavaScript
|
/* extension.js
|
||
|
*
|
||
|
* This program is free software: you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU General Public License as published by
|
||
|
* the Free Software Foundation, either version 2 of the License, or
|
||
|
* (at your option) any later version.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU General Public License
|
||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
|
*
|
||
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
||
|
*/
|
||
|
import GObject from 'gi://GObject';
|
||
|
import GLib from 'gi://GLib';
|
||
|
import Gio from 'gi://Gio';
|
||
|
|
||
|
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
|
||
|
|
||
|
import {Extension, gettext as _} from 'resource:///org/gnome/shell/extensions/extension.js';
|
||
|
import {QuickSlider, SystemIndicator} from 'resource:///org/gnome/shell/ui/quickSettings.js';
|
||
|
|
||
|
const ScreenpadSlider = GObject.registerClass(
|
||
|
class ScreenpadSlider extends QuickSlider {
|
||
|
constructor() {
|
||
|
super({ iconName: 'keyboard-brightness-symbolic' });
|
||
|
|
||
|
this._sliderChangedId = this.slider.connect('notify::value', this._sliderChanged.bind(this));
|
||
|
this.slider.accessible_name = _('Screenpad');
|
||
|
this.slider.value = 0.5;
|
||
|
}
|
||
|
|
||
|
_sliderChanged() {
|
||
|
const byte = Math.round(this.slider.value * 255);
|
||
|
const brightness_file = Gio.File.new_for_path("/sys/class/leds/asus::screenpad/brightness");
|
||
|
brightness_file.replace_contents(new TextEncoder().encode(byte.toString()), null, false, Gio.FileCreateFlags.NONE, null);
|
||
|
}
|
||
|
}
|
||
|
)
|
||
|
|
||
|
export default class ScreenpadExtension extends Extension {
|
||
|
enable() {
|
||
|
this._slider = new SystemIndicator();
|
||
|
this._slider.quickSettingsItems.push(new ScreenpadSlider());
|
||
|
|
||
|
Main.panel.statusArea.quickSettings.addExternalIndicator(this._slider, 2);
|
||
|
}
|
||
|
|
||
|
disable() {
|
||
|
for (const item of this._slider.quickSettingsItems) {
|
||
|
item.destroy();
|
||
|
}
|
||
|
this._slider.destroy();
|
||
|
this._slider = null;
|
||
|
}
|
||
|
}
|