nova-shell/modules/PowerProfile.qml
2026-04-12 14:46:42 +02:00

58 lines
1.4 KiB
QML

import QtQuick
import Quickshell.Io
import "." as M
M.BarIcon {
id: root
tooltip: "Power profile: " + (root.profile || "unknown")
property string profile: ""
color: root.profile === "performance" ? M.Theme.base09
: root.profile === "power-saver" ? M.Theme.base0B
: M.Theme.base05
icon: {
if (root.profile === "performance")
return "\uF0E7";
if (root.profile === "power-saver")
return "\uF06C";
if (root.profile === "balanced")
return "\uF24E";
return "\uF0E7";
}
Process {
id: proc
running: true
command: ["powerprofilesctl", "get"]
stdout: StdioCollector {
onStreamFinished: root.profile = text.trim()
}
}
Timer {
interval: 5000
running: true
repeat: true
onTriggered: proc.running = true
}
Process {
id: setter
property string next: ""
command: ["powerprofilesctl", "set", next]
onRunningChanged: if (!running && next !== "")
proc.running = true
}
MouseArea {
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
onClicked: {
const cycle = ["performance", "balanced", "power-saver"];
const idx = cycle.indexOf(root.profile);
setter.next = cycle[(idx + 1) % cycle.length];
setter.running = true;
}
}
}