| 1 | pragma Singleton |
| 2 | import QtQuick |
| 3 | import Quickshell |
| 4 | import Quickshell.Io |
| 5 | import Quickshell.Bluetooth |
| 6 | |
| 7 | // Small session toggles used by the Home tab and the bar. |
| 8 | Singleton { |
| 9 | id: root |
| 10 | |
| 11 | // ---- caffeine: an IdleInhibitor on the bar (see Bar.qml) keeps hypridle from dimming/locking |
| 12 | property bool caffeine: false |
| 13 | |
| 14 | // ---- airplane: wifi + bluetooth off, previous state restored when turned off again |
| 15 | property bool airplane: false |
| 16 | property bool hadWifi: true |
| 17 | property bool hadBt: false |
| 18 | function setAirplane(on) { |
| 19 | var ad = Bluetooth.defaultAdapter |
| 20 | if (on) { |
| 21 | hadWifi = Net.wifiEnabled |
| 22 | hadBt = ad ? ad.enabled : false |
| 23 | Net.setWifi(false) |
| 24 | if (ad) ad.enabled = false |
| 25 | } else { |
| 26 | if (hadWifi) Net.setWifi(true) |
| 27 | if (ad && hadBt) ad.enabled = true |
| 28 | } |
| 29 | airplane = on |
| 30 | } |
| 31 | |
| 32 | // ---- night light: gammastep (started by Hyprland) toggles on SIGUSR1. It starts enabled, and it |
| 33 | // can't be asked, so the state is tracked here; hasNightLight = gammastep was running at startup. |
| 34 | property bool hasNightLight: false |
| 35 | property bool nightLight: true |
| 36 | function setNightLight(on) { |
| 37 | if (!hasNightLight || on === nightLight) return |
| 38 | Quickshell.execDetached(["pkill", "-USR1", "-x", "gammastep"]) |
| 39 | nightLight = on |
| 40 | } |
| 41 | Process { |
| 42 | command: ["pgrep", "-x", "gammastep"] |
| 43 | running: true |
| 44 | onExited: code => root.hasNightLight = code === 0 |
| 45 | } |
| 46 | |
| 47 | // ---- colour picker: hyprpicker copies the hex itself, we just show it as a notification |
| 48 | property bool hasPicker: false |
| 49 | function pickColour() { if (!picker.running) picker.running = true } |
| 50 | Process { |
| 51 | id: picker |
| 52 | command: ["hyprpicker", "-a", "-f", "hex"] |
| 53 | stdout: StdioCollector { |
| 54 | onStreamFinished: { |
| 55 | var c = text.trim() |
| 56 | if (c !== "") Quickshell.execDetached(["notify-send", "-a", "aurora", "colour copied", c]) |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | Process { |
| 61 | command: ["sh", "-c", "command -v hyprpicker"] |
| 62 | running: true |
| 63 | onExited: code => root.hasPicker = code === 0 |
| 64 | } |
| 65 | } |