From f8015fbe1046b3a7a54809ddebf594c4d0e7730b Mon Sep 17 00:00:00 2001 From: Erica Z Date: Wed, 30 Oct 2024 13:25:27 +0100 Subject: [PATCH] seekbar also works again --- resources/playbar.blp | 12 ++++++------ src/playbin.rs | 7 +++++++ src/ui/playbar.rs | 17 ++++++++--------- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/resources/playbar.blp b/resources/playbar.blp index 91fa730..cb23ad6 100644 --- a/resources/playbar.blp +++ b/resources/playbar.blp @@ -82,7 +82,7 @@ template $AudreyUiPlaybar: Adw.Bin { upper: bind template.playbin as <$AudreyPlaybin>.duration; }; - change-value => $on_play_position_seek (); + change-value => $on_play_position_seek (template); } [end] @@ -105,7 +105,7 @@ template $AudreyUiPlaybar: Adw.Bin { valign: center; sensitive: bind $playbin_active (template.playbin as <$AudreyPlaybin>.state as <$AudreyPlaybinState>) as ; - clicked => $on_skip_backward_clicked (); + clicked => $on_skip_backward_clicked (template); } Button { @@ -113,7 +113,7 @@ template $AudreyUiPlaybar: Adw.Bin { valign: center; sensitive: bind $playbin_active (template.playbin as <$AudreyPlaybin>.state as <$AudreyPlaybinState>) as ; - clicked => $seek_backward (); + clicked => $seek_backward (template); } Button { @@ -129,7 +129,7 @@ template $AudreyUiPlaybar: Adw.Bin { valign: center; sensitive: bind $playbin_active (template.playbin as <$AudreyPlaybin>.state as <$AudreyPlaybinState>) as ; - clicked => $seek_forward (); + clicked => $seek_forward (template); } Button { @@ -137,7 +137,7 @@ template $AudreyUiPlaybar: Adw.Bin { valign: center; sensitive: bind $playbin_active (template.playbin as <$AudreyPlaybin>.state as <$AudreyPlaybinState>) as ; - clicked => $on_skip_forward_clicked (); + clicked => $on_skip_forward_clicked (template); } } } @@ -153,7 +153,7 @@ template $AudreyUiPlaybar: Adw.Bin { icon-name: bind $mute_button_icon_name (template.playbin as <$AudreyPlaybin>.mute) as ; valign: center; - clicked => $on_mute_toggle (); + clicked => $on_mute_toggle (template); } Scale { diff --git a/src/playbin.rs b/src/playbin.rs index 89d0880..43799ec 100644 --- a/src/playbin.rs +++ b/src/playbin.rs @@ -24,6 +24,7 @@ mod ffi { pub fn audrey_playbin_play(self_: *mut AudreyPlaybin); pub fn audrey_playbin_get_volume(self_: *mut AudreyPlaybin) -> std::ffi::c_int; pub fn audrey_playbin_set_volume(self_: *mut AudreyPlaybin, volume: std::ffi::c_int); + pub fn audrey_playbin_seek(self_: *mut AudreyPlaybin, position: f64); } } @@ -67,4 +68,10 @@ impl Playbin { unsafe { ffi::audrey_playbin_set_volume(self.to_glib_none().0, value) } } + + pub fn seek(&self, position: f64) { + use glib::translate::ToGlibPtr; + + unsafe { ffi::audrey_playbin_seek(self.to_glib_none().0, position) } + } } diff --git a/src/ui/playbar.rs b/src/ui/playbar.rs index d0ee4ff..576be40 100644 --- a/src/ui/playbar.rs +++ b/src/ui/playbar.rs @@ -19,7 +19,7 @@ mod imp { show_cover_art: Cell, #[property(get = Self::get_volume, set = Self::set_volume)] - volume: i32, + _volume: i32, } #[glib::object_subclass] @@ -106,17 +106,16 @@ mod imp { #[template_callback] fn on_play_position_seek( &self, - _range: >k::Range, _scroll_type: gtk::ScrollType, - _value: f64, + value: f64, + range: >k::Range, ) -> bool { - /* - if (range.adjustment.lower < range.adjustment.upper) { - this.playbin.seek ((int64) value); + let playbin = self.playbin.borrow(); + let playbin = playbin.as_ref().unwrap(); + if range.adjustment().lower() < range.adjustment().upper() { + playbin.seek(value); } - return false; - */ - todo!() + false } #[template_callback]