smart_keymap/key/composite/
base.rs1use core::fmt::Debug;
2
3#[cfg(feature = "std")]
4use serde::Deserialize;
5
6use crate::key;
7
8use key::callback;
9use key::caps_word;
10use key::custom;
11use key::keyboard;
12use key::layered;
13use key::sticky;
14
15use super::{Context, Event, KeyState, PendingKeyState, PressedKeyResult};
16
17#[derive(Debug, Clone, Copy, PartialEq)]
19#[cfg_attr(feature = "std", derive(Deserialize))]
20#[cfg_attr(feature = "std", serde(untagged))]
21pub enum BaseKey {
22 LayerModifier(layered::ModifierKey),
24 Callback(callback::Key),
26 CapsWord(caps_word::Key),
28 Sticky(sticky::Key),
30 Keyboard(keyboard::Key),
32 Custom(custom::Key),
34}
35
36impl key::Key for BaseKey {
37 type Context = Context;
38 type Event = Event;
39 type PendingKeyState = PendingKeyState;
40 type KeyState = KeyState;
41
42 fn new_pressed_key(
43 &self,
44 context: &Self::Context,
45 key_path: key::KeyPath,
46 ) -> (PressedKeyResult, key::KeyEvents<Self::Event>) {
47 match self {
48 BaseKey::Keyboard(key) => key::Key::new_pressed_key(key, context, key_path),
49 BaseKey::LayerModifier(key) => key::Key::new_pressed_key(key, context, key_path),
50 BaseKey::Callback(key) => key::Key::new_pressed_key(key, context, key_path),
51 BaseKey::CapsWord(key) => key::Key::new_pressed_key(key, context, key_path),
52 BaseKey::Custom(key) => key::Key::new_pressed_key(key, context, key_path),
53 BaseKey::Sticky(key) => key::Key::new_pressed_key(key, context, key_path),
54 }
55 }
56
57 fn handle_event(
58 &self,
59 _pending_state: &mut Self::PendingKeyState,
60 _context: &Self::Context,
61 _key_path: key::KeyPath,
62 _event: key::Event<Self::Event>,
63 ) -> (Option<key::NewPressedKey>, key::KeyEvents<Self::Event>) {
64 panic!()
65 }
66
67 fn lookup(
68 &self,
69 _path: &[u16],
70 ) -> &dyn key::Key<
71 Context = Self::Context,
72 Event = Self::Event,
73 PendingKeyState = Self::PendingKeyState,
74 KeyState = Self::KeyState,
75 > {
76 self
77 }
78}
79
80impl From<keyboard::Key> for BaseKey {
81 fn from(key: keyboard::Key) -> Self {
82 BaseKey::Keyboard(key)
83 }
84}
85
86impl From<layered::ModifierKey> for BaseKey {
87 fn from(key: layered::ModifierKey) -> Self {
88 BaseKey::LayerModifier(key)
89 }
90}
91
92impl From<callback::Key> for BaseKey {
93 fn from(key: callback::Key) -> Self {
94 BaseKey::Callback(key)
95 }
96}
97
98impl From<caps_word::Key> for BaseKey {
99 fn from(key: caps_word::Key) -> Self {
100 BaseKey::CapsWord(key)
101 }
102}
103
104impl From<custom::Key> for BaseKey {
105 fn from(key: custom::Key) -> Self {
106 BaseKey::Custom(key)
107 }
108}
109
110impl From<sticky::Key> for BaseKey {
111 fn from(key: sticky::Key) -> Self {
112 BaseKey::Sticky(key)
113 }
114}