fix(ags audio): fix crash with default and improve toggles
All checks were successful
Discord / discord commits (push) Has been skipped

This commit is contained in:
matt1432 2024-12-07 17:17:30 -05:00
parent 936e9aacb0
commit 0455271294
2 changed files with 88 additions and 73 deletions

View file

@ -7,5 +7,15 @@
padding: 10px; padding: 10px;
border-radius: 8px; border-radius: 8px;
background-color: color.adjust(colors.$window_bg_color, $lightness: -3%); background-color: color.adjust(colors.$window_bg_color, $lightness: -3%);
.body {
.toggle {
padding: 5px;
icon {
font-size: 26px;
}
}
}
} }
} }

View file

@ -3,7 +3,7 @@ import { Gtk, Widget } from 'astal/gtk3';
import AstalWp from 'gi://AstalWp'; import AstalWp from 'gi://AstalWp';
import { RadioButton, ToggleButton } from '../misc/subclasses'; import { RadioButton } from '../misc/subclasses';
import Separator from '../misc/separator'; import Separator from '../misc/separator';
@ -17,56 +17,58 @@ export default () => {
// TODO: make a stack to have outputs, inputs and currently playing apps // TODO: make a stack to have outputs, inputs and currently playing apps
// TODO: figure out ports and profiles // TODO: figure out ports and profiles
const defaultGroup = new RadioButton();
return ( return (
<box vertical className="widget audio"> <box vertical className="widget audio">
{bind(audio, 'speakers').as((speakers) => speakers.map((speaker) => (
{bind(audio, 'speakers').as((speakers) => {
const widgets = speakers.map((speaker, i) => (
<box className="stream" vertical> <box className="stream" vertical>
<box className="title"> <box className="title">
<RadioButton <RadioButton
css="margin-top: 1px;" css="margin-top: 1px;"
group={defaultGroup} active={bind(speaker, 'isDefault')}
active={speaker.isDefault}
setup={(self) => { onRealize={(self) => {
speaker.connect('notify::isDefault', () => { if (i !== 0) {
self.active = speaker.isDefault; self.group = (((widgets[0] as Widget.Box)
}); .get_children()[0] as Widget.Box)
.get_children()[0] as RadioButton);
}
}} }}
onToggled={(self) => { onButtonReleaseEvent={() => {
speaker.isDefault = self.active; speaker.isDefault = true;
}} }}
/> />
<Separator size={8} /> <Separator size={8} />
<label label={bind(speaker, 'description')} /> <label label={bind(speaker, 'description')} />
</box> </box>
<Separator size={4} vertical /> <Separator size={4} vertical />
<box className="body"> <box className="body">
<ToggleButton
<button
cursor="pointer" cursor="pointer"
className="toggle"
valign={Gtk.Align.END} valign={Gtk.Align.END}
active={speaker.mute} onButtonReleaseEvent={() => {
onToggled={(self) => { speaker.mute = !speaker.mute;
speaker.set_mute(self.active);
(self.get_child() as Widget.Icon).icon = self.active ?
'audio-volume-muted-symbolic' :
'audio-speakers-symbolic';
}} }}
> >
<icon icon={speaker.mute ? <icon
icon={bind(speaker, 'mute').as((isMuted) => isMuted ?
'audio-volume-muted-symbolic' : 'audio-volume-muted-symbolic' :
'audio-speakers-symbolic'} 'audio-speakers-symbolic')}
/> />
</ToggleButton> </button>
<Separator size={4} /> <Separator size={4} />
@ -74,24 +76,21 @@ export default () => {
FIXME: lockChannels not working FIXME: lockChannels not working
TODO: have two sliders when lockChannels === false TODO: have two sliders when lockChannels === false
*/} */}
<ToggleButton <button
cursor="pointer" cursor="pointer"
className="toggle"
valign={Gtk.Align.END} valign={Gtk.Align.END}
active={speaker.lockChannels} onButtonReleaseEvent={() => {
onToggled={(self) => { speaker.lockChannels = !speaker.lockChannels;
speaker.set_lock_channels(self.active);
(self.get_child() as Widget.Icon).icon = self.active ?
'channel-secure-symbolic' :
'channel-insecure-symbolic';
}} }}
> >
<icon icon={speaker.lockChannels ? <icon
icon={bind(speaker, 'lockChannels').as((locked) => locked ?
'channel-secure-symbolic' : 'channel-secure-symbolic' :
'channel-insecure-symbolic'} 'channel-insecure-symbolic')}
/> />
</ToggleButton> </button>
<slider <slider
hexpand hexpand
@ -103,9 +102,15 @@ export default () => {
speaker.set_volume(self.value); speaker.set_volume(self.value);
}} }}
/> />
</box> </box>
</box> </box>
)))} ));
return widgets;
})}
</box> </box>
); );
}; };