1 | use raw_window_handle::{DisplayHandle, HandleError, HasDisplayHandle}; |
2 | use winit::error::OsError; |
3 | use winit::event_loop::{ActiveEventLoop, EventLoop}; |
4 | use winit::window::{Window, WindowAttributes}; |
5 | |
6 | use 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. |
11 | pub 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 | |
21 | impl Sealed for ActiveEventLoop {} |
22 | |
23 | impl 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 | |
33 | impl<T> Sealed for EventLoop<T> {} |
34 | |
35 | impl<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 | } |
45 | |