fix(instructions): RemoveSinkInput switches selection sometimes
This commit is contained in:
50
src/mixer.rs
50
src/mixer.rs
@@ -243,57 +243,31 @@ impl Mixer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PulseInstruction::RemoveSinkInput(sink_index) => {
|
PulseInstruction::RemoveSinkInput(sink_index) => 'remove_sink: {
|
||||||
let selected_index_lock = self.selected_index.lock().unwrap();
|
let selected_index_lock = self.selected_index.lock().unwrap();
|
||||||
|
|
||||||
match *selected_index_lock {
|
let Some(selected_index) = *selected_index_lock else {
|
||||||
Some(current_index) => {
|
break 'remove_sink;
|
||||||
|
};
|
||||||
|
|
||||||
drop(selected_index_lock);
|
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)
|
self.sink_inputs.keys().position(|k| *k == sink_index)
|
||||||
{
|
else {
|
||||||
let current_key =
|
break 'remove_sink;
|
||||||
*self.sink_inputs.keys().nth(current_index).unwrap();
|
};
|
||||||
|
|
||||||
|
let current_key = *self.sink_inputs.keys().nth(selected_index).unwrap();
|
||||||
|
|
||||||
if self.sink_inputs.remove(&sink_index).is_some() {
|
if self.sink_inputs.remove(&sink_index).is_some() {
|
||||||
if sink_index == current_key
|
if sink_index == current_key
|
||||||
|| removed_sink_input_index > current_index
|
|| removed_sink_input_index <= selected_index
|
||||||
{
|
{
|
||||||
self.select_previous();
|
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();
|
|
||||||
|
|
||||||
let operation = self
|
|
||||||
.context
|
|
||||||
.borrow_mut()
|
|
||||||
.introspect()
|
|
||||||
.borrow_mut()
|
|
||||||
.get_sink_input_info(sink_index, move |r| {
|
|
||||||
let ListResult::Item(sink_input) = r else {
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
*callback_new_sink_input.lock().unwrap() =
|
|
||||||
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,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
PulseInstruction::UpdateSinkInput(sink_index) => 'update_sink: {
|
PulseInstruction::UpdateSinkInput(sink_index) => 'update_sink: {
|
||||||
let Some(sink_input_mixer_data) = self.sink_inputs.get_mut(&sink_index)
|
let Some(sink_input_mixer_data) = self.sink_inputs.get_mut(&sink_index)
|
||||||
else {
|
else {
|
||||||
|
|||||||
Reference in New Issue
Block a user