mirror of
https://github.com/Xetibo/ReSet.git
synced 2025-04-18 18:48:33 +02:00
wip: Add TAudioStreamObject
This commit is contained in:
parent
7593f2edc1
commit
fc048304ee
|
@ -1,90 +1,25 @@
|
||||||
use std::{sync::Arc, time::Duration};
|
use std::sync::Arc;
|
||||||
|
|
||||||
use adw::traits::ComboRowExt;
|
use adw::traits::ComboRowExt;
|
||||||
use dbus::{
|
use gtk::prelude::{ButtonExt, CheckButtonExt, RangeExt};
|
||||||
arg::{Arg, Get},
|
use re_set_lib::audio::audio_structures::{TAudioObject, TAudioStreamObject};
|
||||||
blocking::Connection,
|
|
||||||
Error,
|
use super::generic_entry::{
|
||||||
|
TAudioBox, TAudioBoxImpl, TAudioEntry, TAudioEntryImpl, TAudioStream, TAudioStreamImpl,
|
||||||
};
|
};
|
||||||
use gtk::{
|
|
||||||
gio,
|
|
||||||
prelude::{ButtonExt, CheckButtonExt, RangeExt},
|
|
||||||
};
|
|
||||||
use re_set_lib::audio::audio_structures::AudioObject;
|
|
||||||
|
|
||||||
use crate::components::{
|
|
||||||
base::error_impl::{show_error, ReSetErrorImpl},
|
|
||||||
utils::{AUDIO, BASE, DBUS_PATH},
|
|
||||||
};
|
|
||||||
|
|
||||||
use super::generic_entry::{Audio, AudioBox, AudioBoxImpl, AudioImpl, DBusFunction};
|
|
||||||
|
|
||||||
pub fn set_volume<T: ReSetErrorImpl + 'static>(
|
|
||||||
value: f64,
|
|
||||||
index: u32,
|
|
||||||
channels: u16,
|
|
||||||
reset_box: Arc<T>,
|
|
||||||
function: &'static DBusFunction,
|
|
||||||
) -> bool {
|
|
||||||
gio::spawn_blocking(move || {
|
|
||||||
let conn = Connection::new_session().unwrap();
|
|
||||||
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
|
||||||
let res: Result<(), Error> =
|
|
||||||
proxy.method_call(AUDIO, function.function, (index, channels, value as u32));
|
|
||||||
if res.is_err() {
|
|
||||||
// TODO: also log this with LOG/ERROR
|
|
||||||
show_error::<T>(reset_box.clone(), function.error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn toggle_audio_object_mute<T: ReSetErrorImpl + 'static>(
|
|
||||||
index: u32,
|
|
||||||
muted: bool,
|
|
||||||
input_box: Arc<T>,
|
|
||||||
function: &'static DBusFunction,
|
|
||||||
) -> bool {
|
|
||||||
gio::spawn_blocking(move || {
|
|
||||||
let conn = Connection::new_session().unwrap();
|
|
||||||
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
|
||||||
let res: Result<(), Error> = proxy.method_call(AUDIO, function.function, (index, muted));
|
|
||||||
if res.is_err() {
|
|
||||||
// TODO: also log this with LOG/ERROR
|
|
||||||
show_error::<T>(input_box.clone(), function.error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_default_audio_object<T, R>(
|
|
||||||
name: Arc<String>,
|
|
||||||
input_box: Arc<T>,
|
|
||||||
function: &'static DBusFunction,
|
|
||||||
) -> Option<R>
|
|
||||||
where
|
|
||||||
T: ReSetErrorImpl + 'static,
|
|
||||||
R: Arg + for<'z> Get<'z>,
|
|
||||||
{
|
|
||||||
let conn = Connection::new_session().unwrap();
|
|
||||||
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
|
||||||
let res: Result<(R,), Error> = proxy.method_call(AUDIO, function.function, (name.as_str(),));
|
|
||||||
if res.is_err() {
|
|
||||||
show_error::<T>(input_box.clone(), function.error);
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
Some(res.unwrap().0)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn refresh_default_audio_object<
|
pub fn refresh_default_audio_object<
|
||||||
A: AudioBox<BoxImpl> + Send + Sync + 'static,
|
AudioObject: TAudioObject + Send + Sync + 'static,
|
||||||
OBJ: AudioObject + Send + Sync + 'static,
|
StreamObject: TAudioStreamObject + Send + Sync + 'static,
|
||||||
Entry: Audio<OBJ, EntryImpl>,
|
AudioEntry: TAudioEntry<AudioEntryImpl>,
|
||||||
EntryImpl: AudioImpl<OBJ>,
|
AudioEntryImpl: TAudioEntryImpl<AudioObject>,
|
||||||
BoxImpl: AudioBoxImpl<OBJ, Entry, EntryImpl>,
|
AudioStream: TAudioStream<AudioStreamImpl>,
|
||||||
|
AudioStreamImpl: TAudioStreamImpl<AudioObject, StreamObject>,
|
||||||
|
AudioBox: TAudioBox<AudioBoxImpl> + Send + Sync + 'static,
|
||||||
|
AudioBoxImpl: TAudioBoxImpl<AudioObject, AudioEntry, AudioStream>,
|
||||||
>(
|
>(
|
||||||
new_audio_object: OBJ,
|
new_audio_object: AudioObject,
|
||||||
reset_box: Arc<A>,
|
reset_box: Arc<AudioBox>,
|
||||||
entry: bool,
|
entry: bool,
|
||||||
) {
|
) {
|
||||||
let volume = *new_audio_object.volume().first().unwrap_or(&0_u32);
|
let volume = *new_audio_object.volume().first().unwrap_or(&0_u32);
|
||||||
|
|
6
src/components/audio/generic_const.rs
Normal file
6
src/components/audio/generic_const.rs
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
use super::generic_entry::DBusFunction;
|
||||||
|
|
||||||
|
pub const LISTCARDS: DBusFunction = DBusFunction {
|
||||||
|
function: "ListCards",
|
||||||
|
error: "Failed to get list profiles",
|
||||||
|
};
|
|
@ -12,32 +12,26 @@ use glib::{
|
||||||
Object,
|
Object,
|
||||||
};
|
};
|
||||||
use gtk::{gio, Button, CheckButton, Label, Scale, StringList, TemplateChild};
|
use gtk::{gio, Button, CheckButton, Label, Scale, StringList, TemplateChild};
|
||||||
use re_set_lib::audio::audio_structures::AudioObject;
|
use re_set_lib::audio::audio_structures::{TAudioObject, TAudioStreamObject};
|
||||||
|
|
||||||
use crate::components::base::error::ReSetError;
|
use crate::components::base::error::ReSetError;
|
||||||
use crate::components::base::error_impl::ReSetErrorImpl;
|
use crate::components::base::error_impl::ReSetErrorImpl;
|
||||||
use crate::components::base::list_entry::ListEntry;
|
use crate::components::base::list_entry::ListEntry;
|
||||||
use crate::components::utils::set_action_row_ellipsis;
|
use crate::components::utils::set_action_row_ellipsis;
|
||||||
|
|
||||||
use super::generic_audio_functions::{
|
use super::generic_audio_functions::refresh_default_audio_object;
|
||||||
refresh_default_audio_object, set_default_audio_object, set_volume, toggle_audio_object_mute,
|
use super::generic_utils::audio_dbus_call;
|
||||||
};
|
|
||||||
|
|
||||||
pub trait Audio<T: AudioObject, IMP: AudioImpl<T>>: IsClass + IsA<glib::Object> {
|
|
||||||
fn entry_imp(&self) -> &IMP;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait AudioBox<AudioBoxImpl> {
|
|
||||||
fn box_imp(&self) -> &AudioBoxImpl;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub type AudioEntryMap<T> = Arc<RwLock<HashMap<u32, (Arc<ListEntry>, Arc<T>, String)>>>;
|
pub type AudioEntryMap<T> = Arc<RwLock<HashMap<u32, (Arc<ListEntry>, Arc<T>, String)>>>;
|
||||||
#[allow(dead_code)]
|
|
||||||
pub type AudioStreamEntryMap<T> = Arc<RwLock<HashMap<u32, (Arc<ListEntry>, Arc<T>)>>>;
|
pub type AudioStreamEntryMap<T> = Arc<RwLock<HashMap<u32, (Arc<ListEntry>, Arc<T>)>>>;
|
||||||
pub type AudioMap = Arc<RwLock<HashMap<String, (u32, String)>>>;
|
pub type AudioMap = Arc<RwLock<HashMap<String, (u32, String)>>>;
|
||||||
|
|
||||||
|
pub trait TAudioBox<AudioBoxImpl> {
|
||||||
|
fn box_imp(&self) -> &AudioBoxImpl;
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub trait AudioBoxImpl<OBJ, ENTRY, STREAMENTRY> {
|
pub trait TAudioBoxImpl<AObject, ENTRY, STREAMENTRY> {
|
||||||
fn audio_object_row(&self) -> &TemplateChild<ActionRow>;
|
fn audio_object_row(&self) -> &TemplateChild<ActionRow>;
|
||||||
fn cards_row(&self) -> &TemplateChild<ActionRow>;
|
fn cards_row(&self) -> &TemplateChild<ActionRow>;
|
||||||
fn audio_object_dropdown(&self) -> &TemplateChild<ComboRow>;
|
fn audio_object_dropdown(&self) -> &TemplateChild<ComboRow>;
|
||||||
|
@ -51,9 +45,9 @@ pub trait AudioBoxImpl<OBJ, ENTRY, STREAMENTRY> {
|
||||||
fn cards(&self) -> &TemplateChild<PreferencesGroup>;
|
fn cards(&self) -> &TemplateChild<PreferencesGroup>;
|
||||||
fn error(&self) -> &TemplateChild<ReSetError>;
|
fn error(&self) -> &TemplateChild<ReSetError>;
|
||||||
fn default_check_button(&self) -> Arc<CheckButton>;
|
fn default_check_button(&self) -> Arc<CheckButton>;
|
||||||
fn default_audio_object(&self) -> Arc<RefCell<OBJ>>;
|
fn default_audio_object(&self) -> Arc<RefCell<AObject>>;
|
||||||
fn audio_object_list(&self) -> &AudioEntryMap<ENTRY>;
|
fn audio_object_list(&self) -> &AudioEntryMap<ENTRY>;
|
||||||
// fn audio_object_stream_list(&self) -> AudioStreamEntryMap<STREAMENTRY>;
|
fn audio_object_stream_list(&self) -> &AudioStreamEntryMap<STREAMENTRY>;
|
||||||
fn model_list(&self) -> Arc<RwLock<StringList>>;
|
fn model_list(&self) -> Arc<RwLock<StringList>>;
|
||||||
fn model_index(&self) -> Arc<RwLock<u32>>;
|
fn model_index(&self) -> Arc<RwLock<u32>>;
|
||||||
fn source_map(&self) -> &AudioMap;
|
fn source_map(&self) -> &AudioMap;
|
||||||
|
@ -61,14 +55,18 @@ pub trait AudioBoxImpl<OBJ, ENTRY, STREAMENTRY> {
|
||||||
fn icons(&self) -> &AudioIcons;
|
fn icons(&self) -> &AudioIcons;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait TAudioEntry<TAudioEntryImpl>: IsClass + IsA<glib::Object> {
|
||||||
|
fn entry_imp(&self) -> &TAudioEntryImpl;
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub trait AudioImpl<T: AudioObject> {
|
pub trait TAudioEntryImpl<AudioObject: TAudioObject> {
|
||||||
fn name(&self) -> &TemplateChild<ActionRow>;
|
fn name(&self) -> &TemplateChild<ActionRow>;
|
||||||
fn selected_audio_object(&self) -> &TemplateChild<CheckButton>;
|
fn selected_audio_object(&self) -> &TemplateChild<CheckButton>;
|
||||||
fn mute(&self) -> &TemplateChild<Button>;
|
fn mute(&self) -> &TemplateChild<Button>;
|
||||||
fn volume_slider(&self) -> &TemplateChild<Scale>;
|
fn volume_slider(&self) -> &TemplateChild<Scale>;
|
||||||
fn volume_percentage(&self) -> &TemplateChild<Label>;
|
fn volume_percentage(&self) -> &TemplateChild<Label>;
|
||||||
fn audio_object(&self) -> Arc<RefCell<T>>;
|
fn audio_object(&self) -> Arc<RefCell<AudioObject>>;
|
||||||
fn volume_time_stamp(&self) -> &RefCell<Option<SystemTime>>;
|
fn volume_time_stamp(&self) -> &RefCell<Option<SystemTime>>;
|
||||||
fn set_volume_fn(&self) -> &'static DBusFunction;
|
fn set_volume_fn(&self) -> &'static DBusFunction;
|
||||||
fn set_audio_object_fn(&self) -> &'static DBusFunction;
|
fn set_audio_object_fn(&self) -> &'static DBusFunction;
|
||||||
|
@ -76,17 +74,19 @@ pub trait AudioImpl<T: AudioObject> {
|
||||||
fn icons(&self) -> &AudioIcons;
|
fn icons(&self) -> &AudioIcons;
|
||||||
}
|
}
|
||||||
|
|
||||||
// pub trait AudioObject {
|
pub trait TAudioStream<TAudioStreamImpl> {
|
||||||
// fn alias(&self) -> String;
|
fn entry_imp(&self) -> &TAudioStreamImpl;
|
||||||
// fn name(&self) -> String;
|
}
|
||||||
// fn volume(&self) -> Vec<u32>;
|
|
||||||
// fn index(&self) -> u32;
|
pub trait TAudioStreamImpl<AudioObject: TAudioObject, StreamObject: TAudioStreamObject> {
|
||||||
// fn channels(&self) -> u16;
|
fn audio_object_selection(&self) -> &TemplateChild<ComboRow>;
|
||||||
// fn muted(&self) -> bool;
|
fn audio_object_mute(&self) -> &TemplateChild<Button>;
|
||||||
// fn toggle_muted(&mut self);
|
fn volume_slider(&self) -> &TemplateChild<Scale>;
|
||||||
// fn active() -> i32;
|
fn volume_percentage(&self) -> &TemplateChild<Label>;
|
||||||
// }
|
fn stream_object(&self) -> Arc<RefCell<StreamObject>>;
|
||||||
//
|
fn associated_audio_object(&self) -> Arc<RefCell<(u32, String)>>;
|
||||||
|
fn volume_time_stamp(&self) -> &RefCell<Option<SystemTime>>;
|
||||||
|
}
|
||||||
|
|
||||||
pub struct AudioIcons {
|
pub struct AudioIcons {
|
||||||
pub muted: &'static str,
|
pub muted: &'static str,
|
||||||
|
@ -99,18 +99,21 @@ pub struct DBusFunction {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_entry<
|
pub fn new_entry<
|
||||||
AObject: AudioObject + Arg + for<'z> Get<'z> + Send + Sync + 'static,
|
AudioObject: TAudioObject + Arg + for<'z> Get<'z> + Send + Sync + 'static,
|
||||||
ABox: AudioBox<BoxImpl> + ReSetErrorImpl + 'static,
|
StreamObject: TAudioStreamObject + Arg + for<'z> Get<'z> + Send + Sync + 'static,
|
||||||
Entry: Audio<AObject, EntryImpl>,
|
AudioEntry: TAudioEntry<AudioEntryImpl>,
|
||||||
EntryImpl: AudioImpl<AObject>,
|
AudioEntryImpl: TAudioEntryImpl<AudioObject>,
|
||||||
BoxImpl: AudioBoxImpl<AObject, Entry, EntryImpl>,
|
AudioStream: TAudioStream<AudioStreamImpl>,
|
||||||
|
AudioStreamImpl: TAudioStreamImpl<AudioObject, StreamObject>,
|
||||||
|
AudioBox: TAudioBox<AudioBoxImpl> + ReSetErrorImpl + 'static,
|
||||||
|
AudioBoxImpl: TAudioBoxImpl<AudioObject, AudioEntry, AudioStream>,
|
||||||
>(
|
>(
|
||||||
is_default: bool,
|
is_default: bool,
|
||||||
check_group: Arc<CheckButton>,
|
check_group: Arc<CheckButton>,
|
||||||
audio_object: AObject,
|
audio_object: AudioObject,
|
||||||
reset_box: Arc<ABox>,
|
reset_box: Arc<AudioBox>,
|
||||||
) -> Arc<Entry> {
|
) -> Arc<AudioEntry> {
|
||||||
let obj: Arc<Entry> = Arc::new(Object::builder().build());
|
let obj: Arc<AudioEntry> = Arc::new(Object::builder().build());
|
||||||
// TODO use event callback for progress bar -> this is the "im speaking" indicator
|
// TODO use event callback for progress bar -> this is the "im speaking" indicator
|
||||||
{
|
{
|
||||||
let imp = obj.entry_imp();
|
let imp = obj.entry_imp();
|
||||||
|
@ -147,11 +150,9 @@ pub fn new_entry<
|
||||||
}
|
}
|
||||||
*time = Some(SystemTime::now());
|
*time = Some(SystemTime::now());
|
||||||
}
|
}
|
||||||
set_volume(
|
audio_dbus_call::<AudioBox, (), (u32, u16, u32)>(
|
||||||
value,
|
|
||||||
index,
|
|
||||||
channels,
|
|
||||||
output_box_slider.clone(),
|
output_box_slider.clone(),
|
||||||
|
(index, channels, value as u32),
|
||||||
imp.set_volume_fn(),
|
imp.set_volume_fn(),
|
||||||
);
|
);
|
||||||
Propagation::Proceed
|
Propagation::Proceed
|
||||||
|
@ -169,21 +170,24 @@ pub fn new_entry<
|
||||||
if button.is_active() {
|
if button.is_active() {
|
||||||
let name = name.clone();
|
let name = name.clone();
|
||||||
gio::spawn_blocking(move || {
|
gio::spawn_blocking(move || {
|
||||||
// TODO: make this generic as well
|
let result = audio_dbus_call::<AudioBox, (AudioObject,), (&String,)>(
|
||||||
let result = set_default_audio_object::<ABox, AObject>(
|
|
||||||
name,
|
|
||||||
output_box_ref.clone(),
|
output_box_ref.clone(),
|
||||||
|
(&name,),
|
||||||
audio_object_fn,
|
audio_object_fn,
|
||||||
);
|
);
|
||||||
if result.is_none() {
|
if result.is_none() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
refresh_default_audio_object::<
|
||||||
refresh_default_audio_object::<ABox, AObject, Entry, EntryImpl, BoxImpl>(
|
AudioObject,
|
||||||
result.unwrap(),
|
StreamObject,
|
||||||
output_box_ref,
|
AudioEntry,
|
||||||
true,
|
AudioEntryImpl,
|
||||||
);
|
AudioStream,
|
||||||
|
AudioStreamImpl,
|
||||||
|
AudioBox,
|
||||||
|
AudioBoxImpl,
|
||||||
|
>(result.unwrap().0, output_box_ref, true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -192,15 +196,15 @@ pub fn new_entry<
|
||||||
let audio_object = imp.audio_object().clone();
|
let audio_object = imp.audio_object().clone();
|
||||||
let mut audio_object = audio_object.borrow_mut();
|
let mut audio_object = audio_object.borrow_mut();
|
||||||
audio_object.toggle_muted();
|
audio_object.toggle_muted();
|
||||||
|
let icons = imp.icons();
|
||||||
if audio_object.muted() {
|
if audio_object.muted() {
|
||||||
imp.mute().set_icon_name("audio-volume-muted-symbolic");
|
imp.mute().set_icon_name(icons.muted);
|
||||||
} else {
|
} else {
|
||||||
imp.mute().set_icon_name("audio-volume-high-symbolic");
|
imp.mute().set_icon_name(icons.active);
|
||||||
}
|
}
|
||||||
toggle_audio_object_mute::<ABox>(
|
audio_dbus_call::<AudioBox, (), (u32, bool)>(
|
||||||
audio_object.index(),
|
|
||||||
audio_object.muted(),
|
|
||||||
output_box_ref.clone(),
|
output_box_ref.clone(),
|
||||||
|
(audio_object.index(), audio_object.muted()),
|
||||||
imp.set_mute_fn(),
|
imp.set_mute_fn(),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
34
src/components/audio/generic_utils.rs
Normal file
34
src/components/audio/generic_utils.rs
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
use std::{sync::Arc, time::Duration};
|
||||||
|
|
||||||
|
use dbus::{
|
||||||
|
arg::{AppendAll, ReadAll},
|
||||||
|
blocking::Connection,
|
||||||
|
Error,
|
||||||
|
};
|
||||||
|
|
||||||
|
use crate::components::{
|
||||||
|
base::error_impl::{show_error, ReSetErrorImpl},
|
||||||
|
utils::{AUDIO, BASE, DBUS_PATH},
|
||||||
|
};
|
||||||
|
|
||||||
|
use super::generic_entry::DBusFunction;
|
||||||
|
|
||||||
|
pub fn audio_dbus_call<B, O, I>(
|
||||||
|
source_box: Arc<B>,
|
||||||
|
args: I,
|
||||||
|
function: &'static DBusFunction,
|
||||||
|
) -> Option<O>
|
||||||
|
where
|
||||||
|
O: ReadAll,
|
||||||
|
I: AppendAll,
|
||||||
|
B: ReSetErrorImpl + 'static,
|
||||||
|
{
|
||||||
|
let conn = Connection::new_session().unwrap();
|
||||||
|
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
||||||
|
let res: Result<O, Error> = proxy.method_call(AUDIO, function.function, args);
|
||||||
|
if res.is_err() {
|
||||||
|
show_error::<B>(source_box.clone(), function.error);
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
Some(res.unwrap())
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::{Duration, SystemTime};
|
use std::time::{Duration, SystemTime};
|
||||||
|
|
||||||
|
use crate::components::audio::generic_entry::TAudioStream;
|
||||||
use crate::components::base::error_impl::show_error;
|
use crate::components::base::error_impl::show_error;
|
||||||
use crate::components::utils::{
|
use crate::components::utils::{
|
||||||
create_dropdown_label_factory, set_combo_row_ellipsis, AUDIO, BASE, DBUS_PATH,
|
create_dropdown_label_factory, set_combo_row_ellipsis, AUDIO, BASE, DBUS_PATH,
|
||||||
|
@ -27,6 +28,12 @@ glib::wrapper! {
|
||||||
unsafe impl Send for OutputStreamEntry {}
|
unsafe impl Send for OutputStreamEntry {}
|
||||||
unsafe impl Sync for OutputStreamEntry {}
|
unsafe impl Sync for OutputStreamEntry {}
|
||||||
|
|
||||||
|
impl TAudioStream<super::output_stream_entry_impl::OutputStreamEntry> for OutputStreamEntry {
|
||||||
|
fn entry_imp(&self) -> &super::output_stream_entry_impl::OutputStreamEntry {
|
||||||
|
self.imp()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl OutputStreamEntry {
|
impl OutputStreamEntry {
|
||||||
pub fn new(source_box: Arc<SourceBox>, stream: OutputStream) -> Self {
|
pub fn new(source_box: Arc<SourceBox>, stream: OutputStream) -> Self {
|
||||||
let obj: Self = Object::builder().build();
|
let obj: Self = Object::builder().build();
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
use adw::subclass::prelude::PreferencesGroupImpl;
|
use adw::subclass::prelude::PreferencesGroupImpl;
|
||||||
use adw::{ComboRow, PreferencesGroup};
|
use adw::{ComboRow, PreferencesGroup};
|
||||||
use re_set_lib::audio::audio_structures::OutputStream;
|
use re_set_lib::audio::audio_structures::{OutputStream, Source};
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
|
|
||||||
|
use crate::components::audio::generic_entry::TAudioStreamImpl;
|
||||||
use crate::components::audio::input::output_stream_entry;
|
use crate::components::audio::input::output_stream_entry;
|
||||||
use gtk::subclass::prelude::*;
|
use gtk::subclass::prelude::*;
|
||||||
use gtk::{Button, CompositeTemplate, Label, Scale};
|
use gtk::{Button, CompositeTemplate, Label, Scale};
|
||||||
|
@ -46,3 +47,33 @@ impl PreferencesGroupImpl for OutputStreamEntry {}
|
||||||
impl ObjectImpl for OutputStreamEntry {}
|
impl ObjectImpl for OutputStreamEntry {}
|
||||||
|
|
||||||
impl WidgetImpl for OutputStreamEntry {}
|
impl WidgetImpl for OutputStreamEntry {}
|
||||||
|
|
||||||
|
impl TAudioStreamImpl<Source, OutputStream> for OutputStreamEntry {
|
||||||
|
fn audio_object_selection(&self) -> &TemplateChild<ComboRow> {
|
||||||
|
&self.reset_source_selection
|
||||||
|
}
|
||||||
|
|
||||||
|
fn audio_object_mute(&self) -> &TemplateChild<Button> {
|
||||||
|
&self.reset_source_mute
|
||||||
|
}
|
||||||
|
|
||||||
|
fn volume_slider(&self) -> &TemplateChild<Scale> {
|
||||||
|
&self.reset_volume_slider
|
||||||
|
}
|
||||||
|
|
||||||
|
fn volume_percentage(&self) -> &TemplateChild<Label> {
|
||||||
|
&self.reset_volume_percentage
|
||||||
|
}
|
||||||
|
|
||||||
|
fn stream_object(&self) -> Arc<RefCell<OutputStream>> {
|
||||||
|
self.stream.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn associated_audio_object(&self) -> Arc<RefCell<(u32, String)>> {
|
||||||
|
self.associated_source.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn volume_time_stamp(&self) -> &RefCell<Option<SystemTime>> {
|
||||||
|
&self.volume_time_stamp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ use glib::Variant;
|
||||||
use gtk::gio;
|
use gtk::gio;
|
||||||
use gtk::prelude::ActionableExt;
|
use gtk::prelude::ActionableExt;
|
||||||
|
|
||||||
use crate::components::audio::generic_entry::AudioBox;
|
use crate::components::audio::generic_entry::TAudioBox;
|
||||||
use crate::components::audio::input::source_box_impl;
|
use crate::components::audio::input::source_box_impl;
|
||||||
use crate::components::base::error::{self};
|
use crate::components::base::error::{self};
|
||||||
use crate::components::base::error_impl::ReSetErrorImpl;
|
use crate::components::base::error_impl::ReSetErrorImpl;
|
||||||
|
@ -46,7 +46,7 @@ impl ReSetErrorImpl for SourceBox {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AudioBox<super::source_box_impl::SourceBox> for SourceBox {
|
impl TAudioBox<super::source_box_impl::SourceBox> for SourceBox {
|
||||||
fn box_imp(&self) -> &super::source_box_impl::SourceBox {
|
fn box_imp(&self) -> &super::source_box_impl::SourceBox {
|
||||||
self.imp()
|
self.imp()
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,19 +11,22 @@ use gtk::{
|
||||||
prelude::{BoxExt, ButtonExt, CheckButtonExt, ListBoxRowExt, RangeExt},
|
prelude::{BoxExt, ButtonExt, CheckButtonExt, ListBoxRowExt, RangeExt},
|
||||||
StringObject,
|
StringObject,
|
||||||
};
|
};
|
||||||
use re_set_lib::signals::{
|
use re_set_lib::{
|
||||||
OutputStreamAdded, OutputStreamChanged, OutputStreamRemoved, SourceAdded, SourceChanged,
|
audio::audio_structures::Source,
|
||||||
SourceRemoved,
|
signals::{
|
||||||
|
OutputStreamAdded, OutputStreamChanged, OutputStreamRemoved, SourceAdded, SourceChanged,
|
||||||
|
SourceRemoved,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::components::{audio::generic_audio_functions::set_volume, base::list_entry::ListEntry};
|
use crate::components::{audio::generic_utils::audio_dbus_call, base::list_entry::ListEntry};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
output_stream_entry::OutputStreamEntry,
|
output_stream_entry::OutputStreamEntry,
|
||||||
source_box::SourceBox,
|
source_box::SourceBox,
|
||||||
source_box_utils::{get_default_source_name, refresh_default_source},
|
source_box_utils::{get_default_source_name, refresh_default_source},
|
||||||
source_const::SETVOLUME,
|
source_const::{SETDEFAULT, SETMUTE, SETVOLUME},
|
||||||
source_entry::{set_default_source, toggle_source_mute, SourceEntry},
|
source_entry::SourceEntry,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn source_added_handler(source_box: Arc<SourceBox>, ir: SourceAdded) -> bool {
|
pub fn source_added_handler(source_box: Arc<SourceBox>, ir: SourceAdded) -> bool {
|
||||||
|
@ -266,11 +269,15 @@ pub fn dropdown_handler(source_box: Arc<SourceBox>, dropdown: &adw::ComboRow) ->
|
||||||
}
|
}
|
||||||
let source = Arc::new(source.unwrap().1.clone());
|
let source = Arc::new(source.unwrap().1.clone());
|
||||||
gio::spawn_blocking(move || {
|
gio::spawn_blocking(move || {
|
||||||
let result = set_default_source(source, source_box_ref.clone());
|
let result = audio_dbus_call::<SourceBox, (Source,), (&String,)>(
|
||||||
|
source_box_ref.clone(),
|
||||||
|
(&source,),
|
||||||
|
&SETDEFAULT,
|
||||||
|
);
|
||||||
if result.is_none() {
|
if result.is_none() {
|
||||||
return ControlFlow::Break;
|
return ControlFlow::Break;
|
||||||
}
|
}
|
||||||
refresh_default_source(result.unwrap(), source_box_ref.clone(), false);
|
refresh_default_source(result.unwrap().0, source_box_ref.clone(), false);
|
||||||
ControlFlow::Continue
|
ControlFlow::Continue
|
||||||
});
|
});
|
||||||
ControlFlow::Continue
|
ControlFlow::Continue
|
||||||
|
@ -291,7 +298,11 @@ pub fn volume_slider_handler(source_box: Arc<SourceBox>, value: f64) -> Propagat
|
||||||
}
|
}
|
||||||
*time = Some(SystemTime::now());
|
*time = Some(SystemTime::now());
|
||||||
}
|
}
|
||||||
set_volume::<SourceBox>(value, index, channels, source_box.clone(), &SETVOLUME);
|
audio_dbus_call::<SourceBox, (), (u32, u16, u32)>(
|
||||||
|
source_box.clone(),
|
||||||
|
(index, channels, value as u32),
|
||||||
|
&SETVOLUME,
|
||||||
|
);
|
||||||
Propagation::Proceed
|
Propagation::Proceed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -306,5 +317,9 @@ pub fn mute_clicked_handler(source_box_ref_mute: Arc<SourceBox>) {
|
||||||
imp.reset_source_mute
|
imp.reset_source_mute
|
||||||
.set_icon_name("audio-input-microphone-symbolic");
|
.set_icon_name("audio-input-microphone-symbolic");
|
||||||
}
|
}
|
||||||
toggle_source_mute(source.index, source.muted, source_box_ref_mute.clone());
|
audio_dbus_call::<SourceBox, (), (u32, bool)>(
|
||||||
|
source_box_ref_mute.clone(),
|
||||||
|
(source.index, source.muted),
|
||||||
|
&SETMUTE,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ use std::collections::HashMap;
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
|
|
||||||
use crate::components::audio::generic_entry::{AudioBoxImpl, AudioIcons};
|
use crate::components::audio::generic_entry::{AudioIcons, TAudioBoxImpl};
|
||||||
use crate::components::audio::input::source_box;
|
use crate::components::audio::input::source_box;
|
||||||
use crate::components::base::error::ReSetError;
|
use crate::components::base::error::ReSetError;
|
||||||
use crate::components::base::list_entry::ListEntry;
|
use crate::components::base::list_entry::ListEntry;
|
||||||
|
@ -95,7 +95,7 @@ impl WindowImpl for SourceBox {}
|
||||||
|
|
||||||
impl ApplicationWindowImpl for SourceBox {}
|
impl ApplicationWindowImpl for SourceBox {}
|
||||||
|
|
||||||
impl AudioBoxImpl<Source, SourceEntry, super::source_entry_impl::SourceEntry> for SourceBox {
|
impl TAudioBoxImpl<Source, SourceEntry, OutputStreamEntry> for SourceBox {
|
||||||
fn audio_object_row(&self) -> &TemplateChild<ActionRow> {
|
fn audio_object_row(&self) -> &TemplateChild<ActionRow> {
|
||||||
&self.reset_source_row
|
&self.reset_source_row
|
||||||
}
|
}
|
||||||
|
@ -158,11 +158,11 @@ impl AudioBoxImpl<Source, SourceEntry, super::source_entry_impl::SourceEntry> fo
|
||||||
&self.reset_source_list
|
&self.reset_source_list
|
||||||
}
|
}
|
||||||
|
|
||||||
// fn audio_object_stream_list(
|
fn audio_object_stream_list(
|
||||||
// &self,
|
&self,
|
||||||
// ) -> &crate::components::audio::generic_entry::AudioStreamEntryMap<SourceEntry> {
|
) -> &crate::components::audio::generic_entry::AudioStreamEntryMap<OutputStreamEntry> {
|
||||||
// &
|
&self.reset_output_stream_list
|
||||||
// }
|
}
|
||||||
|
|
||||||
fn model_list(&self) -> Arc<RwLock<StringList>> {
|
fn model_list(&self) -> Arc<RwLock<StringList>> {
|
||||||
self.reset_model_list.clone()
|
self.reset_model_list.clone()
|
||||||
|
|
|
@ -19,3 +19,23 @@ pub const SETDEFAULT: DBusFunction = DBusFunction {
|
||||||
function: "SetDefaultSource",
|
function: "SetDefaultSource",
|
||||||
error: "Failed to set default source",
|
error: "Failed to set default source",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const GETDEFAULT: DBusFunction = DBusFunction {
|
||||||
|
function: "GetDefaultSource",
|
||||||
|
error: "Failed to get default source",
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const GETDEFAULTNAME: DBusFunction = DBusFunction {
|
||||||
|
function: "GetDefaultSourceName",
|
||||||
|
error: "Failed to get default source name",
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const GETOBJECTS: DBusFunction = DBusFunction {
|
||||||
|
function: "ListSources",
|
||||||
|
error: "Failed to list sources",
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const GETSTREAMS: DBusFunction = DBusFunction {
|
||||||
|
function: "ListOutputStreams",
|
||||||
|
error: "Failed to list output streams",
|
||||||
|
};
|
||||||
|
|
|
@ -1,16 +1,11 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
|
||||||
|
|
||||||
use crate::components::audio::generic_entry::{new_entry, Audio};
|
use crate::components::audio::generic_entry::{new_entry, TAudioEntry};
|
||||||
use crate::components::base::error_impl::show_error;
|
|
||||||
use dbus::blocking::Connection;
|
|
||||||
use dbus::Error;
|
|
||||||
use glib::subclass::types::ObjectSubclassIsExt;
|
use glib::subclass::types::ObjectSubclassIsExt;
|
||||||
use gtk::{gio, CheckButton};
|
use gtk::CheckButton;
|
||||||
use re_set_lib::audio::audio_structures::Source;
|
use re_set_lib::audio::audio_structures::{OutputStream, Source};
|
||||||
|
|
||||||
use crate::components::utils::{AUDIO, BASE, DBUS_PATH};
|
|
||||||
|
|
||||||
|
use super::output_stream_entry::OutputStreamEntry;
|
||||||
use super::source_box::SourceBox;
|
use super::source_box::SourceBox;
|
||||||
use super::source_entry_impl;
|
use super::source_entry_impl;
|
||||||
|
|
||||||
|
@ -23,7 +18,7 @@ glib::wrapper! {
|
||||||
unsafe impl Send for SourceEntry {}
|
unsafe impl Send for SourceEntry {}
|
||||||
unsafe impl Sync for SourceEntry {}
|
unsafe impl Sync for SourceEntry {}
|
||||||
|
|
||||||
impl Audio<Source, super::source_entry_impl::SourceEntry> for SourceEntry {
|
impl TAudioEntry<super::source_entry_impl::SourceEntry> for SourceEntry {
|
||||||
fn entry_imp(&self) -> &super::source_entry_impl::SourceEntry {
|
fn entry_imp(&self) -> &super::source_entry_impl::SourceEntry {
|
||||||
self.imp()
|
self.imp()
|
||||||
}
|
}
|
||||||
|
@ -38,34 +33,13 @@ impl SourceEntry {
|
||||||
) -> Arc<Self> {
|
) -> Arc<Self> {
|
||||||
new_entry::<
|
new_entry::<
|
||||||
Source,
|
Source,
|
||||||
SourceBox,
|
OutputStream,
|
||||||
SourceEntry,
|
SourceEntry,
|
||||||
super::source_entry_impl::SourceEntry,
|
super::source_entry_impl::SourceEntry,
|
||||||
|
OutputStreamEntry,
|
||||||
|
super::output_stream_entry_impl::OutputStreamEntry,
|
||||||
|
SourceBox,
|
||||||
super::source_box_impl::SourceBox,
|
super::source_box_impl::SourceBox,
|
||||||
>(is_default, check_group, source, input_box)
|
>(is_default, check_group, source, input_box)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn toggle_source_mute(index: u32, muted: bool, input_box: Arc<SourceBox>) -> bool {
|
|
||||||
gio::spawn_blocking(move || {
|
|
||||||
let conn = Connection::new_session().unwrap();
|
|
||||||
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
|
||||||
let res: Result<(), Error> = proxy.method_call(AUDIO, "SetSourceMute", (index, muted));
|
|
||||||
if res.is_err() {
|
|
||||||
show_error::<SourceBox>(input_box.clone(), "Failed to mute source");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_default_source(name: Arc<String>, input_box: Arc<SourceBox>) -> Option<Source> {
|
|
||||||
let conn = Connection::new_session().unwrap();
|
|
||||||
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
|
||||||
let res: Result<(Source,), Error> =
|
|
||||||
proxy.method_call(AUDIO, "SetDefaultSource", (name.as_str(),));
|
|
||||||
if res.is_err() {
|
|
||||||
show_error::<SourceBox>(input_box.clone(), "Failed to set default source");
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
Some(res.unwrap().0)
|
|
||||||
}
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ use std::time::SystemTime;
|
||||||
use gtk::subclass::prelude::*;
|
use gtk::subclass::prelude::*;
|
||||||
use gtk::{Button, CheckButton, CompositeTemplate, Label, Scale};
|
use gtk::{Button, CheckButton, CompositeTemplate, Label, Scale};
|
||||||
|
|
||||||
use crate::components::audio::generic_entry::{AudioIcons, AudioImpl, DBusFunction};
|
use crate::components::audio::generic_entry::{AudioIcons, TAudioEntryImpl, DBusFunction};
|
||||||
|
|
||||||
use super::source_const::{ICONS, SETDEFAULT, SETMUTE, SETVOLUME};
|
use super::source_const::{ICONS, SETDEFAULT, SETMUTE, SETVOLUME};
|
||||||
use super::source_entry;
|
use super::source_entry;
|
||||||
|
@ -52,7 +52,7 @@ impl ObjectImpl for SourceEntry {}
|
||||||
|
|
||||||
impl WidgetImpl for SourceEntry {}
|
impl WidgetImpl for SourceEntry {}
|
||||||
|
|
||||||
impl AudioImpl<Source> for SourceEntry {
|
impl TAudioEntryImpl<Source> for SourceEntry {
|
||||||
fn name(&self) -> &TemplateChild<ActionRow> {
|
fn name(&self) -> &TemplateChild<ActionRow> {
|
||||||
&self.reset_source_name
|
&self.reset_source_name
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,3 +2,5 @@ pub mod generic_audio_functions;
|
||||||
pub mod generic_entry;
|
pub mod generic_entry;
|
||||||
pub mod input;
|
pub mod input;
|
||||||
pub mod output;
|
pub mod output;
|
||||||
|
mod generic_const;
|
||||||
|
mod generic_utils;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::{Duration, SystemTime};
|
use std::time::{Duration, SystemTime};
|
||||||
|
|
||||||
|
use crate::components::audio::generic_entry::TAudioStream;
|
||||||
use crate::components::base::error_impl::show_error;
|
use crate::components::base::error_impl::show_error;
|
||||||
use crate::components::utils::{
|
use crate::components::utils::{
|
||||||
create_dropdown_label_factory, set_combo_row_ellipsis, AUDIO, BASE, DBUS_PATH,
|
create_dropdown_label_factory, set_combo_row_ellipsis, AUDIO, BASE, DBUS_PATH,
|
||||||
|
@ -27,6 +28,12 @@ glib::wrapper! {
|
||||||
unsafe impl Send for InputStreamEntry {}
|
unsafe impl Send for InputStreamEntry {}
|
||||||
unsafe impl Sync for InputStreamEntry {}
|
unsafe impl Sync for InputStreamEntry {}
|
||||||
|
|
||||||
|
impl TAudioStream<super::input_stream_entry_impl::InputStreamEntry> for InputStreamEntry {
|
||||||
|
fn entry_imp(&self) -> &super::input_stream_entry_impl::InputStreamEntry {
|
||||||
|
self.imp()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl InputStreamEntry {
|
impl InputStreamEntry {
|
||||||
pub fn new(sink_box: Arc<SinkBox>, stream: InputStream) -> Self {
|
pub fn new(sink_box: Arc<SinkBox>, stream: InputStream) -> Self {
|
||||||
let obj: Self = Object::builder().build();
|
let obj: Self = Object::builder().build();
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use adw::subclass::prelude::PreferencesGroupImpl;
|
use adw::subclass::prelude::PreferencesGroupImpl;
|
||||||
use adw::{ComboRow, PreferencesGroup};
|
use adw::{ComboRow, PreferencesGroup};
|
||||||
use re_set_lib::audio::audio_structures::InputStream;
|
use re_set_lib::audio::audio_structures::{InputStream, Sink};
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
|
@ -8,6 +8,8 @@ use std::time::SystemTime;
|
||||||
use gtk::subclass::prelude::*;
|
use gtk::subclass::prelude::*;
|
||||||
use gtk::{Button, CompositeTemplate, Label, Scale};
|
use gtk::{Button, CompositeTemplate, Label, Scale};
|
||||||
|
|
||||||
|
use crate::components::audio::generic_entry::TAudioStreamImpl;
|
||||||
|
|
||||||
use super::input_stream_entry;
|
use super::input_stream_entry;
|
||||||
|
|
||||||
#[derive(Default, CompositeTemplate)]
|
#[derive(Default, CompositeTemplate)]
|
||||||
|
@ -47,3 +49,33 @@ impl PreferencesGroupImpl for InputStreamEntry {}
|
||||||
impl ObjectImpl for InputStreamEntry {}
|
impl ObjectImpl for InputStreamEntry {}
|
||||||
|
|
||||||
impl WidgetImpl for InputStreamEntry {}
|
impl WidgetImpl for InputStreamEntry {}
|
||||||
|
|
||||||
|
impl TAudioStreamImpl<Sink, InputStream> for InputStreamEntry {
|
||||||
|
fn audio_object_selection(&self) -> &TemplateChild<ComboRow> {
|
||||||
|
&self.reset_sink_selection
|
||||||
|
}
|
||||||
|
|
||||||
|
fn audio_object_mute(&self) -> &TemplateChild<Button> {
|
||||||
|
&self.reset_sink_mute
|
||||||
|
}
|
||||||
|
|
||||||
|
fn volume_slider(&self) -> &TemplateChild<Scale> {
|
||||||
|
&self.reset_volume_slider
|
||||||
|
}
|
||||||
|
|
||||||
|
fn volume_percentage(&self) -> &TemplateChild<Label> {
|
||||||
|
&self.reset_volume_percentage
|
||||||
|
}
|
||||||
|
|
||||||
|
fn stream_object(&self) -> Arc<RefCell<InputStream>> {
|
||||||
|
self.stream.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn associated_audio_object(&self) -> Arc<RefCell<(u32, String)>> {
|
||||||
|
self.associated_sink.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn volume_time_stamp(&self) -> &RefCell<Option<SystemTime>> {
|
||||||
|
&self.volume_time_stamp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ use glib::Variant;
|
||||||
use gtk::gio;
|
use gtk::gio;
|
||||||
use gtk::prelude::ActionableExt;
|
use gtk::prelude::ActionableExt;
|
||||||
|
|
||||||
use crate::components::audio::generic_entry::AudioBox;
|
use crate::components::audio::generic_entry::TAudioBox;
|
||||||
use crate::components::base::error_impl::ReSetErrorImpl;
|
use crate::components::base::error_impl::ReSetErrorImpl;
|
||||||
use crate::components::utils::BASE;
|
use crate::components::utils::BASE;
|
||||||
use crate::components::utils::DBUS_PATH;
|
use crate::components::utils::DBUS_PATH;
|
||||||
|
@ -53,7 +53,7 @@ impl ReSetErrorImpl for SinkBox {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AudioBox<super::sink_box_impl::SinkBox> for SinkBox {
|
impl TAudioBox<super::sink_box_impl::SinkBox> for SinkBox {
|
||||||
fn box_imp(&self) -> &super::sink_box_impl::SinkBox {
|
fn box_imp(&self) -> &super::sink_box_impl::SinkBox {
|
||||||
self.imp()
|
self.imp()
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,17 +14,22 @@ use gtk::{
|
||||||
prelude::{BoxExt, ButtonExt, CheckButtonExt, ListBoxRowExt, RangeExt},
|
prelude::{BoxExt, ButtonExt, CheckButtonExt, ListBoxRowExt, RangeExt},
|
||||||
StringObject,
|
StringObject,
|
||||||
};
|
};
|
||||||
use re_set_lib::signals::{
|
use re_set_lib::{
|
||||||
InputStreamAdded, InputStreamChanged, InputStreamRemoved, SinkAdded, SinkChanged, SinkRemoved,
|
audio::audio_structures::Sink,
|
||||||
|
signals::{
|
||||||
|
InputStreamAdded, InputStreamChanged, InputStreamRemoved, SinkAdded, SinkChanged,
|
||||||
|
SinkRemoved,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::components::base::list_entry::ListEntry;
|
use crate::components::{audio::generic_utils::audio_dbus_call, base::list_entry::ListEntry};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
input_stream_entry::InputStreamEntry,
|
input_stream_entry::InputStreamEntry,
|
||||||
sink_box::SinkBox,
|
sink_box::SinkBox,
|
||||||
sink_box_utils::{get_default_sink_name, refresh_default_sink},
|
sink_box_utils::{get_default_sink_name, refresh_default_sink},
|
||||||
sink_entry::{set_default_sink, set_sink_volume, toggle_sink_mute, SinkEntry},
|
sink_const::{SETDEFAULT, SETMUTE, SETVOLUME},
|
||||||
|
sink_entry::SinkEntry,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn drop_down_handler(sink_box: Arc<SinkBox>, dropdown: &ComboRow) {
|
pub fn drop_down_handler(sink_box: Arc<SinkBox>, dropdown: &ComboRow) {
|
||||||
|
@ -45,11 +50,15 @@ pub fn drop_down_handler(sink_box: Arc<SinkBox>, dropdown: &ComboRow) {
|
||||||
}
|
}
|
||||||
let new_sink_name = Arc::new(sink.unwrap().1.clone());
|
let new_sink_name = Arc::new(sink.unwrap().1.clone());
|
||||||
gio::spawn_blocking(move || {
|
gio::spawn_blocking(move || {
|
||||||
let result = set_default_sink(new_sink_name, sink_box_ref.clone());
|
let result = audio_dbus_call::<SinkBox, (Sink,), (&String,)>(
|
||||||
|
sink_box_ref.clone(),
|
||||||
|
(&new_sink_name,),
|
||||||
|
&SETDEFAULT,
|
||||||
|
);
|
||||||
if result.is_none() {
|
if result.is_none() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let new_sink = result.unwrap();
|
let new_sink = result.unwrap().0;
|
||||||
refresh_default_sink(new_sink, sink_box_ref, false);
|
refresh_default_sink(new_sink, sink_box_ref, false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -69,7 +78,11 @@ pub fn volume_slider_handler(sink_box: Arc<SinkBox>, value: f64) -> glib::Propag
|
||||||
}
|
}
|
||||||
*time = Some(SystemTime::now());
|
*time = Some(SystemTime::now());
|
||||||
}
|
}
|
||||||
set_sink_volume(value, index, channels, sink_box.clone());
|
audio_dbus_call::<SinkBox, (), (u32, u16, u32)>(
|
||||||
|
sink_box.clone(),
|
||||||
|
(index, channels, value as u32),
|
||||||
|
&SETVOLUME,
|
||||||
|
);
|
||||||
Propagation::Proceed
|
Propagation::Proceed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,7 +97,11 @@ pub fn mute_handler(sink_box: Arc<SinkBox>) {
|
||||||
imp.reset_sink_mute
|
imp.reset_sink_mute
|
||||||
.set_icon_name("audio-volume-high-symbolic");
|
.set_icon_name("audio-volume-high-symbolic");
|
||||||
}
|
}
|
||||||
toggle_sink_mute(stream.index, stream.muted, sink_box.clone());
|
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 {
|
pub fn sink_added_handler(sink_box: Arc<SinkBox>, ir: SinkAdded) -> bool {
|
||||||
|
|
|
@ -5,7 +5,7 @@ use std::collections::HashMap;
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
|
|
||||||
use crate::components::audio::generic_entry::{AudioBoxImpl, AudioIcons};
|
use crate::components::audio::generic_entry::{AudioIcons, TAudioBoxImpl};
|
||||||
use crate::components::audio::output::input_stream_entry::InputStreamEntry;
|
use crate::components::audio::output::input_stream_entry::InputStreamEntry;
|
||||||
use crate::components::base::error::ReSetError;
|
use crate::components::base::error::ReSetError;
|
||||||
use crate::components::base::list_entry::ListEntry;
|
use crate::components::base::list_entry::ListEntry;
|
||||||
|
@ -96,7 +96,7 @@ impl WindowImpl for SinkBox {}
|
||||||
|
|
||||||
impl ApplicationWindowImpl for SinkBox {}
|
impl ApplicationWindowImpl for SinkBox {}
|
||||||
|
|
||||||
impl AudioBoxImpl<Sink, SinkEntry, super::sink_entry_impl::SinkEntry> for SinkBox {
|
impl TAudioBoxImpl<Sink, SinkEntry, InputStreamEntry> for SinkBox {
|
||||||
fn audio_object_row(&self) -> &TemplateChild<ActionRow> {
|
fn audio_object_row(&self) -> &TemplateChild<ActionRow> {
|
||||||
&self.reset_sinks_row
|
&self.reset_sinks_row
|
||||||
}
|
}
|
||||||
|
@ -159,11 +159,11 @@ impl AudioBoxImpl<Sink, SinkEntry, super::sink_entry_impl::SinkEntry> for SinkBo
|
||||||
&self.reset_sink_list
|
&self.reset_sink_list
|
||||||
}
|
}
|
||||||
|
|
||||||
// fn audio_object_stream_list(
|
fn audio_object_stream_list(
|
||||||
// &self,
|
&self,
|
||||||
// ) -> &crate::components::audio::generic_entry::AudioStreamEntryMap<SourceEntry> {
|
) -> &crate::components::audio::generic_entry::AudioStreamEntryMap<InputStreamEntry> {
|
||||||
// &
|
&self.reset_input_stream_list
|
||||||
// }
|
}
|
||||||
|
|
||||||
fn model_list(&self) -> Arc<RwLock<StringList>> {
|
fn model_list(&self) -> Arc<RwLock<StringList>> {
|
||||||
self.reset_model_list.clone()
|
self.reset_model_list.clone()
|
||||||
|
|
|
@ -19,3 +19,23 @@ pub const SETDEFAULT: DBusFunction = DBusFunction {
|
||||||
function: "SetDefaultSink",
|
function: "SetDefaultSink",
|
||||||
error: "Failed to set default sink",
|
error: "Failed to set default sink",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const GETDEFAULT: DBusFunction = DBusFunction {
|
||||||
|
function: "GetDefaultSink",
|
||||||
|
error: "Failed to get default sink",
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const GETDEFAULTNAME: DBusFunction = DBusFunction {
|
||||||
|
function: "GetDefaultSinkName",
|
||||||
|
error: "Failed to get default sink name",
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const GETOBJECTS: DBusFunction = DBusFunction {
|
||||||
|
function: "ListSinks",
|
||||||
|
error: "Failed to list sinks",
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const GETSTREAMS: DBusFunction = DBusFunction {
|
||||||
|
function: "ListInputStreams",
|
||||||
|
error: "Failed to list input streams",
|
||||||
|
};
|
||||||
|
|
|
@ -1,16 +1,11 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
|
||||||
|
|
||||||
use crate::components::audio::generic_entry::{new_entry, Audio};
|
use crate::components::audio::generic_entry::{new_entry, TAudioEntry};
|
||||||
use crate::components::base::error_impl::show_error;
|
|
||||||
use dbus::blocking::Connection;
|
|
||||||
use dbus::Error;
|
|
||||||
use glib::subclass::types::ObjectSubclassIsExt;
|
use glib::subclass::types::ObjectSubclassIsExt;
|
||||||
use gtk::{gio, CheckButton};
|
use gtk::CheckButton;
|
||||||
use re_set_lib::audio::audio_structures::Sink;
|
use re_set_lib::audio::audio_structures::{InputStream, Sink};
|
||||||
|
|
||||||
use crate::components::utils::{AUDIO, BASE, DBUS_PATH};
|
|
||||||
|
|
||||||
|
use super::input_stream_entry::InputStreamEntry;
|
||||||
use super::sink_box::SinkBox;
|
use super::sink_box::SinkBox;
|
||||||
use super::sink_entry_impl;
|
use super::sink_entry_impl;
|
||||||
|
|
||||||
|
@ -23,7 +18,7 @@ glib::wrapper! {
|
||||||
unsafe impl Send for SinkEntry {}
|
unsafe impl Send for SinkEntry {}
|
||||||
unsafe impl Sync for SinkEntry {}
|
unsafe impl Sync for SinkEntry {}
|
||||||
|
|
||||||
impl Audio<Sink, super::sink_entry_impl::SinkEntry> for SinkEntry {
|
impl TAudioEntry<super::sink_entry_impl::SinkEntry> for SinkEntry {
|
||||||
fn entry_imp(&self) -> &super::sink_entry_impl::SinkEntry {
|
fn entry_imp(&self) -> &super::sink_entry_impl::SinkEntry {
|
||||||
self.imp()
|
self.imp()
|
||||||
}
|
}
|
||||||
|
@ -38,46 +33,13 @@ impl SinkEntry {
|
||||||
) -> Arc<Self> {
|
) -> Arc<Self> {
|
||||||
new_entry::<
|
new_entry::<
|
||||||
Sink,
|
Sink,
|
||||||
SinkBox,
|
InputStream,
|
||||||
SinkEntry,
|
SinkEntry,
|
||||||
super::sink_entry_impl::SinkEntry,
|
super::sink_entry_impl::SinkEntry,
|
||||||
|
InputStreamEntry,
|
||||||
|
super::input_stream_entry_impl::InputStreamEntry,
|
||||||
|
SinkBox,
|
||||||
super::sink_box_impl::SinkBox,
|
super::sink_box_impl::SinkBox,
|
||||||
>(is_default, check_group, sink, output_box)
|
>(is_default, check_group, sink, output_box)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_sink_volume(value: f64, index: u32, channels: u16, output_box: Arc<SinkBox>) -> bool {
|
|
||||||
gio::spawn_blocking(move || {
|
|
||||||
let conn = Connection::new_session().unwrap();
|
|
||||||
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
|
||||||
let res: Result<(), Error> =
|
|
||||||
proxy.method_call(AUDIO, "SetSinkVolume", (index, channels, value as u32));
|
|
||||||
if res.is_err() {
|
|
||||||
show_error::<SinkBox>(output_box, "Failed to set sink volume")
|
|
||||||
}
|
|
||||||
});
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn toggle_sink_mute(index: u32, muted: bool, output_box: Arc<SinkBox>) -> bool {
|
|
||||||
gio::spawn_blocking(move || {
|
|
||||||
let conn = Connection::new_session().unwrap();
|
|
||||||
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
|
||||||
let res: Result<(), Error> = proxy.method_call(AUDIO, "SetSinkMute", (index, muted));
|
|
||||||
if res.is_err() {
|
|
||||||
show_error::<SinkBox>(output_box, "Failed to mute sink")
|
|
||||||
}
|
|
||||||
});
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_default_sink(name: Arc<String>, output_box: Arc<SinkBox>) -> Option<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, "SetDefaultSink", (name.as_str(),));
|
|
||||||
if res.is_err() {
|
|
||||||
show_error::<SinkBox>(output_box, "Failed to set default sink");
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
Some(res.unwrap().0)
|
|
||||||
}
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ use std::cell::RefCell;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
|
|
||||||
use crate::components::audio::generic_entry::{AudioIcons, AudioImpl, DBusFunction};
|
use crate::components::audio::generic_entry::{AudioIcons, TAudioEntryImpl, DBusFunction};
|
||||||
use crate::components::audio::output::sink_entry;
|
use crate::components::audio::output::sink_entry;
|
||||||
use gtk::subclass::prelude::*;
|
use gtk::subclass::prelude::*;
|
||||||
use gtk::{Button, CheckButton, CompositeTemplate, Label, Scale};
|
use gtk::{Button, CheckButton, CompositeTemplate, Label, Scale};
|
||||||
|
@ -51,7 +51,7 @@ impl ObjectImpl for SinkEntry {}
|
||||||
|
|
||||||
impl WidgetImpl for SinkEntry {}
|
impl WidgetImpl for SinkEntry {}
|
||||||
|
|
||||||
impl AudioImpl<Sink> for SinkEntry {
|
impl TAudioEntryImpl<Sink> for SinkEntry {
|
||||||
fn name(&self) -> &TemplateChild<ActionRow> {
|
fn name(&self) -> &TemplateChild<ActionRow> {
|
||||||
&self.reset_sink_name
|
&self.reset_sink_name
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue