diff --git a/quickshell/Common/SettingsData.qml b/quickshell/Common/SettingsData.qml index 6a33471a..4451b2a2 100644 --- a/quickshell/Common/SettingsData.qml +++ b/quickshell/Common/SettingsData.qml @@ -261,6 +261,7 @@ Singleton { property int batterySuspendTimeout: 0 property int batterySuspendBehavior: SettingsData.SuspendBehavior.Suspend property string batteryProfileName: "" + property int batteryChargeLimit: 100 property bool lockBeforeSuspend: false property bool loginctlLockIntegration: true property bool fadeToLockEnabled: false diff --git a/quickshell/Common/settings/SettingsSpec.js b/quickshell/Common/settings/SettingsSpec.js index 486e5f19..7a272c5e 100644 --- a/quickshell/Common/settings/SettingsSpec.js +++ b/quickshell/Common/settings/SettingsSpec.js @@ -160,6 +160,7 @@ var SPEC = { batterySuspendTimeout: { def: 0 }, batterySuspendBehavior: { def: 0 }, batteryProfileName: { def: "" }, + batteryChargeLimit: { def: 100 }, lockBeforeSuspend: { def: false }, loginctlLockIntegration: { def: true }, fadeToLockEnabled: { def: false }, diff --git a/quickshell/Modules/Settings/PowerSleepTab.qml b/quickshell/Modules/Settings/PowerSleepTab.qml index 47135a76..b83df9d6 100644 --- a/quickshell/Modules/Settings/PowerSleepTab.qml +++ b/quickshell/Modules/Settings/PowerSleepTab.qml @@ -503,6 +503,24 @@ Item { } } } + + SettingsCard { + width: parent.width + iconName: "tune" + title: I18n.tr("Advanced") + collapsible: true + expanded: false + + SettingsSliderRow { + text: I18n.tr("Battery Charge Limit") + description: I18n.tr("Note: this only changes the percentage, it does not actually limit charging.") + value: SettingsData.batteryChargeLimit + minimum: 50 + maximum: 100 + defaultValue: 100 + onSliderValueChanged: newValue => SettingsData.set("batteryChargeLimit", newValue) + } + } } } } diff --git a/quickshell/Services/BatteryService.qml b/quickshell/Services/BatteryService.qml index edf90937..d1f3e737 100644 --- a/quickshell/Services/BatteryService.qml +++ b/quickshell/Services/BatteryService.qml @@ -12,6 +12,8 @@ Singleton { property bool suppressSound: true property bool previousPluggedState: false + readonly property var scale: 100 / SettingsData.batteryChargeLimit + Timer { id: startupTimer interval: 500 @@ -43,14 +45,14 @@ Singleton { return 0; if (batteryCapacity === 0) { if (usePreferred && device && device.ready) - return Math.round(device.percentage * 100); + return Math.round(device.percentage * 100 * scale); const validBatteries = batteries.filter(b => b.ready && b.percentage >= 0); if (validBatteries.length === 0) return 0; const avgPercentage = validBatteries.reduce((sum, b) => sum + b.percentage, 0) / validBatteries.length; - return Math.round(avgPercentage * 100); + return Math.round(avgPercentage * 100 * scale); } - return Math.round((batteryEnergy * 100) / batteryCapacity); + return Math.round((batteryEnergy * 100) / batteryCapacity * scale); } readonly property bool isCharging: batteryAvailable && batteries.some(b => b.state === UPowerDeviceState.Charging) diff --git a/quickshell/translations/en.json b/quickshell/translations/en.json index 37630466..a8c3c8f2 100644 --- a/quickshell/translations/en.json +++ b/quickshell/translations/en.json @@ -869,6 +869,12 @@ "reference": "Modules/Settings/WidgetsTabSection.qml:838, Modules/Settings/WidgetsTab.qml:168, Modules/ControlCenter/Models/WidgetModel.qml:161, Modules/ControlCenter/Widgets/BatteryPill.qml:17", "comment": "" }, + { + "term": "Battery Charge Limit", + "context": "Battery Charge Limit", + "reference": "Modules/Settings/PowerSleepTab.qml:515", + "comment": "" + }, { "term": "Battery and power management", "context": "Battery and power management", @@ -4799,6 +4805,12 @@ "reference": "Modules/Settings/NetworkTab.qml:744", "comment": "" }, + { + "term": "Note: this only changes the displayed percentage, it does not actually limit charging.", + "context": "Note: this only changes the displayed percentage, it does not actually limit charging.", + "reference": "Modules/Settings/PowerSleepTab.qml:516", + "comment": "" + }, { "term": "Notepad", "context": "Notepad", diff --git a/quickshell/translations/template.json b/quickshell/translations/template.json index 956e4818..e3fac51f 100644 --- a/quickshell/translations/template.json +++ b/quickshell/translations/template.json @@ -1014,6 +1014,13 @@ "reference": "", "comment": "" }, + { + "term": "Battery Charge Limit", + "translation": "", + "context": "", + "reference": "", + "comment": "" + }, { "term": "Battery and power management", "translation": "", @@ -5599,6 +5606,13 @@ "reference": "", "comment": "" }, + { + "term": "Note: this only changes the displayed percentage, it does not actually limit charging.", + "translation": "", + "context": "", + "reference": "", + "comment": "" + }, { "term": "Notepad", "translation": "",