winit/platform_impl/linux/wayland/event_loop/
sink.rs
1use std::vec::Drain;
4
5use super::{DeviceId, WindowId};
6use crate::event::{DeviceEvent, DeviceId as RootDeviceId, Event, WindowEvent};
7use crate::platform_impl::platform::DeviceId as PlatformDeviceId;
8use crate::window::WindowId as RootWindowId;
9
10#[derive(Default)]
13pub struct EventSink {
14 pub(crate) window_events: Vec<Event>,
15}
16
17impl EventSink {
18 pub fn new() -> Self {
19 Default::default()
20 }
21
22 #[inline]
24 pub fn is_empty(&self) -> bool {
25 self.window_events.is_empty()
26 }
27
28 #[inline]
30 pub fn push_device_event(&mut self, event: DeviceEvent, device_id: DeviceId) {
31 self.window_events.push(Event::DeviceEvent {
32 event,
33 device_id: RootDeviceId(PlatformDeviceId::Wayland(device_id)),
34 });
35 }
36
37 #[inline]
39 pub fn push_window_event(&mut self, event: WindowEvent, window_id: WindowId) {
40 self.window_events.push(Event::WindowEvent { event, window_id: RootWindowId(window_id) });
41 }
42
43 #[inline]
44 pub fn append(&mut self, other: &mut Self) {
45 self.window_events.append(&mut other.window_events);
46 }
47
48 #[inline]
49 pub(crate) fn drain(&mut self) -> Drain<'_, Event> {
50 self.window_events.drain(..)
51 }
52}