From 9e7a5e99e42d291dbc811094cb5318d95963038b Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Mon, 29 Oct 2018 00:37:00 +0100 Subject: 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. --- src/ffi.rs | 4 ++-- src/map.rs | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ffi.rs b/src/ffi.rs index 0f7054e..22ebfe0 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -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] diff --git a/src/map.rs b/src/map.rs index 7e6441d..cdc5ae1 100644 --- a/src/map.rs +++ b/src/map.rs @@ -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 => (), -- cgit v1.2.3