From c3f2d3deb9849c40b83266fe700095109728fc7a Mon Sep 17 00:00:00 2001 From: pentamassiv <91755244+pentamassiv@users.noreply.github.com> Date: Mon, 23 Oct 2023 00:14:15 +0200 Subject: [PATCH] feat: Add Keysym::NoSymbol * Rename and move NO_SYMBOL to Keysym::NoSymbol * Regenerate the keysyms --- keysym-generator/src/main.rs | 15 ++++++--- src/automatically_generated.rs | 61 +++++++++++++++++++++++----------- src/lib.rs | 36 ++++++++++---------- 3 files changed, 70 insertions(+), 42 deletions(-) diff --git a/keysym-generator/src/main.rs b/keysym-generator/src/main.rs index 0afea39..93be541 100644 --- a/keysym-generator/src/main.rs +++ b/keysym-generator/src/main.rs @@ -57,7 +57,7 @@ fn main() -> Result<()> { let outpath = env::args_os().nth(1).expect("output file name"); let mut outfile = BufWriter::new(fs::File::create(outpath)?); - writeln!( + write!( outfile, " // SPDX-License-Identifier: MIT OR Apache-2.0 OR Zlib @@ -85,19 +85,26 @@ use super::Keysym; /// A list of raw keyboard symbols. pub mod key {{ use crate::RawKeysym; + + #[doc(alias = \"XK_NoSymbol\")] + pub const NoSymbol: RawKeysym = 0x0; " )?; // Items on the keysym type. - let mut keysym_items = "impl Keysym {\n".to_string(); + let mut keysym_items = "impl Keysym { + #[doc(alias = \"XK_NoSymbol\")] + /// The \"empty\" keyboard symbol. + pub const NoSymbol: Keysym = Keysym(key::NoSymbol);\n" + .to_string(); // The matcher for dumping the keysym's name. let mut keysym_dump = " #[allow(unreachable_patterns)] pub(crate) const fn name(keysym: Keysym) -> Option<&'static str> { match keysym { -" - .to_string(); + Keysym::NoSymbol => Some(\"XK_NoSymbol\"),\n" + .to_string(); // we're looking for lines of the following form: // #define {some prefix}XK_{some key name} {some key code} diff --git a/src/automatically_generated.rs b/src/automatically_generated.rs index 0500fb2..95930ea 100644 --- a/src/automatically_generated.rs +++ b/src/automatically_generated.rs @@ -25,6 +25,8 @@ use super::Keysym; pub mod key { use crate::RawKeysym; + #[doc(alias = "XK_NoSymbol")] + pub const NoSymbol: RawKeysym = 0x0; #[doc(alias = "XK_VoidSymbol")] pub const VoidSymbol: RawKeysym = 0xffffff; #[doc(alias = "XK_BackSpace")] @@ -519,14 +521,6 @@ pub mod key { pub const dead_belowcomma: RawKeysym = 0xfe6e; #[doc(alias = "XK_dead_currency")] pub const dead_currency: RawKeysym = 0xfe6f; - #[doc(alias = "XK_dead_lowline")] - pub const dead_lowline: RawKeysym = 0xfe90; - #[doc(alias = "XK_dead_aboveverticalline")] - pub const dead_aboveverticalline: RawKeysym = 0xfe91; - #[doc(alias = "XK_dead_belowverticalline")] - pub const dead_belowverticalline: RawKeysym = 0xfe92; - #[doc(alias = "XK_dead_longsolidusoverlay")] - pub const dead_longsolidusoverlay: RawKeysym = 0xfe93; #[doc(alias = "XK_dead_a")] pub const dead_a: RawKeysym = 0xfe80; #[doc(alias = "XK_dead_A")] @@ -547,6 +541,10 @@ pub mod key { pub const dead_u: RawKeysym = 0xfe88; #[doc(alias = "XK_dead_U")] pub const dead_U: RawKeysym = 0xfe89; + #[doc(alias = "XK_dead_schwa")] + pub const dead_schwa: RawKeysym = 0xfe8a; + #[doc(alias = "XK_dead_SCHWA")] + pub const dead_SCHWA: RawKeysym = 0xfe8b; #[doc(alias = "XK_dead_small_schwa")] pub const dead_small_schwa: RawKeysym = 0xfe8a; #[doc(alias = "XK_dead_capital_schwa")] @@ -933,6 +931,8 @@ pub mod key { pub const copyright: RawKeysym = 0xa9; #[doc(alias = "XK_ordfeminine")] pub const ordfeminine: RawKeysym = 0xaa; + #[doc(alias = "XK_guillemetleft")] + pub const guillemetleft: RawKeysym = 0xab; #[doc(alias = "XK_guillemotleft")] pub const guillemotleft: RawKeysym = 0xab; #[doc(alias = "XK_notsign")] @@ -963,8 +963,12 @@ pub mod key { pub const cedilla: RawKeysym = 0xb8; #[doc(alias = "XK_onesuperior")] pub const onesuperior: RawKeysym = 0xb9; + #[doc(alias = "XK_ordmasculine")] + pub const ordmasculine: RawKeysym = 0xba; #[doc(alias = "XK_masculine")] pub const masculine: RawKeysym = 0xba; + #[doc(alias = "XK_guillemetright")] + pub const guillemetright: RawKeysym = 0xbb; #[doc(alias = "XK_guillemotright")] pub const guillemotright: RawKeysym = 0xbb; #[doc(alias = "XK_onequarter")] @@ -4735,6 +4739,10 @@ pub mod key { pub const XF86_VoiceCommand: RawKeysym = 0x10081246; #[doc(alias = "XF86XK_Assistant")] pub const XF86_Assistant: RawKeysym = 0x10081247; + #[doc(alias = "XF86XK_EmojiPicker")] + pub const XF86_EmojiPicker: RawKeysym = 0x10081249; + #[doc(alias = "XF86XK_Dictate")] + pub const XF86_Dictate: RawKeysym = 0x1008124a; #[doc(alias = "XF86XK_BrightnessMin")] pub const XF86_BrightnessMin: RawKeysym = 0x10081250; #[doc(alias = "XF86XK_BrightnessMax")] @@ -5125,6 +5133,9 @@ pub mod key { pub const block: RawKeysym = 0x100000fc; } impl Keysym { + #[doc(alias = "XK_NoSymbol")] + /// The "empty" keyboard symbol. + pub const NoSymbol: Keysym = Keysym(key::NoSymbol); #[doc(alias = "XK_VoidSymbol")] pub const VoidSymbol: Keysym = Keysym(key::VoidSymbol); #[doc(alias = "XK_BackSpace")] @@ -5619,14 +5630,6 @@ impl Keysym { pub const dead_belowcomma: Keysym = Keysym(key::dead_belowcomma); #[doc(alias = "XK_dead_currency")] pub const dead_currency: Keysym = Keysym(key::dead_currency); - #[doc(alias = "XK_dead_lowline")] - pub const dead_lowline: Keysym = Keysym(key::dead_lowline); - #[doc(alias = "XK_dead_aboveverticalline")] - pub const dead_aboveverticalline: Keysym = Keysym(key::dead_aboveverticalline); - #[doc(alias = "XK_dead_belowverticalline")] - pub const dead_belowverticalline: Keysym = Keysym(key::dead_belowverticalline); - #[doc(alias = "XK_dead_longsolidusoverlay")] - pub const dead_longsolidusoverlay: Keysym = Keysym(key::dead_longsolidusoverlay); #[doc(alias = "XK_dead_a")] pub const dead_a: Keysym = Keysym(key::dead_a); #[doc(alias = "XK_dead_A")] @@ -5647,6 +5650,10 @@ impl Keysym { pub const dead_u: Keysym = Keysym(key::dead_u); #[doc(alias = "XK_dead_U")] pub const dead_U: Keysym = Keysym(key::dead_U); + #[doc(alias = "XK_dead_schwa")] + pub const dead_schwa: Keysym = Keysym(key::dead_schwa); + #[doc(alias = "XK_dead_SCHWA")] + pub const dead_SCHWA: Keysym = Keysym(key::dead_SCHWA); #[doc(alias = "XK_dead_small_schwa")] pub const dead_small_schwa: Keysym = Keysym(key::dead_small_schwa); #[doc(alias = "XK_dead_capital_schwa")] @@ -6033,6 +6040,8 @@ impl Keysym { pub const copyright: Keysym = Keysym(key::copyright); #[doc(alias = "XK_ordfeminine")] pub const ordfeminine: Keysym = Keysym(key::ordfeminine); + #[doc(alias = "XK_guillemetleft")] + pub const guillemetleft: Keysym = Keysym(key::guillemetleft); #[doc(alias = "XK_guillemotleft")] pub const guillemotleft: Keysym = Keysym(key::guillemotleft); #[doc(alias = "XK_notsign")] @@ -6063,8 +6072,12 @@ impl Keysym { pub const cedilla: Keysym = Keysym(key::cedilla); #[doc(alias = "XK_onesuperior")] pub const onesuperior: Keysym = Keysym(key::onesuperior); + #[doc(alias = "XK_ordmasculine")] + pub const ordmasculine: Keysym = Keysym(key::ordmasculine); #[doc(alias = "XK_masculine")] pub const masculine: Keysym = Keysym(key::masculine); + #[doc(alias = "XK_guillemetright")] + pub const guillemetright: Keysym = Keysym(key::guillemetright); #[doc(alias = "XK_guillemotright")] pub const guillemotright: Keysym = Keysym(key::guillemotright); #[doc(alias = "XK_onequarter")] @@ -9835,6 +9848,10 @@ impl Keysym { pub const XF86_VoiceCommand: Keysym = Keysym(key::XF86_VoiceCommand); #[doc(alias = "XF86XK_Assistant")] pub const XF86_Assistant: Keysym = Keysym(key::XF86_Assistant); + #[doc(alias = "XF86XK_EmojiPicker")] + pub const XF86_EmojiPicker: Keysym = Keysym(key::XF86_EmojiPicker); + #[doc(alias = "XF86XK_Dictate")] + pub const XF86_Dictate: Keysym = Keysym(key::XF86_Dictate); #[doc(alias = "XF86XK_BrightnessMin")] pub const XF86_BrightnessMin: Keysym = Keysym(key::XF86_BrightnessMin); #[doc(alias = "XF86XK_BrightnessMax")] @@ -10229,6 +10246,7 @@ impl Keysym { #[allow(unreachable_patterns)] pub(crate) const fn name(keysym: Keysym) -> Option<&'static str> { match keysym { + Keysym::NoSymbol => Some("XK_NoSymbol"), Keysym::VoidSymbol => Some("XK_VoidSymbol"), Keysym::BackSpace => Some("XK_BackSpace"), Keysym::Tab => Some("XK_Tab"), @@ -10476,10 +10494,6 @@ pub(crate) const fn name(keysym: Keysym) -> Option<&'static str> { Keysym::dead_invertedbreve => Some("XK_dead_invertedbreve"), Keysym::dead_belowcomma => Some("XK_dead_belowcomma"), Keysym::dead_currency => Some("XK_dead_currency"), - Keysym::dead_lowline => Some("XK_dead_lowline"), - Keysym::dead_aboveverticalline => Some("XK_dead_aboveverticalline"), - Keysym::dead_belowverticalline => Some("XK_dead_belowverticalline"), - Keysym::dead_longsolidusoverlay => Some("XK_dead_longsolidusoverlay"), Keysym::dead_a => Some("XK_dead_a"), Keysym::dead_A => Some("XK_dead_A"), Keysym::dead_e => Some("XK_dead_e"), @@ -10490,6 +10504,8 @@ pub(crate) const fn name(keysym: Keysym) -> Option<&'static str> { Keysym::dead_O => Some("XK_dead_O"), Keysym::dead_u => Some("XK_dead_u"), Keysym::dead_U => Some("XK_dead_U"), + Keysym::dead_schwa => Some("XK_dead_schwa"), + Keysym::dead_SCHWA => Some("XK_dead_SCHWA"), Keysym::dead_small_schwa => Some("XK_dead_small_schwa"), Keysym::dead_capital_schwa => Some("XK_dead_capital_schwa"), Keysym::dead_greek => Some("XK_dead_greek"), @@ -10683,6 +10699,7 @@ pub(crate) const fn name(keysym: Keysym) -> Option<&'static str> { Keysym::diaeresis => Some("XK_diaeresis"), Keysym::copyright => Some("XK_copyright"), Keysym::ordfeminine => Some("XK_ordfeminine"), + Keysym::guillemetleft => Some("XK_guillemetleft"), Keysym::guillemotleft => Some("XK_guillemotleft"), Keysym::notsign => Some("XK_notsign"), Keysym::hyphen => Some("XK_hyphen"), @@ -10698,7 +10715,9 @@ pub(crate) const fn name(keysym: Keysym) -> Option<&'static str> { Keysym::periodcentered => Some("XK_periodcentered"), Keysym::cedilla => Some("XK_cedilla"), Keysym::onesuperior => Some("XK_onesuperior"), + Keysym::ordmasculine => Some("XK_ordmasculine"), Keysym::masculine => Some("XK_masculine"), + Keysym::guillemetright => Some("XK_guillemetright"), Keysym::guillemotright => Some("XK_guillemotright"), Keysym::onequarter => Some("XK_onequarter"), Keysym::onehalf => Some("XK_onehalf"), @@ -12584,6 +12603,8 @@ pub(crate) const fn name(keysym: Keysym) -> Option<&'static str> { Keysym::XF86_Screensaver => Some("XF86XK_Screensaver"), Keysym::XF86_VoiceCommand => Some("XF86XK_VoiceCommand"), Keysym::XF86_Assistant => Some("XF86XK_Assistant"), + Keysym::XF86_EmojiPicker => Some("XF86XK_EmojiPicker"), + Keysym::XF86_Dictate => Some("XF86XK_Dictate"), Keysym::XF86_BrightnessMin => Some("XF86XK_BrightnessMin"), Keysym::XF86_BrightnessMax => Some("XF86XK_BrightnessMax"), Keysym::XF86_KbdInputAssistPrev => Some("XF86XK_KbdInputAssistPrev"), diff --git a/src/lib.rs b/src/lib.rs index 4f701a1..3338108 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -257,7 +257,7 @@ impl Keysym { || ucs > 0x10ffff || (ucs & 0xfffe == 0xfffe) { - return NO_SYMBOL; + return Keysym::NoSymbol; } // Search main table. @@ -283,7 +283,7 @@ impl From for u32 { } /// The "empty" keyboard symbol. -pub const NO_SYMBOL: Keysym = Keysym(0); +pub const NO_SYMBOL: Keysym = Keysym::NoSymbol; /// Get the keyboard symbol from a keyboard code and its column. /// @@ -318,8 +318,8 @@ pub fn keysym( break; } - // If the keysym we're looking at isn't NO_SYMBOL, we're done. - if keysyms[per - 1] != NO_SYMBOL.0 { + // If the keysym we're looking at isn't NoSymbol, we're done. + if keysyms[per - 1] != Keysym::NoSymbol.0 { break; } @@ -336,7 +336,7 @@ pub fn keysym( // Convert to upper/lower ourselves if the keysym doesn't support it. let alt_column = (column | 1) as usize; - if per <= alt_column || keysyms[alt_column] == NO_SYMBOL.0 { + if per <= alt_column || keysyms[alt_column] == Keysym::NoSymbol.0 { // Convert to upper/lower case. let (upper, lower) = convert_case(Keysym(*keysyms.get(column as usize & !1)?)); return Some(if column & 1 == 0 { upper } else { lower }); @@ -1263,20 +1263,20 @@ mod tests { // Unicode non-characters. // rust doesn't allow building the char from the surrogates. - // assert_eq!(Keysym::from_char('\u{d800}'), NO_SYMBOL)); // Unicode surrogates - // assert_eq!(Keysym::from_char('\u{dfff}'), NO_SYMBOL)); // Unicode surrogates - - assert_eq!(Keysym::from_char('\u{fdd0}'), NO_SYMBOL); - assert_eq!(Keysym::from_char('\u{fdef}'), NO_SYMBOL); - assert_eq!(Keysym::from_char('\u{fffe}'), NO_SYMBOL); - assert_eq!(Keysym::from_char('\u{ffff}'), NO_SYMBOL); - assert_eq!(Keysym::from_char('\u{7fffe}'), NO_SYMBOL); - assert_eq!(Keysym::from_char('\u{7ffff}'), NO_SYMBOL); - assert_eq!(Keysym::from_char('\u{afffe}'), NO_SYMBOL); - assert_eq!(Keysym::from_char('\u{affff}'), NO_SYMBOL); + // assert_eq!(Keysym::from_char('\u{d800}'), Keysym::NoSymbol)); // Unicode surrogates + // assert_eq!(Keysym::from_char('\u{dfff}'), Keysym::NoSymbol)); // Unicode surrogates + + assert_eq!(Keysym::from_char('\u{fdd0}'), Keysym::NoSymbol); + assert_eq!(Keysym::from_char('\u{fdef}'), Keysym::NoSymbol); + assert_eq!(Keysym::from_char('\u{fffe}'), Keysym::NoSymbol); + assert_eq!(Keysym::from_char('\u{ffff}'), Keysym::NoSymbol); + assert_eq!(Keysym::from_char('\u{7fffe}'), Keysym::NoSymbol); + assert_eq!(Keysym::from_char('\u{7ffff}'), Keysym::NoSymbol); + assert_eq!(Keysym::from_char('\u{afffe}'), Keysym::NoSymbol); + assert_eq!(Keysym::from_char('\u{affff}'), Keysym::NoSymbol); // Rust doesn't allow codepoints outside the Unicode planes for char. - // assert_eq!(Keysym::from_char('\u{110000}', NO_SYMBOL); - // assert_eq!(Keysym::from_char('\u{deadbeef}', NO_SYMBOL); + // assert_eq!(Keysym::from_char('\u{110000}', Keysym::NoSymbol); + // assert_eq!(Keysym::from_char('\u{deadbeef}', Keysym::NoSymbol); } }