rio_winit_fork/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 = Some(crate::platform_impl::Backend::Wayland);
51        self
52    }
53
54    #[inline]
55    fn with_any_thread(&mut self, any_thread: bool) -> &mut Self {
56        self.platform_specific.any_thread = any_thread;
57        self
58    }
59}
60
61/// Additional methods on [`Window`] that are specific to Wayland.
62pub trait WindowExtWayland {}
63
64impl WindowExtWayland for Window {}
65
66/// Additional methods on [`WindowAttributes`] that are specific to Wayland.
67pub trait WindowAttributesExtWayland {
68    /// Build window with the given name.
69    ///
70    /// The `general` name sets an application ID, which should match the `.desktop`
71    /// file distributed with your program. The `instance` is a `no-op`.
72    ///
73    /// For details about application ID conventions, see the
74    /// [Desktop Entry Spec](https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#desktop-file-id)
75    fn with_name(self, general: impl Into<String>, instance: impl Into<String>) -> Self;
76}
77
78impl WindowAttributesExtWayland for WindowAttributes {
79    #[inline]
80    fn with_name(mut self, general: impl Into<String>, instance: impl Into<String>) -> Self {
81        self.platform_specific.name =
82            Some(crate::platform_impl::ApplicationName::new(general.into(), instance.into()));
83        self
84    }
85}
86
87/// Additional methods on `MonitorHandle` that are specific to Wayland.
88pub trait MonitorHandleExtWayland {
89    /// Returns the inner identifier of the monitor.
90    fn native_id(&self) -> u32;
91}
92
93impl MonitorHandleExtWayland for MonitorHandle {
94    #[inline]
95    fn native_id(&self) -> u32 {
96        self.inner.native_identifier()
97    }
98}