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 ) -> (
64 Option<key::PressedKeyResult<Self::PendingKeyState, Self::KeyState>>,
65 key::KeyEvents<Self::Event>,
66 ) {
67 panic!()
68 }
69
70 fn lookup(
71 &self,
72 _path: &[u16],
73 ) -> &dyn key::Key<
74 Context = Self::Context,
75 Event = Self::Event,
76 PendingKeyState = Self::PendingKeyState,
77 KeyState = Self::KeyState,
78 > {
79 self
80 }
81}
82
83impl From<keyboard::Key> for BaseKey {
84 fn from(key: keyboard::Key) -> Self {
85 BaseKey::Keyboard(key)
86 }
87}
88
89impl From<layered::ModifierKey> for BaseKey {
90 fn from(key: layered::ModifierKey) -> Self {
91 BaseKey::LayerModifier(key)
92 }
93}
94
95impl From<callback::Key> for BaseKey {
96 fn from(key: callback::Key) -> Self {
97 BaseKey::Callback(key)
98 }
99}
100
101impl From<caps_word::Key> for BaseKey {
102 fn from(key: caps_word::Key) -> Self {
103 BaseKey::CapsWord(key)
104 }
105}
106
107impl From<custom::Key> for BaseKey {
108 fn from(key: custom::Key) -> Self {
109 BaseKey::Custom(key)
110 }
111}
112
113impl From<sticky::Key> for BaseKey {
114 fn from(key: sticky::Key) -> Self {
115 BaseKey::Sticky(key)
116 }
117}