Skip to content

Commit

Permalink
Automatically reload sound system when alsa channel is skewed
Browse files Browse the repository at this point in the history
  • Loading branch information
hasufell committed Jun 20, 2018
1 parent c7a2000 commit 0a39aa8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/audio/alsa/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,5 +352,12 @@ fn on_alsa_event(
self::AudioUser::Unknown,
);
}
AlsaEvent::AlsaCardReload => {
invoke_handlers(
handlers,
self::AudioSignal::CardReload,
self::AudioUser::Unknown,
);
}
}
}
7 changes: 5 additions & 2 deletions src/audio/alsa/card.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ pub enum AlsaEvent {
AlsaCardDiconnected,
/// The values of the mixer changed, including mute state.
AlsaCardValuesChanged,
/// Alsa needs to be reloaded due to recoverable error.
AlsaCardReload,
}


Expand Down Expand Up @@ -236,8 +238,9 @@ extern "C" fn watch_cb(
continue;
}
glib_sys::G_IO_STATUS_NORMAL => {
error!("Alsa failed to clear the channel");
cb(AlsaEvent::AlsaCardError);
// BUG: https://github.com/nicklan/pnmixer/issues/182
warn!("Alsa failed to clear the channel");
cb(AlsaEvent::AlsaCardReload);
}
glib_sys::G_IO_STATUS_ERROR => (),
glib_sys::G_IO_STATUS_EOF => {
Expand Down
1 change: 1 addition & 0 deletions src/audio/frontend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pub enum AudioSignal {
CardDisconnected,
CardError,
ValuesChanged,
CardReload,
}


Expand Down
11 changes: 9 additions & 2 deletions src/ui/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ where
&apps.prefs.borrow(),
AudioUser::Unknown,
));
}
},
(AudioSignal::CardError, _) => {
if run_audio_error_dialog(
&apps.gui.popup_menu.menu_window,
Expand All @@ -84,7 +84,14 @@ where
AudioUser::Unknown,
));
}
}
},
(AudioSignal::CardReload, _) => {
try_w!(audio_reload(
apps.audio.as_ref(),
&apps.prefs.borrow(),
AudioUser::Unknown,
));
},
_ => (),
}),
);
Expand Down

0 comments on commit 0a39aa8

Please sign in to comment.