async_winit/
platform.rs

1/*
2
3`async-winit` is free software: you can redistribute it and/or modify it under the terms of one of
4the following licenses:
5
6* GNU Lesser General Public License as published by the Free Software Foundation, either
7  version 3 of the License, or (at your option) any later version.
8* Mozilla Public License as published by the Mozilla Foundation, version 2.
9
10`async-winit` is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
11the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General
12Public License and the Patron License for more details.
13
14You should have received a copy of the GNU Lesser General Public License and the Mozilla
15Public License along with `async-winit`. If not, see <https://www.gnu.org/licenses/>.
16
17*/
18
19//! Platform specific code.
20
21#[cfg(android_platform)]
22pub mod android;
23
24#[cfg(ios_platform)]
25pub mod ios;
26
27#[cfg(macos_platform)]
28pub mod macos;
29
30#[cfg(orbital_platform)]
31pub mod orbital;
32
33#[cfg(x11_platform)]
34pub mod x11;
35
36#[cfg(wayland_platform)]
37pub mod wayland;
38
39#[cfg(windows)]
40pub mod windows;
41
42#[cfg(any(windows, x11_platform, wayland_platform))]
43pub mod run_return;
44
45cfg_if::cfg_if! {
46    if #[cfg(android_platform)] {
47        pub(crate) use android::PlatformSpecific;
48    } else if #[cfg(ios_platform)] {
49        pub(crate) use ios::PlatformSpecific;
50    } else if #[cfg(macos_platform)] {
51        pub(crate) use macos::PlatformSpecific;
52    } else if #[cfg(orbital_platform)] {
53        pub(crate) use orbital::PlatformSpecific;
54    } else if #[cfg(any(x11_platform, wayland_platform))] {
55        #[cfg(all(feature = "x11", not(feature = "wayland")))]
56        pub(crate) use x11::PlatformSpecific;
57
58        #[cfg(all(not(feature = "x11"), feature = "wayland"))]
59        pub(crate) use wayland::PlatformSpecific;
60
61        #[cfg(all(feature = "x11", feature = "wayland"))]
62        mod free_unix;
63        #[cfg(all(feature = "x11", feature = "wayland"))]
64        pub(crate) use free_unix::PlatformSpecific;
65    } else if #[cfg(windows)] {
66        pub(crate) use windows::PlatformSpecific;
67    }
68}
69
70mod __private {
71    use crate::event_loop::{EventLoop, EventLoopBuilder, EventLoopWindowTarget};
72    use crate::window::{Window, WindowBuilder};
73
74    #[doc(hidden)]
75    pub struct Internal(());
76
77    macro_rules! sealed_trait {
78        ($($name: ident $tname: ident)*) => {$(
79            #[doc(hidden)]
80            pub trait $tname {
81                fn __sealed_marker(i: Internal);
82            }
83
84            impl $tname for $name {
85                fn __sealed_marker(_: Internal) {}
86            }
87        )*}
88    }
89
90    macro_rules! sealed_trait_with_gen {
91        ($($name: ident $tname: ident)*) => {$(
92            #[doc(hidden)]
93            pub trait $tname {
94                fn __sealed_marker(i: Internal);
95            }
96
97            impl<TS: crate::sync::ThreadSafety> $tname for $name<TS> {
98                fn __sealed_marker(_: Internal) {}
99            }
100        )*}
101    }
102
103    sealed_trait! {
104        EventLoopBuilder EventLoopBuilderPrivate
105        WindowBuilder WindowBuilderPrivate
106    }
107
108    sealed_trait_with_gen! {
109        EventLoopWindowTarget EventLoopWindowTargetPrivate
110        EventLoop EventLoopPrivate
111        Window WindowPrivate
112    }
113}