From 85b5aec742ea5766a7496e6a1584e8423c993ca2 Mon Sep 17 00:00:00 2001 From: Marco Allegretti Date: Sat, 9 May 2026 10:00:36 +0200 Subject: [PATCH] Expose power profiles in battery tile Use the existing power profile control in the battery quick setting so users can see and cycle available profiles without opening settings. --- quicksettings/battery/contents/ui/main.qml | 52 ++++++++++++++++++++-- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/quicksettings/battery/contents/ui/main.qml b/quicksettings/battery/contents/ui/main.qml index c6540b0d..4ae535d0 100644 --- a/quicksettings/battery/contents/ui/main.qml +++ b/quicksettings/battery/contents/ui/main.qml @@ -5,11 +5,57 @@ import QtQuick 2.15 import org.kde.plasma.private.mobileshell.quicksettingsplugin as QS import org.kde.plasma.private.mobileshell as MobileShell +import org.kde.plasma.private.mobileshell.gamingshellplugin as GamingShell QS.QuickSetting { + id: root + + readonly property var profileOrder: ["power-saver", "balanced", "performance"] + readonly property bool profileAvailable: GamingShell.PowerProfileControl.available + && GamingShell.PowerProfileControl.profiles.length > 0 + property var toggle: profileAvailable ? root.cycleProfile : undefined + text: i18n("Battery") - status: i18n("%1%", MobileShell.BatteryInfo.percent) - icon: "battery-full" + (MobileShell.BatteryInfo.pluggedIn ? "-charging" : "") - enabled: false + status: profileAvailable + ? i18n("%1% - %2", MobileShell.BatteryInfo.percent, profileLabel(GamingShell.PowerProfileControl.activeProfile)) + : i18n("%1%", MobileShell.BatteryInfo.percent) + icon: profileAvailable ? profileIcon(GamingShell.PowerProfileControl.activeProfile) + : "battery-full" + (MobileShell.BatteryInfo.pluggedIn ? "-charging" : "") + enabled: profileAvailable && GamingShell.PowerProfileControl.activeProfile !== "balanced" settingsCommand: "plasma-open-settings kcm_mobile_power" + + function profileLabel(profile) { + switch (profile) { + case "performance": return i18n("Performance") + case "balanced": return i18n("Balanced") + case "power-saver": return i18n("Power Saver") + default: return profile + } + } + + function profileIcon(profile) { + switch (profile) { + case "performance": return "speedometer" + case "power-saver": return "battery-profile-powersave" + default: return "battery-full" + (MobileShell.BatteryInfo.pluggedIn ? "-charging" : "") + } + } + + function cycleProfile() { + let availableProfiles = [] + for (let i = 0; i < profileOrder.length; ++i) { + let profile = profileOrder[i] + if (GamingShell.PowerProfileControl.profiles.indexOf(profile) >= 0) { + availableProfiles.push(profile) + } + } + + if (availableProfiles.length === 0) { + return + } + + let currentIndex = availableProfiles.indexOf(GamingShell.PowerProfileControl.activeProfile) + let nextIndex = currentIndex < 0 ? 0 : (currentIndex + 1) % availableProfiles.length + GamingShell.PowerProfileControl.activeProfile = availableProfiles[nextIndex] + } }