refactor(quickshell): use event-driven hardware updates

This commit is contained in:
2026-09-25 17:36:46 -04:00
parent 73f74fe05f
commit 4fdb6d90d8
@@ -11,7 +11,11 @@ Scope {
function setBrightness(change) { function setBrightness(change) {
Quickshell.execDetached(["brightnessctl", "set", change]); Quickshell.execDetached(["brightnessctl", "set", change]);
brightnessRefresh.restart(); }
function refreshNetwork() {
if (!networkQuery.running)
networkQuery.running = true;
} }
function refreshWifi() { function refreshWifi() {
@@ -48,39 +52,49 @@ Scope {
} }
} }
Timer {
interval: 5000
repeat: true
running: true
onTriggered: networkQuery.running = true
}
Process { Process {
id: brightnessQuery id: networkMonitor
command: ["brightnessctl", "-m"] command: ["nmcli", "monitor"]
running: true running: true
stdout: StdioCollector { stdout: SplitParser {
onStreamFinished: { onRead: {
const fields = text.trim().split(","); root.refreshNetwork();
root.brightness = fields.length >= 4 if (root.wifiNetworks.length > 0)
? parseInt(fields[3].replace("%", "")) root.refreshWifi();
: -1;
} }
} }
onExited: networkRestart.start()
} }
Timer { Timer {
interval: 2000 id: networkRestart
repeat: true interval: 1000
running: true onTriggered: networkMonitor.running = true
onTriggered: brightnessQuery.running = true
} }
Timer { function updateBrightness() {
id: brightnessRefresh if (!brightnessFile.loaded || !maximumBrightnessFile.loaded)
interval: 250 return;
onTriggered: brightnessQuery.running = true const current = parseInt(brightnessFile.text().trim());
const maximum = parseInt(maximumBrightnessFile.text().trim());
root.brightness = maximum > 0 && !isNaN(current)
? Math.round(current / maximum * 100) : -1;
}
FileView {
id: brightnessFile
path: "file:///sys/class/backlight/intel_backlight/brightness"
watchChanges: true
onFileChanged: reload()
onLoaded: root.updateBrightness()
}
FileView {
id: maximumBrightnessFile
path: "file:///sys/class/backlight/intel_backlight/max_brightness"
onLoaded: root.updateBrightness()
} }
Process { Process {