1use collections::HashMap;
2
3use crate::{KeybindingKeystroke, Keystroke};
4
5/// A trait for platform-specific keyboard layouts
6pub trait PlatformKeyboardLayout {
7 /// Get the keyboard layout ID, which should be unique to the layout
8 fn id(&self) -> &str;
9 /// Get the keyboard layout display name
10 fn name(&self) -> &str;
11}
12
13/// A trait for platform-specific keyboard mappings
14pub trait PlatformKeyboardMapper {
15 /// Map a key equivalent to its platform-specific representation
16 fn map_key_equivalent(
17 &self,
18 keystroke: Keystroke,
19 use_key_equivalents: bool,
20 ) -> KeybindingKeystroke;
21 /// Get the key equivalents for the current keyboard layout,
22 /// only used on macOS
23 fn get_key_equivalents(&self) -> Option<&HashMap<char, char>>;
24}
25
26/// A dummy implementation of the platform keyboard mapper
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}