aboutsummaryrefslogtreecommitdiffstats
path: root/desktop
diff options
context:
space:
mode:
Diffstat (limited to 'desktop')
-rw-r--r--desktop/Prefs.qml36
-rw-r--r--desktop/companion/Companion.qml120
-rw-r--r--desktop/companion/Lines.js123
-rw-r--r--desktop/companion/Mood.js13
-rw-r--r--desktop/companion/README.md35
-rw-r--r--desktop/companion/frames.txt28
-rw-r--r--desktop/companion/test_lines.js79
-rw-r--r--desktop/companion/test_mood.js26
-rw-r--r--desktop/modules/companion/ArtistsModule.qml67
-rw-r--r--desktop/modules/companion/CompanionModule.qml2
-rw-r--r--desktop/modules/companion/PhrasesModule.qml64
-rw-r--r--desktop/modules/companion/PhrasesPage.qml195
-rw-r--r--desktop/shell.qml2
13 files changed, 751 insertions, 39 deletions
diff --git a/desktop/Prefs.qml b/desktop/Prefs.qml
index 80515a4..610e004 100644
--- a/desktop/Prefs.qml
+++ b/desktop/Prefs.qml
@@ -75,6 +75,36 @@ Singleton {
root.write(Object.assign({}, root.doc, { companionBlushFile: p }));
}
+ // The companion's app lines as saved: a map of lowercased window class
+ // to phrases, or null for the defaults in companion/Lines.js. The
+ // Companion phrases page edits it.
+ property var companionApps: null
+ function setCompanionApps(map) {
+ root.companionApps = map;
+ root.write(Object.assign({}, root.doc, { companionApps: map }));
+ }
+ function resetCompanionApps() {
+ root.companionApps = null;
+ const d = Object.assign({}, root.doc);
+ delete d.companionApps;
+ root.write(d);
+ }
+
+ // The companion's artist lines as saved, keyed by lowercased artist, or
+ // null for the defaults in companion/Lines.js. The Companion artists
+ // page edits it.
+ property var companionArtists: null
+ function setCompanionArtists(map) {
+ root.companionArtists = map;
+ root.write(Object.assign({}, root.doc, { companionArtists: map }));
+ }
+ function resetCompanionArtists() {
+ root.companionArtists = null;
+ const d = Object.assign({}, root.doc);
+ delete d.companionArtists;
+ root.write(d);
+ }
+
// The settings window's sidebar width, dragged by its edge.
readonly property int sidebarMin: 160
readonly property int sidebarMax: 420
@@ -137,6 +167,10 @@ Singleton {
const sk = parsed.companionSkirtless;
root.companionSkirtless = Number.isInteger(sk) && sk >= 0 ? sk : 60;
root.companionBlushFile = typeof parsed.companionBlushFile === "string" ? parsed.companionBlushFile : "";
+ const ca = parsed.companionApps;
+ root.companionApps = ca && typeof ca === "object" && !Array.isArray(ca) ? ca : null;
+ const cr = parsed.companionArtists;
+ root.companionArtists = cr && typeof cr === "object" && !Array.isArray(cr) ? cr : null;
root.ready = true;
}
@@ -152,6 +186,6 @@ Singleton {
onFileChanged: reload()
onLoaded: root.reparse()
// Missing file: the defaults, and nothing written.
- onLoadFailed: { root.doc = {}; root.pinnedIp = ""; root.presets = null; root.settingsSidebar = 200; root.assistantModel = ""; root.companion = true; root.companionBlushFile = ""; root.companionSkirtless = 60; root.ready = true; }
+ onLoadFailed: { root.doc = {}; root.pinnedIp = ""; root.presets = null; root.settingsSidebar = 200; root.assistantModel = ""; root.companion = true; root.companionBlushFile = ""; root.companionSkirtless = 60; root.companionApps = null; root.companionArtists = null; root.ready = true; }
}
}
diff --git a/desktop/companion/Companion.qml b/desktop/companion/Companion.qml
index 3102c59..aa0505d 100644
--- a/desktop/companion/Companion.qml
+++ b/desktop/companion/Companion.qml
@@ -12,9 +12,11 @@
import Quickshell
import Quickshell.Io
import Quickshell.Wayland
+import Quickshell.Bluetooth
import Quickshell.Hyprland
import QtQuick
import ".."
+import "../modules/sound"
import "../NotifyConfig.js" as NC
import "Mood.js" as Mood
import "Lines.js" as Lines
@@ -33,13 +35,31 @@ PanelWindow {
// SUPER+\ (the IPC below) and the Companion settings page, through Prefs,
// so it survives a restart.
readonly property bool present: Prefs.ready && Prefs.companion
+ // A hide plays a goodbye first: the wave frames, then the drop.
+ // Re-showing her cancels it and greets as usual.
+ property bool leaving: false
+ property int waveIndex: 0
+ readonly property var waveCycle: ["wave", "wave-l", "wave", "wave-r"]
onPresentChanged: {
if (root.present) {
+ root.leaving = false;
root.destructAt = 0; // the skirt is back
root.now = Date.now();
greet.restart();
} else {
root.stopMonologue();
+ // Nothing to wave at when she is already out of view.
+ if (root.fullscreen !== 2 && !root.hopping) {
+ root.leaving = true;
+ root.waveIndex = 0;
+ root.now = Date.now();
+ // A line one hide in four, like the monologue's roll, and not
+ // forced, so the usual 30 s line cooldown still applies. A
+ // silent wave is only as long as it takes to read nothing.
+ const spoke = Math.random() < 0.25 && root.say("bye");
+ goodbyeTimer.interval = spoke ? Mood.T.goodbye : Mood.T.goodbyeSilent;
+ goodbyeTimer.start();
+ }
}
}
@@ -48,9 +68,13 @@ PanelWindow {
readonly property string focused: Hyprland.focusedMonitor?.name ?? ""
property string here: ""
property bool hopping: false
+ // No focused monitor (outputs gone over a suspend) is not a destination.
+ // Already out of view, there is no exit to wait for: settled would never
+ // fire, hopping would stick and hide her for good, so move at once.
onFocusedChanged: {
- if (root.here === "") root.here = root.focused;
- else if (root.focused !== root.here) root.hopping = true;
+ if (root.focused === "" || root.focused === root.here) return;
+ if (root.here === "" || root.away) root.here = root.focused;
+ else root.hopping = true;
}
Component.onCompleted: root.here = root.focused
@@ -83,6 +107,9 @@ PanelWindow {
property double pulseAt: 0
property double wakeAt: 0
property double admireAt: 0
+ property double singAt: 0
+ property double djAt: 0
+ property string groove: ""
property double lastLineAt: 0
property double lastMonologueAt: 0
property bool monologue: false
@@ -122,7 +149,9 @@ PanelWindow {
root.wakeAt = t;
root.say("wake");
} else if (root.idle === 1 && root.wasIdle === 0) {
- if (Mood.monologue("bored", root.lastMonologueAt, t, Math.random())) root.startMonologue();
+ root.pickGroove();
+ if (Player.playing) root.say("groove");
+ else if (Mood.monologue("bored", root.lastMonologueAt, t, Math.random())) root.startMonologue();
else root.say("bored");
}
root.wasIdle = root.idle;
@@ -188,6 +217,46 @@ PanelWindow {
}
}
+ // Sony headphones connecting, by the island's rule (island/StatusPill.qml):
+ // recognised by their model prefix, since BlueZ gives no class that says
+ // "headphones". A connection makes her sing for Mood.T.singHold. Bluetooth
+ // reads empty for about 2 s after launch, so a shell start with them
+ // already on is not a connection: btReady waits past that.
+ readonly property bool phonesConnected: (Bluetooth.devices?.values ?? [])
+ .some(d => d.connected && /^(WH|WF)-|^LinkBuds/.test(d.deviceName))
+ property bool btReady: false
+ // shortcut: a genuine connection in the first 4 s after a shell start is
+ // missed along with the startup populate; tighten if that bites.
+ Timer { interval: 4000; running: true; onTriggered: root.btReady = true }
+ onPhonesConnectedChanged: {
+ if (!root.phonesConnected || !root.btReady) return;
+ root.singAt = Date.now();
+ root.now = root.singAt;
+ root.say("headphones");
+ }
+
+ // What is playing, from the sound module's player (it already drops the
+ // playerctld and browser-integration duplicates). A new artist+title
+ // while playing is a track start or change: she DJs for Mood.T.djHold
+ // and says the artist's line if she knows them. Paused reads "", and
+ // resuming the same track matches lastTrack, so it does not DJ again.
+ readonly property string track: Player.playing ? Player.artist + "\n" + Player.title : ""
+ property string lastTrack: ""
+ onTrackChanged: {
+ if (root.track === "" || root.track === root.lastTrack) return;
+ root.lastTrack = root.track;
+ root.djAt = Date.now();
+ root.now = root.djAt;
+ root.say("artist:" + Player.artist);
+ }
+ // Music starting while she is already bored needs a groove too.
+ readonly property bool music: Player.playing
+ onMusicChanged: if (root.music && root.idle === 1) root.pickGroove()
+ function pickGroove() {
+ const g = ["whistle", "headbang", "airguitar"];
+ root.groove = g[Math.floor(Math.random() * g.length)];
+ }
+
// A listed wallpaper on an empty workspace: she turns to it and blushes.
// Checked after the events above (switching to an empty workspace,
// closing its last window) and whenever she stops being away: shown,
@@ -238,10 +307,12 @@ PanelWindow {
// --- state ----------------------------------------------------------
readonly property var mood: Mood.pick({
+ leaving: root.leaving,
now: root.now, destructAt: root.destructAt, dodging: root.dodging, shoved: root.shoved,
shovedAt: root.shovedAt,
recording: root.asst.recording, busy: root.asst.busy, repliedAt: root.repliedAt,
clicks: root.clicks, admireAt: root.admireAt, mockAt: root.mockAt, typingAt: root.typingAt, wakeAt: root.wakeAt,
+ singAt: root.singAt, djAt: root.djAt, music: root.music, groove: root.groove,
monologue: root.monologue, idle: root.idle,
})
readonly property string outfit: Mood.outfit(root.destructAt, root.now, Prefs.companionSkirtless * 1000)
@@ -249,19 +320,21 @@ PanelWindow {
onMoodChanged: if (root.monologue && root.mood.state !== "muse") root.stopMonologue()
// Hidden: no sprite, no bubble. Away adds the dodge, which hides the
- // sprite but lets its line show.
- readonly property bool hidden: !root.present || root.fullscreen === 2 || root.hopping
+ // sprite but lets its line show. While waving goodbye she is still on
+ // screen, so a hidden present does not hide her until the wave is done.
+ readonly property bool hidden: (!root.present && !root.leaving) || root.fullscreen === 2 || root.hopping
readonly property bool away: root.hidden || root.dodging || root.remapping
// --- speech ---------------------------------------------------------
function say(kind, force) {
const t = Date.now();
- if (root.hidden || (!force && !Mood.canSpeak(root.lastLineAt, t))) return;
- const line = Lines.pick(kind, Math.random());
- if (line === "") return;
+ if (root.hidden || (!force && !Mood.canSpeak(root.lastLineAt, t))) return false;
+ const line = Lines.pick(kind, Math.random(), Prefs.companionApps, Prefs.companionArtists);
+ if (line === "") return false;
root.lastLineAt = t;
bubble.show(line, 3000);
+ return true;
}
// The opening monologue: about 15 characters a second, one sentence
@@ -353,6 +426,35 @@ PanelWindow {
}
}
+ // The goodbye: she waves, then leaves. With a line she holds long enough
+ // to read it. The hand sways side to side while it lasts.
+ Timer { id: goodbyeTimer; onTriggered: root.leaving = false }
+ Timer {
+ id: waveFlip
+ interval: 250
+ repeat: true
+ running: root.leaving
+ onTriggered: root.waveIndex = (root.waveIndex + 1) % root.waveCycle.length
+ }
+
+ // Frames Mood names that are really a loop: the frame names its cycle
+ // and how fast it turns. Everything else shows as named.
+ readonly property var cycles: ({
+ dj: { frames: ["dj", "dj-scratch"], ms: 450 },
+ headbang: { frames: ["headbang-up", "headbang-down"], ms: 220 },
+ })
+ property int cycleIndex: 0
+ readonly property var cycle: root.cycles[root.mood.frame] ?? null
+ onCycleChanged: root.cycleIndex = 0
+ Timer {
+ interval: root.cycle?.ms ?? 1000
+ repeat: true
+ running: root.cycle !== null && !root.away
+ onTriggered: root.cycleIndex = (root.cycleIndex + 1) % root.cycle.frames.length
+ }
+ readonly property string frame: root.leaving ? root.waveCycle[root.waveIndex]
+ : root.cycle ? root.cycle.frames[root.cycleIndex % root.cycle.frames.length] : root.mood.frame
+
// qs -p <desktop> ipc call companion toggle -> SUPER+\
IpcHandler {
target: "companion"
@@ -388,7 +490,7 @@ PanelWindow {
id: sprite
x: seat.x
y: seat.y
- source: `file://${root.art}/${root.outfit}/${root.mood.frame}.png`
+ source: `file://${root.art}/${root.outfit}/${root.frame}.png`
fallback: `file://${root.art}/${root.outfit}/base.png`
out: root.away
trembling: root.mood.state === "admire" && root.mood.frame === "blush3"
diff --git a/desktop/companion/Lines.js b/desktop/companion/Lines.js
index d6450df..77e7a83 100644
--- a/desktop/companion/Lines.js
+++ b/desktop/companion/Lines.js
@@ -17,34 +17,52 @@
var lines = {
shown: ["Glory to mankind.", "2B, reporting.", "...Back on duty."],
+ bye: ["2B, signing off.", "Rest while you can.", "Duty complete."],
bored: ["...Operator, I'm bored.", "Nothing to report.", "Awaiting orders."],
wake: ["I'm awake.", "Systems online."],
mock: ["Typo again?", "Delete, delete, delete.", "Were you aiming for that key?"],
shoved: ["Hey.", "Rude.", "I was standing here."],
ready: ["Answer's ready.", "Your reply came in."],
+ headphones: ["...Good song.", "Music. Finally.", "I'll allow this one.", "Louder."],
+ groove: ["This one's good.", "...Don't tell 9S.", "Again. Play it again."],
click: ["...Yes?", "Can I help you?"],
blush: ["S-stop that.", "...Operator."],
wallpaper: ["...!", "W-what is this?", "I wasn't staring."],
dodge: ["...Fine.", "I'll move."],
destruct: ["Self-destruct sequence initiated."],
aftermath: ["...That was unpleasant."],
+};
+
+// The lines for a program she recognizes, by lowercased window class: one is
+// said at random when focus moves to it. The settings window's Companion
+// phrases page edits them into Prefs.companionApps, which then replaces this
+// whole set; a class with no entry says nothing.
+var apps = {
+ firefox: ["Researching again?", "Don't open too many tabs.", "The Bunker's network is faster."],
+ kitty: ["A terminal. Serious work.", "Careful with that rm.", "I'll watch your commands."],
+ discord: ["Talking to the Resistance?", "Don't tell them where we are."],
+ signal: ["Encrypted. Good."],
+ steam: ["Training simulation?", "Don't play all night."],
+ gimp: ["Making art?"],
+ "com.obsproject.studio": ["Are we recording?", "I'll stay out of frame."],
+ "md.obsidian.obsidian": ["Writing a report?", "Taking notes. Good habit."],
+ sublime_text: ["Writing code?", "Mind the typos."],
+ qtmaildir: ["Any orders from Command?", "Mail. Anything urgent?"],
+ "virt-manager": ["More machines?", "Androids running androids."],
+ audacious: ["Music. I like this."],
+ llamachat: ["Talking to Pod?"],
+ qtpass: ["I'm not looking."],
+};
- // The focused window's class, lowercased, as "app:<class>". A class
- // with no entry says nothing.
- "app:firefox": ["Researching again?", "Don't open too many tabs.", "The Bunker's network is faster."],
- "app:kitty": ["A terminal. Serious work.", "Careful with that rm.", "I'll watch your commands."],
- "app:discord": ["Talking to the Resistance?", "Don't tell them where we are."],
- "app:signal": ["Encrypted. Good."],
- "app:steam": ["Training simulation?", "Don't play all night."],
- "app:gimp": ["Making art?"],
- "app:com.obsproject.studio": ["Are we recording?", "I'll stay out of frame."],
- "app:md.obsidian.obsidian": ["Writing a report?", "Taking notes. Good habit."],
- "app:sublime_text": ["Writing code?", "Mind the typos."],
- "app:qtmaildir": ["Any orders from Command?", "Mail. Anything urgent?"],
- "app:virt-manager": ["More machines?", "Androids running androids."],
- "app:audacious": ["Music. I like this."],
- "app:llamachat": ["Talking to Pod?"],
- "app:qtpass": ["I'm not looking."],
+// The lines for an artist she knows, keyed by a lowercased name matched as
+// a substring of the reported artist, so "daft punk" also catches
+// collaborations. The Companion artists page edits them into
+// Prefs.companionArtists, which then replaces this whole set.
+var artists = {
+ "linkin park": ["In the end, it doesn't even matter.", "Crawling in my skin... I know this one."],
+ "evanescence": ["Wake me up inside. ...Operator, don't laugh."],
+ "gigi d'agostino": ["L'amour toujours. I'll fly with you.", "...My feet are moving on their own."],
+ "eminem": ["Lose yourself. Understood.", "He talks faster than Pod."],
};
// The game's opening, one sentence per bubble.
@@ -56,8 +74,73 @@ var monologue = [
"I often think about the god who blessed us with this cryptic puzzle...and wonder if we'll ever get the chance to kill him.",
];
-// A line for kind; roll is Math.random(). "" for a kind with no lines.
-function pick(kind, roll) {
- const l = lines[kind] || [];
- return l.length ? l[Math.min(l.length - 1, Math.floor(roll * l.length))] : "";
+// A set in effect: saved when it is a plain object, the defaults (apps
+// unless given) otherwise. A malformed saved value must not leave her mute.
+function appMap(saved, defaults) {
+ return saved && typeof saved === "object" && !Array.isArray(saved) ? saved : (defaults || apps);
+}
+
+// A set as an ordered list of {cls, lines}, for the settings pages; cls is
+// the key, a window class or an artist.
+function appList(saved, defaults) {
+ const m = appMap(saved, defaults);
+ const keys = Object.keys(m);
+ const out = [];
+ for (let i = 0; i < keys.length; i++)
+ out.push({ cls: keys[i], lines: (m[keys[i]] || []).slice() });
+ return out;
+}
+
+function nonEmpty(all) {
+ const l = [];
+ for (let i = 0; i < (all || []).length; i++)
+ if (typeof all[i] === "string" && all[i].trim() !== "") l.push(all[i]);
+ return l;
+}
+
+function at(l, roll) { return l.length ? l[Math.min(l.length - 1, Math.floor(roll * l.length))] : ""; }
+
+// A line for an app class, empty strings skipped; "" when the class has none.
+function pickApp(cls, saved, roll) { return at(nonEmpty(appMap(saved)[cls]), roll); }
+
+// A line for the playing artist: the first key that is a case-insensitive
+// substring of it and has a non-empty line. ponytail: substring, so a
+// short key like "air" also matches "Airbourne"; whole words if that bites.
+function pickArtist(artist, saved, roll) {
+ const a = String(artist || "").toLowerCase();
+ if (a === "") return "";
+ const m = appMap(saved, artists);
+ const keys = Object.keys(m);
+ for (let i = 0; i < keys.length; i++) {
+ const l = nonEmpty(m[keys[i]]);
+ if (keys[i] !== "" && l.length && a.indexOf(keys[i].toLowerCase()) !== -1) return at(l, roll);
+ }
+ return "";
+}
+
+// A line for a reaction kind, or, with an "app:" or "artist:" prefix, for
+// that class or artist.
+function pick(kind, roll, saved, savedArtists) {
+ if (kind.slice(0, 4) === "app:") return pickApp(kind.slice(4), saved, roll);
+ if (kind.slice(0, 7) === "artist:") return pickArtist(kind.slice(7), savedArtists, roll);
+ return at(lines[kind] || [], roll);
+}
+
+// The page's list back to a map for Prefs: empty classes and phrases dropped,
+// the class lowercased (Hyprland reports it that way), a repeated class
+// keeping its last entry.
+function toMap(list) {
+ const m = {};
+ for (let i = 0; i < list.length; i++) {
+ const cls = String(list[i].cls || "").trim().toLowerCase();
+ if (cls === "") continue;
+ const src = list[i].lines || [];
+ const ls = [];
+ for (let j = 0; j < src.length; j++) {
+ const s = String(src[j] || "").trim();
+ if (s !== "") ls.push(s);
+ }
+ if (ls.length) m[cls] = ls;
+ }
+ return m;
}
diff --git a/desktop/companion/Mood.js b/desktop/companion/Mood.js
index 409a958..b59c1ab 100644
--- a/desktop/companion/Mood.js
+++ b/desktop/companion/Mood.js
@@ -23,11 +23,15 @@ var T = {
mockCooldown: 20000,
typingHold: 2000,
waveHold: 3000,
+ singHold: 4000, // her singing reaction to the headphones connecting
+ djHold: 6000, // behind the decks when a track starts or changes
wakeHold: 1500, // the stretch after idling
lineCooldown: 30000,
monologueCooldown: 3600000,
destruct: 1000, // the glow and the flash; the sprite is hidden under it
scorched: 3000,
+ goodbye: 2000, // waving goodbye with a line, enough to read it
+ goodbyeSilent: 1000, // waving goodbye with nothing to read
admireLook: 1500, // turned to the wallpaper, before the blush
admireBlush: 3000,
admireCooldown: 180000,
@@ -53,6 +57,9 @@ function clickFrame(count) {
// The spec's priority table, top to bottom: the first that applies wins.
// idle is 0 awake, 1 bored, 2 yawning, 3 lying down.
function pick(s) {
+ // The user hid her: the goodbye outranks whatever she was doing. The
+ // frame here is a placeholder; Companion.qml cycles the wave frames.
+ if (s.leaving) return st("bye", "wave");
const since = s.destructAt ? s.now - s.destructAt : Infinity;
if (since < T.destruct) return st("destruct", "base");
if (since < T.destruct + T.scorched) return st("scorched", "scorched");
@@ -62,6 +69,8 @@ function pick(s) {
if (s.recording) return st("listen", "listen");
if (s.busy) return st("think", "think");
if (s.now - s.repliedAt < T.waveHold) return st("wave", "wave");
+ if (s.now - s.singAt < T.singHold) return st("sing", "sing");
+ if (s.now - s.djAt < T.djHold) return st("dj", "dj");
if (s.clicks.count > 0 && s.now - s.clicks.at < T.clickHold)
return st("clicks", clickFrame(s.clicks.count));
if (s.now - s.admireAt < T.admireLook + T.admireBlush)
@@ -73,7 +82,9 @@ function pick(s) {
if (s.monologue) return st("muse", "muse");
if (s.idle >= 3) return st("lying", "lying");
if (s.idle === 2) return st("yawn", "yawn");
- if (s.idle === 1) return st("bored", "sleepy");
+ // Music turns boredom into a groove picked by Companion.qml; the
+ // deeper idle stages still win, so music does not keep her awake.
+ if (s.idle === 1) return s.music ? st("groove", s.groove || "whistle") : st("bored", "sleepy");
return st("base", "base");
}
diff --git a/desktop/companion/README.md b/desktop/companion/README.md
index 4bb87f2..4fbe887 100644
--- a/desktop/companion/README.md
+++ b/desktop/companion/README.md
@@ -11,7 +11,7 @@ The design, with what was measured on the way, is
| `Companion.qml` | the window, inputs, timers, speech, IPC (`companion toggle/show/hide`) |
| `Figure.qml` | draws a frame: crossfade, bob, drop out and back, explosion |
| `Mood.js` | which state wins, from a snapshot; all the timings are its `T` |
-| `Lines.js` | her lines and the opening monologue |
+| `Lines.js` | her reaction, per-app and per-artist lines, and the opening monologue |
| `Admired.qml` | the wallpaper list she blushes at, and what wallp has on each monitor |
| `ListFile.js` | that list as plain text: parse and toggle |
| `prep-frames` | generated images to display frames |
@@ -21,9 +21,16 @@ The design, with what was measured on the way, is
it wins over the directory's own file (see AGENTS.md).
Whether she is shown is `companion` in `Prefs.qml`, so it survives a
-restart: SUPER+\ and the switch on Settings > Desktop > Companion
+restart: SUPER+\ and the switch on Settings > Companion
(`desktop/modules/companion/`) both set it.
+A hide by SUPER+\ or that switch plays a goodbye first: she waves (`wave`,
+`wave-l` and `wave-r` cycling) and then drops out. One hide in four she also
+says a `bye` line, under the usual 30 s line cooldown; with a line she holds
+`Mood.T.goodbye` (2 s, enough to read it), silently only
+`Mood.T.goodbyeSilent` (0.5 s). Fullscreen, the lock screen and the monitor
+hop keep their own exits and do not wave.
+
## Art
Not in the repo: the character is Square Enix's and this repo is GPLv2.
@@ -56,14 +63,31 @@ frame falls back to its outfit's `base`.
- The program in front of her is Hyprland's `activewindow` event,
`class,title`. It also fires on every title change, so she reacts
only when the class changes, a third of the time, under the 30 s line
- cooldown. Lines are `app:<class>` in `Lines.js`, class lowercased; a
- class with none says nothing.
-- A listed wallpaper (Settings > Desktop > Companion for the file, the
+ cooldown. Lines are by lowercased class in `Lines.js`; a class with
+ none says nothing. Settings > Companion > Companion phrases edits them
+ into `Prefs.companionApps`, which then replaces the defaults.
+- A listed wallpaper (Settings > Companion for the file, the
heart in the wallpaper picker for entries) on an empty workspace: she
turns to it with `watch` and blushes with `blush3`, at most every 3
minutes. Checked on `workspacev2` and `closewindow`, and whenever she
stops being away. Her monitor's wallpaper comes from wallp's
`wallp.conf` outputs and `wall_h`/`wall_v`.
+- Sony headphones connecting are the island's rule (`island/StatusPill.qml`:
+ `WH-`/`WF-`/`LinkBuds` by name, since BlueZ has no headphones class): she
+ sings once for `Mood.T.singHold`, 4 s, and says a line if the usual 30 s
+ cooldown allows it. A shell start with them already on is not a connection:
+ Bluetooth reads empty for ~2 s, then populates.
+- What is playing is `modules/sound/Player.qml`, which already drops the
+ playerctld and browser-integration duplicates. A new artist+title while
+ playing makes her DJ for `Mood.T.djHold`, 6 s (`dj` and `dj-scratch`
+ cycling), and say the artist's line if one matches: lowercased keys in
+ `Lines.artists`, matched as a substring, edited on Settings > Companion
+ artists into `Prefs.companionArtists`. Pause and resume of the same
+ track is not a change; a shell start with music on DJs once. While
+ music plays, the first idle stage is a groove instead of bored:
+ `whistle`, `headbang` (`headbang-up`/`-down` cycling) or `airguitar`,
+ picked at random, with a `groove` line; yawning and lying down are
+ unchanged.
- She only feels the pointer while it is over her: Quickshell has no
global pointer and Hyprland sends no motion events. Hence the 0.6 s
dodge rather than moving away as the pointer approaches.
@@ -83,3 +107,4 @@ frame falls back to its outfit's `base`.
## Check
node desktop/companion/test_mood.js
+ node desktop/companion/test_lines.js
diff --git a/desktop/companion/frames.txt b/desktop/companion/frames.txt
index 0019db1..087089d 100644
--- a/desktop/companion/frames.txt
+++ b/desktop/companion/frames.txt
@@ -34,6 +34,9 @@ EYES = Her black blindfold stays on as one solid band of cloth fully covering bo
# After the self-destruct the blindfold is gone with the skirt: the whole
# leotard set shows her eyes.
LEOTARD = Her skirt is gone, revealing a plain white leotard underneath, and her blindfold is gone too: both eyes uncovered and clearly visible, pale blue-grey, matching her expression. Everything else stays exactly the same: pose, expression, black gloves, puffy black juliet sleeves, black bodice, black thighhigh boots, black hairband, lips, the small mole under her mouth, chibi proportions, art style and white background.
+# Singing along to whatever is playing: headphones on, eyes shut. The
+# blindfold is gone, but BARE does not fit because it says the eyes show.
+SING = Her black blindfold is gone: nothing over her eyes, no blindfold, no mask; her black hairband stays. Both her eyes are closed, softly shut. Her mouth is open wide as if she is singing loudly. She wears a pair of black over-ear headphones over her head and ears. A couple of small black musical notes float in the air beside her head.
# --- expressions
dress/smile <- dress/base : Change only her expression to a small warm closed-mouth smile; ${POSE} ${EYES} ${KEEP}
@@ -46,6 +49,10 @@ dress/sleepy <- dress/base : Change only her expression to sleepy and drowsy, h
# --- poses
dress/wave <- dress/base : Raise only the hand on the left side of the image beside her head, waving, with a small smile; her other arm stays at her side. ${KEEP}
+# The goodbye wave sways side to side. Edited from wave, the centre of the
+# sway, so klein keeps the arm up and moves only the hand.
+dress/wave-l <- dress/wave : Change only the hand she holds up: bend it at the wrist toward the left side of the image, fingers pointing left, as if in the middle of a goodbye wave; keep the arm raised beside her head, her small smile, and everything else exactly the same. ${KEEP}
+dress/wave-r <- dress/wave : Change only the hand she holds up: bend it at the wrist toward the right side of the image, fingers pointing right, as if in the middle of a goodbye wave; keep the arm raised beside her head, her small smile, and everything else exactly the same. ${KEEP}
# Shown while typing: she faces into the screen, away from the viewer, as if
# reading over the user's shoulder. A profile read as posing, not watching.
dress/watch <- dress/base : Turn her completely around into a back view: we see her from behind, the back of her head with her white bob, crossed by her black hairband and the small black cloth knot of her black blindfold (black, not white, no bow), her back, the back of her dress and the backs of her legs, as if she is facing a screen and watching it; arms relaxed at her sides. Same character, black gloves, puffy black juliet sleeves, black dress with its skirt, black thighhigh boots, black hairband, chibi proportions, art style and white background.
@@ -67,6 +74,18 @@ dress/stretch <- dress/base : She stretches both arms up above her head, waking
# and face were right: refs/shoved-7.png, made from dress/base with
# --seed 7 by the earlier standing prompt (see generated.log), kept in refs/.
dress/shoved <- refs/shoved-7 : Keep her face, her scared expression, her uncovered eyes and both raised hands exactly as they are. Change her body and legs: she is in the air, lifted completely off the ground, knocked flying toward the left side of the image by a strong blast from the right; both feet off the ground, legs trailing behind her toward the right side, her body tilted, her hair and skirt blown toward the left. No ground, no blast effect drawn. ${KEEP_BARE}
+# Headphones connecting: a few seconds of her singing along.
+dress/sing <- dress/base : ${SING} ${POSE} ${KEEP_BARE}
+# Music: behind the decks on a track start or change, and the grooves
+# that replace boredom while music plays.
+DECK = A small black DJ booth stands in front of her: two turntables and a mixer on top at her waist height, and a solid black front panel reaching down to the ground, so her legs and boots are hidden behind it and only her upper body shows above it. No table legs.
+dress/dj <- dress/base : ${DECK} Both gloved hands rest on the turntables, head nodding, a small smile. Her black blindfold is gone: nothing over her eyes, no blindfold, no mask, no band; her black hairband stays. Both her eyes are closed, softly shut, enjoying the music. She wears a pair of black over-ear headphones over her head and ears. ${KEEP_BARE}
+dress/dj-scratch <- dress/dj : Change only her arms: the hand on the left side of the image scratches a record, the other holds one headphone cup to her ear. Everything else exactly the same. ${KEEP}
+dress/whistle <- dress/base : Change only her expression: lips puckered, whistling, a couple of small black musical notes floating beside her mouth. Her black blindfold is gone: nothing over her eyes, no blindfold, no mask, no band; her black hairband stays. Both her eyes are closed, softly shut, relaxed. ${POSE} ${KEEP_BARE}
+dress/headbang-up <- dress/base : She rocks out: her upper body leans far back, her face tipped up to the sky, mouth wide open shouting, eyes squeezed shut, one fist raised high above her head making the horns hand sign with index and little finger up, the other fist clenched at her side, her hair flying back. Her black blindfold is gone: nothing over her eyes, no blindfold, no mask, no band; her black hairband stays. ${KEEP_BARE}
+# headbang-down: the kept result is --seed 7.
+dress/headbang-down <- dress/base : She headbangs hard: seen from the front, her whole upper body is bent forward at the waist by about 45 degrees, her head thrown down so the top of her head faces the viewer, her white hair flung forward and hanging down over her face, both fists clenched in front of her chest, knees slightly bent. Her face is hidden by her hair. Her black blindfold is gone: nothing over her eyes, no blindfold, no mask, no band; her black hairband stays. ${KEEP_BARE}
+dress/airguitar <- dress/base : She plays an electric guitar with a glowing neon blue body and a black neck, held across her hips: one hand strumming at the body, the other fretting the neck to the side, knees bent, eyes shut, mouth open in a big grin. Her black blindfold is gone: nothing over her eyes, no blindfold, no mask, no band; her black hairband stays. ${KEEP_BARE}
# --- the leotard set: the same frames, after the self-destruct
leotard/base <- dress/base : ${LEOTARD}
@@ -80,6 +99,8 @@ leotard/blush2 <- dress/blush2 : ${LEOTARD}
leotard/blush3 <- dress/blush3 : ${LEOTARD}
leotard/sleepy <- dress/sleepy : ${LEOTARD}
leotard/wave <- dress/wave : ${LEOTARD}
+leotard/wave-l <- dress/wave-l : ${LEOTARD}
+leotard/wave-r <- dress/wave-r : ${LEOTARD}
# From dress/watch, klein kept the blindfold's band at the back of her head
# through three prompts, by name and by position; from leotard/base, which
# has no blindfold, the back view is the usual pose edit.
@@ -96,4 +117,11 @@ leotard/think <- dress/think : ${LEOTARD}
leotard/muse <- dress/muse : ${LEOTARD}
leotard/stretch <- dress/stretch : ${LEOTARD}
leotard/shoved <- dress/shoved : ${LEOTARD}
+leotard/sing <- dress/sing : Her skirt is gone, revealing a plain white leotard underneath. Change nothing else: she keeps her closed eyes, her black over-ear headphones, the musical notes beside her head, her pose, black gloves, puffy black juliet sleeves, black bodice, black thighhigh boots, black hairband, lips and the small mole under her mouth. Same character, chibi proportions, art style and white background.
leotard/scorched <- leotard/base : Right after an explosion: her clothes lightly scorched and smudged with soot, a few wisps of smoke rising from her, hair slightly messy, a dazed flat expression; standing, arms at her sides. Her eyes stay uncovered, no blindfold. Her top stays black: the black bodice with its chest cutout and the puffy black juliet sleeves, exactly as in the image; the plain white leotard shows only below her waist, where the skirt was. She keeps her black gloves, black thighhigh boots, black hairband, lips and the small mole under her mouth. Same character, chibi proportions, art style and white background.
+leotard/dj <- dress/dj : ${LEOTARD}
+leotard/dj-scratch <- dress/dj-scratch : ${LEOTARD}
+leotard/whistle <- dress/whistle : ${LEOTARD}
+leotard/headbang-up <- dress/headbang-up : ${LEOTARD}
+leotard/headbang-down <- dress/headbang-down : Her skirt is gone, revealing a plain white leotard underneath. Change nothing else: her head stays lowered with her white hair hanging down over her whole face, hiding it completely, no eyes showing, no blindfold; her fists stay clenched in front of her chest; she keeps her black gloves, puffy black juliet sleeves, black bodice, black thighhigh boots, black hairband and pose. Same character, chibi proportions, art style and white background.
+leotard/airguitar <- dress/airguitar : ${LEOTARD}
diff --git a/desktop/companion/test_lines.js b/desktop/companion/test_lines.js
new file mode 100644
index 0000000..72addf2
--- /dev/null
+++ b/desktop/companion/test_lines.js
@@ -0,0 +1,79 @@
+// 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.
+
+// Run: node desktop/companion/test_lines.js
+// Lines.js is a QML library, so its .pragma line is stripped before node
+// evaluates it.
+
+const fs = require("fs");
+const assert = require("assert");
+
+const src = fs.readFileSync(__dirname + "/Lines.js", "utf8")
+ .replace(/^\.pragma library$/m, "");
+const L = new Function(src +
+ "\nreturn { lines, apps, artists, monologue, appMap, appList, pickApp, pickArtist, pick, toMap };")();
+
+// The defaults are what she says until a set is saved.
+assert.strictEqual(L.pickApp("firefox", null, 0), L.apps.firefox[0]);
+assert.strictEqual(L.pickApp("firefox", null, 0.99), L.apps.firefox[L.apps.firefox.length - 1]);
+assert.strictEqual(L.pickApp("nope", null, 0), "");
+assert.strictEqual(L.appMap(null), L.apps);
+// A hand edit with a typo reads as the defaults, not as silence.
+assert.strictEqual(L.appMap("typo"), L.apps);
+assert.strictEqual(L.appMap(["not", "a", "map"]), L.apps);
+
+// A saved set replaces the defaults, class by class.
+assert.strictEqual(L.pickApp("firefox", { firefox: ["hi"] }, 0), "hi");
+assert.strictEqual(L.pickApp("kitty", { firefox: ["hi"] }, 0), "");
+assert.strictEqual(L.pick("app:firefox", 0, { firefox: ["custom"] }), "custom");
+assert.strictEqual(L.pick("app:firefox", 0), L.apps.firefox[0]);
+
+// Empty phrases are skipped when picking; a class with only empty ones says
+// nothing.
+assert.strictEqual(L.pickApp("firefox", { firefox: ["", " ", "only"] }, 0), "only");
+assert.strictEqual(L.pickApp("firefox", { firefox: ["", " "] }, 0), "");
+
+// Reactions still come from lines.
+assert.strictEqual(L.pick("shown", 0), L.lines.shown[0]);
+assert.strictEqual(L.pick("nope", 0), "");
+
+// The saved set as an ordered list, for the settings page.
+const list = L.appList(null);
+assert.strictEqual(list.length, Object.keys(L.apps).length);
+assert.deepStrictEqual(list[0], { cls: "firefox", lines: L.apps.firefox.slice() });
+assert.deepStrictEqual(L.appList({ kitty: ["a"] }), [{ cls: "kitty", lines: ["a"] }]);
+
+// Back to a map: trim, lowercase the class, drop empty classes and empty
+// phrases, and a repeated class keeps its last entry.
+assert.deepStrictEqual(L.toMap([
+ { cls: " Firefox ", lines: [" one ", "", " ", "two"] },
+ { cls: "", lines: ["dropped"] },
+ { cls: "kitty", lines: ["", " "] },
+ { cls: "firefox", lines: ["last"] },
+]), { firefox: ["last"] });
+
+// Artists: a case-insensitive substring of what MPRIS reports, first
+// matching key wins, empty phrases skipped.
+assert.strictEqual(L.pickArtist("Linkin Park", null, 0), L.artists["linkin park"][0]);
+assert.strictEqual(L.pickArtist("LINKIN PARK, Jay-Z", null, 0), L.artists["linkin park"][0]);
+assert.strictEqual(L.pickArtist("Nobody", null, 0), "");
+assert.strictEqual(L.pickArtist("", null, 0), "");
+assert.strictEqual(L.pickArtist("Air, Beck", { air: ["a"], beck: ["b"] }, 0), "a");
+assert.strictEqual(L.pickArtist("Airbourne", { air: ["", "a"] }, 0), "a");
+assert.strictEqual(L.pick("artist:Eminem", 0, null, null), L.artists.eminem[0]);
+assert.strictEqual(L.pick("artist:Eminem", 0, null, { eminem: ["mine"] }), "mine");
+assert.strictEqual(L.pick("groove", 0), L.lines.groove[0]);
+
+// The same list helpers serve the artist set.
+assert.strictEqual(L.appMap(null, L.artists), L.artists);
+assert.strictEqual(L.appList(null, L.artists).length, Object.keys(L.artists).length);
+assert.deepStrictEqual(L.toMap(L.appList(null, L.artists)), L.artists);
+console.log("ok");
diff --git a/desktop/companion/test_mood.js b/desktop/companion/test_mood.js
index 37af2ea..3439f7c 100644
--- a/desktop/companion/test_mood.js
+++ b/desktop/companion/test_mood.js
@@ -27,8 +27,9 @@ const L = new Function(lsrc + "\nreturn { parse, toggle, outputs };")();
const NOW = 10000000;
// A snapshot with nothing going on, overridden per case.
const calm = over => Object.assign({
- now: NOW, destructAt: 0, dodging: false, shoved: false, shovedAt: 0, recording: false, busy: false,
- repliedAt: 0, clicks: { count: 0, at: 0 }, mockAt: 0, typingAt: 0, wakeAt: 0, admireAt: 0,
+ leaving: false, now: NOW, destructAt: 0, dodging: false, shoved: false, shovedAt: 0, recording: false, busy: false,
+ repliedAt: 0, clicks: { count: 0, at: 0 }, mockAt: 0, typingAt: 0, wakeAt: 0, admireAt: 0, singAt: 0,
+ djAt: 0, music: false, groove: "",
monologue: false, idle: 0,
}, over);
const state = over => M.pick(calm(over)).state;
@@ -40,6 +41,7 @@ assert.deepStrictEqual(M.pick(calm({})), { state: "base", frame: "base" });
// The priority table, top to bottom: with every trigger from a row down
// active at once, that row wins. Merged so a higher row's values win.
const ladder = [
+ ["bye", { leaving: true }],
["destruct", { destructAt: NOW - 10 }],
["scorched", { destructAt: NOW - M.T.destruct - 10 }],
["dodge", { dodging: true }],
@@ -47,6 +49,8 @@ const ladder = [
["listen", { recording: true }],
["think", { busy: true }],
["wave", { repliedAt: NOW - 10 }],
+ ["sing", { singAt: NOW - 10 }],
+ ["dj", { djAt: NOW - 10 }],
["clicks", { clicks: { count: 2, at: NOW - 10 } }],
["admire", { admireAt: NOW - 10 }],
["mock", { mockAt: NOW - 10 }],
@@ -60,6 +64,11 @@ for (let i = 0; i < ladder.length; i++) {
assert.strictEqual(state(all), ladder[i][0], "everything from " + ladder[i][0] + " down");
}
+// A hide: she waves goodbye, above everything else, whatever she was doing.
+assert.deepStrictEqual(
+ M.pick(calm({ leaving: true, idle: 3, clicks: { count: 3, at: NOW - 10 } })),
+ { state: "bye", frame: "wave" });
+
// Shoved: knocked off balance for a moment, then mad beside the balloon
// for as long as it stays.
assert.deepStrictEqual(M.pick(calm({ shoved: true, shovedAt: NOW - 10 })), { state: "shoved", frame: "shoved" });
@@ -71,8 +80,21 @@ assert.deepStrictEqual(M.pick(calm({ idle: 1 })), { state: "bored", frame: "slee
assert.deepStrictEqual(M.pick(calm({ idle: 2 })), { state: "yawn", frame: "yawn" });
assert.deepStrictEqual(M.pick(calm({ idle: 3 })), { state: "lying", frame: "lying" });
+// Music while bored: she grooves with the picked frame instead, whistling
+// when nothing was picked; yawning and lying down are unchanged.
+assert.deepStrictEqual(M.pick(calm({ idle: 1, music: true, groove: "headbang" })), { state: "groove", frame: "headbang" });
+assert.deepStrictEqual(M.pick(calm({ idle: 1, music: true })), { state: "groove", frame: "whistle" });
+assert.deepStrictEqual(M.pick(calm({ idle: 1, groove: "headbang" })), { state: "bored", frame: "sleepy" });
+assert.strictEqual(state({ idle: 2, music: true }), "yawn");
+assert.strictEqual(state({ idle: 3, music: true }), "lying");
+// Music while awake is the rest pose; the DJ is only the burst.
+assert.strictEqual(state({ music: true }), "base");
+assert.deepStrictEqual(M.pick(calm({ djAt: NOW - 10 })), { state: "dj", frame: "dj" });
+
// Holds end on time.
assert.strictEqual(state({ repliedAt: NOW - M.T.waveHold }), "base");
+assert.strictEqual(state({ singAt: NOW - M.T.singHold }), "base");
+assert.strictEqual(state({ djAt: NOW - M.T.djHold }), "base");
assert.strictEqual(state({ typingAt: NOW - M.T.typingHold }), "base");
assert.strictEqual(state({ wakeAt: NOW - M.T.wakeHold }), "base");
assert.strictEqual(state({ clicks: { count: 3, at: NOW - M.T.clickHold } }), "base");
diff --git a/desktop/modules/companion/ArtistsModule.qml b/desktop/modules/companion/ArtistsModule.qml
new file mode 100644
index 0000000..a0d23f4
--- /dev/null
+++ b/desktop/modules/companion/ArtistsModule.qml
@@ -0,0 +1,67 @@
+// 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.
+
+import QtQuick
+import "../.."
+import "../../companion/Lines.js" as Lines
+
+// The lines the companion says when a track by an artist she knows starts,
+// matched as a case-insensitive substring of the player's artist. Same
+// draft, Save and Reset as PhrasesModule, on Prefs.companionArtists and
+// Lines.artists; the page's cls field holds the artist.
+Module {
+ id: am
+ name: "artists"
+ label: "Companion artists"
+ // nf-fa-music, present in Inconsolata Nerd Font.
+ icon: "\uf001"
+ settings: true
+ group: "Companion"
+ keywords: ["companion", "artist", "music", "song", "track", "line", "say", "2b"]
+ searchItems: am.shown.map((a, i) => ({ text: a.cls + ": " + a.lines.join(" / "), key: "app:" + i }))
+
+ property var draft: null
+ property bool resetting: false
+ readonly property var shown: am.draft ?? Lines.appList(Prefs.companionArtists, Lines.artists)
+ readonly property bool valid: am.shown.every(a => String(a.cls).trim() !== ""
+ && (a.lines || []).some(l => String(l).trim() !== ""))
+ dirty: am.draft !== null
+
+ function edit(list) { am.draft = list; am.resetting = false; }
+ function reset() { am.draft = Lines.appList(null, Lines.artists); am.resetting = true; }
+ function save() {
+ if (am.resetting) Prefs.resetCompanionArtists();
+ else Prefs.setCompanionArtists(Lines.toMap(am.draft));
+ am.discard();
+ }
+ function discard() { am.draft = null; am.resetting = false; }
+
+ page: Component {
+ Page {
+ title: "Companion artists"
+ actions: Component {
+ SaveBar { dirty: am.dirty; valid: am.valid; note: "every artist needs a name and a phrase"
+ onSave: am.save(); onDiscard: am.discard() }
+ }
+ PhrasesPage {
+ width: parent.width
+ owner: am
+ intro: "When a track by an artist she knows starts or changes, she says one of their lines at "
+ + "random, under her 30 s line cooldown. The name matches any part of the player's artist, "
+ + "ignoring case, so \"daft punk\" also catches \"Daft Punk, Pharrell Williams\". "
+ + "Save applies at once."
+ keyHint: "artist, e.g. linkin park"
+ addText: "Add artist"
+ saved: Prefs.companionArtists
+ }
+ }
+ }
+}
diff --git a/desktop/modules/companion/CompanionModule.qml b/desktop/modules/companion/CompanionModule.qml
index 6ed36ec..8d6a68d 100644
--- a/desktop/modules/companion/CompanionModule.qml
+++ b/desktop/modules/companion/CompanionModule.qml
@@ -23,7 +23,7 @@ Module {
// nf-md-account_heart, present in Inconsolata Nerd Font.
icon: "\u{F0899}"
settings: true
- group: "Desktop"
+ group: "Companion"
keywords: ["companion", "2b", "mascot", "character", "show", "hide", "wallpaper", "blush", "leotard", "timeout"]
page: Component {
diff --git a/desktop/modules/companion/PhrasesModule.qml b/desktop/modules/companion/PhrasesModule.qml
new file mode 100644
index 0000000..7e4895a
--- /dev/null
+++ b/desktop/modules/companion/PhrasesModule.qml
@@ -0,0 +1,64 @@
+// 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.
+
+import QtQuick
+import "../.."
+import "../../companion/Lines.js" as Lines
+
+// The lines the companion says when focus moves to a program she
+// recognizes, by its lowercased window class. They live in Prefs and she
+// reads them live, so a save needs no restart. The page edits a draft here;
+// Save hands it to Prefs, Reset drops the saved set so Lines.js' defaults
+// show again.
+Module {
+ id: pm
+ name: "phrases"
+ label: "Companion phrases"
+ // nf-fa-comment, present in Inconsolata Nerd Font.
+ icon: "\uf075"
+ settings: true
+ group: "Companion"
+ keywords: ["companion", "phrase", "line", "say", "speak", "app", "program",
+ "window", "class", "firefox", "2b"]
+ searchItems: pm.shown.map((a, i) => ({ text: a.cls + ": " + a.lines.join(" / "), key: "app:" + i }))
+
+ // null while there are no edits: the page then shows the saved set, or
+ // Lines.js' defaults when nothing is saved.
+ property var draft: null
+ // Reset was pressed: Save drops the saved set rather than saving a copy
+ // of the defaults, so later default changes still arrive.
+ property bool resetting: false
+ readonly property var shown: pm.draft ?? Lines.appList(Prefs.companionApps)
+ // Every app needs a class and at least one non-empty phrase; Save waits.
+ readonly property bool valid: pm.shown.every(a => String(a.cls).trim() !== ""
+ && (a.lines || []).some(l => String(l).trim() !== ""))
+ dirty: pm.draft !== null
+
+ function edit(list) { pm.draft = list; pm.resetting = false; }
+ function reset() { pm.draft = Lines.appList(null); pm.resetting = true; }
+ function save() {
+ if (pm.resetting) Prefs.resetCompanionApps();
+ else Prefs.setCompanionApps(Lines.toMap(pm.draft));
+ pm.discard();
+ }
+ function discard() { pm.draft = null; pm.resetting = false; }
+
+ page: Component {
+ Page {
+ title: "Companion phrases"
+ actions: Component {
+ SaveBar { dirty: pm.dirty; valid: pm.valid; note: "every app needs a class and a phrase"
+ onSave: pm.save(); onDiscard: pm.discard() }
+ }
+ PhrasesPage { width: parent.width; owner: pm }
+ }
+ }
+}
diff --git a/desktop/modules/companion/PhrasesPage.qml b/desktop/modules/companion/PhrasesPage.qml
new file mode 100644
index 0000000..1971171
--- /dev/null
+++ b/desktop/modules/companion/PhrasesPage.qml
@@ -0,0 +1,195 @@
+// 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.
+
+import QtQuick
+import "../.."
+
+// One card per recognized program: its window class and the lines she says
+// when focus moves to it. Every change edits the module's draft; the
+// header's Save hands the set to Prefs. Reset fills the draft with the
+// built-in set from Lines.js.
+Column {
+ id: page
+ spacing: 10
+
+ // The module, holding the draft. Not named pm, its id (it would bind to
+ // itself, AGENTS.md).
+ required property QtObject owner
+ // What the cards are keyed by; the defaults are the app set's, so
+ // PhrasesModule passes nothing.
+ property string intro: "When focus moves to a program she recognizes, she says one of its lines at random, a third "
+ + "of the time and under her 30 s line cooldown. The class is Hyprland's window class, "
+ + "lowercased (hyprctl activewindow shows it). Save applies at once."
+ property string keyHint: "window class, e.g. firefox"
+ property string addText: "Add app"
+ // The saved set, for Reset's enabled state; null means the defaults.
+ property var saved: Prefs.companionApps
+ readonly property var list: owner.shown
+ // The app card awaiting a second click on Remove.
+ property int confirming: -1
+
+ // Saves a copy of the list with app i replaced by fn(app), or removed
+ // when fn returns null.
+ function edit(i, fn) {
+ const out = [];
+ for (let j = 0; j < page.list.length; j++) {
+ const a = page.list[j];
+ const c = { cls: a.cls, lines: a.lines.slice() };
+ if (j !== i) { out.push(c); continue; }
+ const r = fn(c);
+ if (r) out.push(r);
+ }
+ page.confirming = -1;
+ page.owner.edit(out);
+ }
+
+ function addApp() { page.owner.edit(page.list.concat([{ cls: "", lines: [""] }])); }
+ function removeApp(i) { page.edit(i, () => null); }
+ function setCls(i, t) { page.edit(i, a => Object.assign(a, { cls: t })); }
+ function addLine(i) { page.edit(i, a => Object.assign(a, { lines: a.lines.concat([""]) })); }
+ function setLine(i, j, t) {
+ page.edit(i, a => {
+ const ls = a.lines.slice();
+ ls[j] = t;
+ return Object.assign(a, { lines: ls });
+ });
+ }
+ function removeLine(i, j) { page.edit(i, a => Object.assign(a, { lines: a.lines.filter((_, k) => k !== j) })); }
+
+ component Small: Text {
+ color: Theme.subtext
+ font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 4 }
+ }
+
+ // Reports every keystroke into the draft. Not bound to value, which
+ // would reset the cursor; it follows the value only when the draft moves
+ // under it (Discard, Reset). Empty is outlined, since Save refuses it.
+ component Field: Rectangle {
+ id: field
+ property string value: ""
+ property string placeholder: ""
+ signal edited(string text)
+ height: 32
+ radius: 8
+ color: Qt.alpha(Theme.base, 0.6)
+ border.width: ti.text.trim() === "" ? 1 : 0
+ border.color: Theme.red
+ onValueChanged: if (ti.text !== field.value) ti.text = field.value
+ TextInput {
+ activeFocusOnTab: true
+ id: ti
+ anchors { fill: parent; leftMargin: 10; rightMargin: 10 }
+ verticalAlignment: TextInput.AlignVCenter
+ clip: true
+ selectByMouse: true
+ color: Theme.text
+ font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 3 }
+ Component.onCompleted: text = field.value
+ onTextEdited: field.edited(text)
+ Text {
+ anchors.verticalCenter: parent.verticalCenter
+ visible: parent.text === ""
+ text: field.placeholder
+ color: Theme.overlay
+ font: parent.font
+ }
+ }
+ }
+
+ Small {
+ width: page.width
+ wrapMode: Text.Wrap
+ text: page.intro
+ }
+
+ Repeater {
+ // A count, not the list: a new list on every keystroke would rebuild
+ // every card and drop the focus of the field being typed in.
+ model: page.list.length
+
+ delegate: Rectangle {
+ id: card
+ required property int index
+ readonly property var modelData: page.list[index] ?? { cls: "", lines: [] }
+ objectName: "app:" + index
+ width: page.width
+ height: body.implicitHeight + 20
+ radius: 10
+ color: Qt.alpha(Theme.surface, 0.45)
+
+ Column {
+ id: body
+ anchors { left: parent.left; right: parent.right; top: parent.top; margins: 10 }
+ spacing: 8
+
+ Item {
+ width: parent.width
+ height: 32
+ Field {
+ anchors { left: parent.left; right: del.left; rightMargin: 8; top: parent.top; bottom: parent.bottom }
+ value: card.modelData.cls
+ placeholder: page.keyHint
+ onEdited: t => page.setCls(card.index, t)
+ }
+ Button {
+ id: del
+ anchors { right: parent.right; verticalCenter: parent.verticalCenter }
+ danger: true
+ text: page.confirming === card.index ? "Confirm" : "Remove"
+ onClicked: {
+ if (page.confirming === card.index) page.removeApp(card.index);
+ else page.confirming = card.index;
+ }
+ }
+ }
+
+ Repeater {
+ model: card.modelData.lines.length
+ delegate: Row {
+ id: phraseRow
+ required property int index
+ width: body.width
+ spacing: 6
+ Field {
+ width: phraseRow.width - removeBtn.width - phraseRow.spacing
+ value: card.modelData.lines[phraseRow.index] ?? ""
+ placeholder: "a line she says"
+ onEdited: t => page.setLine(card.index, phraseRow.index, t)
+ }
+ Button {
+ id: removeBtn
+ // nf-fa-xmark, present in Inconsolata Nerd Font.
+ icon: "\uf00d"
+ danger: true
+ onClicked: page.removeLine(card.index, phraseRow.index)
+ }
+ }
+ }
+
+ Button {
+ text: "Add phrase"
+ onClicked: page.addLine(card.index)
+ }
+ }
+ }
+ }
+
+ Row {
+ spacing: 8
+ Button { text: page.addText; onClicked: page.addApp() }
+ Button {
+ text: "Reset to defaults"
+ danger: true
+ enabled: !page.owner.resetting && (page.saved !== null || page.owner.dirty)
+ onClicked: page.owner.reset()
+ }
+ }
+}
diff --git a/desktop/shell.qml b/desktop/shell.qml
index 8aaead3..35dbe3f 100644
--- a/desktop/shell.qml
+++ b/desktop/shell.qml
@@ -88,6 +88,8 @@ ShellRoot {
SunsetModule {},
IdleModule {},
CompanionModule {},
+ PhrasesModule {},
+ ArtistsModule {},
NotificationsModule {},
AutostartModule {},
ObsScenesModule {},