From c1984b5b7986a304e40f240ac4d33d6ce5c7a0de Mon Sep 17 00:00:00 2001 From: Fabio Lenherr / DashieTM Date: Tue, 14 Nov 2023 21:25:39 +0100 Subject: [PATCH] feat: Add basic functionality to all audio usecases --- Cargo.toml | 2 +- src/components/input/outputStreamEntry.rs | 58 +++++++- src/components/input/outputStreamEntryImpl.rs | 5 + src/components/input/sourceBox.rs | 140 +++++++++++++++++- src/components/input/sourceBoxImpl.rs | 4 +- src/components/input/sourceEntry.rs | 6 +- src/components/input/sourceEntryImpl.rs | 2 +- src/components/output/inputStreamEntry.rs | 8 +- src/components/output/mod.rs | 4 +- .../output/{audioBox.rs => sinkBox.rs} | 70 ++++++--- .../{audioBoxImpl.rs => sinkBoxImpl.rs} | 22 +-- src/components/output/sinkEntry.rs | 6 +- src/components/window/handleSidebarClick.rs | 22 ++- src/resources/resetAudioInput.ui | 7 +- src/resources/resetAudioOutput.ui | 7 +- src/resources/resetBluetooth.ui | 2 +- src/resources/resetBluetoothEntry.ui | 2 +- src/resources/resetInputStreamEntry.ui | 9 +- src/resources/resetListBoxRow.ui | 2 +- src/resources/resetMainWindow.ui | 2 +- src/resources/resetOutpuStreamEntry.ui | 68 --------- src/resources/resetOutputStreamEntry.ui | 13 +- src/resources/resetPopup.ui | 2 +- src/resources/resetSavedWifiEntry.ui | 2 +- src/resources/resetSettingBox.ui | 2 +- src/resources/resetSidebarEntry.ui | 2 +- src/resources/resetSinkEntry.ui | 13 +- src/resources/resetSourceEntry.ui | 13 +- src/resources/resetUI.cmb | 69 +++++---- src/resources/resetWiFi.ui | 2 +- src/resources/resetWifiEntry.ui | 2 +- src/resources/resources.gresource.xml | 1 + 32 files changed, 368 insertions(+), 201 deletions(-) rename src/components/output/{audioBox.rs => sinkBox.rs} (58%) rename src/components/output/{audioBoxImpl.rs => sinkBoxImpl.rs} (82%) delete mode 100644 src/resources/resetOutpuStreamEntry.ui diff --git a/Cargo.toml b/Cargo.toml index 6bf4340..cf9d4fc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ description = "A wip universal Linux settings application." [dependencies] reset_daemon = "0.1.2" -ReSet-Lib = "0.2.7" +ReSet-Lib = "0.2.8" adw = { version = "0.5.3", package = "libadwaita", features = ["v1_4"] } dbus = "0.9.7" gtk = { version = "0.7.3", package = "gtk4", features = ["v4_12"] } diff --git a/src/components/input/outputStreamEntry.rs b/src/components/input/outputStreamEntry.rs index a522b12..dc7599d 100644 --- a/src/components/input/outputStreamEntry.rs +++ b/src/components/input/outputStreamEntry.rs @@ -1,5 +1,15 @@ +use std::cell::RefCell; +use std::sync::Arc; +use std::time::Duration; + use adw::glib; use adw::glib::Object; +use adw::prelude::RangeExt; +use dbus::blocking::Connection; +use dbus::Error; +use ReSet_Lib::audio::audio::OutputStream; +use glib::{clone, Propagation}; +use glib::subclass::types::ObjectSubclassIsExt; use super::outputStreamEntryImpl; @@ -10,7 +20,51 @@ glib::wrapper! { } impl OutputStreamEntry { - pub fn new() -> Self { - Object::builder().build() + pub fn new(stream: OutputStream) -> Self { + let obj: Self = Object::builder().build(); + // TODO use event callback for progress bar -> this is the "im speaking" indicator + // TODO map mute to callback + // TODO map dropdown + { + let imp = obj.imp(); + let name = stream.application_name.clone() + ": " + stream.name.as_str(); + imp.resetSourceName.set_text(name.as_str()); + let volume = stream.volume.first().unwrap_or_else(|| &(0 as u32)); + let fraction = (*volume as f64 / 655.36).round(); + let percentage = (fraction).to_string() + "%"; + imp.resetVolumePercentage.set_text(&percentage); + imp.resetVolumeSlider.set_value(*volume as f64); + imp.stream.replace(stream); + imp.resetVolumeSlider.connect_change_value( + clone!(@weak imp => @default-return Propagation::Stop, move |_, _, value| { + let fraction = (value / 655.36).round(); + let percentage = (fraction).to_string() + "%"; + imp.resetVolumePercentage.set_text(&percentage); + set_outputstream_volume(value, imp.stream.clone()); + Propagation::Proceed + }), + ); + } + obj } } + +fn set_outputstream_volume(value: f64, stream: Arc>) -> bool { + let mut stream = stream.borrow_mut().clone(); + // let x = stream.volume.iter_mut().map(|_| value as u32); + stream.volume = vec![value as u32; stream.channels as usize]; + dbg!(stream.volume.clone()); + + let conn = Connection::new_session().unwrap(); + let proxy = conn.with_proxy( + "org.xetibo.ReSet", + "/org/xetibo/ReSet", + Duration::from_millis(1000), + ); + let res: Result<(bool,), Error> = + proxy.method_call("org.xetibo.ReSet", "SetOutputStreamVolume", (stream,)); + if res.is_err() { + return false; + } + res.unwrap().0 +} diff --git a/src/components/input/outputStreamEntryImpl.rs b/src/components/input/outputStreamEntryImpl.rs index c90ed5e..88dccfe 100644 --- a/src/components/input/outputStreamEntryImpl.rs +++ b/src/components/input/outputStreamEntryImpl.rs @@ -1,4 +1,8 @@ +use std::cell::RefCell; +use std::sync::Arc; + use crate::components::input::outputStreamEntry; +use ReSet_Lib::audio::audio::OutputStream; use gtk::subclass::prelude::*; use gtk::{glib, Button, CompositeTemplate, Label, ProgressBar, Scale, DropDown}; @@ -18,6 +22,7 @@ pub struct OutputStreamEntry { pub resetVolumePercentage: TemplateChild