blob: 991a6ec0a2e41270f48fc249bd940dc668af5652 (
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
36
|
import QtQuick
import Quickshell
import Quickshell.Io
// Simplified brightness service using brightnessctl.
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", "brightnessctl g && brightnessctl m"]
stdout: SplitParser {
onRead: data => {
const lines = data.trim().split("\n")
if (lines.length >= 2) {
const current = parseInt(lines[0])
root.maxBrightness = parseInt(lines[1])
root.brightness = current / root.maxBrightness
}
}
}
}
Component.onCompleted: update()
}
|