Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ release is checked here and released on by hand.
- The on-screen keyboard releases its shared-memory drawing buffers while
hidden, freeing about 9 MiB of RAM at idle (tcballard).

- The shell stops waking the tablet several times a second to check the
battery and the rotation lock: both now update when they change (grierj).

## [0.4.10] - 2026-12-05

Built on orchard 0.3.24.
Expand Down
36 changes: 21 additions & 15 deletions desktop/shell/bin/omarchy-battery-status
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ for candidate in "$base"/*; do
battery=$candidate
done
[[ -n $battery && -r $battery/capacity ]] || exit 0
read -r percentage < "$battery/capacity"
[[ $percentage =~ ^[0-9]+$ && $percentage -le 100 ]] || exit 0
printf 'percentage\t%s%%\n' "$percentage"
read -r percentage < "$battery/capacity" || exit 0
[[ $percentage =~ ^[0-9]{1,3}$ && 10#$percentage -le 100 ]] || exit 0
printf 'percentage\t%d%%\n' $(( 10#$percentage ))

external=unknown
for candidate in "$base"/*; do
Expand All @@ -31,24 +31,30 @@ done
printf 'external_power\t%s\n' "$external"

if [[ -r $battery/energy_full ]] && read -r full < "$battery/energy_full" &&
[[ $full =~ ^[0-9]+$ && $full -gt 0 ]]; then
awk -v uwh="$full" 'BEGIN { printf "size\t%.1fWh\n", uwh / 1000000 }'
[[ $full =~ ^[0-9]{1,15}$ && 10#$full -gt 0 ]]; then
tenths=$(( (10#$full + 50000) / 100000 ))
printf 'size\t%d.%dWh\n' $(( tenths / 10 )) $(( tenths % 10 ))
elif [[ -r $battery/charge_full ]] && read -r full < "$battery/charge_full" &&
[[ $full =~ ^[0-9]+$ && $full -gt 0 ]]; then
[[ $full =~ ^[0-9]{1,15}$ && 10#$full -gt 0 ]]; then
# Charge-reporting gauges (the phones' bq27545) have no energy_full. Show the
# measured mAh; converting to Wh would need a nominal voltage we do not measure.
awk -v uah="$full" 'BEGIN { printf "size\t%.0fmAh\n", uah / 1000 }'
printf 'size\t%dmAh\n' $(( (10#$full + 500) / 1000 ))
fi
if [[ -r $battery/cycle_count ]] && read -r cycles < "$battery/cycle_count"; then
[[ ! $cycles =~ ^[0-9]+$ ]] || printf 'cycles\t%s\n' "$cycles"
fi
if [[ -r $battery/power_now ]]; then
read -r microwatts < "$battery/power_now"
[[ ! $microwatts =~ ^-?[0-9]+$ ]] || awk -v u="$microwatts" 'BEGIN { if (u < 0) u = -u; printf "rate\t%.1fW\n", u / 1000000 }'
elif [[ -r $battery/current_now && -r $battery/voltage_now ]]; then
read -r microamps < "$battery/current_now"
read -r microvolts < "$battery/voltage_now"
if [[ $microamps =~ ^-?[0-9]+$ && $microvolts =~ ^[0-9]+$ ]]; then
awk -v i="$microamps" -v v="$microvolts" 'BEGIN { if (i < 0) i = -i; printf "rate\t%.1fW\n", i * v / 1000000000000 }'
if [[ -r $battery/power_now ]] && read -r microwatts < "$battery/power_now"; then
if [[ $microwatts =~ ^-?[0-9]{1,15}$ ]]; then
abs_u=${microwatts#-}
tenths=$(( (10#$abs_u + 50000) / 100000 ))
printf 'rate\t%d.%dW\n' $(( tenths / 10 )) $(( tenths % 10 ))
fi
elif [[ -r $battery/current_now && -r $battery/voltage_now ]] &&
read -r microamps < "$battery/current_now" &&
read -r microvolts < "$battery/voltage_now"; then
if [[ $microamps =~ ^-?[0-9]{1,9}$ && $microvolts =~ ^[0-9]{1,9}$ ]]; then
abs_i=${microamps#-}
tenths=$(( (10#$abs_i * 10#$microvolts + 50000000000) / 100000000000 ))
printf 'rate\t%d.%dW\n' $(( tenths / 10 )) $(( tenths % 10 ))
fi
fi
67 changes: 67 additions & 0 deletions desktop/shell/shell/Commons/BatteryStatus.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
pragma Singleton
import QtQuick
import Quickshell
import Quickshell.Io
import Quickshell.Services.UPower
import "../plugins/panels/power/Model.js" as Model

// One shared omarchy-battery-status reader for the bar, the lock screen, the
// control center and the power panel. Refreshes immediately on UPower source
// or battery changes and on demand when a panel opens; a slow fallback timer
// keeps discovery independent of UPower without polling every second at idle.
Singleton {
id: root

property var batteryInfo: ({})
property bool refreshPending: false

function refresh() {
// A read already running may have sampled before the event this refresh is
// for, so coalesce one follow-up run once it exits.
if (batteryProc.running) {
refreshPending = true
return
}
refreshPending = false
batteryProc.running = true
}

function updateKeyValue(raw) {
var next = Model.parseKeyValue(raw)
// Keep last known good data if a refresh briefly returns nothing — happens
// around AC plug/unplug events. Avoids the section collapsing mid-transition.
if (Object.keys(next).length > 0) batteryInfo = next
else batteryInfo = Object.assign({}, batteryInfo, { external_power: "unknown" })
}

Process {
id: batteryProc
command: ["omarchy-battery-status", "--shell"]
stdout: StdioCollector { waitForEnd: true; onStreamFinished: root.updateKeyValue(text) }
onExited: {
// Deferred: the process still reports running while signalling exit.
if (root.refreshPending) Qt.callLater(root.refresh)
}
}

Connections {
target: UPower
function onOnBatteryChanged() { root.refresh() }
}

Connections {
target: UPower.displayDevice
ignoreUnknownSignals: true
function onPercentageChanged() { root.refresh() }
function onStateChanged() { root.refresh() }
function onIsPresentChanged() { root.refresh() }
}

Timer {
interval: 30000
running: true
repeat: true
triggeredOnStart: true
onTriggered: root.refresh()
}
}
102 changes: 102 additions & 0 deletions desktop/shell/shell/Commons/RotationLockState.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
pragma Singleton
import QtQuick
import Quickshell
import Quickshell.Io

// One shared rotation-lock and accelerometer probe for the bar, lock screen,
// control center and Display settings. Watches the config directory (and its
// parent so a moved or recreated directory re-arms the watch) so creating or
// removing the lock file updates immediately with no polling timer.
Singleton {
id: root

readonly property string configHome: Quickshell.env("XDG_CONFIG_HOME") || (Quickshell.env("HOME") + "/.config")
readonly property string configDir: configHome + "/omarchy"
readonly property string lockPath: configDir + "/rotation-lock"

property bool locked: false
// Until the proxy has answered, assume a sensor: nothing greys out at start.
property bool sensor: true
property bool activeTarget: false
property bool hasPendingToggle: false
property bool pendingTarget: false

function reload() {
parentDirWatcher.reload()
dirWatcher.reload()
file.reload()
}

function toggle() {
var base = toggleProc.running ? (hasPendingToggle ? pendingTarget : activeTarget) : locked
setLocked(!base)
}

function setLocked(want) {
var next = !!want
if (toggleProc.running) {
hasPendingToggle = true
pendingTarget = next
return
}
activeTarget = next
toggleProc.command = ["omarchy-rotation-lock", next ? "on" : "off"]
toggleProc.running = true
}

Process {
id: toggleProc
onExited: {
if (root.hasPendingToggle) {
var next = root.pendingTarget
root.hasPendingToggle = false
Qt.callLater(function() { root.setLocked(next) })
return
}
root.reload()
}
}

Process {
id: probe
command: ["busctl", "get-property", "net.hadess.SensorProxy", "/net/hadess/SensorProxy",
"net.hadess.SensorProxy", "HasAccelerometer"]
stdout: StdioCollector { id: probeOut }
onExited: function(exitCode) {
root.sensor = exitCode === 0 && probeOut.text.trim() === "b true"
}
}

Component.onCompleted: probe.running = true

// The proxy may still be starting when the shell does: ask once more.
Timer {
interval: 10000
running: true
onTriggered: if (!root.sensor) probe.running = true
}

FileView {
id: parentDirWatcher
path: root.configHome
watchChanges: true
printErrors: false
onFileChanged: root.reload()
}

FileView {
id: dirWatcher
path: root.configDir
watchChanges: true
printErrors: false
onFileChanged: root.reload()
}

FileView {
id: file
path: root.lockPath
printErrors: false
onLoaded: root.locked = true
onLoadFailed: root.locked = false
}
}
2 changes: 2 additions & 0 deletions desktop/shell/shell/Commons/qmldir
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
module qs.Commons
singleton AudioNodes 1.0 AudioNodes.qml
singleton BatteryStatus 1.0 BatteryStatus.qml
singleton Border 1.0 Border.qml
singleton Color 1.0 Color.qml
singleton I18n 1.0 I18n.qml
singleton InputDevices 1.0 InputDevices.qml
singleton IpcRegistry 1.0 IpcRegistry.qml
singleton InputMethodState 1.0 InputMethodState.qml
singleton RotationLockState 1.0 RotationLockState.qml
singleton Style 1.0 Style.qml
singleton TimeZone 1.0 TimeZone.qml
singleton TimeFormat 1.0 TimeFormat.qml
Expand Down
3 changes: 2 additions & 1 deletion desktop/shell/shell/controlcenter/ControlCenter.qml
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ Item {
if (UntypedInput.active) { if (UntypedInput.known) UntypedInput.setMuted(!UntypedInput.muted) }
else if (source && source.audio) source.audio.muted = !source.audio.muted
}
function toggleRotation() { run([omarchy("omarchy-rotation-lock"), rotation.locked ? "off" : "on"]); rotation.locked = !rotation.locked }
function toggleRotation() { rotation.toggle() }
function toggleAwake() { if (idleService) idleService.setIdleEnabled(root.stayAwake) }
function showKeyboard() { root.close(); run([omarchy("omarchy-keyboard"), "toggle"]) }
function setVolume(value) {
Expand Down Expand Up @@ -385,6 +385,7 @@ Item {
// ----------------------------------------------------------- lifecycle

function prepare() {
battery.refresh()
if (!brightnessRead.running) brightnessRead.running = true
if (!autoRead.running) autoRead.running = true
root.focusKey = ""
Expand Down
33 changes: 4 additions & 29 deletions desktop/shell/shell/plugins/panels/power/Status.qml
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import QtQuick
import Quickshell
import Quickshell.Io
import Quickshell.Services.UPower
import qs.Commons
import "Model.js" as Model

// Orchard: the battery state the bar's icon shows, apart from the panel, so
// the status cluster, the lock and the control center show the same thing.
// The panel binds its own properties of these names to it.
// Backed by the shared BatteryStatus singleton so every view reuses one reader.
Item {
id: root
visible: false

// The battery script's readings (omarchy-battery-status --shell), read
// every second: discovery must not depend on a charger event or on UPower.
property var batteryInfo: ({})
readonly property var batteryInfo: BatteryStatus.batteryInfo
readonly property bool externalPower: batteryInfo.external_power === "connected"
readonly property var batteryDevice: {
var device = UPower.displayDevice
Expand All @@ -40,28 +37,6 @@ Item {
}

function refresh() {
if (!batteryProc.running) batteryProc.running = true
}

function updateKeyValue(raw) {
var next = Model.parseKeyValue(raw)
// Keep last known good data if a refresh briefly returns nothing — happens
// around AC plug/unplug events. Avoids the section collapsing mid-transition.
if (Object.keys(next).length > 0) batteryInfo = next
else batteryInfo = Object.assign({}, batteryInfo, { external_power: "unknown" })
}

Process {
id: batteryProc
command: ["omarchy-battery-status", "--shell"]
stdout: StdioCollector { waitForEnd: true; onStreamFinished: root.updateKeyValue(text) }
}

Timer {
interval: 1000
running: true
repeat: true
triggeredOnStart: true
onTriggered: root.refresh()
BatteryStatus.refresh()
}
}
48 changes: 8 additions & 40 deletions desktop/shell/shell/plugins/status/RotationLock.qml
Original file line number Diff line number Diff line change
@@ -1,46 +1,14 @@
import QtQuick
import Quickshell
import Quickshell.Io
import qs.Commons

// Whether rotation is locked: omarchy-rotation-lock's file, which only exists
// while it is. Read every two seconds, as a missing file cannot be watched.
// And whether there is anything to lock: iio-sensor-proxy's accelerometer,
// which the rotation daemon follows. Without one the lock is unavailable.
// Whether rotation is locked and whether an accelerometer is present.
// Backed by the shared RotationLockState singleton so every view reuses one
// directory watcher and one SensorProxy probe with no polling timer.
Item {
id: root
visible: false
property bool locked: false
// Until the proxy has answered, assume a sensor: nothing greys out at start.
property bool sensor: true

Process {
id: probe
command: ["busctl", "get-property", "net.hadess.SensorProxy", "/net/hadess/SensorProxy",
"net.hadess.SensorProxy", "HasAccelerometer"]
stdout: StdioCollector { id: probeOut }
onExited: function(exitCode) {
root.sensor = exitCode === 0 && probeOut.text.trim() === "b true"
}
}
Component.onCompleted: probe.running = true
// The proxy may still be starting when the shell does: ask once more.
Timer {
interval: 10000
running: true
onTriggered: if (!root.sensor) probe.running = true
}

FileView {
id: file
path: (Quickshell.env("XDG_CONFIG_HOME") || (Quickshell.env("HOME") + "/.config")) + "/omarchy/rotation-lock"
printErrors: false
onLoaded: root.locked = true
onLoadFailed: root.locked = false
}
Timer {
interval: 2000
running: true
repeat: true
onTriggered: file.reload()
}
readonly property bool locked: RotationLockState.locked
readonly property bool sensor: RotationLockState.sensor
function setLocked(want) { RotationLockState.setLocked(want) }
function toggle() { RotationLockState.toggle() }
}
5 changes: 1 addition & 4 deletions desktop/shell/shell/settings/DisplayPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,7 @@ Item {
usable: rotation.sensor
isSwitch: true
switchOn: rotation.locked
onActivated: {
Quickshell.execDetached(["omarchy-rotation-lock", rotation.locked ? "off" : "on"])
rotation.locked = !rotation.locked
}
onActivated: rotation.toggle()
}
}
}
Expand Down
Loading
Loading