Skip to main content

gpui_platform/
keyboard.rs

1//! Platform keyboard traits and implementations.
2
3use collections::HashMap;
4use gpui_types::{KeybindingKeystroke, Keystroke};
5
6/// A trait for platform-specific keyboard layouts
7pub trait PlatformKeyboardLayout {
8    /// Get the keyboard layout ID, which should be unique to the layout
9    fn id(&self) -> &str;
10    /// Get the keyboard layout display name
11    fn name(&self) -> &str;
12}
13
14/// A trait for platform-specific keyboard mappings
15pub trait PlatformKeyboardMapper {
16    /// Map a key equivalent to its platform-specific representation
17    fn map_key_equivalent(
18        &self,
19        keystroke: Keystroke,
20        use_key_equivalents: bool,
21    ) -> KeybindingKeystroke;
22    /// Get the key equivalents for the current keyboard layout,
23    /// only used on macOS
24    fn get_key_equivalents(&self) -> Option<&HashMap<char, char>>;
25}
26
27/// A dummy implementation of the platform keyboard mapper
28pub struct DummyKeyboardMapper;
29
30impl PlatformKeyboardMapper for DummyKeyboardMapper {
31    fn map_key_equivalent(
32        &self,
33        keystroke: Keystroke,
34        _use_key_equivalents: bool,
35    ) -> KeybindingKeystroke {
36        KeybindingKeystroke::from_keystroke(keystroke)
37    }
38
39    fn get_key_equivalents(&self) -> Option<&HashMap<char, char>> {
40        None
41    }
42}