Compare commits

...

7 Commits

Author SHA1 Message Date
409
d01da4a0b2 fix(instructions): RemoveSinkInput stay on selection 2024-10-06 04:26:21 +02:00
409
5b34a72fe4 Merge branch 'dev' 2024-10-06 04:18:57 +02:00
409
25e19ed024 chore: bump version to 0.1.1 2024-10-06 04:17:23 +02:00
409
696ab0a089 fix(instructions): RemoveSinkInput switches selection sometimes 2024-10-06 04:16:19 +02:00
409
c9f4341587 refactor(instructions): UpdateSinkInput use channel and reduce nesting 2024-10-06 04:14:44 +02:00
409
cdb2cd5144 Merge branch 'dev' 2024-07-03 14:42:48 +02:00
409
0107ad88f3 Squashed commit of the following:
commit edef922902
Author: 409 <bloecker.s@gmail.com>
Date:   Mon Jul 1 13:22:02 2024 +0200

    feat: automatically select new sink input if the current selection is
    none
2024-07-01 13:26:08 +02:00
3 changed files with 48 additions and 53 deletions

2
Cargo.lock generated
View File

@@ -55,7 +55,7 @@ dependencies = [
[[package]]
name = "mixrs"
version = "0.1.0"
version = "0.1.1"
dependencies = [
"anyhow",
"libpulse-binding",

View File

@@ -1,6 +1,6 @@
[package]
name = "mixrs"
version = "0.1.0"
version = "0.1.1"
edition = "2021"
[dependencies]

View File

@@ -243,39 +243,38 @@ impl Mixer {
}
}
}
PulseInstruction::RemoveSinkInput(sink_index) => {
PulseInstruction::RemoveSinkInput(sink_index) => 'remove_sink: {
let selected_index_lock = self.selected_index.lock().unwrap();
match *selected_index_lock {
Some(current_index) => {
let Some(selected_index) = *selected_index_lock else {
break 'remove_sink;
};
drop(selected_index_lock);
if let Some(removed_sink_input_index) =
let Some(removed_sink_input_index) =
self.sink_inputs.keys().position(|k| *k == sink_index)
{
let current_key =
*self.sink_inputs.keys().nth(current_index).unwrap();
else {
break 'remove_sink;
};
let current_key = *self.sink_inputs.keys().nth(selected_index).unwrap();
if self.sink_inputs.remove(&sink_index).is_some() {
if sink_index == current_key
|| removed_sink_input_index > current_index
|| removed_sink_input_index < selected_index
{
self.select_previous();
}
}
}
}
None => (),
}
}
PulseInstruction::UpdateSinkInput(sink_index) => {
match self.sink_inputs.get_mut(&sink_index) {
Some(sink_input_mixer_data) => {
let new_sink_input: Arc<Mutex<Option<SinkInputMixerData>>> =
Arc::new(Mutex::new(None));
let callback_new_sink_input = new_sink_input.clone();
PulseInstruction::UpdateSinkInput(sink_index) => 'update_sink: {
let Some(sink_input_mixer_data) = self.sink_inputs.get_mut(&sink_index)
else {
break 'update_sink;
};
let (new_sink_tx, new_sink_rx) = channel::<Option<SinkInputMixerData>>();
let operation = self
.context
.borrow_mut()
@@ -283,30 +282,26 @@ impl Mixer {
.borrow_mut()
.get_sink_input_info(sink_index, move |r| {
let ListResult::Item(sink_input) = r else {
let _ = new_sink_tx.send(None);
return;
};
*callback_new_sink_input.lock().unwrap() =
Some(SinkInputMixerData {
let _ = new_sink_tx.send(Some(SinkInputMixerData {
name: get_sink_input_name(&sink_input).unwrap(),
volume: sink_input.volume.avg().0,
channels: sink_input.volume.len(),
muted: sink_input.mute,
});
}));
});
while operation.get_state() == pulse::operation::State::Running {
iterate_mainloop(&mut self.mainloop);
}
let mut sink_input_lock = new_sink_input.lock().unwrap();
if let Some(new_sink_input) = sink_input_lock.take() {
if let Some(new_sink_input) = new_sink_rx.recv().ok().flatten() {
*sink_input_mixer_data = new_sink_input;
}
}
None => (),
}
}
}
}