mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
gex: Add slider for charge control
This commit is contained in:
@@ -7,9 +7,9 @@
|
|||||||
<key type="b" name="panel-od-enabled">
|
<key type="b" name="panel-od-enabled">
|
||||||
<default>false</default>
|
<default>false</default>
|
||||||
</key>
|
</key>
|
||||||
<key type="b" name="supernotice">
|
<key name="charge-level" type="u">
|
||||||
<default>false</default>
|
<range min="20" max="100"/>
|
||||||
<summary>hide the supergfxctl-gex notice</summary>
|
<default>100</default>
|
||||||
</key>
|
</key>
|
||||||
</schema>
|
</schema>
|
||||||
</schemalist>
|
</schemalist>
|
||||||
@@ -13,14 +13,16 @@ import { Platform } from './modules/dbus/platform';
|
|||||||
import { QuickPanelOd } from './modules/quick_toggles/panel_od';
|
import { QuickPanelOd } from './modules/quick_toggles/panel_od';
|
||||||
import { IndicateMiniLed } from './modules/indicators/mini_led';
|
import { IndicateMiniLed } from './modules/indicators/mini_led';
|
||||||
import { QuickMiniLed } from './modules/quick_toggles/mini_led';
|
import { QuickMiniLed } from './modules/quick_toggles/mini_led';
|
||||||
|
import { SliderChargeLevel } from './modules/sliders/charge';
|
||||||
|
|
||||||
class Extension {
|
class Extension {
|
||||||
private _indicateMiniLed: typeof IndicateMiniLed;
|
private _indicateMiniLed: typeof IndicateMiniLed;
|
||||||
private _quickMiniLed: typeof QuickMiniLed;
|
private _quickMiniLed: typeof QuickMiniLed;
|
||||||
private _quickPanelOd: typeof QuickPanelOd;
|
private _quickPanelOd: typeof QuickPanelOd;
|
||||||
private _dbus_power!: Power;
|
private _sliderCharge: typeof SliderChargeLevel;
|
||||||
private _dbus_anime!: AnimeDbus;
|
|
||||||
|
|
||||||
|
public _dbus_power!: Power;
|
||||||
|
public _dbus_anime!: AnimeDbus;
|
||||||
public dbus_platform!: Platform;
|
public dbus_platform!: Platform;
|
||||||
public dbus_supported!: Supported;
|
public dbus_supported!: Supported;
|
||||||
|
|
||||||
@@ -28,6 +30,7 @@ class Extension {
|
|||||||
this._indicateMiniLed = null;
|
this._indicateMiniLed = null;
|
||||||
this._quickMiniLed = null;
|
this._quickMiniLed = null;
|
||||||
this._quickPanelOd = null;
|
this._quickPanelOd = null;
|
||||||
|
this._sliderCharge = null;
|
||||||
|
|
||||||
this.dbus_supported = new Supported();
|
this.dbus_supported = new Supported();
|
||||||
this.dbus_supported.start();
|
this.dbus_supported.start();
|
||||||
@@ -56,6 +59,11 @@ class Extension {
|
|||||||
this._quickPanelOd = new QuickPanelOd(this.dbus_platform);
|
this._quickPanelOd = new QuickPanelOd(this.dbus_platform);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (this.dbus_supported.supported.charge_ctrl.charge_level_set) {
|
||||||
|
if (this._sliderCharge == null) {
|
||||||
|
this._sliderCharge = new SliderChargeLevel(this._dbus_power);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
disable() {
|
disable() {
|
||||||
@@ -71,6 +79,10 @@ class Extension {
|
|||||||
this._quickPanelOd.destroy();
|
this._quickPanelOd.destroy();
|
||||||
this._quickPanelOd = null;
|
this._quickPanelOd = null;
|
||||||
}
|
}
|
||||||
|
if (this._sliderCharge != null) {
|
||||||
|
this._sliderCharge.destroy();
|
||||||
|
this._sliderCharge = null;
|
||||||
|
}
|
||||||
|
|
||||||
this._dbus_power.stop();
|
this._dbus_power.stop();
|
||||||
this.dbus_platform.stop();
|
this.dbus_platform.stop();
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ declare const imports: any;
|
|||||||
const { QuickToggle } = imports.ui.quickSettings;
|
const { QuickToggle } = imports.ui.quickSettings;
|
||||||
const QuickSettingsMenu = imports.ui.main.panel.statusArea.quickSettings;
|
const QuickSettingsMenu = imports.ui.main.panel.statusArea.quickSettings;
|
||||||
|
|
||||||
export function addQuickSettingsItems(items: [typeof QuickToggle]) {
|
export function addQuickSettingsItems(items: [typeof QuickToggle], width = 1) {
|
||||||
// Add the items with the built-in function
|
// Add the items with the built-in function
|
||||||
QuickSettingsMenu._addItems(items);
|
QuickSettingsMenu._addItems(items, width);
|
||||||
|
|
||||||
// Ensure the tile(s) are above the background apps menu
|
// Ensure the tile(s) are above the background apps menu
|
||||||
for (const item of items) {
|
for (const item of items) {
|
||||||
|
|||||||
60
desktop-extensions/gnome/src/modules/sliders/charge.ts
Normal file
60
desktop-extensions/gnome/src/modules/sliders/charge.ts
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
import { Power } from "../dbus/power";
|
||||||
|
import { addQuickSettingsItems } from "../helpers";
|
||||||
|
|
||||||
|
declare const imports: any;
|
||||||
|
|
||||||
|
const { GObject } = imports.gi;
|
||||||
|
const ExtensionUtils = imports.misc.extensionUtils;
|
||||||
|
const QuickSettings = imports.ui.quickSettings;
|
||||||
|
|
||||||
|
export const SliderChargeLevel = GObject.registerClass(
|
||||||
|
class SliderChargeLevel extends QuickSettings.QuickSlider {
|
||||||
|
private _dbus_power: Power;
|
||||||
|
|
||||||
|
constructor(dbus_power: Power) {
|
||||||
|
super({
|
||||||
|
iconName: 'selection-mode-symbolic',
|
||||||
|
});
|
||||||
|
this._dbus_power = dbus_power;
|
||||||
|
|
||||||
|
this._sliderChangedId = this.slider.connect('drag-end',
|
||||||
|
this._onSliderChanged.bind(this));
|
||||||
|
|
||||||
|
// Binding the slider to a GSettings key
|
||||||
|
this._settings = ExtensionUtils.getSettings();
|
||||||
|
|
||||||
|
this._settings.connect('changed::charge-level',
|
||||||
|
this._onSettingsChanged.bind(this));
|
||||||
|
|
||||||
|
// Set an accessible name for the slider
|
||||||
|
this.slider.accessible_name = 'Charge level';
|
||||||
|
|
||||||
|
this._sync();
|
||||||
|
this._onSettingsChanged();
|
||||||
|
|
||||||
|
addQuickSettingsItems([this], 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
_onSettingsChanged() {
|
||||||
|
// Prevent the slider from emitting a change signal while being updated
|
||||||
|
this.slider.block_signal_handler(this._sliderChangedId);
|
||||||
|
this.slider.value = this._settings.get_uint('charge-level') / 100.0;
|
||||||
|
this.slider.unblock_signal_handler(this._sliderChangedId);
|
||||||
|
}
|
||||||
|
|
||||||
|
_onSliderChanged() {
|
||||||
|
// Assuming our GSettings holds values between 0..100, adjust for the
|
||||||
|
// slider taking values between 0..1
|
||||||
|
const percent = Math.floor(this.slider.value * 100);
|
||||||
|
const stored = Math.floor(this._settings.get_uint('charge-level') / 100.0);
|
||||||
|
if (this.slider.value !== stored)
|
||||||
|
this._dbus_power.setChargingLimit(percent);
|
||||||
|
this._settings.set_uint('charge-level', percent);
|
||||||
|
}
|
||||||
|
|
||||||
|
_sync() {
|
||||||
|
const value = this._dbus_power.getChargingLimit();
|
||||||
|
if (this.slider.value !== value / 100)
|
||||||
|
this._settings.set_uint('charge-level', value);
|
||||||
|
}
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user