Top-left under the rail: whether the mic is open, whether she is thinking, and whether she is talking — the states a 5s reply makes you want to see. No avatar yet; the meter is a placeholder for it, and the states and their colours are the part that has to read correctly first. LunaIndicator is Item-rooted so render.sh can shoot all five states offscreen (tests/LunaIndicatorHeadless.qml); LunaCall is the thin PanelWindow. Beside the notification stack rather than among the modals: it never takes the keyboard and raises no scrim, so it is deliberately absent from `modalOpen`. LunaState is read-only — the toggle runs the CLI — and treats a missing socket as normal, since the daemon is a user service that may start after the shell or not be installed at all. Two things measurement decided rather than reasoning. ExclusionMode .Ignore put it OVER the bar (it ignores other surfaces' zones, not just its own), and switching to Normal was not enough either: the rail's exclusive zone still left it at y=8 against a bar occupying 0..147. So the shell passes bar.contentHeight down, the same value the backdrop already reads. And the card is one chamfered path rather than a rectangle with a triangle over its corner, which left the square border showing underneath and read as an artifact. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
107 lines
3.5 KiB
QML
107 lines
3.5 KiB
QML
pragma ComponentBehavior: Bound
|
|
|
|
import QtQuick
|
|
import Quickshell
|
|
import Quickshell.Io
|
|
|
|
// Everything the Luna surfaces know, read off luna-voiced's unix socket
|
|
// (services/desktop/luna-voice.nix).
|
|
//
|
|
// Read-only on purpose: the key that toggles voice mode runs `luna-voice
|
|
// toggle` from Hyprland rather than writing here, so the toggle keeps working
|
|
// while the shell is reloading — and a QML error can never leave the mic on
|
|
// with nothing showing it.
|
|
//
|
|
// The daemon is a USER service that may start after the shell, restart under
|
|
// it, or not be installed at all, so a missing socket is a normal state and
|
|
// not an error: `reconnect` retries quietly and `connected` is what the
|
|
// widget shows.
|
|
QtObject {
|
|
id: root
|
|
|
|
// "idle" | "listening" | "thinking" | "speaking"
|
|
property string state: "idle"
|
|
// Voice mode itself — the widget is only on screen while this is true.
|
|
property bool active: false
|
|
property bool connected: socket.connected
|
|
// Mic level while listening, her output level while speaking. Drives the
|
|
// only genuinely live part of the visuals.
|
|
property real rms: 0
|
|
property string userText: ""
|
|
property string lunaText: ""
|
|
property string error: ""
|
|
|
|
readonly property var socket: Socket {
|
|
id: socket
|
|
path: `${Quickshell.env("XDG_RUNTIME_DIR") ?? "/run/user/1000"}/luna-voiced.sock`
|
|
connected: true
|
|
|
|
onConnectionStateChanged: {
|
|
if (!socket.connected) {
|
|
// A daemon that went away is not a daemon that is idle: reset
|
|
// rather than leave the last frame of a conversation frozen
|
|
// on screen.
|
|
root.active = false;
|
|
root.state = "idle";
|
|
root.rms = 0;
|
|
}
|
|
}
|
|
|
|
parser: SplitParser {
|
|
splitMarker: "\n"
|
|
onRead: line => root.ingest(line)
|
|
}
|
|
}
|
|
|
|
// Retry forever, cheaply. Setting `connected` true on an already-open
|
|
// socket is a no-op, so this doubles as the initial connect.
|
|
readonly property var reconnect: Timer {
|
|
interval: 2000
|
|
running: !socket.connected
|
|
repeat: true
|
|
onTriggered: socket.connected = true
|
|
}
|
|
|
|
function ingest(line: string): void {
|
|
let msg;
|
|
try {
|
|
msg = JSON.parse(line);
|
|
} catch (e) {
|
|
return; // a half-written line is not worth a console error
|
|
}
|
|
|
|
switch (msg.type) {
|
|
case "mode":
|
|
root.active = msg.active;
|
|
if (!msg.active) {
|
|
root.state = "idle";
|
|
root.rms = 0;
|
|
}
|
|
break;
|
|
case "state":
|
|
root.state = msg.value;
|
|
// Level is only meaningful during the phase that produces it.
|
|
if (msg.value !== "listening" && msg.value !== "speaking")
|
|
root.rms = 0;
|
|
break;
|
|
case "amplitude":
|
|
root.rms = msg.rms;
|
|
break;
|
|
case "caption":
|
|
if (msg.speaker === "user") {
|
|
// A new user caption starts a turn, so it is what clears her
|
|
// last reply — NOT speech_start, which arrives after her
|
|
// first caption, not before it.
|
|
root.userText = msg.text;
|
|
root.lunaText = "";
|
|
} else {
|
|
root.lunaText = msg.text;
|
|
}
|
|
break;
|
|
case "error":
|
|
root.error = msg.message;
|
|
break;
|
|
}
|
|
}
|
|
}
|