Skip to content

Commit

Permalink
feat: Add Keysym::NoSymbol
Browse files Browse the repository at this point in the history
* Rename and move NO_SYMBOL to Keysym::NoSymbol

* Regenerate the keysyms
  • Loading branch information
pentamassiv authored Oct 22, 2023
1 parent f2f0526 commit b705222
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 22 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
16 changes: 16 additions & 0 deletions src/automatically_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -4735,6 +4737,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")]
Expand Down Expand Up @@ -5125,6 +5131,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")]
Expand Down Expand Up @@ -9835,6 +9844,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")]
Expand Down Expand Up @@ -10229,6 +10242,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"),
Expand Down Expand Up @@ -12584,6 +12598,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"),
Expand Down
36 changes: 18 additions & 18 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ impl Keysym {
|| ucs > 0x10ffff
|| (ucs & 0xfffe == 0xfffe)
{
return NO_SYMBOL;
return Keysym::NoSymbol;
}

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

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

0 comments on commit b705222

Please sign in to comment.