mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-09-15 19:26:58 +02:00
Remove unused parts of pulseaudio module
This commit is contained in:
parent
d1f433c990
commit
54e91facd3
4 changed files with 27 additions and 190 deletions
|
@ -1,4 +1,4 @@
|
|||
use super::{ArcMutVec, Client, ConnectionState, Event, percent_to_volume, volume_to_percent};
|
||||
use super::{ArcMutVec, Client, Event, volume_to_percent};
|
||||
use crate::channels::SyncSenderExt;
|
||||
use crate::lock;
|
||||
use libpulse_binding::callbacks::ListResult;
|
||||
|
@ -6,7 +6,7 @@ use libpulse_binding::context::Context;
|
|||
use libpulse_binding::context::introspect::SinkInfo;
|
||||
use libpulse_binding::context::subscribe::Operation;
|
||||
use libpulse_binding::def::SinkState;
|
||||
use std::sync::{Arc, Mutex, mpsc};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use tokio::sync::broadcast;
|
||||
use tracing::{debug, error, instrument, trace};
|
||||
|
||||
|
@ -14,7 +14,6 @@ use tracing::{debug, error, instrument, trace};
|
|||
pub struct Sink {
|
||||
index: u32,
|
||||
pub name: String,
|
||||
pub description: String,
|
||||
pub volume: f64,
|
||||
pub muted: bool,
|
||||
pub active: bool,
|
||||
|
@ -29,11 +28,6 @@ impl From<&SinkInfo<'_>> for Sink {
|
|||
.as_ref()
|
||||
.map(ToString::to_string)
|
||||
.unwrap_or_default(),
|
||||
description: value
|
||||
.description
|
||||
.as_ref()
|
||||
.map(ToString::to_string)
|
||||
.unwrap_or_default(),
|
||||
muted: value.mute,
|
||||
volume: volume_to_percent(value.volume),
|
||||
active: value.state == SinkState::Running,
|
||||
|
@ -46,43 +40,6 @@ impl Client {
|
|||
pub fn sinks(&self) -> Arc<Mutex<Vec<Sink>>> {
|
||||
self.data.sinks.clone()
|
||||
}
|
||||
|
||||
#[instrument(level = "trace")]
|
||||
pub fn set_default_sink(&self, name: &str) {
|
||||
if let ConnectionState::Connected { context, .. } = &*lock!(self.connection) {
|
||||
lock!(context).set_default_sink(name, |_| {});
|
||||
}
|
||||
}
|
||||
|
||||
#[instrument(level = "trace")]
|
||||
pub fn set_sink_volume(&self, name: &str, volume_percent: f64) {
|
||||
if let ConnectionState::Connected { introspector, .. } = &mut *lock!(self.connection) {
|
||||
let (tx, rx) = mpsc::channel();
|
||||
|
||||
introspector.get_sink_info_by_name(name, move |info| {
|
||||
let ListResult::Item(info) = info else {
|
||||
return;
|
||||
};
|
||||
tx.send_expect(info.volume);
|
||||
});
|
||||
|
||||
let new_volume = percent_to_volume(volume_percent);
|
||||
|
||||
let mut volume = rx.recv().expect("to receive info");
|
||||
for v in volume.get_mut() {
|
||||
v.0 = new_volume;
|
||||
}
|
||||
|
||||
introspector.set_sink_volume_by_name(name, &volume, None);
|
||||
}
|
||||
}
|
||||
|
||||
#[instrument(level = "trace")]
|
||||
pub fn set_sink_muted(&self, name: &str, muted: bool) {
|
||||
if let ConnectionState::Connected { introspector, .. } = &mut *lock!(self.connection) {
|
||||
introspector.set_sink_mute_by_name(name, muted, None);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn on_event(
|
||||
|
@ -177,10 +134,9 @@ fn update(
|
|||
fn remove(index: u32, sinks: &ArcMutVec<Sink>, tx: &broadcast::Sender<Event>) {
|
||||
trace!("removing {index}");
|
||||
|
||||
let mut sinks = lock!(sinks);
|
||||
let sinks = lock!(sinks);
|
||||
|
||||
if let Some(pos) = sinks.iter().position(|s| s.index == index) {
|
||||
let info = sinks.remove(pos);
|
||||
tx.send_expect(Event::RemoveSink(info.name));
|
||||
if let Some(_pos) = sinks.iter().position(|s| s.index == index) {
|
||||
tx.send_expect(Event::RemoveSink);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue