add powermodes
This commit is contained in:
@@ -28,6 +28,19 @@ RowLayout {
|
|||||||
property string batStatus: ""
|
property string batStatus: ""
|
||||||
property string batTime: "" // "H:MM" remaining, empty when unknown
|
property string batTime: "" // "H:MM" remaining, empty when unknown
|
||||||
property string netIp: ""
|
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 ───────────────────────────────────────────────────────────
|
// ── Line parser ───────────────────────────────────────────────────────────
|
||||||
function parseLine(line) {
|
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 ───────────────────────────────────────────────────────────────
|
||||||
Process {
|
Process {
|
||||||
id: statsProc
|
id: statsProc
|
||||||
@@ -174,15 +218,37 @@ RowLayout {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── CPU load average ──────────────────────────────────────────────────────
|
// ── CPU load average + power profile ─────────────────────────────────────
|
||||||
RowLayout {
|
Item {
|
||||||
spacing: 4
|
implicitWidth: cpuRow.implicitWidth
|
||||||
Text { text: ""; color: Colors.fg; font.pixelSize: 15 }
|
implicitHeight: cpuRow.implicitHeight
|
||||||
Text {
|
|
||||||
text: root.loadAvg.toFixed(2)
|
TapHandler {
|
||||||
color: root.loadAvg > root.cpuCores ? Colors.critical :
|
onTapped: root.cycleProfile()
|
||||||
root.loadAvg > root.cpuCores * 0.7 ? Colors.warning : Colors.fg
|
}
|
||||||
font.pixelSize: 13
|
|
||||||
|
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