2024-12-07 14:17:37 -05:00
|
|
|
import { bind } from 'astal';
|
|
|
|
import { Gtk, Widget } from 'astal/gtk3';
|
|
|
|
|
|
|
|
import AstalWp from 'gi://AstalWp';
|
|
|
|
|
2024-12-07 17:17:30 -05:00
|
|
|
import { RadioButton } from '../misc/subclasses';
|
2024-12-07 14:17:37 -05:00
|
|
|
import Separator from '../misc/separator';
|
|
|
|
|
|
|
|
|
|
|
|
export default () => {
|
|
|
|
const audio = AstalWp.get_default()?.get_audio();
|
|
|
|
|
|
|
|
if (!audio) {
|
|
|
|
throw new Error('Could not find default audio devices.');
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: make a stack to have outputs, inputs and currently playing apps
|
|
|
|
// TODO: figure out ports and profiles
|
|
|
|
|
|
|
|
return (
|
|
|
|
<box vertical className="widget audio">
|
|
|
|
|
2024-12-07 17:17:30 -05:00
|
|
|
{bind(audio, 'speakers').as((speakers) => {
|
|
|
|
const widgets = speakers.map((speaker, i) => (
|
|
|
|
<box className="stream" vertical>
|
2024-12-07 14:17:37 -05:00
|
|
|
|
2024-12-07 17:17:30 -05:00
|
|
|
<box className="title">
|
2024-12-07 14:17:37 -05:00
|
|
|
|
2024-12-07 17:17:30 -05:00
|
|
|
<RadioButton
|
|
|
|
css="margin-top: 1px;"
|
2024-12-07 14:17:37 -05:00
|
|
|
|
2024-12-07 17:17:30 -05:00
|
|
|
active={bind(speaker, 'isDefault')}
|
2024-12-07 14:17:37 -05:00
|
|
|
|
2024-12-07 17:17:30 -05:00
|
|
|
onRealize={(self) => {
|
|
|
|
if (i !== 0) {
|
|
|
|
self.group = (((widgets[0] as Widget.Box)
|
|
|
|
.get_children()[0] as Widget.Box)
|
|
|
|
.get_children()[0] as RadioButton);
|
|
|
|
}
|
|
|
|
}}
|
2024-12-07 14:17:37 -05:00
|
|
|
|
2024-12-07 17:17:30 -05:00
|
|
|
onButtonReleaseEvent={() => {
|
|
|
|
speaker.isDefault = true;
|
|
|
|
}}
|
2024-12-07 14:17:37 -05:00
|
|
|
/>
|
2024-12-07 17:17:30 -05:00
|
|
|
|
|
|
|
<Separator size={8} />
|
|
|
|
|
|
|
|
<label label={bind(speaker, 'description')} />
|
|
|
|
|
|
|
|
</box>
|
|
|
|
|
|
|
|
<Separator size={4} vertical />
|
|
|
|
|
|
|
|
<box className="body">
|
|
|
|
|
|
|
|
<button
|
|
|
|
cursor="pointer"
|
|
|
|
className="toggle"
|
|
|
|
valign={Gtk.Align.END}
|
|
|
|
|
|
|
|
onButtonReleaseEvent={() => {
|
|
|
|
speaker.mute = !speaker.mute;
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<icon
|
|
|
|
icon={bind(speaker, 'mute').as((isMuted) => isMuted ?
|
|
|
|
'audio-volume-muted-symbolic' :
|
|
|
|
'audio-speakers-symbolic')}
|
|
|
|
/>
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<Separator size={4} />
|
|
|
|
|
|
|
|
{/*
|
|
|
|
FIXME: lockChannels not working
|
|
|
|
TODO: have two sliders when lockChannels === false
|
|
|
|
*/}
|
|
|
|
<button
|
|
|
|
cursor="pointer"
|
|
|
|
className="toggle"
|
|
|
|
valign={Gtk.Align.END}
|
|
|
|
|
|
|
|
onButtonReleaseEvent={() => {
|
|
|
|
speaker.lockChannels = !speaker.lockChannels;
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<icon
|
|
|
|
icon={bind(speaker, 'lockChannels').as((locked) => locked ?
|
|
|
|
'channel-secure-symbolic' :
|
|
|
|
'channel-insecure-symbolic')}
|
|
|
|
/>
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<slider
|
|
|
|
hexpand
|
|
|
|
halign={Gtk.Align.FILL}
|
|
|
|
drawValue
|
|
|
|
|
|
|
|
value={bind(speaker, 'volume')}
|
|
|
|
onDragged={(self) => {
|
|
|
|
speaker.set_volume(self.value);
|
|
|
|
}}
|
2024-12-07 14:17:37 -05:00
|
|
|
/>
|
2024-12-07 17:17:30 -05:00
|
|
|
|
|
|
|
</box>
|
|
|
|
|
2024-12-07 14:17:37 -05:00
|
|
|
</box>
|
2024-12-07 17:17:30 -05:00
|
|
|
));
|
|
|
|
|
|
|
|
return widgets;
|
|
|
|
})}
|
|
|
|
|
2024-12-07 14:17:37 -05:00
|
|
|
</box>
|
|
|
|
);
|
|
|
|
};
|