From 330d3a0a70b2587e8e05dcddcc7c7991f12c825b Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 30 Oct 2018 03:12:44 +0100 Subject: parser::map_group(): Use default `MapGroup` as a base This means that if any of ``, ``, or `` are undefined in the mappings file definition, they will be set to their default action values (as set in `MapGroup::default()`). To get rid of the default, map the button trigger to ``. Update a test that didn't map `` to give it the default mapping. --- src/parser.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/parser.rs b/src/parser.rs index 8314e0d..62eea12 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -640,13 +640,12 @@ where { definitions() .map(|definitions| { - let mut maps = HashMap::new(); - let mut modes = HashMap::new(); + let mut map_group = MapGroup::default(); for definition in definitions { match definition { Definition::Map(map) => { - maps.insert( + map_group.maps.insert( map.trigger, MapAction { action: map.action, @@ -655,7 +654,7 @@ where ); }, Definition::Mode(mode) => { - modes.insert( + map_group.modes.insert( mode.trigger, mode.maps, ); @@ -663,10 +662,7 @@ where } } - MapGroup { - maps: maps, - modes: modes, - } + map_group }) } @@ -1243,6 +1239,18 @@ cmd /usr/bin/say hello let mut modes: HashMap = HashMap::new(); let mut mode_maps: MapCollection = HashMap::new(); + maps.insert( + vec![HeadphoneButton::Up], + MapAction { + action: Action::Map( + vec![KeyboardKeyWithModifiers::new( + KeyboardKey::NXKey(key_code::NX_KEYTYPE_SOUND_UP), + vec![], + )] + ), + kind: MapKind::Map, + }, + ); maps.insert( vec![HeadphoneButton::Down], MapAction { -- cgit v1.2.3