diff options
| author | Teddy Wing | 2018-10-29 00:37:00 +0100 |
|---|---|---|
| committer | Teddy Wing | 2018-10-29 00:37:00 +0100 |
| commit | 9e7a5e99e42d291dbc811094cb5318d95963038b (patch) | |
| tree | 3b066276e8c705bd299cc80b329ac3cdc56a5707 /src | |
| parent | ec60f43a0e0b46ad23a840bab4b80efac2310fec (diff) | |
| download | dome-key-map-9e7a5e99e42d291dbc811094cb5318d95963038b.tar.bz2 | |
map::run_key_action(): Add conditional argument for playing audio
Play audio on mode activation and deactivation depending on the value of
the new argument.
Decided to make it an enum instead of a bool for better readability.
Will need to get rid of the `unwrap`s.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ffi.rs | 4 | ||||
| -rw-r--r-- | src/map.rs | 23 |
2 files changed, 25 insertions, 2 deletions
@@ -9,7 +9,7 @@ use xdg; use {HeadphoneButton, MapGroup}; use config::{self, Config}; -use map::run_key_action; +use map::{PlayAudio, run_key_action}; use trial; #[repr(C)] @@ -102,7 +102,7 @@ pub extern "C" fn dome_key_run_key_action( &mut *state }; - run_key_action(&mut state, trigger); + run_key_action(&mut state, trigger, PlayAudio::No); } #[no_mangle] @@ -6,9 +6,24 @@ use {Action, HeadphoneButton, MapAction, MapKind}; use ffi::State; use sounds; +pub enum PlayAudio { + Yes, + No, +} + +impl PlayAudio { + fn yes(&self) -> bool { + match self { + PlayAudio::Yes => true, + PlayAudio::No => false, + } + } +} + pub fn run_key_action<'a>( state: &mut State, trigger: &'a [HeadphoneButton], + play_audio: PlayAudio, ) { match state.map_group { Some(ref map_group) => { @@ -21,6 +36,10 @@ pub fn run_key_action<'a>( if &in_mode[..] == trigger { state.in_mode = None; + if play_audio.yes() { + sounds::play_mode_deactivated().unwrap(); + } + return; } @@ -39,6 +58,10 @@ pub fn run_key_action<'a>( if mode.is_some() { state.in_mode = Some(trigger.to_vec()); + + if play_audio.yes() { + sounds::play_mode_activated().unwrap(); + } } }, None => (), |
