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