1#![cfg(wayland_platform)]
2
3//! Winit's Wayland backend.
4
5use std::fmt::Display;
6use std::sync::Arc;
7
8use sctk::reexports::client::globals::{BindError, GlobalError};
9use sctk::reexports::client::protocol::wl_surface::WlSurface;
10use sctk::reexports::client::{self, ConnectError, DispatchError, Proxy};
11
12use crate::dpi::{LogicalSize, PhysicalSize};
13pub use crate::platform_impl::platform::{OsError, WindowId};
14pub use event_loop::{EventLoop, EventLoopProxy, EventLoopWindowTarget};
15pub use output::{MonitorHandle, VideoMode};
16pub use window::Window;
17
18mod event_loop;
19mod output;
20mod seat;
21mod state;
22mod types;
23mod window;
24
25#[derive(Debug)]
26pub 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
46impl 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
59impl 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)]
67pub struct DeviceId;
68
69impl DeviceId {
70 pub const unsafe fn dummy() -> Self {
71 DeviceId
72 }
73}
74
75/// Get the WindowId out of the surface.
76#[inline]
77fn 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.
82fn 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