diff --git a/quickshell/Common/SettingsData.qml b/quickshell/Common/SettingsData.qml index 2bcd81e7..3697cdc2 100644 --- a/quickshell/Common/SettingsData.qml +++ b/quickshell/Common/SettingsData.qml @@ -248,10 +248,12 @@ Singleton { property int acLockTimeout: 0 property int acSuspendTimeout: 0 property int acSuspendBehavior: SettingsData.SuspendBehavior.Suspend + property string acProfileName: "" property int batteryMonitorTimeout: 0 property int batteryLockTimeout: 0 property int batterySuspendTimeout: 0 property int batterySuspendBehavior: SettingsData.SuspendBehavior.Suspend + property string batteryProfileName: "" property bool lockBeforeSuspend: false property bool preventIdleForMedia: false property bool loginctlLockIntegration: true diff --git a/quickshell/Common/settings/SettingsSpec.js b/quickshell/Common/settings/SettingsSpec.js index 535226c8..60edb2bd 100644 --- a/quickshell/Common/settings/SettingsSpec.js +++ b/quickshell/Common/settings/SettingsSpec.js @@ -147,10 +147,12 @@ var SPEC = { acLockTimeout: { def: 0 }, acSuspendTimeout: { def: 0 }, acSuspendBehavior: { def: 0 }, + acProfileName: { def: "" }, batteryMonitorTimeout: { def: 0 }, batteryLockTimeout: { def: 0 }, batterySuspendTimeout: { def: 0 }, batterySuspendBehavior: { def: 0 }, + batteryProfileName: { def: "" }, lockBeforeSuspend: { def: false }, preventIdleForMedia: { def: false }, loginctlLockIntegration: { def: true }, diff --git a/quickshell/Modules/Settings/PowerSleepTab.qml b/quickshell/Modules/Settings/PowerSleepTab.qml index 26087aa3..68d973d1 100644 --- a/quickshell/Modules/Settings/PowerSleepTab.qml +++ b/quickshell/Modules/Settings/PowerSleepTab.qml @@ -99,6 +99,43 @@ Item { SettingsData.set("fadeToLockGracePeriod", periodValues[index]); } } + SettingsDropdownRow { + id: powerProfileDropdown + property var profileOptions: [I18n.tr("Don't Change"), Theme.getPowerProfileLabel(0), Theme.getPowerProfileLabel(1), Theme.getPowerProfileLabel(2)] + property var profileValues: ["", "0", "1", "2"] + + width: parent.width + addHorizontalPadding: true + text: I18n.tr("Switch to power profile") + options: profileOptions + + Connections { + target: powerCategory + function onCurrentIndexChanged() { + const currentProfile = powerCategory.currentIndex === 0 ? SettingsData.acProfileName : SettingsData.batteryProfileName; + const index = powerProfileDropdown.profileValues.indexOf(currentProfile); + powerProfileDropdown.currentValue = powerProfileDropdown.profileOptions[index] + } + } + + Component.onCompleted: { + const currentProfile = powerCategory.currentIndex === 0 ? SettingsData.acProfileName : SettingsData.batteryProfileName; + const index = profileValues.indexOf(currentProfile); + currentValue = profileOptions[index] + } + + onValueChanged: value => { + const index = profileOptions.indexOf(value); + if (index >= 0) { + const profileValue = profileValues[index]; + if (powerCategory.currentIndex === 0) { + SettingsData.set("acProfileName", profileValue); + } else { + SettingsData.set("batteryProfileName", profileValue); + } + } + } + } Rectangle { width: parent.width diff --git a/quickshell/Services/BatteryService.qml b/quickshell/Services/BatteryService.qml index 4e8b613d..279394d7 100644 --- a/quickshell/Services/BatteryService.qml +++ b/quickshell/Services/BatteryService.qml @@ -72,6 +72,17 @@ Singleton { } } + const profileValue = BatteryService.isPluggedIn + ? SettingsData.acProfileName + : SettingsData.batteryProfileName; + + if (profileValue !== "") { + const targetProfile = parseInt(profileValue); + if (!isNaN(targetProfile) && PowerProfiles.profile !== targetProfile) { + PowerProfiles.profile = targetProfile; + } + } + previousPluggedState = isPluggedIn; }