Native Rust tray app that binds global shortcuts to mute/unmute individual applications' audio, plus a Mute All / Restore All shortcut. - AudioController trait with per-OS backends: WASAPI sessions (Windows), Core Audio process taps (macOS 14.2+, mute only), PulseAudio/PipeWire sink inputs (Linux) - Dedicated audio thread; hotkey presses go straight to it - Snapshot-based Mute All that restores exactly the previous state - Slint UI with software renderer; window destroyed on close - Non-activating on-screen confirmation and tray icon flash - TOML config, launch at login, start minimized, dark/light theme - Procedurally drawn icon embedded into the Windows executable - Docs, AGENTS.md, CLAUDE.md, contributing guide and CI for all three OSes
261 lines
8.5 KiB
Plaintext
261 lines
8.5 KiB
Plaintext
// Small reusable building blocks. Everything is drawn with Slint primitives
|
||
// (no icon fonts, no images) so it renders identically on every OS.
|
||
|
||
import { Theme } from "theme.slint";
|
||
|
||
export component SpeakerIcon inherits Path {
|
||
in property <bool> muted;
|
||
in property <color> color: Theme.text;
|
||
viewbox-width: 24;
|
||
viewbox-height: 24;
|
||
width: 18px;
|
||
height: 18px;
|
||
stroke: color;
|
||
stroke-width: 1.9px;
|
||
fill: transparent;
|
||
commands: muted
|
||
? "M4 9.5h3.5L12 5.5v13l-4.5-4H4z M15.5 9.5l5 5 M20.5 9.5l-5 5"
|
||
: "M4 9.5h3.5L12 5.5v13l-4.5-4H4z M15.5 9a4 4 0 0 1 0 6 M18.2 6.5a7.6 7.6 0 0 1 0 11";
|
||
}
|
||
|
||
export component ThemeIcon inherits Path {
|
||
in property <bool> dark;
|
||
viewbox-width: 24;
|
||
viewbox-height: 24;
|
||
width: 17px;
|
||
height: 17px;
|
||
stroke: Theme.text-muted;
|
||
stroke-width: 1.8px;
|
||
fill: transparent;
|
||
// Moon in dark mode (click → light), sun in light mode.
|
||
commands: dark
|
||
? "M20 14.5A8 8 0 0 1 9.5 4a8 8 0 1 0 10.5 10.5z"
|
||
: "M16 12a4 4 0 1 1-8 0a4 4 0 1 1 8 0z M12 2.5v2 M12 19.5v2 M2.5 12h2 M19.5 12h2 M5.3 5.3l1.4 1.4 M17.3 17.3l1.4 1.4 M5.3 18.7l1.4-1.4 M17.3 6.7l1.4-1.4";
|
||
}
|
||
|
||
export component IconButton inherits Rectangle {
|
||
callback clicked;
|
||
in property <string> tooltip;
|
||
width: 32px;
|
||
height: 32px;
|
||
border-radius: 9px;
|
||
background: touch.has-hover ? Theme.surface-hover : transparent;
|
||
animate background { duration: Theme.fast; }
|
||
accessible-role: button;
|
||
accessible-label: tooltip;
|
||
accessible-action-default => { root.clicked(); }
|
||
touch := TouchArea {
|
||
mouse-cursor: pointer;
|
||
clicked => { root.clicked(); }
|
||
}
|
||
@children
|
||
}
|
||
|
||
export component Tabs inherits Rectangle {
|
||
in property <[string]> items;
|
||
in-out property <int> selected;
|
||
height: 32px;
|
||
border-radius: 10px;
|
||
background: Theme.surface-sunken;
|
||
HorizontalLayout {
|
||
padding: 3px;
|
||
spacing: 2px;
|
||
for item[i] in root.items: Rectangle {
|
||
border-radius: 7px;
|
||
background: i == root.selected ? Theme.surface : transparent;
|
||
drop-shadow-blur: i == root.selected ? 4px : 0;
|
||
drop-shadow-color: #0000001f;
|
||
animate background { duration: Theme.fast; }
|
||
accessible-role: tab;
|
||
accessible-label: item;
|
||
accessible-action-default => { root.selected = i; }
|
||
HorizontalLayout {
|
||
padding-left: 12px;
|
||
padding-right: 12px;
|
||
Text {
|
||
text: item;
|
||
font-size: 12.5px;
|
||
font-weight: i == root.selected ? 600 : 500;
|
||
color: i == root.selected ? Theme.text : Theme.text-muted;
|
||
vertical-alignment: center;
|
||
horizontal-alignment: center;
|
||
}
|
||
}
|
||
TouchArea {
|
||
mouse-cursor: pointer;
|
||
clicked => { root.selected = i; }
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
export component Switch inherits Rectangle {
|
||
in-out property <bool> checked;
|
||
in property <string> label;
|
||
callback toggled(bool);
|
||
width: 40px;
|
||
height: 23px;
|
||
border-radius: self.height / 2;
|
||
background: checked ? Theme.accent : Theme.border-strong;
|
||
animate background { duration: Theme.fast; }
|
||
accessible-role: switch;
|
||
accessible-checkable: true;
|
||
accessible-checked: checked;
|
||
accessible-label: label;
|
||
accessible-action-default => { touch.clicked(); }
|
||
knob := Rectangle {
|
||
width: parent.height - 6px;
|
||
height: self.width;
|
||
y: 3px;
|
||
x: root.checked ? parent.width - self.width - 3px : 3px;
|
||
border-radius: self.width / 2;
|
||
background: white;
|
||
drop-shadow-blur: 3px;
|
||
drop-shadow-color: #00000040;
|
||
animate x { duration: 160ms; easing: ease-out; }
|
||
}
|
||
touch := TouchArea {
|
||
mouse-cursor: pointer;
|
||
clicked => {
|
||
root.checked = !root.checked;
|
||
root.toggled(root.checked);
|
||
}
|
||
}
|
||
}
|
||
|
||
// Click → "Press keys…" → shows the captured combo. × clears it.
|
||
export component ShortcutChip inherits Rectangle {
|
||
in property <string> shortcut;
|
||
in property <bool> capturing;
|
||
in property <bool> on-accent; // white-on-gradient styling for the Mute All card
|
||
in property <bool> enabled: true;
|
||
in property <string> placeholder: "Set shortcut";
|
||
in property <string> label; // accessibility label, e.g. "Spotify shortcut"
|
||
callback clicked;
|
||
callback cleared;
|
||
|
||
property <bool> blink;
|
||
property <bool> bound: shortcut != "";
|
||
|
||
height: 30px;
|
||
min-width: 104px;
|
||
border-radius: 8px;
|
||
border-width: 1px;
|
||
border-color: capturing
|
||
? (on-accent ? white : Theme.accent)
|
||
: on-accent ? #ffffff59 : (bound ? Theme.border-strong : Theme.border);
|
||
background: on-accent
|
||
? (capturing ? #ffffff38 : (touch.has-hover ? #ffffff2e : #ffffff1f))
|
||
: capturing ? Theme.accent-soft : (bound ? Theme.surface-sunken : (touch.has-hover ? Theme.surface-hover : transparent));
|
||
opacity: enabled ? 1 : 0.5;
|
||
animate background, border-color { duration: Theme.fast; }
|
||
|
||
accessible-role: button;
|
||
accessible-label: label + ": " + (capturing ? "press a key combination" : (bound ? shortcut : "not set"));
|
||
accessible-action-default => { root.clicked(); }
|
||
|
||
Timer {
|
||
interval: 450ms;
|
||
running: root.capturing;
|
||
triggered => { root.blink = !root.blink; }
|
||
}
|
||
|
||
touch := TouchArea {
|
||
enabled: root.enabled;
|
||
mouse-cursor: pointer;
|
||
clicked => { root.clicked(); }
|
||
}
|
||
|
||
HorizontalLayout {
|
||
padding-left: 10px;
|
||
padding-right: root.bound && !root.capturing ? 4px : 10px;
|
||
spacing: 6px;
|
||
if root.capturing: Rectangle {
|
||
width: 7px;
|
||
height: 7px;
|
||
y: (parent.height - self.height) / 2;
|
||
border-radius: 3.5px;
|
||
background: root.on-accent ? white : Theme.accent;
|
||
opacity: root.blink ? 0.25 : 1;
|
||
animate opacity { duration: 200ms; }
|
||
}
|
||
Text {
|
||
text: root.capturing ? "Press keys…" : (root.bound ? root.shortcut : root.placeholder);
|
||
font-size: 12px;
|
||
font-weight: root.bound && !root.capturing ? 600 : 500;
|
||
color: root.on-accent ? white : (root.capturing ? Theme.accent : (root.bound ? Theme.text : Theme.text-muted));
|
||
vertical-alignment: center;
|
||
horizontal-alignment: center;
|
||
horizontal-stretch: 1;
|
||
overflow: elide;
|
||
}
|
||
if root.bound && !root.capturing: Rectangle {
|
||
width: 22px;
|
||
height: 22px;
|
||
y: (parent.height - self.height) / 2;
|
||
border-radius: 6px;
|
||
background: clear.has-hover ? (root.on-accent ? #ffffff33 : Theme.border) : transparent;
|
||
accessible-role: button;
|
||
accessible-label: "Clear shortcut";
|
||
accessible-action-default => { root.cleared(); }
|
||
Path {
|
||
width: 10px;
|
||
height: 10px;
|
||
viewbox-width: 10;
|
||
viewbox-height: 10;
|
||
commands: "M1 1l8 8 M9 1l-8 8";
|
||
stroke: root.on-accent ? white : Theme.text-muted;
|
||
stroke-width: 1.5px;
|
||
}
|
||
clear := TouchArea {
|
||
mouse-cursor: pointer;
|
||
clicked => { root.cleared(); }
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
export component SettingRow inherits Rectangle {
|
||
in property <string> title;
|
||
in property <string> subtitle;
|
||
min-height: 58px;
|
||
HorizontalLayout {
|
||
padding-left: 16px;
|
||
padding-right: 16px;
|
||
padding-top: 10px;
|
||
padding-bottom: 10px;
|
||
spacing: 12px;
|
||
VerticalLayout {
|
||
alignment: center;
|
||
spacing: 2px;
|
||
horizontal-stretch: 1;
|
||
Text { text: root.title; font-size: 13.5px; font-weight: 600; color: Theme.text; }
|
||
if root.subtitle != "": Text {
|
||
text: root.subtitle;
|
||
font-size: 12px;
|
||
color: Theme.text-muted;
|
||
wrap: word-wrap;
|
||
}
|
||
}
|
||
VerticalLayout {
|
||
alignment: center;
|
||
@children
|
||
}
|
||
}
|
||
}
|
||
|
||
export component Card inherits Rectangle {
|
||
background: Theme.surface;
|
||
border-radius: Theme.radius;
|
||
border-width: 1px;
|
||
border-color: Theme.border;
|
||
@children
|
||
}
|
||
|
||
export component SectionLabel inherits Text {
|
||
font-size: 11px;
|
||
font-weight: 700;
|
||
letter-spacing: 0.8px;
|
||
color: Theme.text-faint;
|
||
}
|