1mod keyboard;
2mod pointer;
3mod sink;
4mod window;
5
6pub use keyboard::*;
7pub use pointer::*;
8pub use sink::*;
9pub use window::*;
10
11use std::{
12 any::Any,
13 fmt::Debug,
14 sync::{
15 atomic::{AtomicBool, Ordering},
16 Arc,
17 },
18};
19
20use crate::SendSync;
21
22#[derive(Clone)]
23pub struct Event {
24 #[cfg(feature = "multithread")]
25 inner: Arc<dyn Any + Send + Sync>,
26 #[cfg(not(feature = "multithread"))]
27 inner: Arc<dyn Any>,
28 is_handled: Arc<AtomicBool>,
29}
30
31impl Event {
32 pub fn new<T: Any + SendSync>(event: T) -> Self {
33 Self {
34 inner: Arc::new(event),
35 is_handled: Arc::new(AtomicBool::new(false)),
36 }
37 }
38
39 pub fn is_handled(&self) -> bool {
40 self.is_handled.load(Ordering::Acquire)
41 }
42
43 pub fn handle(&self) {
44 self.is_handled.store(true, Ordering::Release);
45 }
46
47 pub fn is<T: Any>(&self) -> bool {
48 self.inner.as_ref().is::<T>()
49 }
50
51 pub fn get<T: Any>(&self) -> Option<&T> {
52 self.inner.downcast_ref()
53 }
54}
55
56impl Debug for Event {
57 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
58 f.debug_struct("Event")
59 .field("is_handled", &self.is_handled())
60 .finish()
61 }
62}
63
64#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
65pub struct Modifiers {
66 pub shift: bool,
67 pub ctrl: bool,
68 pub alt: bool,
69 pub meta: bool,
70}