@@ -25,51 +25,83 @@ macro_rules! modifiers {
2525/// When an action is currently available, and the user enters that input, the action's message is dispatched on the message bus.
2626macro_rules! entry {
2727 // Pattern with canonical parameter
28- ( $input: expr_2021; $( modifiers=[ $( $modifier: ident) ,* ] , ) ? $( refresh_keys=[ $( $refresh: ident) ,* $( , ) ?] , ) ? canonical, action_dispatch=$action_dispatch: expr_2021$( , ) ?) => {
29- entry!( $input; $( $( $modifier) ,* ) ?; $( $( $refresh) ,* ) ?; $action_dispatch; true )
28+ (
29+ $input: expr_2021;
30+ $( modifiers=[ $( $modifier: ident) ,* ] , ) ?
31+ $( refresh_keys=[ $( $refresh: ident) ,* $( , ) ?] , ) ?
32+ canonical,
33+ $( active=$active: expr, ) ?
34+ action_dispatch=$action_dispatch: expr_2021$( , ) ?
35+ ) => {
36+ entry!(
37+ $input;
38+ $( $( $modifier) ,* ) ?;
39+ $( $( $refresh) ,* ) ?;
40+ $action_dispatch;
41+ true ;
42+ true $( && $active ) ?
43+ )
3044 } ;
3145
3246 // Pattern without canonical parameter
33- ( $input: expr_2021; $( modifiers=[ $( $modifier: ident) ,* ] , ) ? $( refresh_keys=[ $( $refresh: ident) ,* $( , ) ?] , ) ? action_dispatch=$action_dispatch: expr_2021$( , ) ?) => {
34- entry!( $input; $( $( $modifier) ,* ) ?; $( $( $refresh) ,* ) ?; $action_dispatch; false )
47+ (
48+ $input: expr_2021;
49+ $( modifiers=[ $( $modifier: ident) ,* ] , ) ?
50+ $( refresh_keys=[ $( $refresh: ident) ,* $( , ) ?] , ) ?
51+ $( active=$active: expr, ) ?
52+ action_dispatch=$action_dispatch: expr_2021$( , ) ?
53+ ) => {
54+ entry!(
55+ $input;
56+ $( $( $modifier) ,* ) ?;
57+ $( $( $refresh) ,* ) ?;
58+ $action_dispatch;
59+ false ;
60+ true $( && $active ) ?
61+ )
3562 } ;
3663
3764 // Implementation macro to avoid code duplication
38- ( $input: expr; $( $modifier: ident) ,* ; $( $refresh: ident) ,* ; $action_dispatch: expr; $canonical: expr) => {
65+ ( $input: expr; $( $modifier: ident) ,* ; $( $refresh: ident) ,* ; $action_dispatch: expr; $canonical: expr; $active: expr) => {
66+
3967 & [ & [
4068 // Cause the `action_dispatch` message to be sent when the specified input occurs.
4169 MappingEntry {
4270 action: $action_dispatch. into( ) ,
4371 input: $input,
4472 modifiers: modifiers!( $( $modifier) ,* ) ,
4573 canonical: $canonical,
74+ active: $active,
4675 } ,
4776
48- // Also cause the `action_dispatch` message to be sent when any of the specified refresh keys change.
4977 $(
5078 MappingEntry {
5179 action: $action_dispatch. into( ) ,
5280 input: InputMapperMessage :: KeyDown ( Key :: $refresh) ,
5381 modifiers: modifiers!( ) ,
5482 canonical: $canonical,
83+ active: $active,
5584 } ,
5685 MappingEntry {
5786 action: $action_dispatch. into( ) ,
5887 input: InputMapperMessage :: KeyUp ( Key :: $refresh) ,
5988 modifiers: modifiers!( ) ,
6089 canonical: $canonical,
90+ active: $active,
6191 } ,
6292 MappingEntry {
6393 action: $action_dispatch. into( ) ,
6494 input: InputMapperMessage :: KeyDownNoRepeat ( Key :: $refresh) ,
6595 modifiers: modifiers!( ) ,
6696 canonical: $canonical,
97+ active: $active,
6798 } ,
6899 MappingEntry {
69100 action: $action_dispatch. into( ) ,
70101 input: InputMapperMessage :: KeyUpNoRepeat ( Key :: $refresh) ,
71102 modifiers: modifiers!( ) ,
72103 canonical: $canonical,
104+ active: $active,
73105 } ,
74106 ) *
75107 ] ]
@@ -97,6 +129,9 @@ macro_rules! mapping {
97129 for entry_slice in $entry {
98130 // Each entry in the slice (usually just one, except when `refresh_keys` adds additional key entries)
99131 for entry in entry_slice. into_iter( ) {
132+ if !entry. active {
133+ continue ;
134+ }
100135 let corresponding_list = match entry. input {
101136 InputMapperMessage :: KeyDown ( key) => & mut key_down[ key as usize ] ,
102137 InputMapperMessage :: KeyUp ( key) => & mut key_up[ key as usize ] ,
0 commit comments