mirror of
https://github.com/Xetibo/ReSet.git
synced 2025-04-12 08:28:32 +02:00
wip: Finish audio generics refactoring
This commit is contained in:
parent
d56dfa505c
commit
595867163a
|
@ -22,16 +22,16 @@ use re_set_lib::{
|
|||
use crate::components::base::{error_impl::ReSetErrorImpl, list_entry::ListEntry};
|
||||
|
||||
use super::{
|
||||
generic_audio_box_utils::{
|
||||
audio_box_utils::{
|
||||
populate_audio_object_information, populate_cards, populate_streams,
|
||||
refresh_default_audio_object,
|
||||
},
|
||||
generic_audio_functions::new_stream_entry,
|
||||
generic_entry::{
|
||||
audio_entry::{
|
||||
new_entry, DBusFunction, TAudioBox, TAudioBoxImpl, TAudioEntry, TAudioEntryImpl,
|
||||
TAudioStream, TAudioStreamImpl,
|
||||
},
|
||||
generic_utils::audio_dbus_call,
|
||||
audio_functions::new_stream_entry,
|
||||
audio_utils::audio_dbus_call,
|
||||
};
|
||||
|
||||
pub fn mute_clicked_handler<
|
||||
|
@ -448,7 +448,7 @@ pub fn object_removed_handler<
|
|||
true
|
||||
}
|
||||
|
||||
pub fn output_stream_added_handler<
|
||||
pub fn audio_stream_added_handler<
|
||||
AudioObject: TAudioObject,
|
||||
StreamObject: TAudioStreamObject,
|
||||
AudioEntry: TAudioEntry<AudioEntryImpl> + IsA<gtk::Widget>,
|
||||
|
@ -466,7 +466,7 @@ pub fn output_stream_added_handler<
|
|||
glib::idle_add_once(move || {
|
||||
let audio_box = audio_box.clone();
|
||||
let imp = audio_box.box_imp();
|
||||
let mut list = imp.audio_object_stream_list();
|
||||
let list = imp.audio_object_stream_list();
|
||||
let mut list = list.write().unwrap();
|
||||
let index = ir.stream_ref().index();
|
||||
let stream = new_stream_entry::<
|
|
@ -23,17 +23,18 @@ use crate::components::{
|
|||
};
|
||||
|
||||
use super::{
|
||||
generic_audio_box_handlers::{
|
||||
audio_box_handlers::{
|
||||
audio_stream_added_handler, audio_stream_changed_handler, audio_stream_removed_handler,
|
||||
dropdown_handler, mute_clicked_handler, object_added_handler, object_changed_handler,
|
||||
object_removed_handler, volume_slider_handler,
|
||||
},
|
||||
generic_audio_functions::new_stream_entry,
|
||||
generic_const::GETCARDS,
|
||||
generic_entry::{
|
||||
audio_const::GETCARDS,
|
||||
audio_entry::{
|
||||
new_entry, DBusFunction, TAudioBox, TAudioBoxImpl, TAudioEntry, TAudioEntryImpl,
|
||||
TAudioStream, TAudioStreamImpl,
|
||||
},
|
||||
generic_utils::audio_dbus_call,
|
||||
audio_functions::new_stream_entry,
|
||||
audio_utils::audio_dbus_call,
|
||||
};
|
||||
|
||||
pub fn setup_audio_box_callbacks<
|
||||
|
@ -308,7 +309,7 @@ pub fn populate_audio_object_information<
|
|||
});
|
||||
}
|
||||
|
||||
pub fn start_source_box_listener<
|
||||
pub fn start_audio_box_listener<
|
||||
AudioObject: TAudioObject,
|
||||
StreamObject: TAudioStreamObject,
|
||||
AudioEntry: TAudioEntry<AudioEntryImpl> + IsA<gtk::Widget>,
|
||||
|
@ -407,8 +408,17 @@ pub fn start_source_box_listener<
|
|||
}
|
||||
|
||||
let res = conn.add_match(stream_added, move |ir: StreamAdded, _, _| {
|
||||
// output_stream_added_handler(output_stream_added_box.clone(), ir)
|
||||
true
|
||||
audio_stream_added_handler::<
|
||||
AudioObject,
|
||||
StreamObject,
|
||||
AudioEntry,
|
||||
AudioEntryImpl,
|
||||
AudioStream,
|
||||
AudioStreamImpl,
|
||||
AudioBox,
|
||||
AudioBoxImpl,
|
||||
StreamAdded,
|
||||
>(stream_added_box.clone(), ir)
|
||||
});
|
||||
if res.is_err() {
|
||||
println!("fail on output stream add event");
|
||||
|
@ -416,8 +426,17 @@ pub fn start_source_box_listener<
|
|||
}
|
||||
|
||||
let res = conn.add_match(stream_changed, move |ir: StreamChanged, _, _| {
|
||||
// output_stream_changed_handler(output_stream_changed_box.clone(), ir)
|
||||
true
|
||||
audio_stream_changed_handler::<
|
||||
AudioObject,
|
||||
StreamObject,
|
||||
AudioEntry,
|
||||
AudioEntryImpl,
|
||||
AudioStream,
|
||||
AudioStreamImpl,
|
||||
AudioBox,
|
||||
AudioBoxImpl,
|
||||
StreamChanged,
|
||||
>(stream_changed_box.clone(), ir)
|
||||
});
|
||||
if res.is_err() {
|
||||
println!("fail on output stream change event");
|
||||
|
@ -425,8 +444,17 @@ pub fn start_source_box_listener<
|
|||
}
|
||||
|
||||
let res = conn.add_match(stream_removed, move |ir: StreamRemoved, _, _| {
|
||||
// output_stream_removed_handler(output_stream_removed_box.clone(), ir)
|
||||
true
|
||||
audio_stream_removed_handler::<
|
||||
AudioObject,
|
||||
StreamObject,
|
||||
AudioEntry,
|
||||
AudioEntryImpl,
|
||||
AudioStream,
|
||||
AudioStreamImpl,
|
||||
AudioBox,
|
||||
AudioBoxImpl,
|
||||
StreamRemoved,
|
||||
>(stream_removed_box.clone(), ir)
|
||||
});
|
||||
if res.is_err() {
|
||||
println!("fail on output stream remove event");
|
|
@ -19,8 +19,8 @@ use crate::components::base::error_impl::ReSetErrorImpl;
|
|||
use crate::components::base::list_entry::ListEntry;
|
||||
use crate::components::utils::set_action_row_ellipsis;
|
||||
|
||||
use super::generic_audio_functions::refresh_default_audio_object;
|
||||
use super::generic_utils::audio_dbus_call;
|
||||
use super::audio_functions::refresh_default_audio_object;
|
||||
use super::audio_utils::audio_dbus_call;
|
||||
|
||||
pub type AudioEntryMap<T> = Arc<RwLock<HashMap<u32, (Arc<ListEntry>, Arc<T>, String)>>>;
|
||||
pub type AudioStreamEntryMap<T> = Arc<RwLock<HashMap<u32, (Arc<ListEntry>, Arc<T>)>>>;
|
|
@ -17,10 +17,10 @@ use crate::components::{
|
|||
};
|
||||
|
||||
use super::{
|
||||
generic_entry::{
|
||||
audio_entry::{
|
||||
TAudioBox, TAudioBoxImpl, TAudioEntry, TAudioEntryImpl, TAudioStream, TAudioStreamImpl,
|
||||
},
|
||||
generic_utils::audio_dbus_call,
|
||||
audio_utils::audio_dbus_call,
|
||||
};
|
||||
|
||||
pub fn refresh_default_audio_object<
|
|
@ -11,7 +11,7 @@ use crate::components::{
|
|||
utils::{AUDIO, BASE, DBUS_PATH},
|
||||
};
|
||||
|
||||
use super::generic_entry::DBusFunction;
|
||||
use super::audio_entry::DBusFunction;
|
||||
|
||||
pub fn audio_dbus_call<B, O, I>(
|
||||
source_box: Arc<B>,
|
|
@ -1,7 +1,6 @@
|
|||
pub mod output_stream_entry;
|
||||
pub mod output_stream_entry_impl;
|
||||
pub mod source_box;
|
||||
mod source_box_handlers;
|
||||
pub mod source_box_impl;
|
||||
mod source_const;
|
||||
pub mod source_entry;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use crate::components::audio::generic_audio_functions::new_stream_entry;
|
||||
use crate::components::audio::generic_entry::TAudioStream;
|
||||
use crate::components::audio::audio_entry::TAudioStream;
|
||||
use crate::components::audio::audio_functions::new_stream_entry;
|
||||
use glib::subclass::types::ObjectSubclassIsExt;
|
||||
use re_set_lib::audio::audio_structures::{OutputStream, Source};
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ use std::cell::RefCell;
|
|||
use std::sync::Arc;
|
||||
use std::time::SystemTime;
|
||||
|
||||
use crate::components::audio::generic_entry::{AudioIcons, TAudioStreamImpl};
|
||||
use crate::components::audio::audio_entry::{AudioIcons, TAudioStreamImpl};
|
||||
use crate::components::audio::input::output_stream_entry;
|
||||
use gtk::subclass::prelude::*;
|
||||
use gtk::{Button, CompositeTemplate, Label, Scale};
|
||||
|
@ -79,17 +79,15 @@ impl TAudioStreamImpl<Source, OutputStream> for OutputStreamEntry {
|
|||
&self.volume_time_stamp
|
||||
}
|
||||
|
||||
fn set_volume_fn(&self) -> &'static crate::components::audio::generic_entry::DBusFunction {
|
||||
fn set_volume_fn(&self) -> &'static crate::components::audio::audio_entry::DBusFunction {
|
||||
&SETSTREAMVOLUME
|
||||
}
|
||||
|
||||
fn set_audio_object_fn(
|
||||
&self,
|
||||
) -> &'static crate::components::audio::generic_entry::DBusFunction {
|
||||
fn set_audio_object_fn(&self) -> &'static crate::components::audio::audio_entry::DBusFunction {
|
||||
&SETSTREAMOBJECT
|
||||
}
|
||||
|
||||
fn set_mute_fn(&self) -> &'static crate::components::audio::generic_entry::DBusFunction {
|
||||
fn set_mute_fn(&self) -> &'static crate::components::audio::audio_entry::DBusFunction {
|
||||
&SETSTREAMMUTE
|
||||
}
|
||||
|
||||
|
|
|
@ -7,28 +7,21 @@ use std::sync::Arc;
|
|||
|
||||
use adw::glib::Object;
|
||||
use dbus::blocking::Connection;
|
||||
use dbus::message::SignalArgs;
|
||||
use dbus::Path;
|
||||
use glib::subclass::prelude::ObjectSubclassIsExt;
|
||||
use gtk::gio;
|
||||
|
||||
use crate::components::audio::generic_audio_box_handlers::populate_audio_objects;
|
||||
use crate::components::audio::generic_audio_box_utils::{
|
||||
populate_audio_object_information, populate_cards, populate_streams, setup_audio_box_callbacks,
|
||||
use crate::components::audio::audio_box_handlers::populate_audio_objects;
|
||||
use crate::components::audio::audio_box_utils::{
|
||||
setup_audio_box_callbacks, start_audio_box_listener,
|
||||
};
|
||||
use crate::components::audio::generic_entry::TAudioBox;
|
||||
use crate::components::audio::generic_utils::audio_dbus_call;
|
||||
use crate::components::audio::audio_entry::TAudioBox;
|
||||
use crate::components::audio::input::source_box_impl;
|
||||
use crate::components::base::error::{self};
|
||||
use crate::components::base::error_impl::ReSetErrorImpl;
|
||||
use crate::components::utils::{BASE, DBUS_PATH};
|
||||
|
||||
use super::output_stream_entry::OutputStreamEntry;
|
||||
use super::source_box_handlers::{
|
||||
output_stream_added_handler, output_stream_changed_handler, output_stream_removed_handler,
|
||||
source_added_handler, source_changed_handler, source_removed_handler,
|
||||
use super::source_const::{
|
||||
GETDEFAULT, GETDEFAULTNAME, GETOBJECTS, GETSTREAMS, SETDEFAULT, SETMUTE, SETVOLUME,
|
||||
};
|
||||
use super::source_const::{GETDEFAULT, GETOBJECTS, GETSTREAMS, SETDEFAULT, SETMUTE, SETVOLUME};
|
||||
use super::source_entry::SourceEntry;
|
||||
|
||||
glib::wrapper! {
|
||||
|
@ -102,83 +95,20 @@ pub fn populate_sources(source_box: Arc<SourceBox>) {
|
|||
}
|
||||
|
||||
pub fn start_source_box_listener(conn: Connection, source_box: Arc<SourceBox>) -> Connection {
|
||||
let source_added =
|
||||
SourceAdded::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH))).static_clone();
|
||||
let source_removed =
|
||||
SourceRemoved::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH))).static_clone();
|
||||
let source_changed =
|
||||
SourceChanged::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH))).static_clone();
|
||||
let output_stream_added =
|
||||
OutputStreamAdded::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH)))
|
||||
.static_clone();
|
||||
let output_stream_removed =
|
||||
OutputStreamRemoved::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH)))
|
||||
.static_clone();
|
||||
let output_stream_changed =
|
||||
OutputStreamChanged::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH)))
|
||||
.static_clone();
|
||||
|
||||
let source_added_box = source_box.clone();
|
||||
let source_removed_box = source_box.clone();
|
||||
let source_changed_box = source_box.clone();
|
||||
let output_stream_added_box = source_box.clone();
|
||||
let output_stream_removed_box = source_box.clone();
|
||||
let output_stream_changed_box = source_box.clone();
|
||||
|
||||
let res = conn.add_match(source_added, move |ir: SourceAdded, _, _| {
|
||||
source_added_handler(source_added_box.clone(), ir)
|
||||
});
|
||||
if res.is_err() {
|
||||
// TODO: handle this with the log/error macro
|
||||
println!("fail on source add event");
|
||||
return conn;
|
||||
}
|
||||
|
||||
let res = conn.add_match(source_removed, move |ir: SourceRemoved, _, _| {
|
||||
source_removed_handler(source_removed_box.clone(), ir)
|
||||
});
|
||||
if res.is_err() {
|
||||
println!("fail on source remove event");
|
||||
return conn;
|
||||
}
|
||||
|
||||
let res = conn.add_match(source_changed, move |ir: SourceChanged, _, _| {
|
||||
source_changed_handler(source_changed_box.clone(), ir)
|
||||
});
|
||||
if res.is_err() {
|
||||
println!("fail on source change event");
|
||||
return conn;
|
||||
}
|
||||
|
||||
let res = conn.add_match(output_stream_added, move |ir: OutputStreamAdded, _, _| {
|
||||
output_stream_added_handler(output_stream_added_box.clone(), ir)
|
||||
});
|
||||
if res.is_err() {
|
||||
println!("fail on output stream add event");
|
||||
return conn;
|
||||
}
|
||||
|
||||
let res = conn.add_match(
|
||||
output_stream_changed,
|
||||
move |ir: OutputStreamChanged, _, _| {
|
||||
output_stream_changed_handler(output_stream_changed_box.clone(), ir)
|
||||
},
|
||||
);
|
||||
if res.is_err() {
|
||||
println!("fail on output stream change event");
|
||||
return conn;
|
||||
}
|
||||
|
||||
let res = conn.add_match(
|
||||
output_stream_removed,
|
||||
move |ir: OutputStreamRemoved, _, _| {
|
||||
output_stream_removed_handler(output_stream_removed_box.clone(), ir)
|
||||
},
|
||||
);
|
||||
if res.is_err() {
|
||||
println!("fail on output stream remove event");
|
||||
return conn;
|
||||
}
|
||||
|
||||
conn
|
||||
start_audio_box_listener::<
|
||||
Source,
|
||||
OutputStream,
|
||||
SourceEntry,
|
||||
super::source_entry_impl::SourceEntry,
|
||||
OutputStreamEntry,
|
||||
super::output_stream_entry_impl::OutputStreamEntry,
|
||||
SourceBox,
|
||||
super::source_box_impl::SourceBox,
|
||||
SourceAdded,
|
||||
SourceChanged,
|
||||
SourceRemoved,
|
||||
OutputStreamAdded,
|
||||
OutputStreamChanged,
|
||||
OutputStreamRemoved,
|
||||
>(conn, source_box, &GETDEFAULTNAME)
|
||||
}
|
||||
|
|
|
@ -1,263 +0,0 @@
|
|||
use std::{
|
||||
sync::Arc,
|
||||
time::{Duration, SystemTime},
|
||||
};
|
||||
|
||||
use adw::prelude::{ComboRowExt, PreferencesRowExt};
|
||||
use glib::prelude::Cast;
|
||||
use glib::{subclass::types::ObjectSubclassIsExt, ControlFlow, Propagation};
|
||||
use gtk::{
|
||||
gio,
|
||||
prelude::{BoxExt, ButtonExt, CheckButtonExt, ListBoxRowExt, RangeExt},
|
||||
StringObject,
|
||||
};
|
||||
use re_set_lib::{
|
||||
audio::audio_structures::{OutputStream, Source},
|
||||
signals::{
|
||||
OutputStreamAdded, OutputStreamChanged, OutputStreamRemoved, SourceAdded, SourceChanged,
|
||||
SourceRemoved,
|
||||
},
|
||||
};
|
||||
|
||||
use crate::components::{
|
||||
audio::{
|
||||
generic_audio_box_utils::refresh_default_audio_object, generic_utils::audio_dbus_call,
|
||||
},
|
||||
base::list_entry::ListEntry,
|
||||
};
|
||||
|
||||
use super::{
|
||||
output_stream_entry::OutputStreamEntry,
|
||||
source_box::SourceBox,
|
||||
source_const::{GETDEFAULTNAME, SETDEFAULT, SETMUTE, SETVOLUME},
|
||||
source_entry::SourceEntry,
|
||||
};
|
||||
|
||||
pub fn source_added_handler(source_box: Arc<SourceBox>, ir: SourceAdded) -> bool {
|
||||
glib::spawn_future(async move {
|
||||
glib::idle_add_once(move || {
|
||||
let source_box = source_box.clone();
|
||||
let source_box_imp = source_box.imp();
|
||||
let source_index = ir.source.index;
|
||||
let alias = ir.source.alias.clone();
|
||||
let name = ir.source.name.clone();
|
||||
let mut is_default = false;
|
||||
if source_box_imp.reset_default_source.borrow().name == ir.source.name {
|
||||
is_default = true;
|
||||
}
|
||||
let source_entry = SourceEntry::new(
|
||||
is_default,
|
||||
source_box_imp.reset_default_check_button.clone(),
|
||||
ir.source,
|
||||
source_box.clone(),
|
||||
);
|
||||
let source_clone = source_entry.clone();
|
||||
let entry = Arc::new(ListEntry::new(&*source_entry));
|
||||
entry.set_activatable(false);
|
||||
let mut list = source_box_imp.reset_source_list.write().unwrap();
|
||||
list.insert(source_index, (entry.clone(), source_clone, alias.clone()));
|
||||
source_box_imp.reset_sources.append(&*entry);
|
||||
let mut map = source_box_imp.reset_source_map.write().unwrap();
|
||||
let mut index = source_box_imp.reset_model_index.write().unwrap();
|
||||
let model_list = source_box_imp.reset_model_list.write().unwrap();
|
||||
if model_list.string(*index - 1) == Some("Monitor of Dummy Output".into()) {
|
||||
model_list.append(&alias);
|
||||
model_list.remove(*index - 1);
|
||||
map.insert(alias, (source_index, name));
|
||||
source_box_imp.reset_source_dropdown.set_selected(0);
|
||||
} else {
|
||||
model_list.append(&alias);
|
||||
map.insert(alias.clone(), (source_index, name));
|
||||
if alias == "Monitor of Dummy Output" {
|
||||
source_box_imp.reset_source_dropdown.set_selected(0);
|
||||
}
|
||||
*index += 1;
|
||||
}
|
||||
});
|
||||
});
|
||||
true
|
||||
}
|
||||
|
||||
pub fn source_removed_handler(source_box: Arc<SourceBox>, ir: SourceRemoved) -> bool {
|
||||
glib::spawn_future(async move {
|
||||
glib::idle_add_once(move || {
|
||||
let source_box = source_box.clone();
|
||||
let source_box_imp = source_box.imp();
|
||||
let entry: Option<(Arc<ListEntry>, Arc<SourceEntry>, String)>;
|
||||
{
|
||||
let mut list = source_box_imp.reset_source_list.write().unwrap();
|
||||
entry = list.remove(&ir.index);
|
||||
if entry.is_none() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
source_box_imp
|
||||
.reset_sources
|
||||
.remove(&*entry.clone().unwrap().0);
|
||||
let mut map = source_box_imp.reset_source_map.write().unwrap();
|
||||
let alias = entry.unwrap().2;
|
||||
map.remove(&alias);
|
||||
let mut index = source_box_imp.reset_model_index.write().unwrap();
|
||||
let model_list = source_box_imp.reset_model_list.write().unwrap();
|
||||
|
||||
if *index == 1 {
|
||||
model_list.append("Monitor of Dummy Output");
|
||||
}
|
||||
for entry in 0..*index {
|
||||
if model_list.string(entry) == Some(alias.clone().into()) {
|
||||
model_list.splice(entry, 1, &[]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if *index > 1 {
|
||||
*index -= 1;
|
||||
}
|
||||
});
|
||||
});
|
||||
true
|
||||
}
|
||||
|
||||
pub fn source_changed_handler(source_box: Arc<SourceBox>, ir: SourceChanged) -> bool {
|
||||
let source =
|
||||
audio_dbus_call::<SourceBox, (String,), ()>(source_box.clone(), (), &GETDEFAULTNAME);
|
||||
if source.is_none() {
|
||||
return false;
|
||||
}
|
||||
let default_source = source.unwrap().0;
|
||||
glib::spawn_future(async move {
|
||||
glib::idle_add_once(move || {
|
||||
let source_box = source_box.clone();
|
||||
let source_box_imp = source_box.imp();
|
||||
let is_default = ir.source.name == default_source;
|
||||
let volume = ir.source.volume.first().unwrap_or(&0_u32);
|
||||
let fraction = (*volume as f64 / 655.36).round();
|
||||
let percentage = (fraction).to_string() + "%";
|
||||
|
||||
let list = source_box_imp.reset_source_list.read().unwrap();
|
||||
let entry = list.get(&ir.source.index);
|
||||
if entry.is_none() {
|
||||
return;
|
||||
}
|
||||
let imp = entry.unwrap().1.imp();
|
||||
if is_default {
|
||||
source_box_imp.reset_volume_percentage.set_text(&percentage);
|
||||
source_box_imp.reset_volume_slider.set_value(*volume as f64);
|
||||
source_box_imp
|
||||
.reset_default_source
|
||||
.replace(ir.source.clone());
|
||||
if ir.source.muted {
|
||||
source_box_imp
|
||||
.reset_source_mute
|
||||
.set_icon_name("microphone-disabled-symbolic");
|
||||
} else {
|
||||
source_box_imp
|
||||
.reset_source_mute
|
||||
.set_icon_name("audio-input-microphone-symbolic");
|
||||
}
|
||||
imp.reset_selected_source.set_active(true);
|
||||
} else {
|
||||
imp.reset_selected_source.set_active(false);
|
||||
}
|
||||
imp.reset_source_name
|
||||
.set_title(ir.source.alias.clone().as_str());
|
||||
imp.reset_volume_percentage.set_text(&percentage);
|
||||
imp.reset_volume_slider.set_value(*volume as f64);
|
||||
if ir.source.muted {
|
||||
imp.reset_source_mute
|
||||
.set_icon_name("microphone-disabled-symbolic");
|
||||
} else {
|
||||
imp.reset_source_mute
|
||||
.set_icon_name("audio-input-microphone-symbolic");
|
||||
}
|
||||
});
|
||||
});
|
||||
true
|
||||
}
|
||||
|
||||
pub fn output_stream_added_handler(source_box: Arc<SourceBox>, ir: OutputStreamAdded) -> bool {
|
||||
glib::spawn_future(async move {
|
||||
glib::idle_add_once(move || {
|
||||
let source_box = source_box.clone();
|
||||
let source_box_imp = source_box.imp();
|
||||
let mut list = source_box_imp.reset_output_stream_list.write().unwrap();
|
||||
let index = ir.stream.index;
|
||||
let output_stream = OutputStreamEntry::new(source_box.clone(), ir.stream);
|
||||
let entry = Arc::new(ListEntry::new(&*output_stream));
|
||||
entry.set_activatable(false);
|
||||
list.insert(index, (entry.clone(), output_stream.clone()));
|
||||
source_box_imp.reset_output_streams.append(&*entry);
|
||||
});
|
||||
});
|
||||
true
|
||||
}
|
||||
|
||||
pub fn output_stream_changed_handler(source_box: Arc<SourceBox>, ir: OutputStreamChanged) -> bool {
|
||||
let imp = source_box.imp();
|
||||
let alias: String;
|
||||
{
|
||||
let source_list = imp.reset_source_list.read().unwrap();
|
||||
if let Some(alias_opt) = source_list.get(&ir.stream.source_index) {
|
||||
alias = alias_opt.2.clone();
|
||||
} else {
|
||||
alias = String::from("");
|
||||
}
|
||||
}
|
||||
glib::spawn_future(async move {
|
||||
glib::idle_add_once(move || {
|
||||
let source_box = source_box.clone();
|
||||
let source_box_imp = source_box.imp();
|
||||
let entry: Arc<OutputStreamEntry>;
|
||||
{
|
||||
let list = source_box_imp.reset_output_stream_list.read().unwrap();
|
||||
let entry_opt = list.get(&ir.stream.index);
|
||||
if entry_opt.is_none() {
|
||||
return;
|
||||
}
|
||||
entry = entry_opt.unwrap().1.clone();
|
||||
}
|
||||
let imp = entry.imp();
|
||||
if ir.stream.muted {
|
||||
imp.reset_source_mute
|
||||
.set_icon_name("microphone-disabled-symbolic");
|
||||
} else {
|
||||
imp.reset_source_mute
|
||||
.set_icon_name("audio-input-microphone-symbolic");
|
||||
}
|
||||
let name = ir.stream.application_name.clone() + ": " + ir.stream.name.as_str();
|
||||
imp.reset_source_selection.set_title(name.as_str());
|
||||
let volume = ir.stream.volume.first().unwrap_or(&0_u32);
|
||||
let fraction = (*volume as f64 / 655.36).round();
|
||||
let percentage = (fraction).to_string() + "%";
|
||||
imp.reset_volume_percentage.set_text(&percentage);
|
||||
imp.reset_volume_slider.set_value(*volume as f64);
|
||||
let index = source_box_imp.reset_model_index.read().unwrap();
|
||||
let model_list = source_box_imp.reset_model_list.read().unwrap();
|
||||
for entry in 0..*index {
|
||||
if model_list.string(entry) == Some(alias.clone().into()) {
|
||||
imp.reset_source_selection.set_selected(entry);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
true
|
||||
}
|
||||
|
||||
pub fn output_stream_removed_handler(source_box: Arc<SourceBox>, ir: OutputStreamRemoved) -> bool {
|
||||
glib::spawn_future(async move {
|
||||
glib::idle_add_once(move || {
|
||||
let source_box = source_box.clone();
|
||||
let source_box_imp = source_box.imp();
|
||||
let mut list = source_box_imp.reset_output_stream_list.write().unwrap();
|
||||
let entry = list.remove(&ir.index);
|
||||
if entry.is_none() {
|
||||
return;
|
||||
}
|
||||
source_box_imp
|
||||
.reset_output_streams
|
||||
.remove(&*entry.unwrap().0);
|
||||
});
|
||||
});
|
||||
true
|
||||
}
|
||||
|
|
@ -5,7 +5,7 @@ use std::collections::HashMap;
|
|||
use std::sync::{Arc, RwLock};
|
||||
use std::time::SystemTime;
|
||||
|
||||
use crate::components::audio::generic_entry::{AudioIcons, TAudioBoxImpl};
|
||||
use crate::components::audio::audio_entry::{AudioIcons, TAudioBoxImpl};
|
||||
use crate::components::audio::input::source_box;
|
||||
use crate::components::base::error::ReSetError;
|
||||
use crate::components::base::list_entry::ListEntry;
|
||||
|
@ -149,13 +149,13 @@ impl TAudioBoxImpl<Source, SourceEntry, OutputStreamEntry> for SourceBox {
|
|||
|
||||
fn audio_object_list(
|
||||
&self,
|
||||
) -> &crate::components::audio::generic_entry::AudioEntryMap<SourceEntry> {
|
||||
) -> &crate::components::audio::audio_entry::AudioEntryMap<SourceEntry> {
|
||||
&self.reset_source_list
|
||||
}
|
||||
|
||||
fn audio_object_stream_list(
|
||||
&self,
|
||||
) -> &crate::components::audio::generic_entry::AudioStreamEntryMap<OutputStreamEntry> {
|
||||
) -> &crate::components::audio::audio_entry::AudioStreamEntryMap<OutputStreamEntry> {
|
||||
&self.reset_output_stream_list
|
||||
}
|
||||
|
||||
|
@ -167,7 +167,7 @@ impl TAudioBoxImpl<Source, SourceEntry, OutputStreamEntry> for SourceBox {
|
|||
self.reset_model_index.clone()
|
||||
}
|
||||
|
||||
fn source_map(&self) -> &crate::components::audio::generic_entry::AudioMap {
|
||||
fn source_map(&self) -> &crate::components::audio::audio_entry::AudioMap {
|
||||
&self.reset_source_map
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::components::audio::generic_entry::{AudioIcons, DBusFunction};
|
||||
use crate::components::audio::audio_entry::{AudioIcons, DBusFunction};
|
||||
|
||||
pub const ICONS: AudioIcons = AudioIcons {
|
||||
muted: "microphone-disabled-symbolic",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use crate::components::audio::generic_entry::{new_entry, TAudioEntry};
|
||||
use crate::components::audio::audio_entry::{new_entry, TAudioEntry};
|
||||
use glib::subclass::types::ObjectSubclassIsExt;
|
||||
use gtk::CheckButton;
|
||||
use re_set_lib::audio::audio_structures::{OutputStream, Source};
|
||||
|
|
|
@ -8,7 +8,7 @@ use std::time::SystemTime;
|
|||
use gtk::subclass::prelude::*;
|
||||
use gtk::{Button, CheckButton, CompositeTemplate, Label, Scale};
|
||||
|
||||
use crate::components::audio::generic_entry::{AudioIcons, DBusFunction, TAudioEntryImpl};
|
||||
use crate::components::audio::audio_entry::{AudioIcons, DBusFunction, TAudioEntryImpl};
|
||||
|
||||
use super::source_const::{ICONS, SETDEFAULT, SETMUTE, SETVOLUME};
|
||||
use super::source_entry;
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
pub mod generic_audio_functions;
|
||||
mod generic_const;
|
||||
pub mod generic_entry;
|
||||
mod generic_utils;
|
||||
mod audio_box_handlers;
|
||||
mod audio_box_utils;
|
||||
mod audio_const;
|
||||
pub mod audio_entry;
|
||||
pub mod audio_functions;
|
||||
mod audio_utils;
|
||||
pub mod input;
|
||||
pub mod output;
|
||||
mod generic_audio_box_utils;
|
||||
mod generic_audio_stream_utils;
|
||||
mod generic_audio_object_entry_utils;
|
||||
mod generic_audio_box_handlers;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use crate::components::audio::generic_audio_functions::new_stream_entry;
|
||||
use crate::components::audio::generic_entry::TAudioStream;
|
||||
use crate::components::audio::audio_entry::TAudioStream;
|
||||
use crate::components::audio::audio_functions::new_stream_entry;
|
||||
use glib::subclass::types::ObjectSubclassIsExt;
|
||||
use re_set_lib::audio::audio_structures::{InputStream, Sink};
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ use std::time::SystemTime;
|
|||
use gtk::subclass::prelude::*;
|
||||
use gtk::{Button, CompositeTemplate, Label, Scale};
|
||||
|
||||
use crate::components::audio::generic_entry::{AudioIcons, TAudioStreamImpl};
|
||||
use crate::components::audio::audio_entry::{AudioIcons, TAudioStreamImpl};
|
||||
|
||||
use super::input_stream_entry;
|
||||
use super::sink_const::{ICONS, SETSTREAMMUTE, SETSTREAMOBJECT, SETSTREAMVOLUME};
|
||||
|
@ -80,17 +80,15 @@ impl TAudioStreamImpl<Sink, InputStream> for InputStreamEntry {
|
|||
&self.volume_time_stamp
|
||||
}
|
||||
|
||||
fn set_volume_fn(&self) -> &'static crate::components::audio::generic_entry::DBusFunction {
|
||||
fn set_volume_fn(&self) -> &'static crate::components::audio::audio_entry::DBusFunction {
|
||||
&SETSTREAMVOLUME
|
||||
}
|
||||
|
||||
fn set_audio_object_fn(
|
||||
&self,
|
||||
) -> &'static crate::components::audio::generic_entry::DBusFunction {
|
||||
fn set_audio_object_fn(&self) -> &'static crate::components::audio::audio_entry::DBusFunction {
|
||||
&SETSTREAMOBJECT
|
||||
}
|
||||
|
||||
fn set_mute_fn(&self) -> &'static crate::components::audio::generic_entry::DBusFunction {
|
||||
fn set_mute_fn(&self) -> &'static crate::components::audio::audio_entry::DBusFunction {
|
||||
&SETSTREAMMUTE
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
pub mod input_stream_entry;
|
||||
pub mod input_stream_entry_impl;
|
||||
pub mod sink_box;
|
||||
mod sink_box_handlers;
|
||||
pub mod sink_box_impl;
|
||||
mod sink_box_utils;
|
||||
mod sink_const;
|
||||
pub mod sink_entry;
|
||||
pub mod sink_entry_impl;
|
||||
|
|
|
@ -9,36 +9,24 @@ use re_set_lib::signals::SinkRemoved;
|
|||
use std::sync::Arc;
|
||||
|
||||
use adw::glib::Object;
|
||||
use adw::prelude::ComboRowExt;
|
||||
use adw::prelude::ListBoxRowExt;
|
||||
use dbus::blocking::Connection;
|
||||
use dbus::message::SignalArgs;
|
||||
use dbus::Path;
|
||||
use glib::subclass::prelude::ObjectSubclassIsExt;
|
||||
use glib::Variant;
|
||||
use gtk::gio;
|
||||
use gtk::prelude::ActionableExt;
|
||||
|
||||
use crate::components::audio::generic_audio_box_utils::setup_audio_box_callbacks;
|
||||
use crate::components::audio::generic_entry::TAudioBox;
|
||||
use crate::components::audio::audio_box_handlers::populate_audio_objects;
|
||||
use crate::components::audio::audio_box_utils::setup_audio_box_callbacks;
|
||||
use crate::components::audio::audio_box_utils::start_audio_box_listener;
|
||||
use crate::components::audio::audio_entry::TAudioBox;
|
||||
use crate::components::base::error_impl::ReSetErrorImpl;
|
||||
use crate::components::utils::BASE;
|
||||
use crate::components::utils::DBUS_PATH;
|
||||
use crate::components::utils::{create_dropdown_label_factory, set_combo_row_ellipsis};
|
||||
|
||||
use super::input_stream_entry::InputStreamEntry;
|
||||
use super::sink_box_handlers::input_stream_added_handler;
|
||||
use super::sink_box_handlers::input_stream_changed_handler;
|
||||
use super::sink_box_handlers::input_stream_removed_handler;
|
||||
use super::sink_box_handlers::sink_added_handler;
|
||||
use super::sink_box_handlers::sink_changed_handler;
|
||||
use super::sink_box_handlers::sink_removed_handler;
|
||||
use super::sink_box_impl;
|
||||
use super::sink_box_utils::get_default_sink;
|
||||
use super::sink_box_utils::get_sinks;
|
||||
use super::sink_box_utils::populate_cards;
|
||||
use super::sink_box_utils::populate_inputstreams;
|
||||
use super::sink_box_utils::populate_sink_information;
|
||||
use super::sink_const::GETDEFAULT;
|
||||
use super::sink_const::GETDEFAULTNAME;
|
||||
use super::sink_const::GETOBJECTS;
|
||||
use super::sink_const::GETSTREAMS;
|
||||
use super::sink_const::SETDEFAULT;
|
||||
use super::sink_const::SETMUTE;
|
||||
use super::sink_const::SETVOLUME;
|
||||
use super::sink_entry::SinkEntry;
|
||||
|
||||
glib::wrapper! {
|
||||
|
@ -93,100 +81,41 @@ impl Default for SinkBox {
|
|||
}
|
||||
|
||||
pub fn populate_sinks(sink_box: Arc<SinkBox>) {
|
||||
gio::spawn_blocking(move || {
|
||||
let sinks = get_sinks(sink_box.clone());
|
||||
{
|
||||
let sink_box_imp = sink_box.imp();
|
||||
let list = sink_box_imp.reset_model_list.write().unwrap();
|
||||
let mut map = sink_box_imp.reset_sink_map.write().unwrap();
|
||||
let mut model_index = sink_box_imp.reset_model_index.write().unwrap();
|
||||
sink_box_imp
|
||||
.reset_default_sink
|
||||
.replace(get_default_sink(sink_box.clone()));
|
||||
for sink in sinks.iter() {
|
||||
list.append(&sink.alias);
|
||||
map.insert(sink.alias.clone(), (sink.index, sink.name.clone()));
|
||||
*model_index += 1;
|
||||
}
|
||||
}
|
||||
populate_inputstreams(sink_box.clone());
|
||||
populate_cards(sink_box.clone());
|
||||
populate_sink_information(sink_box, sinks);
|
||||
});
|
||||
populate_audio_objects::<
|
||||
Sink,
|
||||
InputStream,
|
||||
SinkEntry,
|
||||
super::sink_entry_impl::SinkEntry,
|
||||
InputStreamEntry,
|
||||
super::input_stream_entry_impl::InputStreamEntry,
|
||||
SinkBox,
|
||||
super::sink_box_impl::SinkBox,
|
||||
>(
|
||||
sink_box,
|
||||
&GETOBJECTS,
|
||||
&GETDEFAULT,
|
||||
&SETDEFAULT,
|
||||
&GETSTREAMS,
|
||||
&SETVOLUME,
|
||||
&SETMUTE,
|
||||
);
|
||||
}
|
||||
|
||||
pub fn start_sink_box_listener(conn: Connection, sink_box: Arc<SinkBox>) -> Connection {
|
||||
let sink_added =
|
||||
SinkAdded::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH))).static_clone();
|
||||
let sink_removed =
|
||||
SinkRemoved::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH))).static_clone();
|
||||
let sink_changed =
|
||||
SinkChanged::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH))).static_clone();
|
||||
let input_stream_added =
|
||||
InputStreamAdded::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH)))
|
||||
.static_clone();
|
||||
let input_stream_removed =
|
||||
InputStreamRemoved::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH)))
|
||||
.static_clone();
|
||||
let input_stream_changed =
|
||||
InputStreamChanged::match_rule(Some(&BASE.into()), Some(&Path::from(DBUS_PATH)))
|
||||
.static_clone();
|
||||
|
||||
let sink_added_box = sink_box.clone();
|
||||
let sink_removed_box = sink_box.clone();
|
||||
let sink_changed_box = sink_box.clone();
|
||||
let input_stream_added_box = sink_box.clone();
|
||||
let input_stream_removed_box = sink_box.clone();
|
||||
let input_stream_changed_box = sink_box.clone();
|
||||
|
||||
let res = conn.add_match(sink_added, move |ir: SinkAdded, _, _| {
|
||||
sink_added_handler(sink_added_box.clone(), ir)
|
||||
});
|
||||
if res.is_err() {
|
||||
// TODO: handle this with the log/error macro
|
||||
println!("fail on sink add event");
|
||||
return conn;
|
||||
}
|
||||
|
||||
let res = conn.add_match(sink_removed, move |ir: SinkRemoved, _, _| {
|
||||
sink_removed_handler(sink_removed_box.clone(), ir)
|
||||
});
|
||||
if res.is_err() {
|
||||
println!("fail on sink remove event");
|
||||
return conn;
|
||||
}
|
||||
|
||||
let res = conn.add_match(sink_changed, move |ir: SinkChanged, _, _| {
|
||||
sink_changed_handler(sink_changed_box.clone(), ir)
|
||||
});
|
||||
if res.is_err() {
|
||||
println!("fail on sink change event");
|
||||
return conn;
|
||||
}
|
||||
|
||||
let res = conn.add_match(input_stream_added, move |ir: InputStreamAdded, _, _| {
|
||||
input_stream_added_handler(input_stream_added_box.clone(), ir)
|
||||
});
|
||||
if res.is_err() {
|
||||
println!("fail on input stream add event");
|
||||
return conn;
|
||||
}
|
||||
|
||||
let res = conn.add_match(input_stream_removed, move |ir: InputStreamRemoved, _, _| {
|
||||
input_stream_removed_handler(input_stream_removed_box.clone(), ir)
|
||||
});
|
||||
if res.is_err() {
|
||||
println!("fail on input stream remove event");
|
||||
return conn;
|
||||
}
|
||||
|
||||
let res = conn.add_match(input_stream_changed, move |ir: InputStreamChanged, _, _| {
|
||||
input_stream_changed_handler(input_stream_changed_box.clone(), ir)
|
||||
});
|
||||
if res.is_err() {
|
||||
println!("fail on input stream change event");
|
||||
return conn;
|
||||
}
|
||||
|
||||
conn
|
||||
start_audio_box_listener::<
|
||||
Sink,
|
||||
InputStream,
|
||||
SinkEntry,
|
||||
super::sink_entry_impl::SinkEntry,
|
||||
InputStreamEntry,
|
||||
super::input_stream_entry_impl::InputStreamEntry,
|
||||
SinkBox,
|
||||
super::sink_box_impl::SinkBox,
|
||||
SinkAdded,
|
||||
SinkChanged,
|
||||
SinkRemoved,
|
||||
InputStreamAdded,
|
||||
InputStreamChanged,
|
||||
InputStreamRemoved,
|
||||
>(conn, sink_box, &GETDEFAULTNAME)
|
||||
}
|
||||
|
|
|
@ -1,325 +0,0 @@
|
|||
use std::{
|
||||
sync::Arc,
|
||||
time::{Duration, SystemTime},
|
||||
};
|
||||
|
||||
use adw::{
|
||||
prelude::{ComboRowExt, PreferencesRowExt},
|
||||
ComboRow,
|
||||
};
|
||||
use glib::prelude::Cast;
|
||||
use glib::{subclass::types::ObjectSubclassIsExt, Propagation};
|
||||
use gtk::{
|
||||
gio,
|
||||
prelude::{BoxExt, ButtonExt, CheckButtonExt, ListBoxRowExt, RangeExt},
|
||||
StringObject,
|
||||
};
|
||||
use re_set_lib::{
|
||||
audio::audio_structures::Sink,
|
||||
signals::{
|
||||
InputStreamAdded, InputStreamChanged, InputStreamRemoved, SinkAdded, SinkChanged,
|
||||
SinkRemoved,
|
||||
},
|
||||
};
|
||||
|
||||
use crate::components::{audio::generic_utils::audio_dbus_call, base::list_entry::ListEntry};
|
||||
|
||||
use super::{
|
||||
input_stream_entry::InputStreamEntry,
|
||||
sink_box::SinkBox,
|
||||
sink_box_utils::{get_default_sink_name, refresh_default_sink},
|
||||
sink_const::{SETDEFAULT, SETMUTE, SETVOLUME},
|
||||
sink_entry::SinkEntry,
|
||||
};
|
||||
|
||||
pub fn drop_down_handler(sink_box: Arc<SinkBox>, dropdown: &ComboRow) {
|
||||
let sink_box_ref = sink_box.clone();
|
||||
let sink_box_imp = sink_box.imp();
|
||||
let selected = dropdown.selected_item();
|
||||
if selected.is_none() {
|
||||
return;
|
||||
}
|
||||
let selected = selected.unwrap();
|
||||
let selected = selected.downcast_ref::<StringObject>().unwrap();
|
||||
let selected = selected.string().to_string();
|
||||
|
||||
let sink = sink_box_imp.reset_sink_map.read().unwrap();
|
||||
let sink = sink.get(&selected);
|
||||
if sink.is_none() {
|
||||
return;
|
||||
}
|
||||
let new_sink_name = Arc::new(sink.unwrap().1.clone());
|
||||
gio::spawn_blocking(move || {
|
||||
let result = audio_dbus_call::<SinkBox, (Sink,), (&String,)>(
|
||||
sink_box_ref.clone(),
|
||||
(&new_sink_name,),
|
||||
&SETDEFAULT,
|
||||
);
|
||||
if result.is_none() {
|
||||
return;
|
||||
}
|
||||
let new_sink = result.unwrap().0;
|
||||
refresh_default_sink(new_sink, sink_box_ref, false);
|
||||
});
|
||||
}
|
||||
|
||||
pub fn volume_slider_handler(sink_box: Arc<SinkBox>, value: f64) -> glib::Propagation {
|
||||
let imp = sink_box.imp();
|
||||
let fraction = (value / 655.36).round();
|
||||
let percentage = (fraction).to_string() + "%";
|
||||
imp.reset_volume_percentage.set_text(&percentage);
|
||||
let sink = imp.reset_default_sink.borrow();
|
||||
let index = sink.index;
|
||||
let channels = sink.channels;
|
||||
{
|
||||
let mut time = imp.volume_time_stamp.borrow_mut();
|
||||
if time.is_some() && time.unwrap().elapsed().unwrap() < Duration::from_millis(50) {
|
||||
return Propagation::Proceed;
|
||||
}
|
||||
*time = Some(SystemTime::now());
|
||||
}
|
||||
audio_dbus_call::<SinkBox, (), (u32, u16, u32)>(
|
||||
sink_box.clone(),
|
||||
(index, channels, value as u32),
|
||||
&SETVOLUME,
|
||||
);
|
||||
Propagation::Proceed
|
||||
}
|
||||
|
||||
pub fn mute_handler(sink_box: Arc<SinkBox>) {
|
||||
let imp = sink_box.imp();
|
||||
let mut stream = imp.reset_default_sink.borrow_mut();
|
||||
stream.muted = !stream.muted;
|
||||
if stream.muted {
|
||||
imp.reset_sink_mute
|
||||
.set_icon_name("audio-volume-muted-symbolic");
|
||||
} else {
|
||||
imp.reset_sink_mute
|
||||
.set_icon_name("audio-volume-high-symbolic");
|
||||
}
|
||||
audio_dbus_call::<SinkBox, (), (u32, bool)>(
|
||||
sink_box.clone(),
|
||||
(stream.index, stream.muted),
|
||||
&SETMUTE,
|
||||
);
|
||||
}
|
||||
|
||||
pub fn sink_added_handler(sink_box: Arc<SinkBox>, ir: SinkAdded) -> bool {
|
||||
glib::spawn_future(async move {
|
||||
glib::idle_add_once(move || {
|
||||
let sink_box_imp = sink_box.imp();
|
||||
let sink_index = ir.sink.index;
|
||||
let alias = ir.sink.alias.clone();
|
||||
let name = ir.sink.name.clone();
|
||||
let mut is_default = false;
|
||||
|
||||
if sink_box_imp.reset_default_sink.borrow().name == ir.sink.name {
|
||||
is_default = true;
|
||||
}
|
||||
let sink_entry = SinkEntry::new(
|
||||
is_default,
|
||||
sink_box_imp.reset_default_check_button.clone(),
|
||||
ir.sink,
|
||||
sink_box.clone(),
|
||||
);
|
||||
let sink_clone = sink_entry.clone();
|
||||
let entry = Arc::new(ListEntry::new(&*sink_entry));
|
||||
entry.set_activatable(false);
|
||||
let mut list = sink_box_imp.reset_sink_list.write().unwrap();
|
||||
list.insert(sink_index, (entry.clone(), sink_clone, alias.clone()));
|
||||
sink_box_imp.reset_sinks.append(&*entry);
|
||||
let mut map = sink_box_imp.reset_sink_map.write().unwrap();
|
||||
let mut index = sink_box_imp.reset_model_index.write().unwrap();
|
||||
let model_list = sink_box_imp.reset_model_list.write().unwrap();
|
||||
if model_list.string(*index - 1) == Some("Dummy Output".into()) {
|
||||
model_list.append(&alias);
|
||||
model_list.remove(*index - 1);
|
||||
map.insert(alias, (sink_index, name));
|
||||
sink_box_imp.reset_sink_dropdown.set_selected(0);
|
||||
} else {
|
||||
model_list.append(&alias);
|
||||
map.insert(alias.clone(), (sink_index, name));
|
||||
if alias == "Dummy Output" {
|
||||
sink_box_imp.reset_sink_dropdown.set_selected(0);
|
||||
}
|
||||
*index += 1;
|
||||
}
|
||||
});
|
||||
});
|
||||
true
|
||||
}
|
||||
|
||||
pub fn sink_removed_handler(sink_box: Arc<SinkBox>, ir: SinkRemoved) -> bool {
|
||||
glib::spawn_future(async move {
|
||||
glib::idle_add_once(move || {
|
||||
let sink_box_imp = sink_box.imp();
|
||||
|
||||
let entry: Option<(Arc<ListEntry>, Arc<SinkEntry>, String)>;
|
||||
{
|
||||
let mut list = sink_box_imp.reset_sink_list.write().unwrap();
|
||||
entry = list.remove(&ir.index);
|
||||
if entry.is_none() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
sink_box_imp.reset_sinks.remove(&*entry.clone().unwrap().0);
|
||||
let alias = entry.unwrap().2;
|
||||
let mut index = sink_box_imp.reset_model_index.write().unwrap();
|
||||
let model_list = sink_box_imp.reset_model_list.write().unwrap();
|
||||
|
||||
// add dummy entry when no other devices are available
|
||||
if *index == 1 {
|
||||
model_list.append("Dummy Output");
|
||||
}
|
||||
|
||||
let mut map = sink_box_imp.reset_sink_map.write().unwrap();
|
||||
map.remove(&alias);
|
||||
|
||||
for entry in 0..*index {
|
||||
if model_list.string(entry) == Some(alias.clone().into()) {
|
||||
model_list.splice(entry, 1, &[]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// dummy enforces a minimum of 1
|
||||
if *index > 1 {
|
||||
*index -= 1;
|
||||
}
|
||||
});
|
||||
});
|
||||
true
|
||||
}
|
||||
|
||||
pub fn sink_changed_handler(sink_box: Arc<SinkBox>, ir: SinkChanged) -> bool {
|
||||
glib::spawn_future(async move {
|
||||
glib::idle_add_once(move || {
|
||||
let default_sink = get_default_sink_name(sink_box.clone());
|
||||
let sink_box_imp = sink_box.imp();
|
||||
let is_default = ir.sink.name == default_sink;
|
||||
let volume = ir.sink.volume.first().unwrap_or(&0_u32);
|
||||
let fraction = (*volume as f64 / 655.36).round();
|
||||
let percentage = (fraction).to_string() + "%";
|
||||
|
||||
let list = sink_box_imp.reset_sink_list.read().unwrap();
|
||||
let entry = list.get(&ir.sink.index);
|
||||
if entry.is_none() {
|
||||
return;
|
||||
}
|
||||
let imp = entry.unwrap().1.imp();
|
||||
if is_default {
|
||||
sink_box_imp.reset_volume_percentage.set_text(&percentage);
|
||||
sink_box_imp.reset_volume_slider.set_value(*volume as f64);
|
||||
sink_box_imp.reset_default_sink.replace(ir.sink.clone());
|
||||
if ir.sink.muted {
|
||||
sink_box_imp
|
||||
.reset_sink_mute
|
||||
.set_icon_name("audio-volume-muted-symbolic");
|
||||
} else {
|
||||
sink_box_imp
|
||||
.reset_sink_mute
|
||||
.set_icon_name("audio-volume-high-symbolic");
|
||||
}
|
||||
imp.reset_selected_sink.set_active(true);
|
||||
} else {
|
||||
imp.reset_selected_sink.set_active(false);
|
||||
}
|
||||
imp.reset_sink_name
|
||||
.set_title(ir.sink.alias.clone().as_str());
|
||||
imp.reset_volume_percentage.set_text(&percentage);
|
||||
imp.reset_volume_slider.set_value(*volume as f64);
|
||||
if ir.sink.muted {
|
||||
imp.reset_sink_mute
|
||||
.set_icon_name("audio-volume-muted-symbolic");
|
||||
} else {
|
||||
imp.reset_sink_mute
|
||||
.set_icon_name("audio-volume-high-symbolic");
|
||||
}
|
||||
});
|
||||
});
|
||||
true
|
||||
}
|
||||
|
||||
pub fn input_stream_added_handler(sink_box: Arc<SinkBox>, ir: InputStreamAdded) -> bool {
|
||||
glib::spawn_future(async move {
|
||||
glib::idle_add_once(move || {
|
||||
let sink_box_imp = sink_box.imp();
|
||||
let mut list = sink_box_imp.reset_input_stream_list.write().unwrap();
|
||||
let index = ir.stream.index;
|
||||
let input_stream = InputStreamEntry::new(sink_box.clone(), ir.stream);
|
||||
let entry = Arc::new(ListEntry::new(&*input_stream));
|
||||
entry.set_activatable(false);
|
||||
list.insert(index, (entry.clone(), input_stream.clone()));
|
||||
sink_box_imp.reset_input_streams.append(&*entry);
|
||||
});
|
||||
});
|
||||
true
|
||||
}
|
||||
|
||||
pub fn input_stream_removed_handler(sink_box: Arc<SinkBox>, ir: InputStreamRemoved) -> bool {
|
||||
glib::spawn_future(async move {
|
||||
glib::idle_add_once(move || {
|
||||
let sink_box_imp = sink_box.imp();
|
||||
let mut list = sink_box_imp.reset_input_stream_list.write().unwrap();
|
||||
let entry = list.remove(&ir.index);
|
||||
if entry.is_none() {
|
||||
return;
|
||||
}
|
||||
sink_box_imp.reset_input_streams.remove(&*entry.unwrap().0);
|
||||
});
|
||||
});
|
||||
true
|
||||
}
|
||||
|
||||
pub fn input_stream_changed_handler(sink_box: Arc<SinkBox>, ir: InputStreamChanged) -> bool {
|
||||
let imp = sink_box.imp();
|
||||
let alias: String;
|
||||
{
|
||||
let sink_list = imp.reset_sink_list.read().unwrap();
|
||||
if let Some(alias_opt) = sink_list.get(&ir.stream.sink_index) {
|
||||
alias = alias_opt.2.clone();
|
||||
} else {
|
||||
alias = String::from("");
|
||||
}
|
||||
}
|
||||
let sink_box = sink_box.clone();
|
||||
glib::spawn_future(async move {
|
||||
glib::idle_add_once(move || {
|
||||
let sink_box = sink_box.clone();
|
||||
let sink_box_imp = sink_box.imp();
|
||||
let entry: Arc<InputStreamEntry>;
|
||||
{
|
||||
let list = sink_box_imp.reset_input_stream_list.read().unwrap();
|
||||
let entry_opt = list.get(&ir.stream.index);
|
||||
if entry_opt.is_none() {
|
||||
return;
|
||||
}
|
||||
entry = entry_opt.unwrap().1.clone();
|
||||
}
|
||||
let imp = entry.imp();
|
||||
if ir.stream.muted {
|
||||
imp.reset_sink_mute
|
||||
.set_icon_name("audio-volume-muted-symbolic");
|
||||
} else {
|
||||
imp.reset_sink_mute
|
||||
.set_icon_name("audio-volume-high-symbolic");
|
||||
}
|
||||
let name = ir.stream.application_name.clone() + ": " + ir.stream.name.as_str();
|
||||
imp.reset_sink_selection.set_title(name.as_str());
|
||||
let volume = ir.stream.volume.first().unwrap_or(&0_u32);
|
||||
let fraction = (*volume as f64 / 655.36).round();
|
||||
let percentage = (fraction).to_string() + "%";
|
||||
imp.reset_volume_percentage.set_text(&percentage);
|
||||
imp.reset_volume_slider.set_value(*volume as f64);
|
||||
let index = sink_box_imp.reset_model_index.read().unwrap();
|
||||
let model_list = sink_box_imp.reset_model_list.read().unwrap();
|
||||
for entry in 0..*index {
|
||||
if model_list.string(entry) == Some(alias.clone().into()) {
|
||||
imp.reset_sink_selection.set_selected(entry);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
true
|
||||
}
|
|
@ -5,7 +5,7 @@ use std::collections::HashMap;
|
|||
use std::sync::{Arc, RwLock};
|
||||
use std::time::SystemTime;
|
||||
|
||||
use crate::components::audio::generic_entry::{AudioIcons, TAudioBoxImpl};
|
||||
use crate::components::audio::audio_entry::{AudioIcons, TAudioBoxImpl};
|
||||
use crate::components::audio::output::input_stream_entry::InputStreamEntry;
|
||||
use crate::components::base::error::ReSetError;
|
||||
use crate::components::base::list_entry::ListEntry;
|
||||
|
@ -150,13 +150,13 @@ impl TAudioBoxImpl<Sink, SinkEntry, InputStreamEntry> for SinkBox {
|
|||
|
||||
fn audio_object_list(
|
||||
&self,
|
||||
) -> &crate::components::audio::generic_entry::AudioEntryMap<SinkEntry> {
|
||||
) -> &crate::components::audio::audio_entry::AudioEntryMap<SinkEntry> {
|
||||
&self.reset_sink_list
|
||||
}
|
||||
|
||||
fn audio_object_stream_list(
|
||||
&self,
|
||||
) -> &crate::components::audio::generic_entry::AudioStreamEntryMap<InputStreamEntry> {
|
||||
) -> &crate::components::audio::audio_entry::AudioStreamEntryMap<InputStreamEntry> {
|
||||
&self.reset_input_stream_list
|
||||
}
|
||||
|
||||
|
@ -168,7 +168,7 @@ impl TAudioBoxImpl<Sink, SinkEntry, InputStreamEntry> for SinkBox {
|
|||
self.reset_model_index.clone()
|
||||
}
|
||||
|
||||
fn source_map(&self) -> &crate::components::audio::generic_entry::AudioMap {
|
||||
fn source_map(&self) -> &crate::components::audio::audio_entry::AudioMap {
|
||||
&self.reset_sink_map
|
||||
}
|
||||
|
||||
|
|
|
@ -1,232 +0,0 @@
|
|||
use std::{sync::Arc, time::Duration};
|
||||
|
||||
use adw::prelude::{ComboRowExt, PreferencesGroupExt};
|
||||
use dbus::{blocking::Connection, Error};
|
||||
use glib::subclass::types::ObjectSubclassIsExt;
|
||||
use gtk::{
|
||||
gio,
|
||||
prelude::{BoxExt, ButtonExt, CheckButtonExt, ListBoxRowExt, RangeExt},
|
||||
};
|
||||
use re_set_lib::audio::audio_structures::{Card, InputStream, Sink};
|
||||
|
||||
use crate::components::{
|
||||
base::{card_entry::CardEntry, error_impl::show_error, list_entry::ListEntry},
|
||||
utils::{AUDIO, BASE, DBUS_PATH},
|
||||
};
|
||||
|
||||
use super::{
|
||||
input_stream_entry::InputStreamEntry,
|
||||
sink_box::SinkBox,
|
||||
sink_box_handlers::{drop_down_handler, mute_handler, volume_slider_handler},
|
||||
sink_entry::SinkEntry,
|
||||
};
|
||||
|
||||
pub fn populate_sink_information(sink_box: Arc<SinkBox>, sinks: Vec<Sink>) {
|
||||
glib::spawn_future(async move {
|
||||
glib::idle_add_once(move || {
|
||||
let sink_box_ref_select = sink_box.clone();
|
||||
let sink_box_ref_slider = sink_box.clone();
|
||||
let sink_box_ref_mute = sink_box.clone();
|
||||
let sink_box_ref = sink_box.clone();
|
||||
{
|
||||
let sink_box_imp = sink_box_ref.imp();
|
||||
let default_sink = sink_box_imp.reset_default_sink.clone();
|
||||
let sink = default_sink.borrow();
|
||||
|
||||
if sink.muted {
|
||||
sink_box_imp
|
||||
.reset_sink_mute
|
||||
.set_icon_name("audio-volume-muted-symbolic");
|
||||
} else {
|
||||
sink_box_imp
|
||||
.reset_sink_mute
|
||||
.set_icon_name("audio-volume-high-symbolic");
|
||||
}
|
||||
|
||||
let volume = sink.volume.first().unwrap_or(&0);
|
||||
let fraction = (*volume as f64 / 655.36).round();
|
||||
let percentage = (fraction).to_string() + "%";
|
||||
sink_box_imp.reset_volume_percentage.set_text(&percentage);
|
||||
sink_box_imp.reset_volume_slider.set_value(*volume as f64);
|
||||
let mut list = sink_box_imp.reset_sink_list.write().unwrap();
|
||||
for sink in sinks {
|
||||
let index = sink.index;
|
||||
let alias = sink.alias.clone();
|
||||
let mut is_default = false;
|
||||
if sink_box_imp.reset_default_sink.borrow().name == sink.name {
|
||||
is_default = true;
|
||||
}
|
||||
let sink_entry = SinkEntry::new(
|
||||
is_default,
|
||||
sink_box_imp.reset_default_check_button.clone(),
|
||||
sink,
|
||||
sink_box.clone(),
|
||||
);
|
||||
let sink_clone = sink_entry.clone();
|
||||
let entry = Arc::new(ListEntry::new(&*sink_entry));
|
||||
entry.set_activatable(false);
|
||||
list.insert(index, (entry.clone(), sink_clone, alias));
|
||||
sink_box_imp.reset_sinks.append(&*entry);
|
||||
}
|
||||
let list = sink_box_imp.reset_model_list.read().unwrap();
|
||||
sink_box_imp.reset_sink_dropdown.set_model(Some(&*list));
|
||||
let name = sink_box_imp.reset_default_sink.borrow();
|
||||
|
||||
let index = sink_box_imp.reset_model_index.read().unwrap();
|
||||
let model_list = sink_box_imp.reset_model_list.read().unwrap();
|
||||
for entry in 0..*index {
|
||||
if model_list.string(entry) == Some(name.alias.clone().into()) {
|
||||
sink_box_imp.reset_sink_dropdown.set_selected(entry);
|
||||
break;
|
||||
}
|
||||
}
|
||||
sink_box_imp
|
||||
.reset_sink_dropdown
|
||||
.connect_selected_notify(move |dropdown| {
|
||||
drop_down_handler(sink_box_ref_select.clone(), dropdown);
|
||||
});
|
||||
}
|
||||
sink_box_ref
|
||||
.imp()
|
||||
.reset_volume_slider
|
||||
.connect_change_value(move |_, _, value| {
|
||||
volume_slider_handler(sink_box_ref_slider.clone(), value)
|
||||
});
|
||||
sink_box_ref
|
||||
.imp()
|
||||
.reset_sink_mute
|
||||
.connect_clicked(move |_| {
|
||||
mute_handler(sink_box_ref_mute.clone());
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
pub fn refresh_default_sink(new_sink: Sink, sink_box: Arc<SinkBox>, entry: bool) {
|
||||
let volume = *new_sink.volume.first().unwrap_or(&0_u32);
|
||||
let fraction = (volume as f64 / 655.36).round();
|
||||
let percentage = (fraction).to_string() + "%";
|
||||
glib::spawn_future(async move {
|
||||
glib::idle_add_once(move || {
|
||||
let imp = sink_box.imp();
|
||||
if !entry {
|
||||
let list = imp.reset_sink_list.read().unwrap();
|
||||
let entry = list.get(&new_sink.index);
|
||||
if entry.is_none() {
|
||||
return;
|
||||
}
|
||||
let entry_imp = entry.unwrap().1.imp();
|
||||
entry_imp.reset_selected_sink.set_active(true);
|
||||
} else {
|
||||
let index = imp.reset_model_index.read().unwrap();
|
||||
let model_list = imp.reset_model_list.read().unwrap();
|
||||
for entry in 0..*index {
|
||||
if model_list.string(entry) == Some(new_sink.alias.clone().into()) {
|
||||
imp.reset_sink_dropdown.set_selected(entry);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
imp.reset_volume_percentage.set_text(&percentage);
|
||||
imp.reset_volume_slider.set_value(volume as f64);
|
||||
if new_sink.muted {
|
||||
imp.reset_sink_mute
|
||||
.set_icon_name("audio-volume-muted-symbolic");
|
||||
} else {
|
||||
imp.reset_sink_mute
|
||||
.set_icon_name("audio-volume-high-symbolic");
|
||||
}
|
||||
imp.reset_default_sink.replace(new_sink);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
pub fn populate_inputstreams(sink_box: Arc<SinkBox>) {
|
||||
gio::spawn_blocking(move || {
|
||||
let streams = get_input_streams(sink_box.clone());
|
||||
glib::spawn_future(async move {
|
||||
glib::idle_add_once(move || {
|
||||
let sink_box_imp = sink_box.imp();
|
||||
let mut list = sink_box_imp.reset_input_stream_list.write().unwrap();
|
||||
for stream in streams {
|
||||
let index = stream.index;
|
||||
let input_stream = InputStreamEntry::new(sink_box.clone(), stream);
|
||||
let entry = Arc::new(ListEntry::new(&*input_stream));
|
||||
entry.set_activatable(false);
|
||||
list.insert(index, (entry.clone(), input_stream.clone()));
|
||||
sink_box_imp.reset_input_streams.append(&*entry);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
pub fn populate_cards(sink_box: Arc<SinkBox>) {
|
||||
gio::spawn_blocking(move || {
|
||||
let sink_box_ref = sink_box.clone();
|
||||
let cards = get_cards(sink_box.clone());
|
||||
glib::spawn_future(async move {
|
||||
glib::idle_add_once(move || {
|
||||
let imp = sink_box_ref.imp();
|
||||
for card in cards {
|
||||
imp.reset_cards.add(&CardEntry::new(card));
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
pub fn get_input_streams(sink_box: Arc<SinkBox>) -> Vec<InputStream> {
|
||||
let conn = Connection::new_session().unwrap();
|
||||
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
||||
let res: Result<(Vec<InputStream>,), Error> = proxy.method_call(AUDIO, "ListInputStreams", ());
|
||||
if res.is_err() {
|
||||
show_error::<SinkBox>(sink_box.clone(), "Failed to list input streams");
|
||||
return Vec::new();
|
||||
}
|
||||
res.unwrap().0
|
||||
}
|
||||
|
||||
pub fn get_sinks(sink_box: Arc<SinkBox>) -> Vec<Sink> {
|
||||
let conn = Connection::new_session().unwrap();
|
||||
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
||||
let res: Result<(Vec<Sink>,), Error> = proxy.method_call(AUDIO, "ListSinks", ());
|
||||
if res.is_err() {
|
||||
show_error::<SinkBox>(sink_box.clone(), "Failed to list sinks");
|
||||
return Vec::new();
|
||||
}
|
||||
res.unwrap().0
|
||||
}
|
||||
|
||||
pub fn get_cards(sink_box: Arc<SinkBox>) -> Vec<Card> {
|
||||
let conn = Connection::new_session().unwrap();
|
||||
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
||||
let res: Result<(Vec<Card>,), Error> = proxy.method_call(AUDIO, "ListCards", ());
|
||||
if res.is_err() {
|
||||
show_error::<SinkBox>(sink_box.clone(), "Failed to list profiles");
|
||||
return Vec::new();
|
||||
}
|
||||
res.unwrap().0
|
||||
}
|
||||
|
||||
pub fn get_default_sink_name(sink_box: Arc<SinkBox>) -> String {
|
||||
let conn = Connection::new_session().unwrap();
|
||||
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
||||
let res: Result<(String,), Error> = proxy.method_call(AUDIO, "GetDefaultSinkName", ());
|
||||
if res.is_err() {
|
||||
show_error::<SinkBox>(sink_box.clone(), "Failed to get default sink name");
|
||||
return String::from("");
|
||||
}
|
||||
res.unwrap().0
|
||||
}
|
||||
|
||||
pub fn get_default_sink(sink_box: Arc<SinkBox>) -> Sink {
|
||||
let conn = Connection::new_session().unwrap();
|
||||
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
||||
let res: Result<(Sink,), Error> = proxy.method_call(AUDIO, "GetDefaultSink", ());
|
||||
if res.is_err() {
|
||||
show_error::<SinkBox>(sink_box.clone(), "Failed to get default sink");
|
||||
return Sink::default();
|
||||
}
|
||||
res.unwrap().0
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
use crate::components::audio::generic_entry::{AudioIcons, DBusFunction};
|
||||
use crate::components::audio::audio_entry::{AudioIcons, DBusFunction};
|
||||
|
||||
pub const ICONS: AudioIcons = AudioIcons {
|
||||
muted: "audio-volume-muted-symbolic",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use crate::components::audio::generic_entry::{new_entry, TAudioEntry};
|
||||
use crate::components::audio::audio_entry::{new_entry, TAudioEntry};
|
||||
use glib::subclass::types::ObjectSubclassIsExt;
|
||||
use gtk::CheckButton;
|
||||
use re_set_lib::audio::audio_structures::{InputStream, Sink};
|
||||
|
|
|
@ -5,7 +5,7 @@ use std::cell::RefCell;
|
|||
use std::sync::Arc;
|
||||
use std::time::SystemTime;
|
||||
|
||||
use crate::components::audio::generic_entry::{AudioIcons, DBusFunction, TAudioEntryImpl};
|
||||
use crate::components::audio::audio_entry::{AudioIcons, DBusFunction, TAudioEntryImpl};
|
||||
use crate::components::audio::output::sink_entry;
|
||||
use gtk::subclass::prelude::*;
|
||||
use gtk::{Button, CheckButton, CompositeTemplate, Label, Scale};
|
||||
|
|
Loading…
Reference in a new issue