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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//! Types related to events produced by this library.
use crate::{AreaId, Error, ItemId, NotificationId};
/// A mouse button.
#[derive(Debug, Clone, Copy)]
#[non_exhaustive]
#[repr(u32)]
pub enum MouseButton {
/// Left mouse button.
Left = 0x1,
/// Right mouse button.
Right = 0x2,
}
/// A collection of mouse buttons.
#[derive(Debug)]
pub struct MouseButtons(u32);
impl MouseButtons {
/// A set containing only the right mouse button.
pub(super) const RIGHT: Self = Self(MouseButton::Right as u32);
/// Copy the buttons collection.
///
/// Note that we don't want to implement [`Copy`] for this type as it would
/// be too leaky.
pub(super) const fn copy_data(&self) -> Self {
Self(self.0)
}
/// Create a new empty collection of mouse buttons.
pub(super) const fn empty() -> Self {
Self(0)
}
/// Create a new collection of mouse buttons.
pub(super) fn from_iter<I>(iter: I) -> Self
where
I: IntoIterator<Item = MouseButton>,
{
let mut buttons = 0;
for button in iter {
buttons |= button as u32;
}
Self(buttons)
}
/// Test if the given mouse button is active.
pub fn test(&self, button: MouseButton) -> bool {
self.0 & button as u32 != 0
}
}
/// An event generated by a mouse click.
#[derive(Debug)]
#[non_exhaustive]
pub struct MouseEvent {
/// Mouse button responsible for the event.
pub buttons: MouseButtons,
}
/// A clipbaord event.
#[derive(Debug)]
#[non_exhaustive]
pub enum ClipboardEvent {
/// A bitmap has been copied.
BitMap(Vec<u8>),
/// A string has been copied.
Text(String),
}
/// An event emitted by the event loop.
#[derive(Debug)]
#[non_exhaustive]
pub enum Event {
/// Window has been shut down.
Shutdown {},
/// The menu item identified by [`ItemId`] has been clicked.
MenuItemClicked {
/// The item that was clicked.
item_id: ItemId,
/// The generated event.
event: MouseEvent,
},
/// An icon has been clicked.
IconClicked {
/// The area that was clicked.
area_id: AreaId,
/// The generated event.
event: MouseEvent,
},
/// Indicates that the notification with the associated token has been clicked.
NotificationClicked {
/// The area the notification belonged to.
area_id: AreaId,
/// The identifier of the notification.
id: NotificationId,
/// The generated event.
event: MouseEvent,
},
/// The notification associated with the given token either timed out or was dismissed.
NotificationDismissed {
/// The area from which the dismissed notification originated.
area_id: AreaId,
/// The identifier of the dismissed notification.
id: NotificationId,
},
/// The system clipboard has been modified.
Clipboard {
/// The generated clipboard event.
event: ClipboardEvent,
},
/// Data was copied to the current process remotely using
/// [`Window::copy_data`].
///
/// [`Window::copy_data`]: crate::Window::copy_data
CopyData {
/// The type parameter passed when sending the data.
ty: usize,
/// The data.
data: Vec<u8>,
},
/// A non-fatal error has been reported.
Error {
/// The reported error.
error: Error,
},
}