mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-04-03 20:32:07 -04:00
Change power profile by scrolling battery (#2142)
Scrolling up "increases" the profile (Power Saver -> Balanced -> Performance). Supports touchpad.
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import QtQuick
|
import QtQuick
|
||||||
|
import Quickshell.Services.UPower
|
||||||
import qs.Common
|
import qs.Common
|
||||||
import qs.Modules.Plugins
|
import qs.Modules.Plugins
|
||||||
import qs.Services
|
import qs.Services
|
||||||
@@ -10,6 +11,8 @@ BasePill {
|
|||||||
property bool batteryPopupVisible: false
|
property bool batteryPopupVisible: false
|
||||||
property var popoutTarget: null
|
property var popoutTarget: null
|
||||||
|
|
||||||
|
property real touchpadAccumulator: 0
|
||||||
|
|
||||||
readonly property int barPosition: {
|
readonly property int barPosition: {
|
||||||
switch (axis?.edge) {
|
switch (axis?.edge) {
|
||||||
case "top":
|
case "top":
|
||||||
@@ -119,5 +122,44 @@ BasePill {
|
|||||||
battery.triggerRipple(this, mouse.x, mouse.y);
|
battery.triggerRipple(this, mouse.x, mouse.y);
|
||||||
toggleBatteryPopup();
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user