From 1021a210cf94d6c65fe636efbaa725bac27ea19a Mon Sep 17 00:00:00 2001 From: Aaron Tulino Date: Fri, 3 Apr 2026 09:04:00 -0700 Subject: [PATCH] Change power profile by scrolling battery (#2142) Scrolling up "increases" the profile (Power Saver -> Balanced -> Performance). Supports touchpad. --- .../Modules/DankBar/Widgets/Battery.qml | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/quickshell/Modules/DankBar/Widgets/Battery.qml b/quickshell/Modules/DankBar/Widgets/Battery.qml index 17f3f988..51d4b546 100644 --- a/quickshell/Modules/DankBar/Widgets/Battery.qml +++ b/quickshell/Modules/DankBar/Widgets/Battery.qml @@ -1,4 +1,5 @@ import QtQuick +import Quickshell.Services.UPower import qs.Common import qs.Modules.Plugins import qs.Services @@ -10,6 +11,8 @@ BasePill { property bool batteryPopupVisible: false property var popoutTarget: null + property real touchpadAccumulator: 0 + readonly property int barPosition: { switch (axis?.edge) { case "top": @@ -119,5 +122,44 @@ BasePill { battery.triggerRipple(this, mouse.x, mouse.y); toggleBatteryPopup(); } + onWheel: wheel => { + var delta = wheel.angleDelta.y; + if (delta === 0) + return; + + // Check if this is a touchpad + if (delta !== 120 && delta !== -120) { + touchpadAccumulator += delta; + console.info("Acc: "+touchpadAccumulator); + if (Math.abs(touchpadAccumulator) < 500) + return; + delta = touchpadAccumulator; + touchpadAccumulator = 0; + } + console.info("Trigger! Delta: "+delta) + + // This is after the other delta checks so it only shows on valid Y scroll + if (typeof PowerProfiles === "undefined") { + ToastService.showError("power-profiles-daemon not available"); + return; + } + + // Get list of profiles, and current index + const profiles = [PowerProfile.PowerSaver, PowerProfile.Balanced].concat(PowerProfiles.hasPerformanceProfile ? [PowerProfile.Performance] : []); + var index = profiles.findIndex(profile => PowerProfiles.profile === profile); + + // Step once based on mouse wheel direction + if (delta > 0) index += 1; + else index -= 1; + + // Already at end of list, can't go further + if (index < 0 || index >= profiles.length) return; + + // Set new profile + PowerProfiles.profile = profiles[index]; + if (PowerProfiles.profile !== profiles[index]) { + ToastService.showError("Failed to set power profile"); + } + } } }