mirror of
https://github.com/Xetibo/ReSet.git
synced 2025-07-01 15:57:46 +02:00
fix: Use buffer for sending volume updates
This commit is contained in:
parent
67f3457e3a
commit
52445b9ba0
8 changed files with 61 additions and 16 deletions
|
@ -1,5 +1,6 @@
|
|||
use std::cell::RefCell;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use std::time::{Duration, SystemTime};
|
||||
|
||||
use adw::glib;
|
||||
use adw::glib::Object;
|
||||
|
@ -8,7 +9,8 @@ use dbus::blocking::Connection;
|
|||
use dbus::Error;
|
||||
use glib::subclass::types::ObjectSubclassIsExt;
|
||||
use glib::{clone, Cast, Propagation};
|
||||
use gtk::{gio, StringObject};
|
||||
use gtk::prelude::ScaleExt;
|
||||
use gtk::{gio, PositionType, StringObject};
|
||||
use ReSet_Lib::audio::audio::InputStream;
|
||||
|
||||
use super::inputStreamEntryImpl;
|
||||
|
@ -59,6 +61,13 @@ impl InputStreamEntry {
|
|||
let stream = stream.unwrap();
|
||||
let index = stream.index;
|
||||
let channels = stream.channels;
|
||||
{
|
||||
let mut time = imp.volumeTimeStamp.borrow_mut();
|
||||
if time.is_some() && time.unwrap().elapsed().unwrap() < Duration::from_millis(50) {
|
||||
return Propagation::Proceed;
|
||||
}
|
||||
*time = Some(SystemTime::now());
|
||||
}
|
||||
set_inputstream_volume(value, index, channels);
|
||||
Propagation::Proceed
|
||||
}),
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use std::cell::RefCell;
|
||||
use std::sync::Arc;
|
||||
use std::time::SystemTime;
|
||||
|
||||
use gtk::subclass::prelude::*;
|
||||
use gtk::{glib, Button, CompositeTemplate, DropDown, Label, ProgressBar, Scale};
|
||||
|
@ -25,6 +26,7 @@ pub struct InputStreamEntry {
|
|||
pub resetVolumeMeter: TemplateChild<ProgressBar>,
|
||||
pub stream: Arc<RefCell<InputStream>>,
|
||||
pub associatedSink: Arc<RefCell<(u32, String)>>,
|
||||
pub volumeTimeStamp: RefCell<Option<SystemTime>>,
|
||||
}
|
||||
|
||||
#[glib::object_subclass]
|
||||
|
|
|
@ -35,7 +35,13 @@ unsafe impl Sync for SinkBox {}
|
|||
|
||||
impl SinkBox {
|
||||
pub fn new() -> Self {
|
||||
Object::builder().build()
|
||||
let obj: Self = Object::builder().build();
|
||||
{
|
||||
let imp = obj.imp();
|
||||
let mut model_index = imp.resetModelIndex.write().unwrap();
|
||||
*model_index = 0;
|
||||
}
|
||||
obj
|
||||
}
|
||||
|
||||
pub fn setupCallbacks(&self) {
|
||||
|
@ -53,6 +59,12 @@ impl SinkBox {
|
|||
}
|
||||
}
|
||||
|
||||
impl Default for SinkBox {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn populate_sinks(output_box: Arc<SinkBox>) {
|
||||
gio::spawn_blocking(move || {
|
||||
let output_box_ref = output_box.clone();
|
||||
|
@ -81,7 +93,7 @@ pub fn populate_sinks(output_box: Arc<SinkBox>) {
|
|||
let default_sink = output_box_imp.resetDefaultSink.clone();
|
||||
let sink = default_sink.borrow();
|
||||
|
||||
let volume = sink.volume.first().unwrap_or_else(|| &(0 as u32));
|
||||
let volume = sink.volume.first().unwrap_or(&0);
|
||||
let fraction = (*volume as f64 / 655.36).round();
|
||||
let percentage = (fraction).to_string() + "%";
|
||||
output_box_imp.resetVolumePercentage.set_text(&percentage);
|
||||
|
@ -239,7 +251,11 @@ fn get_default_sink() -> Sink {
|
|||
res.unwrap().0
|
||||
}
|
||||
|
||||
pub fn start_output_box_listener(conn: Connection, listeners: Arc<Listeners>, sink_box: Arc<SinkBox>) -> Connection {
|
||||
pub fn start_output_box_listener(
|
||||
conn: Connection,
|
||||
listeners: Arc<Listeners>,
|
||||
sink_box: Arc<SinkBox>,
|
||||
) -> Connection {
|
||||
if listeners.network_listener.load(Ordering::SeqCst) {
|
||||
return conn;
|
||||
}
|
||||
|
@ -339,7 +355,9 @@ pub fn start_output_box_listener(conn: Connection, listeners: Arc<Listeners>, si
|
|||
let mut map = output_box_imp.resetSinkMap.write().unwrap();
|
||||
map.remove(&alias.unwrap().2);
|
||||
let mut index = output_box_imp.resetModelIndex.write().unwrap();
|
||||
*index -= 1;
|
||||
if *index != 0 {
|
||||
*index -= 1;
|
||||
}
|
||||
});
|
||||
});
|
||||
true
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue