winit/platform/
wayland.rs1use std::marker::PhantomData;
17use std::os::raw::c_void;
18use std::ptr::NonNull;
19
20use rwh_06::HandleError;
21
22use crate::event_loop::{ActiveEventLoop, EventLoop, EventLoopBuilder};
23use crate::monitor::MonitorHandle;
24pub use crate::window::Theme;
25use crate::window::{Window as CoreWindow, WindowAttributes};
26
27pub trait ActiveEventLoopExtWayland {
29 fn is_wayland(&self) -> bool;
31}
32
33impl ActiveEventLoopExtWayland for dyn ActiveEventLoop + '_ {
34 #[inline]
35 fn is_wayland(&self) -> bool {
36 self.as_any().downcast_ref::<crate::platform_impl::wayland::ActiveEventLoop>().is_some()
37 }
38}
39
40pub trait EventLoopExtWayland {
42 fn is_wayland(&self) -> bool;
44}
45
46impl EventLoopExtWayland for EventLoop {
47 #[inline]
48 fn is_wayland(&self) -> bool {
49 self.event_loop.is_wayland()
50 }
51}
52
53pub trait EventLoopBuilderExtWayland {
55 fn with_wayland(&mut self) -> &mut Self;
57
58 fn with_any_thread(&mut self, any_thread: bool) -> &mut Self;
63}
64
65impl EventLoopBuilderExtWayland for EventLoopBuilder {
66 #[inline]
67 fn with_wayland(&mut self) -> &mut Self {
68 self.platform_specific.forced_backend = Some(crate::platform_impl::Backend::Wayland);
69 self
70 }
71
72 #[inline]
73 fn with_any_thread(&mut self, any_thread: bool) -> &mut Self {
74 self.platform_specific.any_thread = any_thread;
75 self
76 }
77}
78
79pub struct XdgSurfaceHandle<'a> {
80 raw: NonNull<c_void>,
81 _marker: PhantomData<&'a ()>,
82}
83
84impl<'a> XdgSurfaceHandle<'a> {
85 pub unsafe fn borrow_raw(raw: NonNull<c_void>) -> Self {
87 Self { raw, _marker: PhantomData }
88 }
89
90 pub fn as_raw(&self) -> NonNull<c_void> {
92 self.raw
93 }
94}
95
96pub trait HasXdgSurfaceHandle {
97 fn xdg_surface_handle(&self) -> Result<XdgSurfaceHandle<'_>, HandleError>;
98}
99
100pub trait WindowExtWayland {
104 fn xdg_surface_handle<'a>(&'a self) -> Option<&dyn HasXdgSurfaceHandle>;
105}
106
107impl WindowExtWayland for dyn CoreWindow + '_ {
108 fn xdg_surface_handle(&self) -> Option<&dyn HasXdgSurfaceHandle> {
109 let window = self.as_any().downcast_ref::<crate::platform_impl::wayland::Window>();
110 window.map(|w| w as &dyn HasXdgSurfaceHandle)
111 }
112}
113
114pub trait WindowAttributesExtWayland {
116 fn with_name(self, general: impl Into<String>, instance: impl Into<String>) -> Self;
124}
125
126impl WindowAttributesExtWayland for WindowAttributes {
127 #[inline]
128 fn with_name(mut self, general: impl Into<String>, instance: impl Into<String>) -> Self {
129 self.platform_specific.name =
130 Some(crate::platform_impl::ApplicationName::new(general.into(), instance.into()));
131 self
132 }
133}
134
135pub trait MonitorHandleExtWayland {
137 fn native_id(&self) -> u32;
139}
140
141impl MonitorHandleExtWayland for MonitorHandle {
142 #[inline]
143 fn native_id(&self) -> u32 {
144 self.inner.native_identifier()
145 }
146}