Skip to content

Commit 787e3db

Browse files
authored
Align the debug output with what libxkbcommon does
The documentation of libxkbcommon says: "Any Unicode/ISO 10646 character in the range U+0100 to U+10FFFF can be represented by a keysym value in the range 0x01000100 to 0x0110FFFF. The name of Unicode keysyms is U<codepoint>, e.g. UA1B2. The name of other unnamed keysyms is the hexadecimal representation of their value, e.g. 0xabcd1234"
1 parent 77596eb commit 787e3db

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ impl fmt::Debug for Keysym {
111111
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
112112
match self.name() {
113113
Some(name) => f.write_str(name),
114+
None if (0x0100_0100..=0x0110_FFFF).contains(&keysym.raw()) => {
115+
// strip the 0x01000000 prefix
116+
let codepoint = self.0 & 0x00FF_FFFF;
117+
// Uppercase hex, no leading zeros: e.g. "UA1B2"
118+
format!("U{:X}", codepoint)
119+
}
114120
None => write!(f, "{:#x}", self.0),
115121
}
116122
}

0 commit comments

Comments
 (0)