floem_winit/platform/
wayland.rs

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