1#![allow(unsafe_code)]
12
13use crate::{Event, Remap};
14use std::task::{Context, Poll};
15
16#[cfg_attr(
17 any(target_arch = "wasm32", target_arch = "asmjs"),
18 cfg_attr(target_os = "wasi", path = "raw/wasi.rs"),
19 cfg_attr(target_os = "ardaku", path = "raw/ardaku.rs"),
20 cfg_attr(
21 any(target_os = "unknown", target_os = "emscripten"),
22 path = "raw/dom.rs"
23 )
24)]
25#[cfg_attr(
26 not(any(target_arch = "wasm32", target_arch = "asmjs")),
27 cfg_attr(target_os = "linux", path = "raw/linux.rs"),
28 cfg_attr(target_os = "android", path = "raw/android.rs"),
29 cfg_attr(target_os = "macos", path = "raw/macos.rs"),
30 cfg_attr(target_os = "ios", path = "raw/ios.rs"),
31 cfg_attr(target_os = "windows", path = "raw/windows.rs"),
32 cfg_attr(target_os = "fuchsia", path = "raw/fuchsia.rs"),
33 cfg_attr(target_os = "redox", path = "raw/redox.rs"),
34 cfg_attr(
35 any(
36 target_os = "freebsd",
37 target_os = "dragonfly",
38 target_os = "bitrig",
39 target_os = "openbsd",
40 target_os = "netbsd"
41 ),
42 path = "raw/bsd.rs",
43 )
44)]
45mod ffi;
46
47struct FakeGlobal;
49
50impl Global for FakeGlobal {}
51
52struct FakeListener;
54
55impl Listener for FakeListener {
56 fn poll(&mut self, _cx: &mut Context<'_>) -> Poll<crate::Controller> {
57 Poll::Pending
58 }
59}
60
61pub(crate) trait Listener: Send {
63 fn poll(&mut self, cx: &mut Context<'_>) -> Poll<crate::Controller>;
65}
66
67pub(crate) trait Controller: Send {
69 fn id(&self) -> u64 {
71 0
72 }
73 fn poll(&mut self, _cx: &mut Context<'_>) -> Poll<Event> {
75 Poll::Pending
76 }
77 fn rumble(&mut self, _left: f32, _right: f32) {}
79 fn name(&self) -> &str {
81 "Unknown"
82 }
83 fn pressure(&self, input: f64) -> f64 {
85 input
86 }
87 fn axis(&self, input: f64) -> f64 {
89 input
90 }
91}
92
93pub(crate) trait Global: std::any::Any {
95 fn enable(&self) {}
97 fn disable(&self) {}
99 fn listener(&self, _remap: Remap) -> Box<dyn Listener> {
101 Box::new(FakeListener)
102 }
103}
104
105thread_local! {
106 pub(crate) static GLOBAL: Box<dyn Global> = ffi::global();
107}