winit/platform/
wayland.rs1use std::ffi::c_void;
18use std::ptr::NonNull;
19
20use crate::event_loop::{ActiveEventLoop, EventLoop, EventLoopBuilder};
21use crate::monitor::MonitorHandle;
22use crate::window::{Window, WindowAttributes};
23
24pub use crate::window::Theme;
25
26pub trait ActiveEventLoopExtWayland {
28 fn is_wayland(&self) -> bool;
30}
31
32impl ActiveEventLoopExtWayland for ActiveEventLoop {
33 #[inline]
34 fn is_wayland(&self) -> bool {
35 self.p.is_wayland()
36 }
37}
38
39pub trait EventLoopExtWayland {
41 fn is_wayland(&self) -> bool;
43}
44
45impl<T: 'static> EventLoopExtWayland for EventLoop<T> {
46 #[inline]
47 fn is_wayland(&self) -> bool {
48 self.event_loop.is_wayland()
49 }
50}
51
52pub trait EventLoopBuilderExtWayland {
54 fn with_wayland(&mut self) -> &mut Self;
56
57 fn with_any_thread(&mut self, any_thread: bool) -> &mut Self;
62}
63
64impl<T> EventLoopBuilderExtWayland for EventLoopBuilder<T> {
65 #[inline]
66 fn with_wayland(&mut self) -> &mut Self {
67 self.platform_specific.forced_backend = Some(crate::platform_impl::Backend::Wayland);
68 self
69 }
70
71 #[inline]
72 fn with_any_thread(&mut self, any_thread: bool) -> &mut Self {
73 self.platform_specific.any_thread = any_thread;
74 self
75 }
76}
77
78pub trait WindowExtWayland {
82 fn xdg_toplevel(&self) -> Option<NonNull<c_void>>;
84}
85
86impl WindowExtWayland for Window {
87 #[inline]
88 fn xdg_toplevel(&self) -> Option<NonNull<c_void>> {
89 #[allow(clippy::single_match)]
90 match &self.window {
91 #[cfg(x11_platform)]
92 crate::platform_impl::Window::X(_) => None,
93 #[cfg(wayland_platform)]
94 crate::platform_impl::Window::Wayland(window) => window.xdg_toplevel(),
95 }
96 }
97}
98
99pub trait WindowAttributesExtWayland {
101 fn with_name(self, general: impl Into<String>, instance: impl Into<String>) -> Self;
109}
110
111impl WindowAttributesExtWayland for WindowAttributes {
112 #[inline]
113 fn with_name(mut self, general: impl Into<String>, instance: impl Into<String>) -> Self {
114 self.platform_specific.name =
115 Some(crate::platform_impl::ApplicationName::new(general.into(), instance.into()));
116 self
117 }
118}
119
120pub trait MonitorHandleExtWayland {
122 fn native_id(&self) -> u32;
124}
125
126impl MonitorHandleExtWayland for MonitorHandle {
127 #[inline]
128 fn native_id(&self) -> u32 {
129 self.inner.native_identifier()
130 }
131}