add powermodes
This commit is contained in:
@@ -28,6 +28,19 @@ RowLayout {
|
||||
property string batStatus: ""
|
||||
property string batTime: "" // "H:MM" remaining, empty when unknown
|
||||
property string netIp: ""
|
||||
property string powerProfile: "balanced"
|
||||
|
||||
readonly property var profileIcons: ({
|
||||
"power-saver": "",
|
||||
"balanced": "",
|
||||
"performance": ""
|
||||
})
|
||||
|
||||
readonly property var profileColors: ({
|
||||
"power-saver": Colors.accent,
|
||||
"balanced": Colors.fg,
|
||||
"performance": Colors.warning
|
||||
})
|
||||
|
||||
// ── Line parser ───────────────────────────────────────────────────────────
|
||||
function parseLine(line) {
|
||||
@@ -64,6 +77,37 @@ RowLayout {
|
||||
}
|
||||
}
|
||||
|
||||
// ── Power profile ─────────────────────────────────────────────────────────
|
||||
Process {
|
||||
id: getPowerProc
|
||||
command: ["powerprofilesctl", "get"]
|
||||
running: true
|
||||
stdout: SplitParser {
|
||||
onRead: data => {
|
||||
const p = data.trim();
|
||||
if (p.length > 0) root.powerProfile = p;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Process {
|
||||
id: setPowerProc
|
||||
property string target: ""
|
||||
command: ["powerprofilesctl", "set", setPowerProc.target]
|
||||
onExited: (code, status) => {
|
||||
if (code === 0) getPowerProc.running = true;
|
||||
}
|
||||
}
|
||||
|
||||
function cycleProfile() {
|
||||
const profiles = ["power-saver", "balanced", "performance"];
|
||||
const idx = profiles.indexOf(powerProfile);
|
||||
const next = profiles[(idx + 1) % profiles.length];
|
||||
powerProfile = next;
|
||||
setPowerProc.target = next;
|
||||
setPowerProc.running = true;
|
||||
}
|
||||
|
||||
// ── Process ───────────────────────────────────────────────────────────────
|
||||
Process {
|
||||
id: statsProc
|
||||
@@ -174,15 +218,37 @@ RowLayout {
|
||||
}
|
||||
}
|
||||
|
||||
// ── CPU load average ──────────────────────────────────────────────────────
|
||||
RowLayout {
|
||||
spacing: 4
|
||||
Text { text: ""; color: Colors.fg; font.pixelSize: 15 }
|
||||
Text {
|
||||
text: root.loadAvg.toFixed(2)
|
||||
color: root.loadAvg > root.cpuCores ? Colors.critical :
|
||||
root.loadAvg > root.cpuCores * 0.7 ? Colors.warning : Colors.fg
|
||||
font.pixelSize: 13
|
||||
// ── CPU load average + power profile ─────────────────────────────────────
|
||||
Item {
|
||||
implicitWidth: cpuRow.implicitWidth
|
||||
implicitHeight: cpuRow.implicitHeight
|
||||
|
||||
TapHandler {
|
||||
onTapped: root.cycleProfile()
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
id: cpuRow
|
||||
anchors.fill: parent
|
||||
spacing: 4
|
||||
|
||||
Text {
|
||||
text: ""
|
||||
color: Colors.fg
|
||||
font.pixelSize: 15
|
||||
}
|
||||
Text {
|
||||
text: root.profileIcons[root.powerProfile] ?? ""
|
||||
color: root.profileColors[root.powerProfile] ?? Colors.fg
|
||||
font.pixelSize: 13
|
||||
Behavior on color { ColorAnimation { duration: 80 } }
|
||||
}
|
||||
Text {
|
||||
text: root.loadAvg.toFixed(2)
|
||||
color: root.loadAvg > root.cpuCores ? Colors.critical :
|
||||
root.loadAvg > root.cpuCores * 0.7 ? Colors.warning : Colors.fg
|
||||
font.pixelSize: 13
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user