1 | //! An event loop's sink to deliver events from the Wayland event callbacks. |
2 | |
3 | use std::vec::Drain; |
4 | |
5 | use crate::event::{DeviceEvent, DeviceId as RootDeviceId, Event, WindowEvent}; |
6 | use crate::platform_impl::platform::DeviceId as PlatformDeviceId; |
7 | use crate::window::WindowId as RootWindowId; |
8 | |
9 | use super::{DeviceId, WindowId}; |
10 | |
11 | /// An event loop's sink to deliver events from the Wayland event callbacks |
12 | /// to the winit's user. |
13 | #[derive (Default)] |
14 | pub struct EventSink { |
15 | pub window_events: Vec<Event<()>>, |
16 | } |
17 | |
18 | impl EventSink { |
19 | pub fn new() -> Self { |
20 | Default::default() |
21 | } |
22 | |
23 | /// Return `true` if there're pending events. |
24 | #[inline ] |
25 | pub fn is_empty(&self) -> bool { |
26 | self.window_events.is_empty() |
27 | } |
28 | |
29 | /// Add new device event to a queue. |
30 | #[inline ] |
31 | pub fn push_device_event(&mut self, event: DeviceEvent, device_id: DeviceId) { |
32 | self.window_events.push(Event::DeviceEvent { |
33 | event, |
34 | device_id: RootDeviceId(PlatformDeviceId::Wayland(device_id)), |
35 | }); |
36 | } |
37 | |
38 | /// Add new window event to a queue. |
39 | #[inline ] |
40 | pub fn push_window_event(&mut self, event: WindowEvent, window_id: WindowId) { |
41 | self.window_events.push(Event::WindowEvent { |
42 | event, |
43 | window_id: RootWindowId(window_id), |
44 | }); |
45 | } |
46 | |
47 | #[inline ] |
48 | pub fn append(&mut self, other: &mut Self) { |
49 | self.window_events.append(&mut other.window_events); |
50 | } |
51 | |
52 | #[inline ] |
53 | pub fn drain(&mut self) -> Drain<'_, Event<()>> { |
54 | self.window_events.drain(..) |
55 | } |
56 | } |
57 | |