| 1 | pragma Singleton |
| 2 | import QtQuick |
| 3 | import Quickshell |
| 4 | import Quickshell.Io |
| 5 | |
| 6 | // hypridle timeouts from the settings app. The repo's hypridle.conf keeps `general {}` and sources |
| 7 | // ~/.config/aurora/hypridle.conf, which this writes (also on startup when it's missing: hypridle errors |
| 8 | // on a missing source). hypridle is restarted through Hyprland's exec so it lives outside aurora's |
| 9 | // systemd unit (an aurora restart would kill it otherwise). Seconds, 0 = never. |
| 10 | Singleton { |
| 11 | id: root |
| 12 | readonly property string file: Quickshell.env("HOME") + "/.config/aurora/hypridle.conf" |
| 13 | readonly property int dim: Settings.idleDim |
| 14 | readonly property int screenOff: Settings.idleOff |
| 15 | readonly property int lock: Settings.idleLock |
| 16 | readonly property int suspend: Settings.idleSuspend |
| 17 | |
| 18 | function setTimeout(key, v) { Settings[key] = Math.max(0, Math.round(v)) } |
| 19 | // any change (slider, Settings.reset(), hand edit of settings.json) rewrites the file |
| 20 | onDimChanged: writeTimer.restart() |
| 21 | onScreenOffChanged: writeTimer.restart() |
| 22 | onLockChanged: writeTimer.restart() |
| 23 | onSuspendChanged: writeTimer.restart() |
| 24 | |
| 25 | function render() { |
| 26 | var off = "hyprctl dispatch 'hl.dsp.dpms({action=\"off\"})'" |
| 27 | var on = "hyprctl dispatch 'hl.dsp.dpms({action=\"on\"})'" |
| 28 | var l = ["# generated by aurora's settings app (Idle.qml); edit there, not here", ""] |
| 29 | function listener(t, timeout, resume) { |
| 30 | if (t <= 0) return |
| 31 | l.push("listener {", " timeout = " + t, " on-timeout = " + timeout) |
| 32 | if (resume) l.push(" on-resume = " + resume) |
| 33 | l.push("}", "") |
| 34 | } |
| 35 | listener(dim, "brightnessctl -s set 5", "brightnessctl -r") // dim the panel, restore on activity |
| 36 | listener(screenOff, off, on + " && brightnessctl -r") |
| 37 | listener(lock, "loginctl lock-session", "") |
| 38 | listener(suspend, "systemctl suspend", "") |
| 39 | return l.join("\n") |
| 40 | } |
| 41 | function write() { |
| 42 | fv.setText(render()) |
| 43 | restartTimer.restart() |
| 44 | } |
| 45 | |
| 46 | Timer { id: writeTimer; interval: 800; onTriggered: root.write() } |
| 47 | Timer { |
| 48 | id: restartTimer |
| 49 | interval: 300 |
| 50 | onTriggered: Quickshell.execDetached(["sh", "-c", |
| 51 | "pkill -x hypridle; for i in 1 2 3 4 5 6 7 8 9 10; do pgrep -x hypridle >/dev/null || break; sleep 0.1; done; " + |
| 52 | "hyprctl dispatch 'hl.dsp.exec_cmd(\"hypridle\")' >/dev/null"]) |
| 53 | } |
| 54 | |
| 55 | FileView { |
| 56 | id: fv |
| 57 | path: root.file |
| 58 | printErrors: false |
| 59 | onLoadFailed: err => { if (err === FileViewError.FileNotFound) root.write() } |
| 60 | } |
| 61 | } |