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