1 | //! # Wayland |
2 | //! |
3 | //! **Note:** Windows don't appear on Wayland until you draw/present to them. |
4 | //! |
5 | //! By default, Winit loads system libraries using `dlopen`. This can be |
6 | //! disabled by disabling the `"wayland-dlopen"` cargo feature. |
7 | //! |
8 | //! ## Client-side decorations |
9 | //! |
10 | //! Winit provides client-side decorations by default, but the behaviour can |
11 | //! be controlled with the following feature flags: |
12 | //! |
13 | //! * `wayland-csd-adwaita` (default). |
14 | //! * `wayland-csd-adwaita-crossfont`. |
15 | //! * `wayland-csd-adwaita-notitle`. |
16 | use crate::event_loop::{ActiveEventLoop, EventLoop, EventLoopBuilder}; |
17 | use crate::monitor::MonitorHandle; |
18 | use crate::window::{Window, WindowAttributes}; |
19 | |
20 | pub use crate::window::Theme; |
21 | |
22 | /// Additional methods on [`ActiveEventLoop`] that are specific to Wayland. |
23 | pub trait ActiveEventLoopExtWayland { |
24 | /// True if the [`ActiveEventLoop`] uses Wayland. |
25 | fn is_wayland(&self) -> bool; |
26 | } |
27 | |
28 | impl ActiveEventLoopExtWayland for ActiveEventLoop { |
29 | #[inline ] |
30 | fn is_wayland(&self) -> bool { |
31 | self.p.is_wayland() |
32 | } |
33 | } |
34 | |
35 | /// Additional methods on [`EventLoop`] that are specific to Wayland. |
36 | pub trait EventLoopExtWayland { |
37 | /// True if the [`EventLoop`] uses Wayland. |
38 | fn is_wayland(&self) -> bool; |
39 | } |
40 | |
41 | impl<T: 'static> EventLoopExtWayland for EventLoop<T> { |
42 | #[inline ] |
43 | fn is_wayland(&self) -> bool { |
44 | self.event_loop.is_wayland() |
45 | } |
46 | } |
47 | |
48 | /// Additional methods on [`EventLoopBuilder`] that are specific to Wayland. |
49 | pub trait EventLoopBuilderExtWayland { |
50 | /// Force using Wayland. |
51 | fn with_wayland(&mut self) -> &mut Self; |
52 | |
53 | /// Whether to allow the event loop to be created off of the main thread. |
54 | /// |
55 | /// By default, the window is only allowed to be created on the main |
56 | /// thread, to make platform compatibility easier. |
57 | fn with_any_thread(&mut self, any_thread: bool) -> &mut Self; |
58 | } |
59 | |
60 | impl<T> EventLoopBuilderExtWayland for EventLoopBuilder<T> { |
61 | #[inline ] |
62 | fn with_wayland(&mut self) -> &mut Self { |
63 | self.platform_specific.forced_backend = Some(crate::platform_impl::Backend::Wayland); |
64 | self |
65 | } |
66 | |
67 | #[inline ] |
68 | fn with_any_thread(&mut self, any_thread: bool) -> &mut Self { |
69 | self.platform_specific.any_thread = any_thread; |
70 | self |
71 | } |
72 | } |
73 | |
74 | /// Additional methods on [`Window`] that are specific to Wayland. |
75 | pub trait WindowExtWayland {} |
76 | |
77 | impl WindowExtWayland for Window {} |
78 | |
79 | /// Additional methods on [`WindowAttributes`] that are specific to Wayland. |
80 | pub trait WindowAttributesExtWayland { |
81 | /// Build window with the given name. |
82 | /// |
83 | /// The `general` name sets an application ID, which should match the `.desktop` |
84 | /// file distributed with your program. The `instance` is a `no-op`. |
85 | /// |
86 | /// For details about application ID conventions, see the |
87 | /// [Desktop Entry Spec](https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#desktop-file-id) |
88 | fn with_name(self, general: impl Into<String>, instance: impl Into<String>) -> Self; |
89 | } |
90 | |
91 | impl WindowAttributesExtWayland for WindowAttributes { |
92 | #[inline ] |
93 | fn with_name(mut self, general: impl Into<String>, instance: impl Into<String>) -> Self { |
94 | self.platform_specific.name = |
95 | Some(crate::platform_impl::ApplicationName::new(general.into(), instance.into())); |
96 | self |
97 | } |
98 | } |
99 | |
100 | /// Additional methods on `MonitorHandle` that are specific to Wayland. |
101 | pub trait MonitorHandleExtWayland { |
102 | /// Returns the inner identifier of the monitor. |
103 | fn native_id(&self) -> u32; |
104 | } |
105 | |
106 | impl MonitorHandleExtWayland for MonitorHandle { |
107 | #[inline ] |
108 | fn native_id(&self) -> u32 { |
109 | self.inner.native_identifier() |
110 | } |
111 | } |
112 | |