mirror of
https://github.com/Xetibo/ReSet.git
synced 2025-12-15 10:01:39 +01:00
fix: Improve performance by passing smaller datatypes to dbus
This commit is contained in:
parent
c1984b5b79
commit
dbcf2ab635
6 changed files with 223 additions and 41 deletions
|
|
@ -4,7 +4,7 @@ use std::time::Duration;
|
|||
|
||||
use adw::glib;
|
||||
use adw::glib::Object;
|
||||
use adw::prelude::RangeExt;
|
||||
use adw::prelude::{ButtonExt, RangeExt};
|
||||
use dbus::blocking::Connection;
|
||||
use dbus::Error;
|
||||
use glib::subclass::types::ObjectSubclassIsExt;
|
||||
|
|
@ -42,21 +42,53 @@ impl SourceEntry {
|
|||
println!("{fraction}");
|
||||
let percentage = (fraction).to_string() + "%";
|
||||
imp.resetVolumePercentage.set_text(&percentage);
|
||||
set_source_volume(value, imp.stream.clone());
|
||||
let source = imp.stream.borrow();
|
||||
let index = source.index;
|
||||
let channels = source.channels;
|
||||
set_source_volume(value, index, channels);
|
||||
Propagation::Proceed
|
||||
}),
|
||||
);
|
||||
imp.resetSourceMute
|
||||
.connect_clicked(clone!(@weak imp => move |_| {
|
||||
let stream = imp.stream.clone();
|
||||
let mut stream = stream.borrow_mut();
|
||||
stream.muted = !stream.muted;
|
||||
let muted = stream.muted;
|
||||
let index = stream.index;
|
||||
if muted {
|
||||
imp.resetSourceMute
|
||||
.set_icon_name("audio-volume-muted-symbolic");
|
||||
} else {
|
||||
imp.resetSourceMute
|
||||
.set_icon_name("audio-volume-high-symbolic");
|
||||
}
|
||||
toggle_source_mute(index, muted);
|
||||
}));
|
||||
}
|
||||
obj
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_source_volume(value: f64, stream: Arc<RefCell<Source>>) -> bool {
|
||||
let mut stream = stream.borrow_mut().clone();
|
||||
// let x = stream.volume.iter_mut().map(|_| value as u32);
|
||||
stream.volume = vec![value as u32; stream.channels as usize];
|
||||
dbg!(stream.volume.clone());
|
||||
pub fn set_source_volume(value: f64, index: u32, channels: u16) -> bool {
|
||||
let conn = Connection::new_session().unwrap();
|
||||
let proxy = conn.with_proxy(
|
||||
"org.xetibo.ReSet",
|
||||
"/org/xetibo/ReSet",
|
||||
Duration::from_millis(1000),
|
||||
);
|
||||
let res: Result<(bool,), Error> = proxy.method_call(
|
||||
"org.xetibo.ReSet",
|
||||
"SetSourceVolume",
|
||||
(index, channels, value as u32),
|
||||
);
|
||||
if res.is_err() {
|
||||
return false;
|
||||
}
|
||||
res.unwrap().0
|
||||
}
|
||||
|
||||
pub fn toggle_source_mute(index: u32, muted: bool) -> bool {
|
||||
let conn = Connection::new_session().unwrap();
|
||||
let proxy = conn.with_proxy(
|
||||
"org.xetibo.ReSet",
|
||||
|
|
@ -64,7 +96,7 @@ pub fn set_source_volume(value: f64, stream: Arc<RefCell<Source>>) -> bool {
|
|||
Duration::from_millis(1000),
|
||||
);
|
||||
let res: Result<(bool,), Error> =
|
||||
proxy.method_call("org.xetibo.ReSet", "SetSourceVolume", (stream,));
|
||||
proxy.method_call("org.xetibo.ReSet", "SetSourceMute", (index, muted));
|
||||
if res.is_err() {
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue