mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-23 13:51:30 +11:00
Use cfg aliases throught the code base
Co-authored-by: Mads Marquart <mads@marquart.dk>
This commit is contained in:
parent
58ec458877
commit
5e77d70245
|
@ -45,6 +45,9 @@ wayland-csd-adwaita-notitle = ["sctk-adwaita"]
|
|||
android-native-activity = [ "android-activity/native-activity" ]
|
||||
android-game-activity = [ "android-activity/game-activity" ]
|
||||
|
||||
[build-dependencies]
|
||||
cfg_aliases = "0.1.1"
|
||||
|
||||
[dependencies]
|
||||
instant = { version = "0.1", features = ["wasm-bindgen"] }
|
||||
once_cell = "1.12"
|
||||
|
|
21
build.rs
Normal file
21
build.rs
Normal file
|
@ -0,0 +1,21 @@
|
|||
use cfg_aliases::cfg_aliases;
|
||||
|
||||
fn main() {
|
||||
// The script doesn't depend on our code
|
||||
println!("cargo:rerun-if-changed=build.rs");
|
||||
// Setup cfg aliases
|
||||
cfg_aliases! {
|
||||
// Systems.
|
||||
android_platform: { target_os = "android" },
|
||||
wasm_platform: { target_arch = "wasm32" },
|
||||
macos_platform: { target_os = "macos" },
|
||||
ios_platform: { target_os = "ios" },
|
||||
windows_platform: { target_os = "windows" },
|
||||
apple: { any(target_os = "ios", target_os = "macos") },
|
||||
free_unix: { all(unix, not(apple), not(android_platform)) },
|
||||
|
||||
// Native displays.
|
||||
x11_platform: { all(feature = "x11", free_unix, not(wasm)) },
|
||||
wayland_platform: { all(feature = "wayland", free_unix, not(wasm)) },
|
||||
}
|
||||
}
|
|
@ -1,8 +1,4 @@
|
|||
#[cfg(any(
|
||||
all(target_os = "linux", feature = "x11"),
|
||||
target_os = "macos",
|
||||
target_os = "windows"
|
||||
))]
|
||||
#[cfg(any(x11_platform, macos_platform, windows_platform))]
|
||||
fn main() {
|
||||
use std::collections::HashMap;
|
||||
|
||||
|
@ -78,11 +74,7 @@ fn main() {
|
|||
})
|
||||
}
|
||||
|
||||
#[cfg(not(any(
|
||||
all(target_os = "linux", feature = "x11"),
|
||||
target_os = "macos",
|
||||
target_os = "windows"
|
||||
)))]
|
||||
#[cfg(not(any(x11_platform, macos_platform, windows_platform)))]
|
||||
fn main() {
|
||||
panic!("This example is supported only on x11, macOS, and Windows.");
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#![allow(clippy::single_match)]
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[cfg(not(wasm_platform))]
|
||||
fn main() {
|
||||
use simple_logger::SimpleLogger;
|
||||
use winit::{
|
||||
|
@ -49,7 +49,7 @@ fn main() {
|
|||
});
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[cfg(wasm_platform)]
|
||||
fn main() {
|
||||
panic!("This example is not supported on web.");
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#![allow(clippy::single_match)]
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[cfg(not(wasm_platform))]
|
||||
fn main() {
|
||||
use std::{collections::HashMap, sync::mpsc, thread, time::Duration};
|
||||
|
||||
|
@ -193,7 +193,7 @@ fn main() {
|
|||
})
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[cfg(wasm_platform)]
|
||||
fn main() {
|
||||
panic!("Example not supported on Wasm");
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#![allow(clippy::single_match)]
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[cfg(not(wasm_platform))]
|
||||
fn main() {
|
||||
use std::{thread, time};
|
||||
|
||||
|
@ -42,7 +42,7 @@ fn main() {
|
|||
});
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[cfg(wasm_platform)]
|
||||
fn main() {
|
||||
unimplemented!() // `Window` can't be sent between threads
|
||||
}
|
||||
|
|
|
@ -14,13 +14,13 @@ pub fn main() {
|
|||
.build(&event_loop)
|
||||
.unwrap();
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[cfg(wasm_platform)]
|
||||
let log_list = wasm::insert_canvas_and_create_log_list(&window);
|
||||
|
||||
event_loop.run(move |event, _, control_flow| {
|
||||
control_flow.set_wait();
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[cfg(wasm_platform)]
|
||||
wasm::log_event(&log_list, &event);
|
||||
|
||||
match event {
|
||||
|
@ -36,7 +36,7 @@ pub fn main() {
|
|||
});
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[cfg(wasm_platform)]
|
||||
mod wasm {
|
||||
use wasm_bindgen::prelude::*;
|
||||
use winit::{event::Event, window::Window};
|
||||
|
|
|
@ -2,7 +2,7 @@ pub fn main() {
|
|||
println!("This example must be run with cargo run-wasm --example web_aspect_ratio")
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[cfg(wasm_platform)]
|
||||
mod wasm {
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::JsCast;
|
||||
|
|
|
@ -2,14 +2,11 @@
|
|||
|
||||
// Limit this example to only compatible platforms.
|
||||
#[cfg(any(
|
||||
target_os = "windows",
|
||||
target_os = "macos",
|
||||
target_os = "linux",
|
||||
target_os = "dragonfly",
|
||||
target_os = "freebsd",
|
||||
target_os = "netbsd",
|
||||
target_os = "openbsd",
|
||||
target_os = "android",
|
||||
windows_platform,
|
||||
macos_platform,
|
||||
x11_platform,
|
||||
wayland_platform,
|
||||
android_platform
|
||||
))]
|
||||
fn main() {
|
||||
use std::{thread::sleep, time::Duration};
|
||||
|
@ -60,7 +57,7 @@ fn main() {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "ios", target_arch = "wasm32"))]
|
||||
#[cfg(any(ios_platform, wasm_platform))]
|
||||
fn main() {
|
||||
println!("This platform doesn't support run_return.");
|
||||
}
|
||||
|
|
|
@ -102,11 +102,11 @@ impl<T> EventLoopBuilder<T> {
|
|||
///
|
||||
/// [`platform`]: crate::platform
|
||||
#[cfg_attr(
|
||||
target_os = "android",
|
||||
android,
|
||||
doc = "[`.with_android_app(app)`]: crate::platform::android::EventLoopBuilderExtAndroid::with_android_app"
|
||||
)]
|
||||
#[cfg_attr(
|
||||
not(target_os = "android"),
|
||||
not(android),
|
||||
doc = "[`.with_android_app(app)`]: #only-available-on-android"
|
||||
)]
|
||||
#[inline]
|
||||
|
@ -339,14 +339,7 @@ impl<T> EventLoopWindowTarget<T> {
|
|||
///
|
||||
/// [`DeviceEvent`]: crate::event::DeviceEvent
|
||||
pub fn set_device_event_filter(&self, _filter: DeviceEventFilter) {
|
||||
#[cfg(any(
|
||||
target_os = "linux",
|
||||
target_os = "dragonfly",
|
||||
target_os = "freebsd",
|
||||
target_os = "netbsd",
|
||||
target_os = "openbsd",
|
||||
target_os = "windows"
|
||||
))]
|
||||
#[cfg(any(x11_platform, wayland_platform, windows))]
|
||||
self.p.set_device_event_filter(_filter);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,47 +15,26 @@
|
|||
//!
|
||||
//! However only the module corresponding to the platform you're compiling to will be available.
|
||||
|
||||
#[cfg(target_os = "android")]
|
||||
#[cfg(android_platform)]
|
||||
pub mod android;
|
||||
#[cfg(target_os = "ios")]
|
||||
#[cfg(ios_platform)]
|
||||
pub mod ios;
|
||||
#[cfg(target_os = "macos")]
|
||||
#[cfg(macos_platform)]
|
||||
pub mod macos;
|
||||
#[cfg(all(
|
||||
feature = "wayland",
|
||||
any(
|
||||
target_os = "linux",
|
||||
target_os = "dragonfly",
|
||||
target_os = "freebsd",
|
||||
target_os = "netbsd",
|
||||
target_os = "openbsd",
|
||||
)
|
||||
))]
|
||||
#[cfg(wayland_platform)]
|
||||
pub mod wayland;
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[cfg(wasm_platform)]
|
||||
pub mod web;
|
||||
#[cfg(target_os = "windows")]
|
||||
#[cfg(windows_platform)]
|
||||
pub mod windows;
|
||||
#[cfg(all(
|
||||
feature = "x11",
|
||||
any(
|
||||
target_os = "linux",
|
||||
target_os = "dragonfly",
|
||||
target_os = "freebsd",
|
||||
target_os = "netbsd",
|
||||
target_os = "openbsd",
|
||||
)
|
||||
))]
|
||||
#[cfg(x11_platform)]
|
||||
pub mod x11;
|
||||
|
||||
#[cfg(any(
|
||||
target_os = "windows",
|
||||
target_os = "macos",
|
||||
target_os = "android",
|
||||
target_os = "linux",
|
||||
target_os = "dragonfly",
|
||||
target_os = "freebsd",
|
||||
target_os = "netbsd",
|
||||
target_os = "openbsd"
|
||||
windows_platform,
|
||||
macos_platform,
|
||||
android_platform,
|
||||
x11_platform,
|
||||
wayland_platform
|
||||
))]
|
||||
pub mod run_return;
|
||||
|
|
|
@ -41,7 +41,7 @@ impl<T> EventLoopWindowTargetExtWayland for EventLoopWindowTarget<T> {
|
|||
LinuxEventLoopWindowTarget::Wayland(ref p) => {
|
||||
Some(p.display().get_display_ptr() as *mut _)
|
||||
}
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ impl WindowExtWayland for Window {
|
|||
fn wayland_surface(&self) -> Option<*mut raw::c_void> {
|
||||
match self.window {
|
||||
LinuxWindow::Wayland(ref w) => Some(w.surface().as_ref().c_ptr() as *mut _),
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ impl WindowExtWayland for Window {
|
|||
fn wayland_display(&self) -> Option<*mut raw::c_void> {
|
||||
match self.window {
|
||||
LinuxWindow::Wayland(ref w) => Some(w.display().get_display_ptr() as *mut _),
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ impl<T> EventLoopWindowTargetExtX11 for EventLoopWindowTarget<T> {
|
|||
fn xlib_xconnection(&self) -> Option<Arc<XConnection>> {
|
||||
match self.p {
|
||||
LinuxEventLoopWindowTarget::X(ref e) => Some(e.x_connection().clone()),
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ impl WindowExtX11 for Window {
|
|||
fn xlib_window(&self) -> Option<raw::c_ulong> {
|
||||
match self.window {
|
||||
LinuxWindow::X(ref w) => Some(w.xlib_window()),
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
@ -133,7 +133,7 @@ impl WindowExtX11 for Window {
|
|||
fn xlib_display(&self) -> Option<*mut raw::c_void> {
|
||||
match self.window {
|
||||
LinuxWindow::X(ref w) => Some(w.xlib_display()),
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ impl WindowExtX11 for Window {
|
|||
fn xlib_screen_id(&self) -> Option<raw::c_int> {
|
||||
match self.window {
|
||||
LinuxWindow::X(ref w) => Some(w.xlib_screen_id()),
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
@ -151,7 +151,7 @@ impl WindowExtX11 for Window {
|
|||
fn xlib_xconnection(&self) -> Option<Arc<XConnection>> {
|
||||
match self.window {
|
||||
LinuxWindow::X(ref w) => Some(w.xlib_xconnection()),
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
@ -160,7 +160,7 @@ impl WindowExtX11 for Window {
|
|||
fn xcb_connection(&self) -> Option<*mut raw::c_void> {
|
||||
match self.window {
|
||||
LinuxWindow::X(ref w) => Some(w.xcb_connection()),
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#![cfg(target_os = "android")]
|
||||
#![cfg(android_platform)]
|
||||
|
||||
use std::{
|
||||
collections::VecDeque,
|
||||
|
|
|
@ -55,7 +55,7 @@
|
|||
//!
|
||||
//! Also note that app may not receive the LoopDestroyed event if suspended; it might be SIGKILL'ed.
|
||||
|
||||
#![cfg(target_os = "ios")]
|
||||
#![cfg(ios_platform)]
|
||||
#![allow(clippy::let_unit_value)]
|
||||
|
||||
// TODO: (mtak-) UIKit requires main thread for virtually all function/method calls. This could be
|
||||
|
|
|
@ -1,19 +1,13 @@
|
|||
#![cfg(any(
|
||||
target_os = "linux",
|
||||
target_os = "dragonfly",
|
||||
target_os = "freebsd",
|
||||
target_os = "netbsd",
|
||||
target_os = "openbsd"
|
||||
))]
|
||||
#![cfg(free_unix)]
|
||||
|
||||
#[cfg(all(not(feature = "x11"), not(feature = "wayland")))]
|
||||
#[cfg(all(not(x11_platform), not(wayland_platform)))]
|
||||
compile_error!("Please select a feature to build for unix: `x11`, `wayland`");
|
||||
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
use std::error::Error;
|
||||
|
||||
use std::{collections::VecDeque, env, fmt};
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
use std::{
|
||||
ffi::CStr,
|
||||
mem::MaybeUninit,
|
||||
|
@ -21,15 +15,15 @@ use std::{
|
|||
sync::{Arc, Mutex},
|
||||
};
|
||||
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
use once_cell::sync::Lazy;
|
||||
use raw_window_handle::{RawDisplayHandle, RawWindowHandle};
|
||||
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
pub use self::x11::XNotSupported;
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
use self::x11::{ffi::XVisualInfo, util::WindowType as XWindowType, XConnection, XError};
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
use crate::platform::x11::XlibErrorHook;
|
||||
use crate::{
|
||||
dpi::{PhysicalPosition, PhysicalSize, Position, Size},
|
||||
|
@ -48,9 +42,9 @@ use crate::{
|
|||
pub(crate) use crate::icon::RgbaIcon as PlatformIcon;
|
||||
pub(self) use crate::platform_impl::Fullscreen;
|
||||
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
pub mod wayland;
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
pub mod x11;
|
||||
|
||||
/// Environment variable specifying which backend should be used on unix platform.
|
||||
|
@ -64,9 +58,9 @@ const BACKEND_PREFERENCE_ENV_VAR: &str = "WINIT_UNIX_BACKEND";
|
|||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
||||
pub(crate) enum Backend {
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
X,
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
Wayland,
|
||||
}
|
||||
|
||||
|
@ -91,15 +85,15 @@ impl ApplicationName {
|
|||
#[derive(Clone)]
|
||||
pub struct PlatformSpecificWindowBuilderAttributes {
|
||||
pub name: Option<ApplicationName>,
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
pub visual_infos: Option<XVisualInfo>,
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
pub screen_id: Option<i32>,
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
pub base_size: Option<Size>,
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
pub override_redirect: bool,
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
pub x11_window_types: Vec<XWindowType>,
|
||||
}
|
||||
|
||||
|
@ -107,51 +101,51 @@ impl Default for PlatformSpecificWindowBuilderAttributes {
|
|||
fn default() -> Self {
|
||||
Self {
|
||||
name: None,
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
visual_infos: None,
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
screen_id: None,
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
base_size: None,
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
override_redirect: false,
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
x11_window_types: vec![XWindowType::Normal],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
pub static X11_BACKEND: Lazy<Mutex<Result<Arc<XConnection>, XNotSupported>>> =
|
||||
Lazy::new(|| Mutex::new(XConnection::new(Some(x_error_callback)).map(Arc::new)));
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum OsError {
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
XError(XError),
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
XMisc(&'static str),
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
WaylandMisc(&'static str),
|
||||
}
|
||||
|
||||
impl fmt::Display for OsError {
|
||||
fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
||||
match *self {
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
OsError::XError(ref e) => _f.pad(&e.description),
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
OsError::XMisc(e) => _f.pad(e),
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
OsError::WaylandMisc(e) => _f.pad(e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub enum Window {
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
X(x11::Window),
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
Wayland(wayland::Window),
|
||||
}
|
||||
|
||||
|
@ -178,26 +172,26 @@ impl WindowId {
|
|||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub enum DeviceId {
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
X(x11::DeviceId),
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
Wayland(wayland::DeviceId),
|
||||
}
|
||||
|
||||
impl DeviceId {
|
||||
pub const unsafe fn dummy() -> Self {
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
return DeviceId::Wayland(wayland::DeviceId::dummy());
|
||||
#[cfg(all(not(feature = "wayland"), feature = "x11"))]
|
||||
#[cfg(all(not(wayland_platform), x11_platform))]
|
||||
return DeviceId::X(x11::DeviceId::dummy());
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub enum MonitorHandle {
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
X(x11::MonitorHandle),
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
Wayland(wayland::MonitorHandle),
|
||||
}
|
||||
|
||||
|
@ -213,17 +207,17 @@ pub enum MonitorHandle {
|
|||
macro_rules! x11_or_wayland {
|
||||
(match $what:expr; $enum:ident ( $($c1:tt)* ) => $x:expr; as $enum2:ident ) => {
|
||||
match $what {
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
$enum::X($($c1)*) => $enum2::X($x),
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
$enum::Wayland($($c1)*) => $enum2::Wayland($x),
|
||||
}
|
||||
};
|
||||
(match $what:expr; $enum:ident ( $($c1:tt)* ) => $x:expr) => {
|
||||
match $what {
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
$enum::X($($c1)*) => $x,
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
$enum::Wayland($($c1)*) => $x,
|
||||
}
|
||||
};
|
||||
|
@ -268,9 +262,9 @@ impl MonitorHandle {
|
|||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum VideoMode {
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
X(x11::VideoMode),
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
Wayland(wayland::VideoMode),
|
||||
}
|
||||
|
||||
|
@ -304,11 +298,11 @@ impl Window {
|
|||
pl_attribs: PlatformSpecificWindowBuilderAttributes,
|
||||
) -> Result<Self, RootOsError> {
|
||||
match *window_target {
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
EventLoopWindowTarget::Wayland(ref window_target) => {
|
||||
wayland::Window::new(window_target, attribs, pl_attribs).map(Window::Wayland)
|
||||
}
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
EventLoopWindowTarget::X(ref window_target) => {
|
||||
x11::Window::new(window_target, attribs, pl_attribs).map(Window::X)
|
||||
}
|
||||
|
@ -318,9 +312,9 @@ impl Window {
|
|||
#[inline]
|
||||
pub fn id(&self) -> WindowId {
|
||||
match self {
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
Self::Wayland(window) => window.id(),
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
Self::X(window) => window.id(),
|
||||
}
|
||||
}
|
||||
|
@ -483,9 +477,9 @@ impl Window {
|
|||
#[inline]
|
||||
pub fn set_window_level(&self, _level: WindowLevel) {
|
||||
match self {
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
Window::X(ref w) => w.set_window_level(_level),
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
Window::Wayland(_) => (),
|
||||
}
|
||||
}
|
||||
|
@ -493,9 +487,9 @@ impl Window {
|
|||
#[inline]
|
||||
pub fn set_window_icon(&self, _window_icon: Option<Icon>) {
|
||||
match self {
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
Window::X(ref w) => w.set_window_icon(_window_icon),
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
Window::Wayland(_) => (),
|
||||
}
|
||||
}
|
||||
|
@ -513,17 +507,17 @@ impl Window {
|
|||
#[inline]
|
||||
pub fn focus_window(&self) {
|
||||
match self {
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
Window::X(ref w) => w.focus_window(),
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
Window::Wayland(_) => (),
|
||||
}
|
||||
}
|
||||
pub fn request_user_attention(&self, request_type: Option<UserAttentionType>) {
|
||||
match self {
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
Window::X(ref w) => w.request_user_attention(request_type),
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
Window::Wayland(ref w) => w.request_user_attention(request_type),
|
||||
}
|
||||
}
|
||||
|
@ -536,12 +530,12 @@ impl Window {
|
|||
#[inline]
|
||||
pub fn current_monitor(&self) -> Option<MonitorHandle> {
|
||||
match self {
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
Window::X(ref window) => {
|
||||
let current_monitor = MonitorHandle::X(window.current_monitor());
|
||||
Some(current_monitor)
|
||||
}
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
Window::Wayland(ref window) => {
|
||||
let current_monitor = MonitorHandle::Wayland(window.current_monitor()?);
|
||||
Some(current_monitor)
|
||||
|
@ -552,13 +546,13 @@ impl Window {
|
|||
#[inline]
|
||||
pub fn available_monitors(&self) -> VecDeque<MonitorHandle> {
|
||||
match self {
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
Window::X(ref window) => window
|
||||
.available_monitors()
|
||||
.into_iter()
|
||||
.map(MonitorHandle::X)
|
||||
.collect(),
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
Window::Wayland(ref window) => window
|
||||
.available_monitors()
|
||||
.into_iter()
|
||||
|
@ -570,12 +564,12 @@ impl Window {
|
|||
#[inline]
|
||||
pub fn primary_monitor(&self) -> Option<MonitorHandle> {
|
||||
match self {
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
Window::X(ref window) => {
|
||||
let primary_monitor = MonitorHandle::X(window.primary_monitor());
|
||||
Some(primary_monitor)
|
||||
}
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
Window::Wayland(ref window) => window.primary_monitor(),
|
||||
}
|
||||
}
|
||||
|
@ -607,11 +601,11 @@ impl Window {
|
|||
}
|
||||
|
||||
/// Hooks for X11 errors.
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
pub(crate) static mut XLIB_ERROR_HOOKS: Lazy<Mutex<Vec<XlibErrorHook>>> =
|
||||
Lazy::new(|| Mutex::new(Vec::new()));
|
||||
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
unsafe extern "C" fn x_error_callback(
|
||||
display: *mut x11::ffi::Display,
|
||||
event: *mut x11::ffi::XErrorEvent,
|
||||
|
@ -654,16 +648,16 @@ unsafe extern "C" fn x_error_callback(
|
|||
}
|
||||
|
||||
pub enum EventLoop<T: 'static> {
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
Wayland(Box<wayland::EventLoop<T>>),
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
X(x11::EventLoop<T>),
|
||||
}
|
||||
|
||||
pub enum EventLoopProxy<T: 'static> {
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
X(x11::EventLoopProxy<T>),
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
Wayland(wayland::EventLoopProxy<T>),
|
||||
}
|
||||
|
||||
|
@ -684,13 +678,13 @@ impl<T: 'static> EventLoop<T> {
|
|||
);
|
||||
}
|
||||
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
if attributes.forced_backend == Some(Backend::X) {
|
||||
// TODO: Propagate
|
||||
return EventLoop::new_x11_any_thread().unwrap();
|
||||
}
|
||||
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
if attributes.forced_backend == Some(Backend::Wayland) {
|
||||
// TODO: Propagate
|
||||
return EventLoop::new_wayland_any_thread().expect("failed to open Wayland connection");
|
||||
|
@ -700,17 +694,17 @@ impl<T: 'static> EventLoop<T> {
|
|||
match env_var.as_str() {
|
||||
"x11" => {
|
||||
// TODO: propagate
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
return EventLoop::new_x11_any_thread()
|
||||
.expect("Failed to initialize X11 backend");
|
||||
#[cfg(not(feature = "x11"))]
|
||||
#[cfg(not(x11_platform))]
|
||||
panic!("x11 feature is not enabled")
|
||||
}
|
||||
"wayland" => {
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
return EventLoop::new_wayland_any_thread()
|
||||
.expect("Failed to initialize Wayland backend");
|
||||
#[cfg(not(feature = "wayland"))]
|
||||
#[cfg(not(wayland_platform))]
|
||||
panic!("wayland feature is not enabled");
|
||||
}
|
||||
_ => panic!(
|
||||
|
@ -720,21 +714,21 @@ impl<T: 'static> EventLoop<T> {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
let wayland_err = match EventLoop::new_wayland_any_thread() {
|
||||
Ok(event_loop) => return event_loop,
|
||||
Err(err) => err,
|
||||
};
|
||||
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
let x11_err = match EventLoop::new_x11_any_thread() {
|
||||
Ok(event_loop) => return event_loop,
|
||||
Err(err) => err,
|
||||
};
|
||||
|
||||
#[cfg(not(feature = "wayland"))]
|
||||
#[cfg(not(wayland_platform))]
|
||||
let wayland_err = "backend disabled";
|
||||
#[cfg(not(feature = "x11"))]
|
||||
#[cfg(not(x11_platform))]
|
||||
let x11_err = "backend disabled";
|
||||
|
||||
panic!(
|
||||
|
@ -743,12 +737,12 @@ impl<T: 'static> EventLoop<T> {
|
|||
);
|
||||
}
|
||||
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
fn new_wayland_any_thread() -> Result<EventLoop<T>, Box<dyn Error>> {
|
||||
wayland::EventLoop::new().map(|evlp| EventLoop::Wayland(Box::new(evlp)))
|
||||
}
|
||||
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
fn new_x11_any_thread() -> Result<EventLoop<T>, XNotSupported> {
|
||||
let xconn = match X11_BACKEND.lock().unwrap().as_ref() {
|
||||
Ok(xconn) => xconn.clone(),
|
||||
|
@ -788,9 +782,9 @@ impl<T: 'static> EventLoopProxy<T> {
|
|||
}
|
||||
|
||||
pub enum EventLoopWindowTarget<T> {
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
Wayland(wayland::EventLoopWindowTarget<T>),
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
X(x11::EventLoopWindowTarget<T>),
|
||||
}
|
||||
|
||||
|
@ -798,9 +792,9 @@ impl<T> EventLoopWindowTarget<T> {
|
|||
#[inline]
|
||||
pub fn is_wayland(&self) -> bool {
|
||||
match *self {
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
EventLoopWindowTarget::Wayland(_) => true,
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
@ -808,13 +802,13 @@ impl<T> EventLoopWindowTarget<T> {
|
|||
#[inline]
|
||||
pub fn available_monitors(&self) -> VecDeque<MonitorHandle> {
|
||||
match *self {
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
EventLoopWindowTarget::Wayland(ref evlp) => evlp
|
||||
.available_monitors()
|
||||
.into_iter()
|
||||
.map(MonitorHandle::Wayland)
|
||||
.collect(),
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
EventLoopWindowTarget::X(ref evlp) => evlp
|
||||
.x_connection()
|
||||
.available_monitors()
|
||||
|
@ -827,9 +821,9 @@ impl<T> EventLoopWindowTarget<T> {
|
|||
#[inline]
|
||||
pub fn primary_monitor(&self) -> Option<MonitorHandle> {
|
||||
match *self {
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
EventLoopWindowTarget::Wayland(ref evlp) => evlp.primary_monitor(),
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
EventLoopWindowTarget::X(ref evlp) => {
|
||||
let primary_monitor = MonitorHandle::X(evlp.x_connection().primary_monitor());
|
||||
Some(primary_monitor)
|
||||
|
@ -840,9 +834,9 @@ impl<T> EventLoopWindowTarget<T> {
|
|||
#[inline]
|
||||
pub fn set_device_event_filter(&self, _filter: DeviceEventFilter) {
|
||||
match *self {
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
EventLoopWindowTarget::Wayland(_) => (),
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
EventLoopWindowTarget::X(ref evlp) => evlp.set_device_event_filter(_filter),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -268,7 +268,7 @@ impl<T: 'static> EventLoop<T> {
|
|||
PlatformEventLoopWindowTarget::Wayland(window_target) => {
|
||||
window_target.state.get_mut()
|
||||
}
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
|
@ -561,7 +561,7 @@ impl<T: 'static> EventLoop<T> {
|
|||
fn with_state<U, F: FnOnce(&mut WinitState) -> U>(&mut self, f: F) -> U {
|
||||
let state = match &mut self.window_target.p {
|
||||
PlatformEventLoopWindowTarget::Wayland(window_target) => window_target.state.get_mut(),
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
|
@ -571,7 +571,7 @@ impl<T: 'static> EventLoop<T> {
|
|||
fn loop_dispatch<D: Into<Option<std::time::Duration>>>(&mut self, timeout: D) -> IOResult<()> {
|
||||
let state = match &mut self.window_target.p {
|
||||
PlatformEventLoopWindowTarget::Wayland(window_target) => window_target.state.get_mut(),
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
|
|
|
@ -1,10 +1,4 @@
|
|||
#![cfg(any(
|
||||
target_os = "linux",
|
||||
target_os = "dragonfly",
|
||||
target_os = "freebsd",
|
||||
target_os = "netbsd",
|
||||
target_os = "openbsd"
|
||||
))]
|
||||
#![cfg(wayland_platform)]
|
||||
|
||||
use sctk::reexports::client::protocol::wl_surface::WlSurface;
|
||||
|
||||
|
|
|
@ -219,7 +219,7 @@ impl Window {
|
|||
Some(Fullscreen::Borderless(monitor)) => {
|
||||
let monitor = monitor.and_then(|monitor| match monitor {
|
||||
PlatformMonitorHandle::Wayland(monitor) => Some(monitor.proxy),
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
PlatformMonitorHandle::X(_) => None,
|
||||
});
|
||||
|
||||
|
@ -490,7 +490,7 @@ impl Window {
|
|||
Some(Fullscreen::Borderless(monitor)) => {
|
||||
let monitor = monitor.and_then(|monitor| match monitor {
|
||||
PlatformMonitorHandle::Wayland(monitor) => Some(monitor.proxy),
|
||||
#[cfg(feature = "x11")]
|
||||
#[cfg(x11_platform)]
|
||||
PlatformMonitorHandle::X(_) => None,
|
||||
});
|
||||
|
||||
|
|
|
@ -1,10 +1,4 @@
|
|||
#![cfg(any(
|
||||
target_os = "linux",
|
||||
target_os = "dragonfly",
|
||||
target_os = "freebsd",
|
||||
target_os = "netbsd",
|
||||
target_os = "openbsd"
|
||||
))]
|
||||
#![cfg(x11_platform)]
|
||||
|
||||
mod dnd;
|
||||
mod event_processor;
|
||||
|
@ -536,7 +530,7 @@ impl<T: 'static> EventLoop<T> {
|
|||
pub(crate) fn get_xtarget<T>(target: &RootELW<T>) -> &EventLoopWindowTarget<T> {
|
||||
match target.p {
|
||||
super::EventLoopWindowTarget::X(ref target) => target,
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -697,7 +697,7 @@ impl UnownedWindow {
|
|||
(None, monitor)
|
||||
}
|
||||
Fullscreen::Borderless(None) => (None, self.current_monitor()),
|
||||
#[cfg(feature = "wayland")]
|
||||
#[cfg(wayland_platform)]
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
|
|
|
@ -1,28 +1,22 @@
|
|||
use crate::monitor::{MonitorHandle as RootMonitorHandle, VideoMode as RootVideoMode};
|
||||
use crate::window::Fullscreen as RootFullscreen;
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
#[cfg(windows_platform)]
|
||||
#[path = "windows/mod.rs"]
|
||||
mod platform;
|
||||
#[cfg(any(
|
||||
target_os = "linux",
|
||||
target_os = "dragonfly",
|
||||
target_os = "freebsd",
|
||||
target_os = "netbsd",
|
||||
target_os = "openbsd"
|
||||
))]
|
||||
#[cfg(any(x11_platform, wayland_platform))]
|
||||
#[path = "linux/mod.rs"]
|
||||
mod platform;
|
||||
#[cfg(target_os = "macos")]
|
||||
#[cfg(macos_platform)]
|
||||
#[path = "macos/mod.rs"]
|
||||
mod platform;
|
||||
#[cfg(target_os = "android")]
|
||||
#[cfg(android_platform)]
|
||||
#[path = "android/mod.rs"]
|
||||
mod platform;
|
||||
#[cfg(target_os = "ios")]
|
||||
#[cfg(ios_platform)]
|
||||
#[path = "ios/mod.rs"]
|
||||
mod platform;
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[cfg(wasm_platform)]
|
||||
#[path = "web/mod.rs"]
|
||||
mod platform;
|
||||
|
||||
|
@ -58,15 +52,12 @@ impl From<Fullscreen> for RootFullscreen {
|
|||
}
|
||||
|
||||
#[cfg(all(
|
||||
not(target_os = "ios"),
|
||||
not(target_os = "windows"),
|
||||
not(target_os = "linux"),
|
||||
not(target_os = "macos"),
|
||||
not(target_os = "android"),
|
||||
not(target_os = "dragonfly"),
|
||||
not(target_os = "freebsd"),
|
||||
not(target_os = "netbsd"),
|
||||
not(target_os = "openbsd"),
|
||||
not(target_arch = "wasm32"),
|
||||
not(ios_platform),
|
||||
not(windows_platform),
|
||||
not(macos_platform),
|
||||
not(android_platform),
|
||||
not(x11_platform),
|
||||
not(wayland_platform),
|
||||
not(wasm_platform),
|
||||
))]
|
||||
compile_error!("The platform you're compiling for is not supported by winit");
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#![cfg(target_os = "windows")]
|
||||
#![cfg(windows_platform)]
|
||||
|
||||
use windows_sys::Win32::{
|
||||
Foundation::{HANDLE, HWND},
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#![cfg(target_os = "windows")]
|
||||
#![cfg(windows_platform)]
|
||||
|
||||
use raw_window_handle::{
|
||||
RawDisplayHandle, RawWindowHandle, Win32WindowHandle, WindowsDisplayHandle,
|
||||
|
|
|
@ -1056,7 +1056,7 @@ impl Window {
|
|||
///
|
||||
/// [`NSWindowSharingNone`]: https://developer.apple.com/documentation/appkit/nswindowsharingtype/nswindowsharingnone
|
||||
pub fn set_content_protected(&self, _protected: bool) {
|
||||
#[cfg(any(target_os = "macos", target_os = "windows"))]
|
||||
#[cfg(any(macos_platform, windows_platform))]
|
||||
self.window.set_content_protected(_protected);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#[allow(dead_code)]
|
||||
fn needs_send<T: Send>() {}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[cfg(not(wasm_platform))]
|
||||
#[test]
|
||||
fn event_loop_proxy_send() {
|
||||
#[allow(dead_code)]
|
||||
|
@ -11,7 +11,7 @@ fn event_loop_proxy_send() {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[cfg(not(wasm_platform))]
|
||||
#[test]
|
||||
fn window_send() {
|
||||
// ensures that `winit::Window` implements `Send`
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#[allow(dead_code)]
|
||||
fn needs_sync<T: Sync>() {}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[cfg(not(wasm_platform))]
|
||||
#[test]
|
||||
fn window_sync() {
|
||||
// ensures that `winit::Window` implements `Sync`
|
||||
|
|
Loading…
Reference in a new issue