glutin/events.rs
1use std::path::PathBuf;
2
3#[derive(Clone, Debug)]
4pub enum Event {
5 /// The size of the window has changed.
6 Resized(u32, u32),
7
8 /// The position of the window has changed.
9 Moved(i32, i32),
10
11 /// The window has been closed.
12 Closed,
13
14 /// A file has been dropped into the window.
15 DroppedFile(PathBuf),
16
17 /// The window received a unicode character.
18 ReceivedCharacter(char),
19
20 /// The window gained or lost focus.
21 ///
22 /// The parameter is true if the window has gained focus, and false if it has lost focus.
23 Focused(bool),
24
25 /// An event from the keyboard has been received.
26 KeyboardInput(ElementState, ScanCode, Option<VirtualKeyCode>),
27
28 /// The cursor has moved on the window.
29 ///
30 /// The parameter are the (x,y) coords in pixels relative to the top-left corner of the window.
31 MouseMoved(i32, i32),
32
33 /// A mouse wheel movement or touchpad scroll occurred.
34 MouseWheel(MouseScrollDelta, TouchPhase, Option<(i32, i32)>),
35
36 /// An event from the mouse has been received.
37 MouseInput(ElementState, MouseButton, Option<(i32, i32)>),
38
39 /// Touchpad pressure event.
40 ///
41 /// At the moment, only supported on Apple forcetouch-capable macbooks.
42 /// The parameters are: pressure level (value between 0 and 1 representing how hard the touchpad
43 /// is being pressed) and stage (integer representing the click level).
44 TouchpadPressure(f32, i64),
45
46 /// The event loop was woken up by another thread.
47 Awakened,
48
49 /// The window needs to be redrawn.
50 Refresh,
51
52 /// App has been suspended or resumed.
53 ///
54 /// The parameter is true if app was suspended, and false if it has been resumed.
55 Suspended(bool),
56
57
58 /// Touch event has been received
59 Touch(Touch)
60}
61
62#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
63pub enum TouchPhase {
64 Started,
65 Moved,
66 Ended,
67 Cancelled
68}
69
70#[derive(Debug, Clone, Copy)]
71/// Represents touch event
72///
73/// Every time user touches screen new Start event with some finger id is generated.
74/// When the finger is removed from the screen End event with same id is generated.
75///
76/// For every id there will be at least 2 events with phases Start and End (or Cancelled).
77/// There may be 0 or more Move events.
78///
79///
80/// Depending on platform implementation id may or may not be reused by system after End event.
81///
82/// Gesture regonizer using this event should assume that Start event received with same id
83/// as previously received End event is a new finger and has nothing to do with an old one.
84///
85/// Touch may be cancelled if for example window lost focus.
86pub struct Touch {
87 pub phase: TouchPhase,
88 pub location: (f64,f64),
89 /// unique identifier of a finger.
90 pub id: u64
91}
92
93pub type ScanCode = u8;
94
95#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
96pub enum ElementState {
97 Pressed,
98 Released,
99}
100
101#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
102pub enum MouseButton {
103 Left,
104 Right,
105 Middle,
106 Other(u8),
107}
108
109#[derive(Debug, Clone, Copy, PartialEq)]
110pub enum MouseScrollDelta {
111 /// Amount in lines or rows to scroll in the horizontal
112 /// and vertical directions.
113 ///
114 /// Positive values indicate movement forward
115 /// (away from the user) or rightwards.
116 LineDelta(f32, f32),
117 /// Amount in pixels to scroll in the horizontal and
118 /// vertical direction.
119 ///
120 /// Scroll events are expressed as a PixelDelta if
121 /// supported by the device (eg. a touchpad) and
122 /// platform.
123 PixelDelta(f32, f32)
124}
125
126#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
127pub enum VirtualKeyCode {
128 /// The '1' key over the letters.
129 Key1,
130 /// The '2' key over the letters.
131 Key2,
132 /// The '3' key over the letters.
133 Key3,
134 /// The '4' key over the letters.
135 Key4,
136 /// The '5' key over the letters.
137 Key5,
138 /// The '6' key over the letters.
139 Key6,
140 /// The '7' key over the letters.
141 Key7,
142 /// The '8' key over the letters.
143 Key8,
144 /// The '9' key over the letters.
145 Key9,
146 /// The '0' key over the 'O' and 'P' keys.
147 Key0,
148
149 A,
150 B,
151 C,
152 D,
153 E,
154 F,
155 G,
156 H,
157 I,
158 J,
159 K,
160 L,
161 M,
162 N,
163 O,
164 P,
165 Q,
166 R,
167 S,
168 T,
169 U,
170 V,
171 W,
172 X,
173 Y,
174 Z,
175
176 /// The Escape key, next to F1.
177 Escape,
178
179 F1,
180 F2,
181 F3,
182 F4,
183 F5,
184 F6,
185 F7,
186 F8,
187 F9,
188 F10,
189 F11,
190 F12,
191 F13,
192 F14,
193 F15,
194
195 /// Print Screen/SysRq.
196 Snapshot,
197 /// Scroll Lock.
198 Scroll,
199 /// Pause/Break key, next to Scroll lock.
200 Pause,
201
202 /// `Insert`, next to Backspace.
203 Insert,
204 Home,
205 Delete,
206 End,
207 PageDown,
208 PageUp,
209
210 Left,
211 Up,
212 Right,
213 Down,
214
215 /// The Backspace key, right over Enter.
216 // TODO: rename
217 Back,
218 /// The Enter key.
219 Return,
220 /// The space bar.
221 Space,
222
223 /// The "Compose" key on Linux.
224 Compose,
225
226 Numlock,
227 Numpad0,
228 Numpad1,
229 Numpad2,
230 Numpad3,
231 Numpad4,
232 Numpad5,
233 Numpad6,
234 Numpad7,
235 Numpad8,
236 Numpad9,
237
238 AbntC1,
239 AbntC2,
240 Add,
241 Apostrophe,
242 Apps,
243 At,
244 Ax,
245 Backslash,
246 Calculator,
247 Capital,
248 Colon,
249 Comma,
250 Convert,
251 Decimal,
252 Divide,
253 Equals,
254 Grave,
255 Kana,
256 Kanji,
257 LAlt,
258 LBracket,
259 LControl,
260 LMenu,
261 LShift,
262 LWin,
263 Mail,
264 MediaSelect,
265 MediaStop,
266 Minus,
267 Multiply,
268 Mute,
269 MyComputer,
270 NavigateForward, // also called "Prior"
271 NavigateBackward, // also called "Next"
272 NextTrack,
273 NoConvert,
274 NumpadComma,
275 NumpadEnter,
276 NumpadEquals,
277 OEM102,
278 Period,
279 PlayPause,
280 Power,
281 PrevTrack,
282 RAlt,
283 RBracket,
284 RControl,
285 RMenu,
286 RShift,
287 RWin,
288 Semicolon,
289 Slash,
290 Sleep,
291 Stop,
292 Subtract,
293 Sysrq,
294 Tab,
295 Underline,
296 Unlabeled,
297 VolumeDown,
298 VolumeUp,
299 Wake,
300 WebBack,
301 WebFavorites,
302 WebForward,
303 WebHome,
304 WebRefresh,
305 WebSearch,
306 WebStop,
307 Yen,
308}