rio_window/platform/
wayland.rs

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`.
16use crate::event_loop::{ActiveEventLoop, EventLoopBuilder};
17use crate::monitor::MonitorHandle;
18use crate::window::{Window, WindowAttributes};
19
20pub use crate::window::Theme;
21
22/// Additional methods on [`ActiveEventLoop`] that are specific to Wayland.
23pub trait ActiveEventLoopExtWayland {
24    /// True if the [`ActiveEventLoop`] uses Wayland.
25    fn is_wayland(&self) -> bool;
26}
27
28impl ActiveEventLoopExtWayland for ActiveEventLoop {
29    #[inline]
30    fn is_wayland(&self) -> bool {
31        self.p.is_wayland()
32    }
33}
34
35/// Additional methods on [`EventLoopBuilder`] that are specific to Wayland.
36pub trait EventLoopBuilderExtWayland {
37    /// Force using Wayland.
38    fn with_wayland(&mut self) -> &mut Self;
39
40    /// Whether to allow the event loop to be created off of the main thread.
41    ///
42    /// By default, the window is only allowed to be created on the main
43    /// thread, to make platform compatibility easier.
44    fn with_any_thread(&mut self, any_thread: bool) -> &mut Self;
45}
46
47impl<T> EventLoopBuilderExtWayland for EventLoopBuilder<T> {
48    #[inline]
49    fn with_wayland(&mut self) -> &mut Self {
50        self.platform_specific.forced_backend =
51            Some(crate::platform_impl::Backend::Wayland);
52        self
53    }
54
55    #[inline]
56    fn with_any_thread(&mut self, any_thread: bool) -> &mut Self {
57        self.platform_specific.any_thread = any_thread;
58        self
59    }
60}
61
62/// Additional methods on [`Window`] that are specific to Wayland.
63pub trait WindowExtWayland {}
64
65impl WindowExtWayland for Window {}
66
67/// Additional methods on [`WindowAttributes`] that are specific to Wayland.
68pub trait WindowAttributesExtWayland {
69    /// Build window with the given name.
70    ///
71    /// The `general` name sets an application ID, which should match the `.desktop`
72    /// file distributed with your program. The `instance` is a `no-op`.
73    ///
74    /// For details about application ID conventions, see the
75    /// [Desktop Entry Spec](https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#desktop-file-id)
76    fn with_name(self, general: impl Into<String>, instance: impl Into<String>) -> Self;
77}
78
79impl WindowAttributesExtWayland for WindowAttributes {
80    #[inline]
81    fn with_name(
82        mut self,
83        general: impl Into<String>,
84        instance: impl Into<String>,
85    ) -> Self {
86        self.platform_specific.name = Some(crate::platform_impl::ApplicationName::new(
87            general.into(),
88            instance.into(),
89        ));
90        self
91    }
92}
93
94/// Additional methods on `MonitorHandle` that are specific to Wayland.
95pub trait MonitorHandleExtWayland {
96    /// Returns the inner identifier of the monitor.
97    fn native_id(&self) -> u32;
98}
99
100impl MonitorHandleExtWayland for MonitorHandle {
101    #[inline]
102    fn native_id(&self) -> u32 {
103        self.inner.native_identifier()
104    }
105}