From 871098d3e7e2934dff871db2185baad23bf17e66 Mon Sep 17 00:00:00 2001 From: Tim Wundenberg Date: Thu, 16 Apr 2026 09:34:19 +0200 Subject: [PATCH] add powermodes --- bar/SystemStats.qml | 84 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 75 insertions(+), 9 deletions(-) diff --git a/bar/SystemStats.qml b/bar/SystemStats.qml index 98bd4ed..6f30bd7 100644 --- a/bar/SystemStats.qml +++ b/bar/SystemStats.qml @@ -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 + } } }