From 5ad030282af1be49f5d3e5546911dbaa4ce4069d Mon Sep 17 00:00:00 2001 From: Roberto Previdi Date: Thu, 26 Dec 2024 23:33:29 +0100 Subject: [PATCH 1/7] mth and th macros --- rmk/src/layout_macro.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/rmk/src/layout_macro.rs b/rmk/src/layout_macro.rs index 73a25ecb..7b100b91 100644 --- a/rmk/src/layout_macro.rs +++ b/rmk/src/layout_macro.rs @@ -60,6 +60,28 @@ macro_rules! lt { }; } +/// Create a modifier-tap-hold action +#[macro_export] +macro_rules! mth { + ($m: expr, $k: ident) => { + $crate::action::KeyAction::ModifierTapHold( + $m, + $crate::action::Action::Key($crate::keycode::KeyCode::$k), + ) + }; +} + +/// Create a tap-hold action +#[macro_export] +macro_rules! th { + ($h: ident, $t: ident) => { + $crate::action::KeyAction::TapHold( + $t, + $h, + ) + }; +} + /// Create an oneshot layer key in keymap #[macro_export] macro_rules! osl { From 022ffa78d5d97bf674b99b390fdb4cf6159f9bf6 Mon Sep 17 00:00:00 2001 From: Roberto Previdi Date: Thu, 26 Dec 2024 23:51:02 +0100 Subject: [PATCH 2/7] extract duplicated code as function --- rmk-macro/src/layout.rs | 136 ++++++++++++---------------------------- 1 file changed, 40 insertions(+), 96 deletions(-) diff --git a/rmk-macro/src/layout.rs b/rmk-macro/src/layout.rs index 70479d29..25d259c2 100644 --- a/rmk-macro/src/layout.rs +++ b/rmk-macro/src/layout.rs @@ -37,6 +37,43 @@ fn expand_row(row: Vec) -> TokenStream2 { quote! { [#(#keys), *] } } +/// Get modifier combination, in types of mod1 | mod2 | ... +fn parse_modifiers(modifiers_str: &str) -> (bool, bool, bool, bool, bool){ + let mut right = false; + let mut gui = false; + let mut alt = false; + let mut shift = false; + let mut ctrl = false; + let tokens = modifiers_str.split_terminator("|"); + tokens.for_each(|w| { + let w = w.trim(); + match w { + "LShift" => shift = true, + "LCtrl" => ctrl = true, + "LAlt" => alt = true, + "Lgui" => gui = true, + "RShift" => { + right = true; + shift = true; + } + "RCtrl" => { + right = true; + ctrl = true; + } + "RAlt" => { + right = true; + alt = true; + } + "Rgui" => { + right = true; + gui = true; + } + _ => (), + } + }); + return (right, gui, alt, shift, ctrl); +} + /// Parse the key string at a single position fn parse_key(key: String) -> TokenStream2 { if key.len() < 5 { @@ -63,38 +100,7 @@ fn parse_key(key: String) -> TokenStream2 { let ident = format_ident!("{}", keys[0].to_string()); - // Get modifier combination, in types of mod1 | mod2 | ... - let mut right = false; - let mut gui = false; - let mut alt = false; - let mut shift = false; - let mut ctrl = false; - keys[1].split_terminator("|").for_each(|w| { - let w = w.trim(); - match w { - "LShift" => shift = true, - "LCtrl" => ctrl = true, - "LAlt" => alt = true, - "Lgui" => gui = true, - "RShift" => { - right = true; - shift = true; - } - "RCtrl" => { - right = true; - ctrl = true; - } - "RAlt" => { - right = true; - alt = true; - } - "Rgui" => { - right = true; - gui = true; - } - _ => (), - } - }); + let (right, gui, alt, shift, ctrl) = parse_modifiers(keys[1]); if (gui || alt || shift || ctrl) == false { return quote! { @@ -124,38 +130,7 @@ fn parse_key(key: String) -> TokenStream2 { } "OSM" => { if let Some(internal) = key.trim_start_matches("OSM(").strip_suffix(")") { - // Get modifier combination, in types of mod1 | mod2 | ... - let mut right = false; - let mut gui = false; - let mut alt = false; - let mut shift = false; - let mut ctrl = false; - internal.split_terminator("|").for_each(|w| { - let w = w.trim(); - match w { - "LShift" => shift = true, - "LCtrl" => ctrl = true, - "LAlt" => alt = true, - "Lgui" => gui = true, - "RShift" => { - right = true; - shift = true; - } - "RCtrl" => { - right = true; - ctrl = true; - } - "RAlt" => { - right = true; - alt = true; - } - "Rgui" => { - right = true; - gui = true; - } - _ => (), - } - }); + let (right, gui, alt, shift, ctrl) = parse_modifiers(internal); if !(gui || alt || shift || ctrl) { return quote! { @@ -185,38 +160,7 @@ fn parse_key(key: String) -> TokenStream2 { } let layer = keys[0].parse::().unwrap(); - // Get modifier combination, in types of mod1 | mod2 | ... - let mut right = false; - let mut gui = false; - let mut alt = false; - let mut shift = false; - let mut ctrl = false; - keys[1].split_terminator("|").for_each(|w| { - let w = w.trim(); - match w { - "LShift" => shift = true, - "LCtrl" => ctrl = true, - "LAlt" => alt = true, - "Lgui" => gui = true, - "RShift" => { - right = true; - shift = true; - } - "RCtrl" => { - right = true; - ctrl = true; - } - "RAlt" => { - right = true; - alt = true; - } - "Rgui" => { - right = true; - gui = true; - } - _ => (), - } - }); + let (right, gui, alt, shift, ctrl) = parse_modifiers(keys[1]); if (gui || alt || shift || ctrl) == false { return quote! { From 89281eb305cfee8e35e42544f6dd4f00462b9121 Mon Sep 17 00:00:00 2001 From: Roberto Previdi Date: Fri, 27 Dec 2024 00:17:22 +0100 Subject: [PATCH 3/7] implemented MTH and TH parsers --- rmk-macro/src/layout.rs | 48 +++++++++++++++++++++++++++++++++++++++++ rmk/src/layout_macro.rs | 4 ++-- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/rmk-macro/src/layout.rs b/rmk-macro/src/layout.rs index 25d259c2..8519bfdd 100644 --- a/rmk-macro/src/layout.rs +++ b/rmk-macro/src/layout.rs @@ -219,6 +219,54 @@ fn parse_key(key: String) -> TokenStream2 { ::rmk::df!(#layer) } } + "MTH(" => { + let keys: Vec<&str> = key + .trim_start_matches("MTH(") + .trim_end_matches(")") + .split_terminator(",") + .map(|w| w.trim()) + .filter(|w| w.len() > 0) + .collect(); + if keys.len() != 2 { + return quote! { + compile_error!("keyboard.toml: MTH(modifiers, key) invalid, please check the documentation: https://haobogu.github.io/rmk/keyboard_configuration.html"); + }; + } + let ident = format_ident!("{}", keys[0].to_string()); + + let (right, gui, alt, shift, ctrl) = parse_modifiers(keys[1]); + + if (gui || alt || shift || ctrl) == false { + return quote! { + compile_error!("keyboard.toml: modifier in MTH(modifier, key) is not valid! Please check the documentation: https://haobogu.github.io/rmk/keyboard_configuration.html"); + }; + } + quote! { + ::rmk::mth!(#ident, ::rmk::keycode::ModifierCombination::new_from(#right, #gui, #alt, #shift, #ctrl)) + } + + } + "TH(" => { + let keys: Vec<&str> = key + .trim_start_matches("TH(") + .trim_end_matches(")") + .split_terminator(",") + .map(|w| w.trim()) + .filter(|w| w.len() > 0) + .collect(); + if keys.len() != 2 { + return quote! { + compile_error!("keyboard.toml: TH(modifiers, key) invalid, please check the documentation: https://haobogu.github.io/rmk/keyboard_configuration.html"); + }; + } + let ident1 = format_ident!("{}", keys[0].to_string()); + let ident2 = format_ident!("{}", keys[1].to_string()); + + quote! { + ::rmk::th!(#ident1, #ident2) + } + + } _ => { let ident = format_ident!("{}", key); quote! {::rmk::k!(#ident) } diff --git a/rmk/src/layout_macro.rs b/rmk/src/layout_macro.rs index 7b100b91..cb52e863 100644 --- a/rmk/src/layout_macro.rs +++ b/rmk/src/layout_macro.rs @@ -63,7 +63,7 @@ macro_rules! lt { /// Create a modifier-tap-hold action #[macro_export] macro_rules! mth { - ($m: expr, $k: ident) => { + ($k: ident, $m: expr) => { $crate::action::KeyAction::ModifierTapHold( $m, $crate::action::Action::Key($crate::keycode::KeyCode::$k), @@ -74,7 +74,7 @@ macro_rules! mth { /// Create a tap-hold action #[macro_export] macro_rules! th { - ($h: ident, $t: ident) => { + ($t: ident, $h: ident) => { $crate::action::KeyAction::TapHold( $t, $h, From 3187c19278b4f60db4618d5ba9b33cdd738f6b31 Mon Sep 17 00:00:00 2001 From: Roberto Previdi Date: Fri, 27 Dec 2024 00:21:18 +0100 Subject: [PATCH 4/7] updated docs --- docs/src/keyboard_configuration.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/src/keyboard_configuration.md b/docs/src/keyboard_configuration.md index 005fe17e..f4eb3dd1 100644 --- a/docs/src/keyboard_configuration.md +++ b/docs/src/keyboard_configuration.md @@ -151,9 +151,12 @@ The key string should follow several rules: 7. Use `"TT(n)"` to create a layer activate or tap toggle action, `n` is the layer number 8. Use `"TG(n)"` to create a layer toggle action, `n` is the layer number 9. Use `"TO(n)"` to create a layer toggle only action (activate layer `n` and deactivate all other layers), `n` is the layer number - + The definitions of those operations are same with QMK, you can found [here](https://docs.qmk.fm/#/feature_layers). If you want other actions, please [fire an issue](https://github.com/HaoboGu/rmk/issues/new). +4. For modifier-tap-hold, use `MTH(key, modifier)` where the modifier can be a chain like explained on point 1 + +5. For generic key tap-hold, use `TH(key-tap, key-hold)`. ### `[behavior]` From a8f19c51dedc129ec05f67436d75b629cff33948 Mon Sep 17 00:00:00 2001 From: Roberto Previdi Date: Fri, 27 Dec 2024 12:09:09 +0100 Subject: [PATCH 5/7] fixes --- docs/src/keyboard_configuration.md | 2 +- rmk-macro/src/layout.rs | 82 ++++++++++++++++-------------- rmk/src/layout_macro.rs | 6 +-- 3 files changed, 48 insertions(+), 42 deletions(-) diff --git a/docs/src/keyboard_configuration.md b/docs/src/keyboard_configuration.md index f4eb3dd1..b3e18a87 100644 --- a/docs/src/keyboard_configuration.md +++ b/docs/src/keyboard_configuration.md @@ -154,7 +154,7 @@ The key string should follow several rules: The definitions of those operations are same with QMK, you can found [here](https://docs.qmk.fm/#/feature_layers). If you want other actions, please [fire an issue](https://github.com/HaoboGu/rmk/issues/new). -4. For modifier-tap-hold, use `MTH(key, modifier)` where the modifier can be a chain like explained on point 1 +4. For modifier-tap-hold, use `MTH(key, modifier)` where the modifier can be a chain like explained on point 1. For example for a Home row modifier config you can use `MTH(F,LShift)` 5. For generic key tap-hold, use `TH(key-tap, key-hold)`. diff --git a/rmk-macro/src/layout.rs b/rmk-macro/src/layout.rs index 8519bfdd..9005568d 100644 --- a/rmk-macro/src/layout.rs +++ b/rmk-macro/src/layout.rs @@ -51,7 +51,7 @@ fn parse_modifiers(modifiers_str: &str) -> (bool, bool, bool, bool, bool){ "LShift" => shift = true, "LCtrl" => ctrl = true, "LAlt" => alt = true, - "Lgui" => gui = true, + "LGui" => gui = true, "RShift" => { right = true; shift = true; @@ -219,52 +219,58 @@ fn parse_key(key: String) -> TokenStream2 { ::rmk::df!(#layer) } } - "MTH(" => { - let keys: Vec<&str> = key - .trim_start_matches("MTH(") - .trim_end_matches(")") - .split_terminator(",") - .map(|w| w.trim()) - .filter(|w| w.len() > 0) - .collect(); - if keys.len() != 2 { - return quote! { - compile_error!("keyboard.toml: MTH(modifiers, key) invalid, please check the documentation: https://haobogu.github.io/rmk/keyboard_configuration.html"); - }; - } - let ident = format_ident!("{}", keys[0].to_string()); - - let (right, gui, alt, shift, ctrl) = parse_modifiers(keys[1]); + "MTH" => { + if let Some(internal) = key.trim_start_matches("MTH(").strip_suffix(")") { + let keys: Vec<&str> = internal + .split_terminator(",") + .map(|w| w.trim()) + .filter(|w| w.len() > 0) + .collect(); + if keys.len() != 2 { + return quote! { + compile_error!("keyboard.toml: MTH(key, modifier) invalid, please check the documentation: https://haobogu.github.io/rmk/keyboard_configuration.html"); + }; + } + let ident = format_ident!("{}", keys[0].to_string()); + let (right, gui, alt, shift, ctrl) = parse_modifiers(keys[1]); - if (gui || alt || shift || ctrl) == false { + if (gui || alt || shift || ctrl) == false { + return quote! { + compile_error!("keyboard.toml: modifier in MTH(key, modifier) is not valid! Please check the documentation: https://haobogu.github.io/rmk/keyboard_configuration.html"); + }; + } + quote! { + ::rmk::mth!(#ident, ::rmk::keycode::ModifierCombination::new_from(#right, #gui, #alt, #shift, #ctrl)) + } + } else { return quote! { - compile_error!("keyboard.toml: modifier in MTH(modifier, key) is not valid! Please check the documentation: https://haobogu.github.io/rmk/keyboard_configuration.html"); + compile_error!("keyboard.toml: MTH(key, modifier) invalid, please check the documentation: https://haobogu.github.io/rmk/keyboard_configuration.html"); }; } - quote! { - ::rmk::mth!(#ident, ::rmk::keycode::ModifierCombination::new_from(#right, #gui, #alt, #shift, #ctrl)) - } - } "TH(" => { - let keys: Vec<&str> = key - .trim_start_matches("TH(") - .trim_end_matches(")") - .split_terminator(",") - .map(|w| w.trim()) - .filter(|w| w.len() > 0) - .collect(); - if keys.len() != 2 { + if let Some(internal) = key.trim_start_matches("TH(").strip_suffix(")") { + let keys: Vec<&str> = internal + .split_terminator(",") + .map(|w| w.trim()) + .filter(|w| w.len() > 0) + .collect(); + if keys.len() != 2 { + return quote! { + compile_error!("keyboard.toml: TH(key_tap, key_hold) invalid, please check the documentation: https://haobogu.github.io/rmk/keyboard_configuration.html"); + }; + } + let ident1 = format_ident!("{}", keys[0].to_string()); + let ident2 = format_ident!("{}", keys[1].to_string()); + + quote! { + ::rmk::th!(#ident1, #ident2) + } + } else { return quote! { - compile_error!("keyboard.toml: TH(modifiers, key) invalid, please check the documentation: https://haobogu.github.io/rmk/keyboard_configuration.html"); + compile_error!("keyboard.toml: TH(key_tap, key_hold) invalid, please check the documentation: https://haobogu.github.io/rmk/keyboard_configuration.html"); }; } - let ident1 = format_ident!("{}", keys[0].to_string()); - let ident2 = format_ident!("{}", keys[1].to_string()); - - quote! { - ::rmk::th!(#ident1, #ident2) - } } _ => { diff --git a/rmk/src/layout_macro.rs b/rmk/src/layout_macro.rs index cb52e863..bf59f59a 100644 --- a/rmk/src/layout_macro.rs +++ b/rmk/src/layout_macro.rs @@ -65,8 +65,8 @@ macro_rules! lt { macro_rules! mth { ($k: ident, $m: expr) => { $crate::action::KeyAction::ModifierTapHold( - $m, $crate::action::Action::Key($crate::keycode::KeyCode::$k), + $m, ) }; } @@ -76,8 +76,8 @@ macro_rules! mth { macro_rules! th { ($t: ident, $h: ident) => { $crate::action::KeyAction::TapHold( - $t, - $h, + $crate::action::Action::Key($crate::keycode::KeyCode::$t), + $crate::action::Action::Key($crate::keycode::KeyCode::$h), ) }; } From 7a87ca79f0fa60aa7bc9467abfc40ddb997f1ddb Mon Sep 17 00:00:00 2001 From: Roberto Previdi Date: Sun, 29 Dec 2024 01:09:42 +0100 Subject: [PATCH 6/7] use MT for modifier tap/hold --- docs/src/keyboard_configuration.md | 2 +- rmk-macro/src/layout.rs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/src/keyboard_configuration.md b/docs/src/keyboard_configuration.md index b3e18a87..6368607e 100644 --- a/docs/src/keyboard_configuration.md +++ b/docs/src/keyboard_configuration.md @@ -154,7 +154,7 @@ The key string should follow several rules: The definitions of those operations are same with QMK, you can found [here](https://docs.qmk.fm/#/feature_layers). If you want other actions, please [fire an issue](https://github.com/HaoboGu/rmk/issues/new). -4. For modifier-tap-hold, use `MTH(key, modifier)` where the modifier can be a chain like explained on point 1. For example for a Home row modifier config you can use `MTH(F,LShift)` +4. For modifier-tap-hold, use `MT(key, modifier)` where the modifier can be a chain like explained on point 1. For example for a Home row modifier config you can use `MT(F,LShift)` 5. For generic key tap-hold, use `TH(key-tap, key-hold)`. diff --git a/rmk-macro/src/layout.rs b/rmk-macro/src/layout.rs index 9005568d..3f2dd0a1 100644 --- a/rmk-macro/src/layout.rs +++ b/rmk-macro/src/layout.rs @@ -219,8 +219,8 @@ fn parse_key(key: String) -> TokenStream2 { ::rmk::df!(#layer) } } - "MTH" => { - if let Some(internal) = key.trim_start_matches("MTH(").strip_suffix(")") { + "MT(" => { + if let Some(internal) = key.trim_start_matches("MT(").strip_suffix(")") { let keys: Vec<&str> = internal .split_terminator(",") .map(|w| w.trim()) @@ -228,7 +228,7 @@ fn parse_key(key: String) -> TokenStream2 { .collect(); if keys.len() != 2 { return quote! { - compile_error!("keyboard.toml: MTH(key, modifier) invalid, please check the documentation: https://haobogu.github.io/rmk/keyboard_configuration.html"); + compile_error!("keyboard.toml: MT(key, modifier) invalid, please check the documentation: https://haobogu.github.io/rmk/keyboard_configuration.html"); }; } let ident = format_ident!("{}", keys[0].to_string()); @@ -236,7 +236,7 @@ fn parse_key(key: String) -> TokenStream2 { if (gui || alt || shift || ctrl) == false { return quote! { - compile_error!("keyboard.toml: modifier in MTH(key, modifier) is not valid! Please check the documentation: https://haobogu.github.io/rmk/keyboard_configuration.html"); + compile_error!("keyboard.toml: modifier in MT(key, modifier) is not valid! Please check the documentation: https://haobogu.github.io/rmk/keyboard_configuration.html"); }; } quote! { @@ -244,7 +244,7 @@ fn parse_key(key: String) -> TokenStream2 { } } else { return quote! { - compile_error!("keyboard.toml: MTH(key, modifier) invalid, please check the documentation: https://haobogu.github.io/rmk/keyboard_configuration.html"); + compile_error!("keyboard.toml: MT(key, modifier) invalid, please check the documentation: https://haobogu.github.io/rmk/keyboard_configuration.html"); }; } } From 7e6e5359bc91236af2a3c4571a92a8facd8c0fbf Mon Sep 17 00:00:00 2001 From: Roberto Previdi Date: Sun, 29 Dec 2024 01:21:34 +0100 Subject: [PATCH 7/7] aggregate tuples in a struct --- rmk-macro/src/layout.rs | 94 +++++++++++++++++++++++++++-------------- 1 file changed, 63 insertions(+), 31 deletions(-) diff --git a/rmk-macro/src/layout.rs b/rmk-macro/src/layout.rs index 3f2dd0a1..68c157e5 100644 --- a/rmk-macro/src/layout.rs +++ b/rmk-macro/src/layout.rs @@ -37,41 +37,73 @@ fn expand_row(row: Vec) -> TokenStream2 { quote! { [#(#keys), *] } } +struct ModifierCombinationMacro { + right: bool, + gui: bool, + alt: bool, + shift: bool, + ctrl: bool, +} +impl ModifierCombinationMacro { + fn new() -> Self { + Self { + right: false, + gui: false, + alt: false, + shift: false, + ctrl: false, + } + } + fn is_empty(&self) -> bool { + !(self.gui || self.alt || self.shift || self.ctrl) + } +} +// Allows to use `#modifiers` in the quote +impl quote::ToTokens for ModifierCombinationMacro { + fn to_tokens(&self, tokens: &mut TokenStream2) { + let right = self.right; + let gui = self.gui; + let alt = self.alt; + let shift = self.shift; + let ctrl = self.ctrl; + + tokens.extend(quote! { + ::rmk::keycode::ModifierCombination::new_from(#right, #gui, #alt, #shift, #ctrl) + }); + } +} + /// Get modifier combination, in types of mod1 | mod2 | ... -fn parse_modifiers(modifiers_str: &str) -> (bool, bool, bool, bool, bool){ - let mut right = false; - let mut gui = false; - let mut alt = false; - let mut shift = false; - let mut ctrl = false; +fn parse_modifiers(modifiers_str: &str) -> ModifierCombinationMacro { + let mut combination = ModifierCombinationMacro::new(); let tokens = modifiers_str.split_terminator("|"); tokens.for_each(|w| { let w = w.trim(); match w { - "LShift" => shift = true, - "LCtrl" => ctrl = true, - "LAlt" => alt = true, - "LGui" => gui = true, + "LShift" => combination.shift = true, + "LCtrl" => combination.ctrl = true, + "LAlt" => combination.alt = true, + "LGui" => combination.gui = true, "RShift" => { - right = true; - shift = true; + combination.right = true; + combination.shift = true; } "RCtrl" => { - right = true; - ctrl = true; + combination.right = true; + combination.ctrl = true; } "RAlt" => { - right = true; - alt = true; + combination.right = true; + combination.alt = true; } "Rgui" => { - right = true; - gui = true; + combination.right = true; + combination.gui = true; } _ => (), } }); - return (right, gui, alt, shift, ctrl); + combination } /// Parse the key string at a single position @@ -100,15 +132,15 @@ fn parse_key(key: String) -> TokenStream2 { let ident = format_ident!("{}", keys[0].to_string()); - let (right, gui, alt, shift, ctrl) = parse_modifiers(keys[1]); + let modifiers = parse_modifiers(keys[1]); - if (gui || alt || shift || ctrl) == false { + if modifiers.is_empty() { return quote! { compile_error!("keyboard.toml: modifier in WM(layer, modifier) is not valid! Please check the documentation: https://haobogu.github.io/rmk/keyboard_configuration.html"); }; } quote! { - ::rmk::wm!(#ident, ::rmk::keycode::ModifierCombination::new_from(#right, #gui, #alt, #shift, #ctrl)) + ::rmk::wm!(#ident, #modifiers) } } else { return quote! { @@ -130,15 +162,15 @@ fn parse_key(key: String) -> TokenStream2 { } "OSM" => { if let Some(internal) = key.trim_start_matches("OSM(").strip_suffix(")") { - let (right, gui, alt, shift, ctrl) = parse_modifiers(internal); + let modifiers = parse_modifiers(internal); - if !(gui || alt || shift || ctrl) { + if modifiers.is_empty() { return quote! { compile_error!("keyboard.toml: modifier in OSM(modifier) is not valid! Please check the documentation: https://haobogu.github.io/rmk/keyboard_configuration.html"); }; } quote! { - ::rmk::osm!(::rmk::keycode::ModifierCombination::new_from(#right, #gui, #alt, #shift, #ctrl)) + ::rmk::osm!(#modifiers) } } else { quote! { @@ -160,15 +192,15 @@ fn parse_key(key: String) -> TokenStream2 { } let layer = keys[0].parse::().unwrap(); - let (right, gui, alt, shift, ctrl) = parse_modifiers(keys[1]); + let modifiers = parse_modifiers(keys[1]); - if (gui || alt || shift || ctrl) == false { + if modifiers.is_empty() { return quote! { compile_error!("keyboard.toml: modifier in LM(layer, modifier) is not valid! Please check the documentation: https://haobogu.github.io/rmk/keyboard_configuration.html"); }; } quote! { - ::rmk::lm!(#layer, ::rmk::keycode::ModifierCombination::new_from(#right, #gui, #alt, #shift, #ctrl)) + ::rmk::lm!(#layer, #modifiers) } } else { return quote! { @@ -232,15 +264,15 @@ fn parse_key(key: String) -> TokenStream2 { }; } let ident = format_ident!("{}", keys[0].to_string()); - let (right, gui, alt, shift, ctrl) = parse_modifiers(keys[1]); + let modifiers = parse_modifiers(keys[1]); - if (gui || alt || shift || ctrl) == false { + if modifiers.is_empty() { return quote! { compile_error!("keyboard.toml: modifier in MT(key, modifier) is not valid! Please check the documentation: https://haobogu.github.io/rmk/keyboard_configuration.html"); }; } quote! { - ::rmk::mth!(#ident, ::rmk::keycode::ModifierCombination::new_from(#right, #gui, #alt, #shift, #ctrl)) + ::rmk::mth!(#ident, #modifiers) } } else { return quote! {