diff --git a/crates/bevy_internal/Cargo.toml b/crates/bevy_internal/Cargo.toml index 35be208d1ba6d..20af546e726e3 100644 --- a/crates/bevy_internal/Cargo.toml +++ b/crates/bevy_internal/Cargo.toml @@ -48,8 +48,8 @@ filesystem_watcher = ["bevy_asset/filesystem_watcher"] serialize = ["bevy_input/serialize"] # Display server protocol support (X11 is enabled by default) -wayland = ["bevy_winit/wayland"] -x11 = ["bevy_winit/x11"] +wayland = ["bevy_winit/wayland", "bevy_window/wayland"] +x11 = ["bevy_winit/x11", "bevy_window/x11"] # enable rendering of font glyphs using subpixel accuracy subpixel_glyph_atlas = ["bevy_text/subpixel_glyph_atlas"] diff --git a/crates/bevy_window/Cargo.toml b/crates/bevy_window/Cargo.toml index f77605cc76c80..53fe6d803841e 100644 --- a/crates/bevy_window/Cargo.toml +++ b/crates/bevy_window/Cargo.toml @@ -8,6 +8,10 @@ repository = "https://github.com/bevyengine/bevy" license = "MIT OR Apache-2.0" keywords = ["bevy"] +[features] +wayland = [] +x11 = [] + [dependencies] # bevy bevy_app = { path = "../bevy_app", version = "0.8.0-dev" } @@ -22,3 +26,6 @@ raw-window-handle = "0.4.2" [target.'cfg(target_arch = "wasm32")'.dependencies] web-sys = "0.3" + +[package.metadata.docs.rs] +features = ["x11"] \ No newline at end of file diff --git a/crates/bevy_window/src/window.rs b/crates/bevy_window/src/window.rs index dc4225db9b384..d97c67edac203 100644 --- a/crates/bevy_window/src/window.rs +++ b/crates/bevy_window/src/window.rs @@ -610,6 +610,26 @@ pub struct WindowDescriptor { pub resize_constraints: WindowResizeConstraints, pub scale_factor_override: Option, pub title: String, + #[cfg(all( + any( + target_os = "linux", + target_os = "freebsd", + target_os = "netbsd", + target_os = "openbsd" + ), + any(feature = "x11", feature = "wayland") + ))] + pub desktop_id: String, + #[cfg(all( + any( + target_os = "linux", + target_os = "freebsd", + target_os = "netbsd", + target_os = "openbsd" + ), + feature = "x11" + ))] + pub desktop_instance: String, #[doc(alias = "vsync")] pub present_mode: PresentMode, pub resizable: bool, @@ -633,6 +653,26 @@ impl Default for WindowDescriptor { fn default() -> Self { WindowDescriptor { title: "app".to_string(), + #[cfg(all( + any( + target_os = "linux", + target_os = "freebsd", + target_os = "netbsd", + target_os = "openbsd" + ), + any(feature = "x11", feature = "wayland") + ))] + desktop_id: "app".to_string(), + #[cfg(all( + any( + target_os = "linux", + target_os = "freebsd", + target_os = "netbsd", + target_os = "openbsd" + ), + feature = "x11" + ))] + desktop_instance: "Main".to_string(), width: 1280., height: 720., position: None, diff --git a/crates/bevy_winit/src/winit_windows.rs b/crates/bevy_winit/src/winit_windows.rs index 020b474650924..6f55399aa3e42 100644 --- a/crates/bevy_winit/src/winit_windows.rs +++ b/crates/bevy_winit/src/winit_windows.rs @@ -4,6 +4,17 @@ use bevy_window::{Window, WindowDescriptor, WindowId, WindowMode}; use raw_window_handle::HasRawWindowHandle; use winit::dpi::LogicalSize; +#[cfg(all( + any( + target_os = "linux", + target_os = "freebsd", + target_os = "netbsd", + target_os = "openbsd" + ), + any(feature = "x11", feature = "wayland") +))] +use winit::platform::unix::WindowBuilderExtUnix; + #[derive(Debug, Default)] pub struct WinitWindows { pub windows: HashMap, @@ -102,6 +113,44 @@ impl WinitWindows { #[allow(unused_mut)] let mut winit_window_builder = winit_window_builder.with_title(&window_descriptor.title); + #[allow(unused_mut)] + #[cfg(all( + any( + target_os = "linux", + target_os = "freebsd", + target_os = "netbsd", + target_os = "openbsd" + ), + feature = "x11" + ))] + let mut winit_window_builder = winit_window_builder.with_class( + window_descriptor.desktop_instance.clone(), // That's actually WM_INSTANCE + window_descriptor.desktop_id.clone(), // And that's WM_CLASS + ); + + // The right `with_class` function signature is: + // fn with_class(mut self, instance: String, class: String) -> Self; + + // When winit is upgraded to v0.27.0, change this to + // let mut winit_window_builder = winit_window_builder.with_name( + // window_descriptor.desktop_id.clone(), + // window_descriptor.desktop_instance.clone() + // ) + // (Source) https://github.com/rust-windowing/winit/blob/ce890c34551d9fb542f10dcb644d22d382e0c921/src/platform/unix.rs#L288 + + #[allow(unused_mut)] + #[cfg(all( + any( + target_os = "linux", + target_os = "freebsd", + target_os = "netbsd", + target_os = "openbsd" + ), + feature = "wayland" + ))] + let mut winit_window_builder = + winit_window_builder.with_app_id(window_descriptor.desktop_id.clone()); + #[cfg(target_arch = "wasm32")] { use wasm_bindgen::JsCast;