winit/platform_impl/linux/wayland/event_loop/
sink.rs

1//! An event loop's sink to deliver events from the Wayland event callbacks.
2
3use std::vec::Drain;
4
5use crate::event::{DeviceEvent, DeviceId as RootDeviceId, Event, WindowEvent};
6use crate::platform_impl::platform::DeviceId as PlatformDeviceId;
7use crate::window::WindowId as RootWindowId;
8
9use 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)]
14pub struct EventSink {
15    pub window_events: Vec<Event<()>>,
16}
17
18impl 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 { event, window_id: RootWindowId(window_id) });
42    }
43
44    #[inline]
45    pub fn append(&mut self, other: &mut Self) {
46        self.window_events.append(&mut other.window_events);
47    }
48
49    #[inline]
50    pub fn drain(&mut self) -> Drain<'_, Event<()>> {
51        self.window_events.drain(..)
52    }
53}