rktk/hooks/interface/master.rs
1pub use rktk_keymanager::{
2 interface::state::{
3 input_event::{EncoderDirection, KeyChangeEvent},
4 output_event::OutputEvent,
5 },
6 state::hid_report::Report,
7};
8
9use crate::drivers::interface::{
10 keyscan::KeyscanDriver, mouse::MouseDriver, reporter::ReporterDriver,
11};
12
13/// Hooks called for master side
14pub trait MasterHooks {
15 /// Called after master side initialization.
16 async fn on_master_init(
17 &mut self,
18 _key_scanner: &mut impl KeyscanDriver,
19 _mouse: Option<&mut impl MouseDriver>,
20 // _reporter: &impl ReporterDriver,
21 ) {
22 }
23
24 /// Called after keyboard event occur, before state update and report send.
25 ///
26 /// # Parameters
27 /// - `events`: The keyboard events.
28 ///
29 /// # Returns
30 /// If false, this event will be ignored.
31 async fn on_keyboard_event(&mut self, _event: &mut KeyChangeEvent) -> bool {
32 true
33 }
34
35 /// Called after mouse move event occur, before state update and report send.
36 ///
37 /// # Parameters
38 /// - `mouse_move`: The mouse move event. If None, no mouse move event occurred. If Some, the
39 /// tuple contains the x and y offset of the mouse move event.
40 ///
41 /// # Returns
42 /// If false, this event will be ignored.
43 async fn on_mouse_event(&mut self, _mouse_move: &mut (i8, i8)) -> bool {
44 true
45 }
46
47 /// Called after encoder event occur, before state update and report send.
48 ///
49 /// # Parameters
50 /// - `id`: The encoder id.
51 /// - `dir`: The encoder direction.
52 ///
53 /// # Returns
54 /// If false, this event will be ignored.
55 async fn on_encoder_event(&mut self, _id: &mut u8, _dir: &mut EncoderDirection) -> bool {
56 true
57 }
58
59 /// Called after keymanager event occur.
60 ///
61 /// This hook can be used to handle custom keycode.
62 fn on_keymanager_event(&mut self, _event: OutputEvent) {}
63
64 /// Called after state update, before report send.
65 ///
66 /// WARNING: Mutating the state_report or returning false can cause
67 /// inconsistent state.
68 ///
69 /// # Parameters
70 /// - `state_report`: Report returned from rktk-keymanager's update function.
71 ///
72 /// # Returns
73 /// If false, this report will be ignored.
74 async fn on_state_update(
75 &mut self,
76 _state_report: &mut Report,
77 _usb_reporter: &Option<impl ReporterDriver>,
78 _ble_reporter: &Option<impl ReporterDriver>,
79 ) -> bool {
80 true
81 }
82}