- Per-app volume slider and a system volume card (slider + mute) - Default output device picker; per-app output device picker (Windows via IPolicyConfig / IAudioPolicyConfigFactory, Linux via sink moves; macOS has no per-app routing API) - Slider commands are coalesced on the audio thread - Fix the Windows title-bar and taskbar icon (set via winit attributes) - About: "by X4Lo" and a GitHub link - README: app icon above the title - --list prints output devices and system volume - CI: run on master and on manual dispatch
452 lines
15 KiB
Plaintext
452 lines
15 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;
|
||
}
|
||
|
||
// Horizontal volume slider. `value` comes from Rust; while dragging the knob follows the
|
||
// pointer locally, so periodic refreshes never make it jump under the user's finger.
|
||
export component VolumeSlider inherits Rectangle {
|
||
in property <float> value; // 0..1
|
||
in property <bool> enabled: true;
|
||
in property <bool> dimmed; // muted: grey fill
|
||
in property <string> label;
|
||
callback moved(float); // 0..1, fires continuously while dragging
|
||
|
||
property <float> drag-value;
|
||
property <float> shown: touch.pressed ? drag-value : clamp(value, 0, 1);
|
||
property <length> knob: 14px;
|
||
|
||
height: 22px;
|
||
min-width: 60px;
|
||
opacity: enabled ? 1 : 0.4;
|
||
|
||
accessible-role: slider;
|
||
accessible-label: label;
|
||
accessible-value: round(root.shown * 100) + "%";
|
||
accessible-value-minimum: 0;
|
||
accessible-value-maximum: 100;
|
||
accessible-value-step: 5;
|
||
accessible-action-increment => { root.moved(min(1, root.value + 0.05)); }
|
||
accessible-action-decrement => { root.moved(max(0, root.value - 0.05)); }
|
||
|
||
function set-from(x: length) {
|
||
root.drag-value = clamp((x - root.knob / 2) / max(1px, root.width - root.knob), 0, 1);
|
||
root.moved(root.drag-value);
|
||
}
|
||
|
||
Rectangle {
|
||
y: (parent.height - 4px) / 2;
|
||
height: 4px;
|
||
border-radius: 2px;
|
||
background: Theme.border;
|
||
}
|
||
Rectangle {
|
||
x: 0;
|
||
y: (parent.height - 4px) / 2;
|
||
height: 4px;
|
||
width: (root.width - root.knob) * root.shown + root.knob / 2;
|
||
border-radius: 2px;
|
||
background: root.dimmed ? Theme.text-faint : Theme.accent;
|
||
}
|
||
Rectangle {
|
||
x: (root.width - root.knob) * root.shown;
|
||
y: (parent.height - root.knob) / 2;
|
||
width: root.knob;
|
||
height: root.knob;
|
||
border-radius: root.knob / 2;
|
||
background: white;
|
||
border-width: 1px;
|
||
border-color: touch.has-hover || touch.pressed ? (root.dimmed ? Theme.text-faint : Theme.accent) : Theme.border-strong;
|
||
drop-shadow-blur: 3px;
|
||
drop-shadow-color: #00000040;
|
||
}
|
||
touch := TouchArea {
|
||
enabled: root.enabled;
|
||
mouse-cursor: pointer;
|
||
pointer-event(e) => {
|
||
if (e.kind == PointerEventKind.down && e.button == PointerEventButton.left) {
|
||
root.set-from(self.mouse-x);
|
||
}
|
||
}
|
||
moved => {
|
||
if (self.pressed) {
|
||
root.set-from(self.mouse-x);
|
||
}
|
||
}
|
||
scroll-event(e) => {
|
||
if (e.delta-y == 0) {
|
||
return reject;
|
||
}
|
||
root.moved(clamp(root.value + (e.delta-y > 0 ? 0.05 : -0.05), 0, 1));
|
||
accept
|
||
}
|
||
}
|
||
}
|
||
|
||
// Compact drop-down: shows the selected option, opens a themed popup list.
|
||
export component DevicePicker inherits Rectangle {
|
||
in property <[string]> options;
|
||
in property <int> selected; // index into options, -1 = none
|
||
in property <string> label; // accessibility label
|
||
in property <bool> enabled: true;
|
||
in property <length> popup-width: 260px;
|
||
callback picked(int);
|
||
|
||
property <string> current: selected >= 0 && selected < options.length ? options[selected] : "—";
|
||
|
||
height: 28px;
|
||
min-width: 80px;
|
||
border-radius: 8px;
|
||
border-width: 1px;
|
||
border-color: Theme.border;
|
||
background: touch.has-hover ? Theme.surface-hover : Theme.surface-sunken;
|
||
opacity: enabled ? 1 : 0.5;
|
||
animate background { duration: Theme.fast; }
|
||
|
||
accessible-role: combobox;
|
||
accessible-label: label;
|
||
accessible-value: current;
|
||
accessible-action-default => { if (root.enabled) { popup.show(); } }
|
||
|
||
HorizontalLayout {
|
||
padding-left: 10px;
|
||
padding-right: 9px;
|
||
spacing: 6px;
|
||
Text {
|
||
text: root.current;
|
||
font-size: 12px;
|
||
color: Theme.text;
|
||
vertical-alignment: center;
|
||
overflow: elide;
|
||
horizontal-stretch: 1;
|
||
}
|
||
Path {
|
||
width: 9px;
|
||
height: 5px;
|
||
y: (parent.height - self.height) / 2;
|
||
viewbox-width: 10;
|
||
viewbox-height: 6;
|
||
commands: "M1 1l4 4 4-4";
|
||
stroke: Theme.text-muted;
|
||
stroke-width: 1.5px;
|
||
fill: transparent;
|
||
}
|
||
}
|
||
touch := TouchArea {
|
||
enabled: root.enabled;
|
||
mouse-cursor: pointer;
|
||
clicked => { popup.show(); }
|
||
}
|
||
popup := PopupWindow {
|
||
x: root.width - root.popup-width;
|
||
y: root.height + 4px;
|
||
width: root.popup-width;
|
||
Rectangle {
|
||
background: Theme.surface;
|
||
border-radius: 10px;
|
||
border-width: 1px;
|
||
border-color: Theme.border-strong;
|
||
drop-shadow-blur: 16px;
|
||
drop-shadow-offset-y: 4px;
|
||
drop-shadow-color: #00000059;
|
||
VerticalLayout {
|
||
padding: 4px;
|
||
spacing: 1px;
|
||
for option[i] in root.options: Rectangle {
|
||
height: 30px;
|
||
border-radius: 6px;
|
||
background: item.has-hover ? Theme.surface-hover : transparent;
|
||
accessible-role: list-item;
|
||
accessible-label: option;
|
||
accessible-action-default => { root.picked(i); }
|
||
HorizontalLayout {
|
||
padding-left: 10px;
|
||
padding-right: 10px;
|
||
spacing: 8px;
|
||
Text {
|
||
text: option;
|
||
font-size: 12px;
|
||
font-weight: i == root.selected ? 600 : 400;
|
||
color: i == root.selected ? Theme.accent : Theme.text;
|
||
vertical-alignment: center;
|
||
overflow: elide;
|
||
horizontal-stretch: 1;
|
||
}
|
||
if i == root.selected: Path {
|
||
width: 11px;
|
||
height: 8px;
|
||
y: (parent.height - self.height) / 2;
|
||
viewbox-width: 12;
|
||
viewbox-height: 9;
|
||
commands: "M1 4.5l3.5 3.5 6.5-7";
|
||
stroke: Theme.accent;
|
||
stroke-width: 1.7px;
|
||
fill: transparent;
|
||
}
|
||
}
|
||
item := TouchArea {
|
||
mouse-cursor: pointer;
|
||
clicked => { root.picked(i); }
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|