Skip to content

Commit

Permalink
Rename and move NO_SYMBOL to Keysym::NoSymbol
Browse files Browse the repository at this point in the history
  • Loading branch information
pentamassiv committed Oct 5, 2023
1 parent 060e9e4 commit cf18479
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
15 changes: 11 additions & 4 deletions keysym-generator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand Down
37 changes: 17 additions & 20 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ impl Keysym {
|| ucs > 0x10ffff
|| (ucs & 0xfffe == 0xfffe)
{
return NO_SYMBOL;
return Keysym::NoSymbol;
}

// Search main table.
Expand All @@ -281,9 +281,6 @@ impl From<Keysym> 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
Expand Down Expand Up @@ -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;
}

Expand All @@ -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 });
Expand Down Expand Up @@ -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);
}
}

0 comments on commit cf18479

Please sign in to comment.