aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTeddy Wing2018-10-29 00:37:00 +0100
committerTeddy Wing2018-10-29 00:37:00 +0100
commit9e7a5e99e42d291dbc811094cb5318d95963038b (patch)
tree3b066276e8c705bd299cc80b329ac3cdc56a5707 /src
parentec60f43a0e0b46ad23a840bab4b80efac2310fec (diff)
downloaddome-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.rs4
-rw-r--r--src/map.rs23
2 files changed, 25 insertions, 2 deletions
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 => (),