Add battery percentage toggle to power widget

This commit is contained in:
David Heinemeier Hansson
2026-08-01 12:58:45 -07:00
parent 3d59f9127e
commit 3ffd9cdfc5
3 changed files with 22 additions and 3 deletions
+1 -1
View File
@@ -68,7 +68,7 @@ Example `shell.json` (bar subtree only shown):
| `omarchy.network` | Wi-Fi/Ethernet icon + popup with Wi-Fi scan, signal, connect, DNS provider selection | left = popup · right = nmtui |
| `omarchy.tailscale` | Tailscale status, connection switcher, machine browser, and copy actions | left = popup · right = toggle · middle = refresh |
| `omarchy.model-usage` | Claude Code and Codex limits with pace, today, last week, and all-time model breakdown | left = panel · right = refresh · middle = next subscription |
| `omarchy.power` | Battery/AC icon + popup with battery stats, power profiles, and system info | left = popup |
| `omarchy.power` | Battery/AC icon + popup with battery stats, power profiles, and system info | left = popup · right = toggle percentage |
| `omarchy.bluetooth` | Bluetooth icon + popup with device list, connect/disconnect, battery | left = popup · right = toggle radio · middle = bluetoothctl TUI |
| `omarchy.monitor` | Brightness and laptop display controls | left = popup |
+15 -2
View File
@@ -16,6 +16,7 @@ Panel {
property string activeProfile: ""
property int profileIndex: 0
property bool cursorActive: false
readonly property bool showPercentage: setting("showPercentage", false) === true
readonly property bool batteryPresent: {
var device = UPower.displayDevice
return !!(device && device.isPresent)
@@ -161,6 +162,11 @@ Panel {
actionProc.running = true
}
function togglePercentage() {
root.settings = Object.assign({}, root.settings, { showPercentage: !root.showPercentage })
if (root.bar && root.bar.shell) root.bar.shell.updateEntryInline(root.moduleName, root.settings)
}
onOpenedChanged: {
if (opened) {
if (!batteryPresent) {
@@ -253,9 +259,16 @@ Panel {
id: button
anchors.fill: parent
bar: root.bar
text: root.batteryIcon()
text: root.showPercentage && !vertical
? Math.round(root.batteryFraction * 100) + "% " + root.batteryIcon()
: root.batteryIcon()
slotSize: Style.bar.iconSlot * (root.showPercentage && !vertical ? 2 : 1)
tooltipText: ""
onPressed: function(b) { if (root.batteryPresent) root.toggle() }
onPressed: function(b) {
if (!root.batteryPresent) return
if (b === Qt.RightButton) root.togglePercentage()
else root.toggle()
}
}
KeyboardPanel {