Skip to main content

rgpui/platform/
keyboard.rs

1use crate::collections::HashMap;
2
3use crate::{KeybindingKeystroke, Keystroke};
4
5/// 平台特定键盘布局的 trait
6pub trait PlatformKeyboardLayout {
7    /// 获取键盘布局 ID,该 ID 对布局应该是唯一的
8    fn id(&self) -> &str;
9    /// 获取键盘布局显示名称
10    fn name(&self) -> &str;
11}
12
13/// 平台特定键盘映射的 trait
14pub trait PlatformKeyboardMapper {
15    /// 将按键等效映射为平台特定的表示
16    fn map_key_equivalent(
17        &self,
18        keystroke: Keystroke,
19        use_key_equivalents: bool,
20    ) -> KeybindingKeystroke;
21    /// 获取当前键盘布局的按键等效映射,
22    /// 仅在 macOS 上使用
23    fn get_key_equivalents(&self) -> Option<&HashMap<char, char>>;
24}
25
26/// 平台键盘映射器的虚拟实现
27pub struct DummyKeyboardMapper;
28
29impl PlatformKeyboardMapper for DummyKeyboardMapper {
30    fn map_key_equivalent(
31        &self,
32        keystroke: Keystroke,
33        _use_key_equivalents: bool,
34    ) -> KeybindingKeystroke {
35        KeybindingKeystroke::from_keystroke(keystroke)
36    }
37
38    fn get_key_equivalents(&self) -> Option<&HashMap<char, char>> {
39        None
40    }
41}