This commit is contained in:
Erica Z 2024-11-03 16:17:54 +01:00
parent 0c2a614375
commit acd1d7d803
4 changed files with 26 additions and 3 deletions

View file

@ -150,7 +150,7 @@ template $AudreyUiPlaybar: Adw.Bin {
} }
Button { Button {
icon-name: bind $mute_button_icon_name (template.playbin as <$AudreyPlaybin>.mute) as <string>; icon-name: bind $mute_button_icon_name (template.mute) as <string>;
valign: center; valign: center;
clicked => $on_mute_toggle () swapped; clicked => $on_mute_toggle () swapped;

View file

@ -237,6 +237,10 @@ where
self.volume_changed.signal() self.volume_changed.signal()
} }
pub fn muted_changed(&self) -> Signal<'_, Self, ()> {
self.muted_changed.signal()
}
pub fn file_started(&self) -> Signal<'_, Self, ()> { pub fn file_started(&self) -> Signal<'_, Self, ()> {
self.file_started.signal() self.file_started.signal()
} }

View file

@ -21,6 +21,8 @@ mod imp {
#[property(get, set)] #[property(get, set)]
volume: Cell<i32>, volume: Cell<i32>,
#[property(get, set)]
mute: Cell<bool>,
} }
#[glib::object_subclass] #[glib::object_subclass]
@ -156,8 +158,7 @@ mod imp {
#[template_callback] #[template_callback]
fn on_mute_toggle(&self) { fn on_mute_toggle(&self) {
let playbin = self.playbin.upgrade().unwrap(); self.obj().set_mute(!self.obj().mute());
playbin.set_mute(!playbin.mute());
} }
} }

View file

@ -189,6 +189,7 @@ impl Window {
let window: Self = glib::Object::builder().property("application", app).build(); let window: Self = glib::Object::builder().property("application", app).build();
// manual bidirectional sync // manual bidirectional sync
window.imp().playbar.set_volume(window.imp().playbin2.volume() as i32);
window.imp().playbin2.volume_changed().connect_object( window.imp().playbin2.volume_changed().connect_object(
&*window.imp().playbar, &*window.imp().playbar,
|playbin, playbar, ()| { |playbin, playbar, ()| {
@ -205,6 +206,23 @@ impl Window {
), ),
); );
window.imp().playbar.set_mute(window.imp().playbin2.muted());
window.imp().playbin2.muted_changed().connect_object(
&*window.imp().playbar,
|playbin, playbar, ()| {
playbar.set_mute(playbin.muted());
true
},
);
window.imp().playbar.connect_notify_local(
Some("mute"),
glib::clone!(
#[weak(rename_to = playbin)]
window.imp().playbin2,
move |playbar, _| playbin.set_muted(playbar.mute())
),
);
window window
.imp() .imp()
.setup .setup