aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTeddy Wing2018-09-24 11:20:03 +0200
committerTeddy Wing2018-09-24 11:20:03 +0200
commit882dfbe6f0aad091613839841d2f54334e37b32e (patch)
treeb1639e7fcd8cfb1cdb7c02069f82844f181255c1 /src
parent457b2796e6fc268074b87d36c9f9a2c25eb4b5af (diff)
downloaddome-key-map-882dfbe6f0aad091613839841d2f54334e37b32e.tar.bz2
run_key_action_for_mode(): Keep track of `in_mode` in `state`
Instead of letting the Objective-C code keep track of `in_mode` by passing it around in `CKeyActionResult`, keep track of it in a `State` struct. Derive `Clone` on `HeadphoneButton` to resolve this error: error[E0277]: the trait bound `parser::HeadphoneButton: std::clone::Clone` is not satisfied --> src/cocoa_bridge.rs:273:38 | 273 | state.in_mode = Some(trigger.to_vec()); | ^^^^^^ the trait `std::clone::Clone` is not implemented for `parser::HeadphoneButton`
Diffstat (limited to 'src')
-rw-r--r--src/cocoa_bridge.rs13
-rw-r--r--src/parser.rs2
2 files changed, 12 insertions, 3 deletions
diff --git a/src/cocoa_bridge.rs b/src/cocoa_bridge.rs
index a864e13..11dc1c9 100644
--- a/src/cocoa_bridge.rs
+++ b/src/cocoa_bridge.rs
@@ -110,6 +110,7 @@ pub extern "C" fn state_free(ptr: *mut State) {
#[no_mangle]
pub extern "C" fn c_run_key_action(
+ state: *mut State,
trigger: Trigger,
mode: *const Trigger,
) -> *const CKeyActionResult {
@@ -133,7 +134,12 @@ pub extern "C" fn c_run_key_action(
};
println!("Mode after unsafe (118): {:?}", mode);
- let result = run_key_action_for_mode(trigger, mode);
+ let mut state = unsafe {
+ assert!(!state.is_null());
+ &mut *state
+ };
+
+ let result = run_key_action_for_mode(&mut state, trigger, mode);
let result = match result {
Some(k) => {
let action = k.action.map_or_else(
@@ -200,6 +206,7 @@ pub extern "C" fn c_run_key_action(
#[no_mangle]
pub extern "C" fn run_key_action_for_mode<'a>(
+ state: &mut State,
trigger: &'a [HeadphoneButton],
in_mode: Option<&[HeadphoneButton]>
) -> Option<KeyActionResult<'a>> {
@@ -217,7 +224,7 @@ mode <play><up> {
let map = map_group.maps.get(trigger);
let mode = map_group.modes.get(trigger);
- if let Some(in_mode) = in_mode {
+ if let Some(ref mut in_mode) = state.in_mode {
if let Some(mode) = map_group.modes.get(in_mode) {
if let Some(map) = mode.get(trigger) {
return match map.kind {
@@ -263,6 +270,8 @@ mode <play><up> {
}
if let Some(mode) = mode {
+ state.in_mode = Some(trigger.to_vec());
+
return Some(
KeyActionResult::new(ActionKind::Mode)
.in_mode(trigger)
diff --git a/src/parser.rs b/src/parser.rs
index 1d9aa56..ea96740 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -14,7 +14,7 @@ use combine::parser::repeat::take_until;
use combine::stream::state::{SourcePosition, State};
#[repr(C)]
-#[derive(Debug, Hash, Eq, PartialEq)]
+#[derive(Clone, Debug, Hash, Eq, PartialEq)]
pub enum HeadphoneButton {
Play,
Up,