blob: 61421888c076207ef6943bbeb82f38b06780dba0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
import QtQuick
import Quickshell
import Quickshell.Io
QtObject {
id: root
property real brightness: 0
property int maxBrightness: 1
function update() {
updateProc.running = true;
}
function setBrightness(value) {
const raw = Math.round(value * maxBrightness);
Quickshell.execDetached(["brightnessctl", "s", raw.toString()]);
brightness = value;
}
readonly property Process updateProc: Process {
command: ["sh", "-c", "printf '%s %s\\n' \"$(brightnessctl g)\" \"$(brightnessctl m)\""]
stdout: SplitParser {
onRead: data => {
const parts = data.trim().split(/\s+/);
if (parts.length >= 2) {
const current = parseInt(parts[0]);
root.maxBrightness = parseInt(parts[1]);
root.brightness = current / root.maxBrightness;
}
}
}
}
Component.onCompleted: update()
}
|