use is_immutable_key again

This commit is contained in:
Junkui Zhang
2025-05-06 19:22:28 +08:00
parent d37b7f5d21
commit cb893ccd84
2 changed files with 64 additions and 9 deletions

View File

@@ -61,7 +61,7 @@ impl PlatformKeyboardMapper for LinuxKeyboardMapper {
}
fn get_shifted_key(&self, key: &str) -> anyhow::Result<Option<String>> {
if key.chars().count() != 1 {
if is_immutable_key(key) {
return Ok(None);
}
if is_alphabetic_key(key) {
@@ -183,6 +183,68 @@ const TYPEABLE_CODES: &[u32] = &[
0x003d, // / Slash
];
#[cfg(any(feature = "wayland", feature = "x11"))]
fn is_immutable_key(key: &str) -> bool {
matches!(
key,
"f1" | "f2"
| "f3"
| "f4"
| "f5"
| "f6"
| "f7"
| "f8"
| "f9"
| "f10"
| "f11"
| "f12"
| "f13"
| "f14"
| "f15"
| "f16"
| "f17"
| "f18"
| "f19"
| "f20"
| "f21"
| "f22"
| "f23"
| "f24"
| "backspace"
| "delete"
| "left"
| "right"
| "up"
| "down"
| "pageup"
| "pagedown"
| "insert"
| "home"
| "end"
| "back"
| "forward"
| "escape"
| "space"
| "tab"
| "enter"
| "shift"
| "control"
| "alt"
| "platform"
| "cmd"
| "super"
| "win"
| "fn"
| "menu"
| "copy"
| "paste"
| "cut"
| "find"
| "open"
| "save"
)
}
#[cfg(any(feature = "wayland", feature = "x11"))]
fn get_scan_code(scan_code: ScanCode) -> Option<u32> {
// https://github.com/microsoft/node-native-keymap/blob/main/deps/chromium/dom_code_data.inc

View File

@@ -140,14 +140,7 @@ impl<P: LinuxClient + 'static> Platform for P {
}
fn keyboard_mapper(&self) -> Box<dyn PlatformKeyboardMapper> {
#[cfg(any(feature = "wayland", feature = "x11"))]
{
Box::new(super::LinuxKeyboardMapper::new())
}
#[cfg(not(any(feature = "wayland", feature = "x11")))]
{
Box::new(crate::EmptyKeyboardMapper)
}
Box::new(super::LinuxKeyboardMapper::new())
}
fn keyboard_layout(&self) -> Box<dyn PlatformKeyboardLayout> {