glutin_winit/
event_loop.rs

1use raw_window_handle::{DisplayHandle, HandleError, HasDisplayHandle};
2use winit::error::OsError;
3use winit::event_loop::{ActiveEventLoop, EventLoop};
4use winit::window::{Window, WindowAttributes};
5
6use crate::private::Sealed;
7
8/// [`ActiveEventLoop`] is the recommended way to interact with the event
9/// loop, but for compatibility purposes [`EventLoop`] is also supported
10/// although not recommended anymore as it has been deprecated by Winit.
11pub trait GlutinEventLoop: Sealed {
12    /// Create the window.
13    ///
14    /// See [`ActiveEventLoop::create_window`] for details.
15    fn create_window(&self, window_attributes: WindowAttributes) -> Result<Window, OsError>;
16
17    /// Get a handle to the display controller of the windowing system.
18    fn glutin_display_handle(&self) -> Result<DisplayHandle<'_>, HandleError>;
19}
20
21impl Sealed for ActiveEventLoop {}
22
23impl GlutinEventLoop for ActiveEventLoop {
24    fn create_window(&self, window_attributes: WindowAttributes) -> Result<Window, OsError> {
25        self.create_window(window_attributes)
26    }
27
28    fn glutin_display_handle(&self) -> Result<DisplayHandle<'_>, HandleError> {
29        self.display_handle()
30    }
31}
32
33impl<T> Sealed for EventLoop<T> {}
34
35impl<T> GlutinEventLoop for EventLoop<T> {
36    #[allow(deprecated)]
37    fn create_window(&self, window_attributes: WindowAttributes) -> Result<Window, OsError> {
38        self.create_window(window_attributes)
39    }
40
41    fn glutin_display_handle(&self) -> Result<DisplayHandle<'_>, HandleError> {
42        self.display_handle()
43    }
44}