winit/platform_impl/linux/wayland/
mod.rs
1use std::fmt::Display;
4use std::sync::Arc;
5
6use sctk::reexports::client::globals::{BindError, GlobalError};
7use sctk::reexports::client::protocol::wl_surface::WlSurface;
8use sctk::reexports::client::{self, ConnectError, DispatchError, Proxy};
9
10pub(super) use crate::cursor::OnlyCursorImage as CustomCursor;
11use crate::dpi::{LogicalSize, PhysicalSize};
12pub use crate::platform_impl::platform::{OsError, WindowId};
13pub use event_loop::{ActiveEventLoop, EventLoop, EventLoopProxy};
14pub use output::{MonitorHandle, VideoModeHandle};
15pub use window::Window;
16
17mod event_loop;
18mod output;
19mod seat;
20mod state;
21mod types;
22mod window;
23
24#[derive(Debug)]
25pub enum WaylandError {
26 Connection(ConnectError),
28
29 Global(GlobalError),
31
32 Bind(BindError),
34
35 Dispatch(DispatchError),
37
38 Calloop(calloop::Error),
40
41 Wire(client::backend::WaylandError),
43}
44
45impl Display for WaylandError {
46 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
47 match self {
48 WaylandError::Connection(error) => error.fmt(f),
49 WaylandError::Global(error) => error.fmt(f),
50 WaylandError::Bind(error) => error.fmt(f),
51 WaylandError::Dispatch(error) => error.fmt(f),
52 WaylandError::Calloop(error) => error.fmt(f),
53 WaylandError::Wire(error) => error.fmt(f),
54 }
55 }
56}
57
58impl From<WaylandError> for OsError {
59 fn from(value: WaylandError) -> Self {
60 Self::WaylandError(Arc::new(value))
61 }
62}
63
64#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
66pub struct DeviceId;
67
68impl DeviceId {
69 pub const fn dummy() -> Self {
70 DeviceId
71 }
72}
73
74#[inline]
76fn make_wid(surface: &WlSurface) -> WindowId {
77 WindowId(surface.id().as_ptr() as u64)
78}
79
80fn logical_to_physical_rounded(size: LogicalSize<u32>, scale_factor: f64) -> PhysicalSize<u32> {
82 let width = size.width as f64 * scale_factor;
83 let height = size.height as f64 * scale_factor;
84 (width.round(), height.round()).into()
85}