From acd1d7d80363e79f87afb977d5657b59b1eab511 Mon Sep 17 00:00:00 2001 From: Erica Z Date: Sun, 3 Nov 2024 16:17:54 +0100 Subject: [PATCH] mute --- resources/playbar.blp | 2 +- src/playbin2.rs | 4 ++++ src/ui/playbar.rs | 5 +++-- src/ui/window.rs | 18 ++++++++++++++++++ 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/resources/playbar.blp b/resources/playbar.blp index 7abc917..c357af6 100644 --- a/resources/playbar.blp +++ b/resources/playbar.blp @@ -150,7 +150,7 @@ template $AudreyUiPlaybar: Adw.Bin { } Button { - icon-name: bind $mute_button_icon_name (template.playbin as <$AudreyPlaybin>.mute) as ; + icon-name: bind $mute_button_icon_name (template.mute) as ; valign: center; clicked => $on_mute_toggle () swapped; diff --git a/src/playbin2.rs b/src/playbin2.rs index f0252f5..3785aec 100644 --- a/src/playbin2.rs +++ b/src/playbin2.rs @@ -237,6 +237,10 @@ where self.volume_changed.signal() } + pub fn muted_changed(&self) -> Signal<'_, Self, ()> { + self.muted_changed.signal() + } + pub fn file_started(&self) -> Signal<'_, Self, ()> { self.file_started.signal() } diff --git a/src/ui/playbar.rs b/src/ui/playbar.rs index c7fa04f..698a0f7 100644 --- a/src/ui/playbar.rs +++ b/src/ui/playbar.rs @@ -21,6 +21,8 @@ mod imp { #[property(get, set)] volume: Cell, + #[property(get, set)] + mute: Cell, } #[glib::object_subclass] @@ -156,8 +158,7 @@ mod imp { #[template_callback] fn on_mute_toggle(&self) { - let playbin = self.playbin.upgrade().unwrap(); - playbin.set_mute(!playbin.mute()); + self.obj().set_mute(!self.obj().mute()); } } diff --git a/src/ui/window.rs b/src/ui/window.rs index 60defd5..98401ba 100644 --- a/src/ui/window.rs +++ b/src/ui/window.rs @@ -189,6 +189,7 @@ impl Window { let window: Self = glib::Object::builder().property("application", app).build(); // manual bidirectional sync + window.imp().playbar.set_volume(window.imp().playbin2.volume() as i32); window.imp().playbin2.volume_changed().connect_object( &*window.imp().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 .imp() .setup