Skip to content

Commit b705222

Browse files
authored
feat: Add Keysym::NoSymbol
* Rename and move NO_SYMBOL to Keysym::NoSymbol * Regenerate the keysyms
1 parent f2f0526 commit b705222

File tree

3 files changed

+45
-22
lines changed

3 files changed

+45
-22
lines changed

keysym-generator/src/main.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ fn main() -> Result<()> {
5757
let outpath = env::args_os().nth(1).expect("output file name");
5858
let mut outfile = BufWriter::new(fs::File::create(outpath)?);
5959

60-
writeln!(
60+
write!(
6161
outfile,
6262
"
6363
// SPDX-License-Identifier: MIT OR Apache-2.0 OR Zlib
@@ -85,19 +85,26 @@ use super::Keysym;
8585
/// A list of raw keyboard symbols.
8686
pub mod key {{
8787
use crate::RawKeysym;
88+
89+
#[doc(alias = \"XK_NoSymbol\")]
90+
pub const NoSymbol: RawKeysym = 0x0;
8891
"
8992
)?;
9093

9194
// Items on the keysym type.
92-
let mut keysym_items = "impl Keysym {\n".to_string();
95+
let mut keysym_items = "impl Keysym {
96+
#[doc(alias = \"XK_NoSymbol\")]
97+
/// The \"empty\" keyboard symbol.
98+
pub const NoSymbol: Keysym = Keysym(key::NoSymbol);\n"
99+
.to_string();
93100

94101
// The matcher for dumping the keysym's name.
95102
let mut keysym_dump = "
96103
#[allow(unreachable_patterns)]
97104
pub(crate) const fn name(keysym: Keysym) -> Option<&'static str> {
98105
match keysym {
99-
"
100-
.to_string();
106+
Keysym::NoSymbol => Some(\"XK_NoSymbol\"),\n"
107+
.to_string();
101108

102109
// we're looking for lines of the following form:
103110
// #define {some prefix}XK_{some key name} {some key code}

src/automatically_generated.rs

+16
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ use super::Keysym;
2525
pub mod key {
2626
use crate::RawKeysym;
2727

28+
#[doc(alias = "XK_NoSymbol")]
29+
pub const NoSymbol: RawKeysym = 0x0;
2830
#[doc(alias = "XK_VoidSymbol")]
2931
pub const VoidSymbol: RawKeysym = 0xffffff;
3032
#[doc(alias = "XK_BackSpace")]
@@ -4735,6 +4737,10 @@ pub mod key {
47354737
pub const XF86_VoiceCommand: RawKeysym = 0x10081246;
47364738
#[doc(alias = "XF86XK_Assistant")]
47374739
pub const XF86_Assistant: RawKeysym = 0x10081247;
4740+
#[doc(alias = "XF86XK_EmojiPicker")]
4741+
pub const XF86_EmojiPicker: RawKeysym = 0x10081249;
4742+
#[doc(alias = "XF86XK_Dictate")]
4743+
pub const XF86_Dictate: RawKeysym = 0x1008124a;
47384744
#[doc(alias = "XF86XK_BrightnessMin")]
47394745
pub const XF86_BrightnessMin: RawKeysym = 0x10081250;
47404746
#[doc(alias = "XF86XK_BrightnessMax")]
@@ -5125,6 +5131,9 @@ pub mod key {
51255131
pub const block: RawKeysym = 0x100000fc;
51265132
}
51275133
impl Keysym {
5134+
#[doc(alias = "XK_NoSymbol")]
5135+
/// The "empty" keyboard symbol.
5136+
pub const NoSymbol: Keysym = Keysym(key::NoSymbol);
51285137
#[doc(alias = "XK_VoidSymbol")]
51295138
pub const VoidSymbol: Keysym = Keysym(key::VoidSymbol);
51305139
#[doc(alias = "XK_BackSpace")]
@@ -9835,6 +9844,10 @@ impl Keysym {
98359844
pub const XF86_VoiceCommand: Keysym = Keysym(key::XF86_VoiceCommand);
98369845
#[doc(alias = "XF86XK_Assistant")]
98379846
pub const XF86_Assistant: Keysym = Keysym(key::XF86_Assistant);
9847+
#[doc(alias = "XF86XK_EmojiPicker")]
9848+
pub const XF86_EmojiPicker: Keysym = Keysym(key::XF86_EmojiPicker);
9849+
#[doc(alias = "XF86XK_Dictate")]
9850+
pub const XF86_Dictate: Keysym = Keysym(key::XF86_Dictate);
98389851
#[doc(alias = "XF86XK_BrightnessMin")]
98399852
pub const XF86_BrightnessMin: Keysym = Keysym(key::XF86_BrightnessMin);
98409853
#[doc(alias = "XF86XK_BrightnessMax")]
@@ -10229,6 +10242,7 @@ impl Keysym {
1022910242
#[allow(unreachable_patterns)]
1023010243
pub(crate) const fn name(keysym: Keysym) -> Option<&'static str> {
1023110244
match keysym {
10245+
Keysym::NoSymbol => Some("XK_NoSymbol"),
1023210246
Keysym::VoidSymbol => Some("XK_VoidSymbol"),
1023310247
Keysym::BackSpace => Some("XK_BackSpace"),
1023410248
Keysym::Tab => Some("XK_Tab"),
@@ -12584,6 +12598,8 @@ pub(crate) const fn name(keysym: Keysym) -> Option<&'static str> {
1258412598
Keysym::XF86_Screensaver => Some("XF86XK_Screensaver"),
1258512599
Keysym::XF86_VoiceCommand => Some("XF86XK_VoiceCommand"),
1258612600
Keysym::XF86_Assistant => Some("XF86XK_Assistant"),
12601+
Keysym::XF86_EmojiPicker => Some("XF86XK_EmojiPicker"),
12602+
Keysym::XF86_Dictate => Some("XF86XK_Dictate"),
1258712603
Keysym::XF86_BrightnessMin => Some("XF86XK_BrightnessMin"),
1258812604
Keysym::XF86_BrightnessMax => Some("XF86XK_BrightnessMax"),
1258912605
Keysym::XF86_KbdInputAssistPrev => Some("XF86XK_KbdInputAssistPrev"),

src/lib.rs

+18-18
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ impl Keysym {
257257
|| ucs > 0x10ffff
258258
|| (ucs & 0xfffe == 0xfffe)
259259
{
260-
return NO_SYMBOL;
260+
return Keysym::NoSymbol;
261261
}
262262

263263
// Search main table.
@@ -283,7 +283,7 @@ impl From<Keysym> for u32 {
283283
}
284284

285285
/// The "empty" keyboard symbol.
286-
pub const NO_SYMBOL: Keysym = Keysym(0);
286+
pub const NO_SYMBOL: Keysym = Keysym::NoSymbol;
287287

288288
/// Get the keyboard symbol from a keyboard code and its column.
289289
///
@@ -318,8 +318,8 @@ pub fn keysym(
318318
break;
319319
}
320320

321-
// If the keysym we're looking at isn't NO_SYMBOL, we're done.
322-
if keysyms[per - 1] != NO_SYMBOL.0 {
321+
// If the keysym we're looking at isn't NoSymbol, we're done.
322+
if keysyms[per - 1] != Keysym::NoSymbol.0 {
323323
break;
324324
}
325325

@@ -336,7 +336,7 @@ pub fn keysym(
336336

337337
// Convert to upper/lower ourselves if the keysym doesn't support it.
338338
let alt_column = (column | 1) as usize;
339-
if per <= alt_column || keysyms[alt_column] == NO_SYMBOL.0 {
339+
if per <= alt_column || keysyms[alt_column] == Keysym::NoSymbol.0 {
340340
// Convert to upper/lower case.
341341
let (upper, lower) = convert_case(Keysym(*keysyms.get(column as usize & !1)?));
342342
return Some(if column & 1 == 0 { upper } else { lower });
@@ -1263,20 +1263,20 @@ mod tests {
12631263
// Unicode non-characters.
12641264

12651265
// rust doesn't allow building the char from the surrogates.
1266-
// assert_eq!(Keysym::from_char('\u{d800}'), NO_SYMBOL)); // Unicode surrogates
1267-
// assert_eq!(Keysym::from_char('\u{dfff}'), NO_SYMBOL)); // Unicode surrogates
1268-
1269-
assert_eq!(Keysym::from_char('\u{fdd0}'), NO_SYMBOL);
1270-
assert_eq!(Keysym::from_char('\u{fdef}'), NO_SYMBOL);
1271-
assert_eq!(Keysym::from_char('\u{fffe}'), NO_SYMBOL);
1272-
assert_eq!(Keysym::from_char('\u{ffff}'), NO_SYMBOL);
1273-
assert_eq!(Keysym::from_char('\u{7fffe}'), NO_SYMBOL);
1274-
assert_eq!(Keysym::from_char('\u{7ffff}'), NO_SYMBOL);
1275-
assert_eq!(Keysym::from_char('\u{afffe}'), NO_SYMBOL);
1276-
assert_eq!(Keysym::from_char('\u{affff}'), NO_SYMBOL);
1266+
// assert_eq!(Keysym::from_char('\u{d800}'), Keysym::NoSymbol)); // Unicode surrogates
1267+
// assert_eq!(Keysym::from_char('\u{dfff}'), Keysym::NoSymbol)); // Unicode surrogates
1268+
1269+
assert_eq!(Keysym::from_char('\u{fdd0}'), Keysym::NoSymbol);
1270+
assert_eq!(Keysym::from_char('\u{fdef}'), Keysym::NoSymbol);
1271+
assert_eq!(Keysym::from_char('\u{fffe}'), Keysym::NoSymbol);
1272+
assert_eq!(Keysym::from_char('\u{ffff}'), Keysym::NoSymbol);
1273+
assert_eq!(Keysym::from_char('\u{7fffe}'), Keysym::NoSymbol);
1274+
assert_eq!(Keysym::from_char('\u{7ffff}'), Keysym::NoSymbol);
1275+
assert_eq!(Keysym::from_char('\u{afffe}'), Keysym::NoSymbol);
1276+
assert_eq!(Keysym::from_char('\u{affff}'), Keysym::NoSymbol);
12771277

12781278
// Rust doesn't allow codepoints outside the Unicode planes for char.
1279-
// assert_eq!(Keysym::from_char('\u{110000}', NO_SYMBOL);
1280-
// assert_eq!(Keysym::from_char('\u{deadbeef}', NO_SYMBOL);
1279+
// assert_eq!(Keysym::from_char('\u{110000}', Keysym::NoSymbol);
1280+
// assert_eq!(Keysym::from_char('\u{deadbeef}', Keysym::NoSymbol);
12811281
}
12821282
}

0 commit comments

Comments
 (0)