diff options
| author | Danilo M. <danix@danix.xyz> | 2026-10-07 18:45:37 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-10-07 18:45:37 +0200 |
| commit | 0ea72748e5908e9522566e251e9d8940a5ff765a (patch) | |
| tree | c352e5915b67bc88e182cdb8900200414223dca7 /desktop/island/Logic.js | |
| parent | d9783e91a4b98f14e02a3d7f947ab6617cb96047 (diff) | |
| download | quickshell-0ea72748e5908e9522566e251e9d8940a5ff765a.tar.gz quickshell-0ea72748e5908e9522566e251e9d8940a5ff765a.zip | |
feat(island): pure logic for icons, dot colours and events
The island's decisions that do not need a running shell: which volume icon,
which colour a VM dot takes, which flag a keymap shows, the order of the
privacy segments, and how an openwindow event splits. Kept out of QML so
node can check them.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Diffstat (limited to 'desktop/island/Logic.js')
| -rw-r--r-- | desktop/island/Logic.js | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/desktop/island/Logic.js b/desktop/island/Logic.js new file mode 100644 index 0000000..8df35de --- /dev/null +++ b/desktop/island/Logic.js @@ -0,0 +1,62 @@ +.pragma library + +// Copyright (C) 2026 Danilo M. <danix@danix.xyz> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2 as +// published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// The default sink's icon name. Thresholds in thirds, as waybar's wb-icon did. +function volumeIcon(volume, muted) { + if (muted || volume <= 0) return "audio-volume-muted"; + if (volume < 0.33) return "audio-volume-low"; + if (volume < 0.66) return "audio-volume-medium"; + return "audio-volume-high"; +} + +// A VM's dot colour as a Theme property name, or "" for no dot. States are +// the names Virsh._stateName gives libvirt's enum: "blocked" is what virsh +// list prints as idle, "suspended" is pmsuspended. A shut-off VM only gets a +// dot when it carries a managed save, because starting it is then a restore. +function vmRole(vm) { + if (!vm || !vm.state) return ""; + if (vm.state === "shut off") return vm.saved ? "blue" : ""; + return ({ + "running": "green", + "paused": "yellow", + "blocked": "yellow", + "shutting down": "yellow", + "suspended": "accent", + "crashed": "red", + })[vm.state] || ""; +} + +// Flag image for a Hyprland active_keymap string, wb-lang's mapping. +function flagFor(keymap) { + if (!keymap || keymap.startsWith("Italian")) return "flag-it.svg"; + return "burger.svg"; +} + +// Active capture kinds as Theme property names, in a fixed order so the +// sliver's segments do not shuffle. +function privacyRoles(mic, cam, loc, scr) { + const out = []; + if (mic) out.push("green"); + if (cam) out.push("yellow"); + if (loc) out.push("blue"); + if (scr) out.push("red"); + return out; +} + +// Hyprland's openwindow event data: "address,workspace,class,title". The +// title is last and may contain commas, so only the first three fields are +// read. +function parseOpenWindow(data) { + const p = String(data || "").split(","); + return { address: p[0] || "", workspace: p[1] || "", appClass: p[2] || "" }; +} |
