1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
pub mod ev;
pub mod wacom;
pub mod gpio;
pub mod multitouch;
#[derive(PartialEq, Copy, Clone)]
pub enum InputDevice {
Wacom,
Multitouch,
GPIO,
Unknown,
}
#[derive(PartialEq, Clone)]
pub enum InputEvent {
WacomEvent { event: wacom::WacomEvent },
MultitouchEvent { event: multitouch::MultitouchEvent },
GPIO { event: gpio::GPIOEvent },
Unknown {},
}
impl Default for InputEvent {
fn default() -> InputEvent {
InputEvent::Unknown {}
}
}
use evdev;
use std;
pub trait EvdevHandler {
fn on_init(&mut self, path: String);
fn on_event(&mut self, device: InputDevice, event: evdev::raw::input_event);
}
unsafe impl Send for UnifiedInputHandler {}
unsafe impl Sync for UnifiedInputHandler {}
pub struct UnifiedInputHandler {
pub wacom: wacom::WacomState,
pub gpio: gpio::GPIOState,
pub mt: multitouch::MultitouchState,
pub tx: std::sync::mpsc::Sender<InputEvent>,
pub rx: std::sync::mpsc::Receiver<InputEvent>,
}
impl UnifiedInputHandler {
pub fn new() -> UnifiedInputHandler {
let (tx, rx) = std::sync::mpsc::channel();
UnifiedInputHandler {
gpio: gpio::GPIOState::new(),
wacom: wacom::WacomState::new(),
mt: multitouch::MultitouchState::new(),
rx,
tx,
}
}
pub fn get_producer(&mut self) -> &mut std::sync::mpsc::Sender<InputEvent> {
&mut self.tx
}
pub fn get_consumer(&self) -> &std::sync::mpsc::Receiver<InputEvent> {
&self.rx
}
}
impl<'a> EvdevHandler for UnifiedInputHandler {
fn on_init(&mut self, path: String) {
info!("Input device at path '{0}' EPOLL initialized", path);
}
fn on_event(&mut self, device: InputDevice, ev: evdev::raw::input_event) {
match device {
InputDevice::Wacom => self.wacom_handler(&ev),
InputDevice::Multitouch => self.multitouch_handler(&ev),
InputDevice::GPIO => self.gpio_handler(&ev),
_ => {}
}
}
}