1 | //! Winit's Wayland backend. |
2 | |
3 | use std::fmt::Display; |
4 | use std::sync::Arc; |
5 | |
6 | use sctk::reexports::client::globals::{BindError, GlobalError}; |
7 | use sctk::reexports::client::protocol::wl_surface::WlSurface; |
8 | use sctk::reexports::client::{self, ConnectError, DispatchError, Proxy}; |
9 | |
10 | pub(super) use crate::cursor::OnlyCursorImage as CustomCursor; |
11 | use crate::dpi::{LogicalSize, PhysicalSize}; |
12 | pub use crate::platform_impl::platform::{OsError, WindowId}; |
13 | pub use event_loop::{ActiveEventLoop, EventLoop, EventLoopProxy}; |
14 | pub use output::{MonitorHandle, VideoModeHandle}; |
15 | pub use window::Window; |
16 | |
17 | mod event_loop; |
18 | mod output; |
19 | mod seat; |
20 | mod state; |
21 | mod types; |
22 | mod window; |
23 | |
24 | #[derive (Debug)] |
25 | pub enum WaylandError { |
26 | /// Error connecting to the socket. |
27 | Connection(ConnectError), |
28 | |
29 | /// Error binding the global. |
30 | Global(GlobalError), |
31 | |
32 | // Bind error. |
33 | Bind(BindError), |
34 | |
35 | /// Error during the dispatching the event queue. |
36 | Dispatch(DispatchError), |
37 | |
38 | /// Calloop error. |
39 | Calloop(calloop::Error), |
40 | |
41 | /// Wayland |
42 | Wire(client::backend::WaylandError), |
43 | } |
44 | |
45 | impl Display for WaylandError { |
46 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
47 | match self { |
48 | WaylandError::Connection(error: &ConnectError) => error.fmt(f), |
49 | WaylandError::Global(error: &GlobalError) => error.fmt(f), |
50 | WaylandError::Bind(error: &BindError) => error.fmt(f), |
51 | WaylandError::Dispatch(error: &DispatchError) => error.fmt(f), |
52 | WaylandError::Calloop(error: &Error) => error.fmt(f), |
53 | WaylandError::Wire(error: &WaylandError) => error.fmt(f), |
54 | } |
55 | } |
56 | } |
57 | |
58 | impl From<WaylandError> for OsError { |
59 | fn from(value: WaylandError) -> Self { |
60 | Self::WaylandError(Arc::new(data:value)) |
61 | } |
62 | } |
63 | |
64 | /// Dummy device id, since Wayland doesn't have device events. |
65 | #[derive (Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] |
66 | pub struct DeviceId; |
67 | |
68 | impl DeviceId { |
69 | pub const fn dummy() -> Self { |
70 | DeviceId |
71 | } |
72 | } |
73 | |
74 | /// Get the WindowId out of the surface. |
75 | #[inline ] |
76 | fn make_wid(surface: &WlSurface) -> WindowId { |
77 | WindowId(surface.id().as_ptr() as u64) |
78 | } |
79 | |
80 | /// The default routine does floor, but we need round on Wayland. |
81 | fn logical_to_physical_rounded(size: LogicalSize<u32>, scale_factor: f64) -> PhysicalSize<u32> { |
82 | let width: f64 = size.width as f64 * scale_factor; |
83 | let height: f64 = size.height as f64 * scale_factor; |
84 | (width.round(), height.round()).into() |
85 | } |
86 | |