| 1 | pragma Singleton |
| 2 | import QtQuick |
| 3 | import Quickshell |
| 4 | import Quickshell.Io |
| 5 | |
| 6 | // Backlight via brightnessctl. Hides itself if brightnessctl isn't installed. |
| 7 | Singleton { |
| 8 | id: root |
| 9 | property int percent: -1 |
| 10 | readonly property bool available: percent >= 0 |
| 11 | property int pending: -1 |
| 12 | |
| 13 | function refresh() { getProc.running = true } |
| 14 | function setPercent(v) { |
| 15 | percent = Math.round(v) |
| 16 | pending = percent |
| 17 | debounce.restart() |
| 18 | } |
| 19 | |
| 20 | Timer { |
| 21 | id: debounce |
| 22 | interval: 70 |
| 23 | onTriggered: { |
| 24 | if (setProc.running) { debounce.restart(); return } |
| 25 | setProc.command = ["brightnessctl", "set", Math.max(1, root.pending) + "%"] |
| 26 | setProc.running = true |
| 27 | } |
| 28 | } |
| 29 | Process { id: setProc } |
| 30 | Process { |
| 31 | id: getProc |
| 32 | command: ["brightnessctl", "-m"] |
| 33 | running: true |
| 34 | stdout: StdioCollector { |
| 35 | onStreamFinished: { |
| 36 | var p = text.trim().split(",") |
| 37 | if (p.length >= 4) root.percent = parseInt(p[3]) |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | } |