fix: Use buffer for all audio sliders

This commit is contained in:
Fabio Lenherr / DashieTM 2023-11-18 15:28:23 +01:00
parent 5a0e5d86bb
commit 03fc3790c0
19 changed files with 145 additions and 59 deletions

View file

@ -1042,14 +1042,14 @@
{ {
"type": "archive", "type": "archive",
"archive-type": "tar-gzip", "archive-type": "tar-gzip",
"url": "https://static.crates.io/crates/reset_daemon/reset_daemon-0.1.7.crate", "url": "https://static.crates.io/crates/reset_daemon/reset_daemon-0.1.8.crate",
"sha256": "f7b48ba0698bdb4ead119140a557346907b40ae17cac324687a032b4d6ea9851", "sha256": "a861e230340e001757325a01fa33cfce9e29111f0228dd2abd1d62206f742803",
"dest": "cargo/vendor/reset_daemon-0.1.7" "dest": "cargo/vendor/reset_daemon-0.1.8"
}, },
{ {
"type": "inline", "type": "inline",
"contents": "{\"package\": \"f7b48ba0698bdb4ead119140a557346907b40ae17cac324687a032b4d6ea9851\", \"files\": {}}", "contents": "{\"package\": \"a861e230340e001757325a01fa33cfce9e29111f0228dd2abd1d62206f742803\", \"files\": {}}",
"dest": "cargo/vendor/reset_daemon-0.1.7", "dest": "cargo/vendor/reset_daemon-0.1.8",
"dest-filename": ".cargo-checksum.json" "dest-filename": ".cargo-checksum.json"
}, },
{ {

View file

@ -1,5 +1,5 @@
use std::sync::Arc; use std::sync::Arc;
use std::time::Duration; use std::time::{Duration, SystemTime};
use adw::glib; use adw::glib;
use adw::glib::Object; use adw::glib::Object;
@ -50,6 +50,15 @@ impl OutputStreamEntry {
let stream = stream.unwrap(); let stream = stream.unwrap();
let index = stream.index; let index = stream.index;
let channels = stream.channels; 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_outputstream_volume(value, index, channels); set_outputstream_volume(value, index, channels);
Propagation::Proceed Propagation::Proceed
}), }),
@ -127,39 +136,39 @@ impl OutputStreamEntry {
fn set_outputstream_volume(value: f64, index: u32, channels: u16) -> bool { fn set_outputstream_volume(value: f64, index: u32, channels: u16) -> bool {
gio::spawn_blocking(move || { gio::spawn_blocking(move || {
let conn = Connection::new_session().unwrap(); let conn = Connection::new_session().unwrap();
let proxy = conn.with_proxy( let proxy = conn.with_proxy(
"org.xetibo.ReSet", "org.xetibo.ReSet",
"/org/xetibo/ReSet", "/org/xetibo/ReSet",
Duration::from_millis(1000), Duration::from_millis(1000),
); );
let _: Result<(), Error> = proxy.method_call( let _: Result<(), Error> = proxy.method_call(
"org.xetibo.ReSet", "org.xetibo.ReSet",
"SetOutputStreamVolume", "SetOutputStreamVolume",
(index, channels, value as u32), (index, channels, value as u32),
); );
// if res.is_err() { // if res.is_err() {
// return false; // return false;
// } // }
// res.unwrap().0 // res.unwrap().0
}); });
true true
} }
fn toggle_output_stream_mute(index: u32, muted: bool) -> bool { fn toggle_output_stream_mute(index: u32, muted: bool) -> bool {
gio::spawn_blocking(move || { gio::spawn_blocking(move || {
let conn = Connection::new_session().unwrap(); let conn = Connection::new_session().unwrap();
let proxy = conn.with_proxy( let proxy = conn.with_proxy(
"org.xetibo.ReSet", "org.xetibo.ReSet",
"/org/xetibo/ReSet", "/org/xetibo/ReSet",
Duration::from_millis(1000), Duration::from_millis(1000),
); );
let _: Result<(), Error> = let _: Result<(), Error> =
proxy.method_call("org.xetibo.ReSet", "SetOutputStreamMute", (index, muted)); proxy.method_call("org.xetibo.ReSet", "SetOutputStreamMute", (index, muted));
// if res.is_err() { // if res.is_err() {
// return false; // return false;
// } // }
// res.unwrap().0 // res.unwrap().0
}); });
true true
} }

View file

@ -1,5 +1,6 @@
use std::cell::RefCell; use std::cell::RefCell;
use std::sync::Arc; use std::sync::Arc;
use std::time::SystemTime;
use crate::components::input::outputStreamEntry; use crate::components::input::outputStreamEntry;
use gtk::subclass::prelude::*; use gtk::subclass::prelude::*;
@ -24,6 +25,7 @@ pub struct OutputStreamEntry {
pub resetVolumeMeter: TemplateChild<ProgressBar>, pub resetVolumeMeter: TemplateChild<ProgressBar>,
pub stream: Arc<RefCell<OutputStream>>, pub stream: Arc<RefCell<OutputStream>>,
pub associatedSource: Arc<RefCell<(u32, String)>>, pub associatedSource: Arc<RefCell<(u32, String)>>,
pub volumeTimeStamp: RefCell<Option<SystemTime>>,
} }
#[glib::object_subclass] #[glib::object_subclass]

View file

@ -1,6 +1,6 @@
use std::sync::atomic::Ordering; use std::sync::atomic::Ordering;
use std::sync::Arc; use std::sync::Arc;
use std::time::Duration; use std::time::{Duration, SystemTime};
use crate::components::base::listEntry::ListEntry; use crate::components::base::listEntry::ListEntry;
use crate::components::base::utils::{ use crate::components::base::utils::{
@ -151,6 +151,15 @@ pub fn populate_sources(input_box: Arc<SourceBox>) {
let source = imp.resetDefaultSource.borrow(); let source = imp.resetDefaultSource.borrow();
let index = source.index; let index = source.index;
let channels = source.channels; let channels = source.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_source_volume(value, index, channels); set_source_volume(value, index, channels);
Propagation::Proceed Propagation::Proceed
}); });

View file

@ -1,6 +1,7 @@
use std::cell::RefCell; use std::cell::RefCell;
use std::collections::HashMap; use std::collections::HashMap;
use std::sync::{Arc, RwLock}; use std::sync::{Arc, RwLock};
use std::time::SystemTime;
use crate::components::base::listEntry::ListEntry; use crate::components::base::listEntry::ListEntry;
use crate::components::input::sourceBox; use crate::components::input::sourceBox;
@ -43,6 +44,7 @@ pub struct SourceBox {
// first u32 is the index of the source, the second the index in the model list and the third is // first u32 is the index of the source, the second the index in the model list and the third is
// the full name // the full name
pub resetSourceMap: Arc<RwLock<HashMap<String, (u32, u32, String)>>>, pub resetSourceMap: Arc<RwLock<HashMap<String, (u32, u32, String)>>>,
pub volumeTimeStamp: RefCell<Option<SystemTime>>,
} }
#[glib::object_subclass] #[glib::object_subclass]

View file

@ -1,5 +1,5 @@
use std::sync::Arc; use std::sync::Arc;
use std::time::Duration; use std::time::{Duration, SystemTime};
use adw::glib; use adw::glib;
use adw::glib::Object; use adw::glib::Object;
@ -44,6 +44,15 @@ impl SourceEntry {
let source = imp.stream.borrow(); let source = imp.stream.borrow();
let index = source.index; let index = source.index;
let channels = source.channels; let channels = source.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_source_volume(value, index, channels); set_source_volume(value, index, channels);
Propagation::Proceed Propagation::Proceed
}), }),
@ -83,21 +92,21 @@ impl SourceEntry {
pub fn set_source_volume(value: f64, index: u32, channels: u16) -> bool { pub fn set_source_volume(value: f64, index: u32, channels: u16) -> bool {
gio::spawn_blocking(move || { gio::spawn_blocking(move || {
let conn = Connection::new_session().unwrap(); let conn = Connection::new_session().unwrap();
let proxy = conn.with_proxy( let proxy = conn.with_proxy(
"org.xetibo.ReSet", "org.xetibo.ReSet",
"/org/xetibo/ReSet", "/org/xetibo/ReSet",
Duration::from_millis(1000), Duration::from_millis(1000),
); );
let _: Result<(), Error> = proxy.method_call( let _: Result<(), Error> = proxy.method_call(
"org.xetibo.ReSet", "org.xetibo.ReSet",
"SetSourceVolume", "SetSourceVolume",
(index, channels, value as u32), (index, channels, value as u32),
); );
// if res.is_err() { // if res.is_err() {
// return false; // return false;
// } // }
// res.unwrap().0 // res.unwrap().0
}); });
true true
} }

View file

@ -1,5 +1,6 @@
use std::cell::RefCell; use std::cell::RefCell;
use std::sync::Arc; use std::sync::Arc;
use std::time::SystemTime;
use gtk::subclass::prelude::*; use gtk::subclass::prelude::*;
use gtk::{glib, Button, CompositeTemplate, Label, ProgressBar, Scale, CheckButton}; use gtk::{glib, Button, CompositeTemplate, Label, ProgressBar, Scale, CheckButton};
@ -24,6 +25,7 @@ pub struct SourceEntry {
#[template_child] #[template_child]
pub resetVolumeMeter: TemplateChild<ProgressBar>, pub resetVolumeMeter: TemplateChild<ProgressBar>,
pub stream: Arc<RefCell<Source>>, pub stream: Arc<RefCell<Source>>,
pub volumeTimeStamp: RefCell<Option<SystemTime>>,
} }
#[glib::object_subclass] #[glib::object_subclass]

View file

@ -1,4 +1,3 @@
use std::cell::RefCell;
use std::sync::Arc; use std::sync::Arc;
use std::time::{Duration, SystemTime}; use std::time::{Duration, SystemTime};
@ -9,8 +8,7 @@ use dbus::blocking::Connection;
use dbus::Error; use dbus::Error;
use glib::subclass::types::ObjectSubclassIsExt; use glib::subclass::types::ObjectSubclassIsExt;
use glib::{clone, Cast, Propagation}; use glib::{clone, Cast, Propagation};
use gtk::prelude::ScaleExt; use gtk::{gio, StringObject};
use gtk::{gio, PositionType, StringObject};
use ReSet_Lib::audio::audio::InputStream; use ReSet_Lib::audio::audio::InputStream;
use super::inputStreamEntryImpl; use super::inputStreamEntryImpl;

View file

@ -1,6 +1,6 @@
use std::sync::atomic::Ordering; use std::sync::atomic::Ordering;
use std::sync::Arc; use std::sync::Arc;
use std::time::Duration; use std::time::{Duration, SystemTime};
use crate::components::base::listEntry::ListEntry; use crate::components::base::listEntry::ListEntry;
use crate::components::base::utils::{ use crate::components::base::utils::{
@ -159,6 +159,15 @@ pub fn populate_sinks(output_box: Arc<SinkBox>) {
let sink = imp.resetDefaultSink.borrow(); let sink = imp.resetDefaultSink.borrow();
let index = sink.index; let index = sink.index;
let channels = sink.channels; let channels = sink.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_sink_volume(value, index, channels); set_sink_volume(value, index, channels);
Propagation::Proceed Propagation::Proceed
}); });

View file

@ -1,6 +1,7 @@
use std::cell::RefCell; use std::cell::RefCell;
use std::collections::HashMap; use std::collections::HashMap;
use std::sync::{Arc, RwLock}; use std::sync::{Arc, RwLock};
use std::time::SystemTime;
use crate::components::base::listEntry::ListEntry; use crate::components::base::listEntry::ListEntry;
use crate::components::output::inputStreamEntry::InputStreamEntry; use crate::components::output::inputStreamEntry::InputStreamEntry;
@ -46,6 +47,7 @@ pub struct SinkBox {
// the full name // the full name
pub resetSinkMap: Arc<RwLock<HashMap<String, (u32, u32, String)>>>, pub resetSinkMap: Arc<RwLock<HashMap<String, (u32, u32, String)>>>,
// pub : Arc<Mutex<Vec<ListEntry>>>, // pub : Arc<Mutex<Vec<ListEntry>>>,
pub volumeTimeStamp: RefCell<Option<SystemTime>>,
} }
#[glib::object_subclass] #[glib::object_subclass]

View file

@ -1,5 +1,5 @@
use std::sync::Arc; use std::sync::Arc;
use std::time::Duration; use std::time::{Duration, SystemTime};
use adw::glib; use adw::glib;
use adw::glib::Object; use adw::glib::Object;
@ -42,6 +42,13 @@ impl SinkEntry {
let sink = imp.stream.borrow(); let sink = imp.stream.borrow();
let index = sink.index; let index = sink.index;
let channels = sink.channels; let channels = sink.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_sink_volume(value, index, channels); set_sink_volume(value, index, channels);
Propagation::Proceed Propagation::Proceed
}), }),

View file

@ -1,5 +1,6 @@
use std::cell::RefCell; use std::cell::RefCell;
use std::sync::Arc; use std::sync::Arc;
use std::time::SystemTime;
use crate::components::output::sinkEntry; use crate::components::output::sinkEntry;
use gtk::subclass::prelude::*; use gtk::subclass::prelude::*;
@ -23,6 +24,7 @@ pub struct SinkEntry {
#[template_child] #[template_child]
pub resetVolumeMeter: TemplateChild<ProgressBar>, pub resetVolumeMeter: TemplateChild<ProgressBar>,
pub stream: Arc<RefCell<Sink>>, pub stream: Arc<RefCell<Sink>>,
pub volumeTimeStamp: RefCell<Option<SystemTime>>,
} }
#[glib::object_subclass] #[glib::object_subclass]

View file

@ -92,6 +92,9 @@
<property name="hexpand">True</property> <property name="hexpand">True</property>
<property name="valign">center</property> <property name="valign">center</property>
<property name="value-pos">bottom</property> <property name="value-pos">bottom</property>
<marks>
<mark position="bottom" value="65536.0">100%</mark>
</marks>
</object> </object>
</child> </child>
<child> <child>

View file

@ -92,6 +92,9 @@
<property name="hexpand">True</property> <property name="hexpand">True</property>
<property name="valign">center</property> <property name="valign">center</property>
<property name="value-pos">bottom</property> <property name="value-pos">bottom</property>
<marks>
<mark position="bottom" value="65536.0">100%</mark>
</marks>
</object> </object>
</child> </child>
<child> <child>

View file

@ -42,7 +42,7 @@
<object class="GtkScale" id="resetVolumeSlider"> <object class="GtkScale" id="resetVolumeSlider">
<property name="adjustment"> <property name="adjustment">
<object class="GtkAdjustment"> <object class="GtkAdjustment">
<property name="page-increment">10000.0</property> <property name="page-increment">2005.4016</property>
<property name="step-increment">2005.4016</property> <property name="step-increment">2005.4016</property>
<property name="upper">100270.08</property> <property name="upper">100270.08</property>
</object> </object>

View file

@ -50,6 +50,9 @@
<property name="hexpand">True</property> <property name="hexpand">True</property>
<property name="valign">center</property> <property name="valign">center</property>
<property name="value-pos">bottom</property> <property name="value-pos">bottom</property>
<marks>
<mark position="bottom" value="65536.0">100%</mark>
</marks>
</object> </object>
</child> </child>
<child> <child>

View file

@ -50,6 +50,9 @@
<property name="hexpand">True</property> <property name="hexpand">True</property>
<property name="valign">center</property> <property name="valign">center</property>
<property name="value-pos">bottom</property> <property name="value-pos">bottom</property>
<marks>
<mark position="bottom" value="65536.0">100%</mark>
</marks>
</object> </object>
</child> </child>
<child> <child>

View file

@ -50,6 +50,9 @@
<property name="hexpand">True</property> <property name="hexpand">True</property>
<property name="valign">center</property> <property name="valign">center</property>
<property name="value-pos">bottom</property> <property name="value-pos">bottom</property>
<marks>
<mark position="bottom" value="65536.0">100%</mark>
</marks>
</object> </object>
</child> </child>
<child> <child>

View file

@ -438,7 +438,7 @@
(7,9,"GtkScale","value-pos","bottom",None,None,None,None,None,None,None,None,None), (7,9,"GtkScale","value-pos","bottom",None,None,None,None,None,None,None,None,None),
(7,9,"GtkWidget","hexpand","True",None,None,None,None,None,None,None,None,None), (7,9,"GtkWidget","hexpand","True",None,None,None,None,None,None,None,None,None),
(7,9,"GtkWidget","valign","center",None,None,None,None,None,None,None,None,None), (7,9,"GtkWidget","valign","center",None,None,None,None,None,None,None,None,None),
(7,10,"GtkAdjustment","page-increment","10000.0",None,None,None,None,None,None,None,None,None), (7,10,"GtkAdjustment","page-increment","2005.4016",None,None,None,None,None,None,None,None,None),
(7,10,"GtkAdjustment","step-increment","2005.4016",None,None,None,None,None,None,None,None,None), (7,10,"GtkAdjustment","step-increment","2005.4016",None,None,None,None,None,None,None,None,None),
(7,10,"GtkAdjustment","upper","100270.08",None,None,None,None,None,None,None,None,None), (7,10,"GtkAdjustment","upper","100270.08",None,None,None,None,None,None,None,None,None),
(7,11,"GtkButton","icon-name","audio-volume-high-symbolic",None,None,None,None,None,None,None,None,None), (7,11,"GtkButton","icon-name","audio-volume-high-symbolic",None,None,None,None,None,None,None,None,None),
@ -800,11 +800,31 @@
(3,42,"GtkWidget",1,1,None,None,None,None,None,None), (3,42,"GtkWidget",1,1,None,None,None,None,None,None),
(3,42,"GtkWidget",2,2,None,1,None,None,None,None), (3,42,"GtkWidget",2,2,None,1,None,None,None,None),
(7,9,"GtkScale",1,1,None,None,None,None,None,None), (7,9,"GtkScale",1,1,None,None,None,None,None,None),
(7,9,"GtkScale",2,2,"100%",1,None,None,None,None) (7,9,"GtkScale",2,2,"100%",1,None,None,None,None),
(8,99,"GtkScale",1,1,None,None,None,None,None,None),
(8,99,"GtkScale",2,2,"100%",1,None,None,None,None),
(12,25,"GtkScale",1,1,None,None,None,None,None,None),
(12,25,"GtkScale",2,2,"100%",1,None,None,None,None),
(13,17,"GtkScale",1,1,None,None,None,None,None,None),
(13,17,"GtkScale",2,2,"100%",1,None,None,None,None),
(18,7,"GtkScale",1,1,None,None,None,None,None,None),
(18,7,"GtkScale",2,2,"100%",1,None,None,None,None),
(19,7,"GtkScale",1,1,None,None,None,None,None,None),
(19,7,"GtkScale",2,2,"100%",1,None,None,None,None)
</object_data> </object_data>
<object_data_arg> <object_data_arg>
(7,9,"GtkScale",2,2,"value","65536.0"), (7,9,"GtkScale",2,2,"value","65536.0"),
(3,42,"GtkWidget",2,2,"name","b"), (3,42,"GtkWidget",2,2,"name","b"),
(7,9,"GtkScale",2,2,"position","bottom") (7,9,"GtkScale",2,2,"position","bottom"),
(8,99,"GtkScale",2,2,"position","bottom"),
(8,99,"GtkScale",2,2,"value","65536.0"),
(12,25,"GtkScale",2,2,"value","65536.0"),
(12,25,"GtkScale",2,2,"position","bottom"),
(13,17,"GtkScale",2,2,"value","65536.0"),
(13,17,"GtkScale",2,2,"position","bottom"),
(18,7,"GtkScale",2,2,"position","bottom"),
(18,7,"GtkScale",2,2,"value","65536.0"),
(19,7,"GtkScale",2,2,"position","bottom"),
(19,7,"GtkScale",2,2,"value","65536.0")
</object_data_arg> </object_data_arg>
</cambalache-project> </cambalache-project>