69 lines
1.9 KiB
QML
69 lines
1.9 KiB
QML
pragma Singleton
|
|
|
|
import QtQuick
|
|
import Quickshell
|
|
import Quickshell.Io
|
|
import Quickshell.Hyprland
|
|
|
|
Singleton {
|
|
id: brightness
|
|
property var monitors: []
|
|
Process {
|
|
id: lsbacklight
|
|
running: true
|
|
command: ["find", "/sys/class/backlight", "-maxdepth", "1", "-mindepth", "1"]
|
|
stdout: StdioCollector {
|
|
onStreamFinished: brightness.monitors = this.text.split('\n')
|
|
.filter(mon => mon)
|
|
.map(mon => brightnessMonitorGen.createObject(brightness, {path: mon}))
|
|
}
|
|
}
|
|
Component {
|
|
id: brightnessMonitorGen
|
|
BrightnessMonitor {}
|
|
}
|
|
component BrightnessMonitor: QtObject {
|
|
id: monitor
|
|
property var path
|
|
property var value
|
|
property var max
|
|
property var get: Process {
|
|
running: true
|
|
command: ["brightnessctl", "i", "-m"]
|
|
stdout: StdioCollector {
|
|
onStreamFinished: [,,value,,max] = this.text.split(",")
|
|
}
|
|
}
|
|
property var setInterp: Process {
|
|
running: false
|
|
command: ["brillo", "-r", "-u", "300000", "-S", value]
|
|
}
|
|
property var setInstant: Process {
|
|
running: false
|
|
command: ["brightnessctl", "s", value]
|
|
}
|
|
function increase() {
|
|
value += value * 0.1 + max * 0.01
|
|
value = Math.min(max, value)
|
|
setInterp.startDetached()
|
|
}
|
|
function decrease() {
|
|
value -= value * 0.1 + max * 0.01
|
|
value = Math.max(0, value)
|
|
setInterp.startDetached()
|
|
}
|
|
function set(value) {
|
|
this.value = Math.max(Math.min(value, max), 0)
|
|
setInstant.startDetached()
|
|
}
|
|
}
|
|
GlobalShortcut {
|
|
name: "increase_brightness"
|
|
onPressed: monitors[0]?.increase()
|
|
}
|
|
GlobalShortcut {
|
|
name: "decrease_brightness"
|
|
onPressed: monitors[0]?.decrease()
|
|
}
|
|
}
|