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/lib.rs b/src/lib.rs index 5f65d77..8c00fc9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -256,7 +256,7 @@ impl Keysym { || ucs > 0x10ffff || (ucs & 0xfffe == 0xfffe) { - return NO_SYMBOL; + return Keysym::NoSymbol; } // Search main table. @@ -281,9 +281,6 @@ impl From for u32 { } } -/// The "empty" keyboard symbol. -pub const NO_SYMBOL: Keysym = Keysym(0); - /// Get the keyboard symbol from a keyboard code and its column. /// /// `min_keycode` can be retrieved from the X11 setup, and `keysyms_per_keycode` and `keysyms` can be @@ -317,8 +314,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; } @@ -335,7 +332,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 }); @@ -1262,20 +1259,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); } }