diff --git a/crates/bevy_window/src/window.rs b/crates/bevy_window/src/window.rs index 611371b586..31fb061b61 100644 --- a/crates/bevy_window/src/window.rs +++ b/crates/bevy_window/src/window.rs @@ -138,6 +138,21 @@ pub struct Window { pub resolution: WindowResolution, /// Stores the title of the window. pub title: String, + /// Stores the application ID (on **`Wayland`**), `WM_CLASS` (on **`X11`**) or window class name (on **`Windows`**) of the window. + /// + /// For details about application ID conventions, see the [Desktop Entry Spec](https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#desktop-file-id). + /// For details about `WM_CLASS`, see the [X11 Manual Pages](https://www.x.org/releases/current/doc/man/man3/XAllocClassHint.3.xhtml). + /// For details about **`Windows`**'s window class names, see [About Window Classes](https://learn.microsoft.com/en-us/windows/win32/winmsg/about-window-classes). + /// + /// ## Platform-specific + /// + /// - **`Windows`**: Can only be set while building the window, setting the window's window class name. + /// - **`Wayland`**: Can only be set while building the window, setting the window's application ID. + /// - **`X11`**: Can only be set while building the window, setting the window's `WM_CLASS`. + /// - **`macOS`**, **`iOS`**, **`Android`**, and **`Web`**: not applicable. + /// + /// Notes: Changing this field during runtime will have no effect for now. + pub name: Option, /// How the alpha channel of textures should be handled while compositing. pub composite_alpha_mode: CompositeAlphaMode, /// The limits of the window's logical size @@ -242,6 +257,7 @@ impl Default for Window { fn default() -> Self { Self { title: "App".to_owned(), + name: None, cursor: Default::default(), present_mode: Default::default(), mode: Default::default(), diff --git a/crates/bevy_winit/src/winit_windows.rs b/crates/bevy_winit/src/winit_windows.rs index 484a7669f4..48757887b8 100644 --- a/crates/bevy_winit/src/winit_windows.rs +++ b/crates/bevy_winit/src/winit_windows.rs @@ -96,6 +96,60 @@ impl WinitWindows { .with_transparent(window.transparent) .with_visible(window.visible); + #[cfg(any( + target_os = "linux", + target_os = "dragonfly", + target_os = "freebsd", + target_os = "netbsd", + target_os = "openbsd", + target_os = "windows" + ))] + if let Some(name) = &window.name { + #[cfg(all( + feature = "wayland", + any( + target_os = "linux", + target_os = "dragonfly", + target_os = "freebsd", + target_os = "netbsd", + target_os = "openbsd" + ) + ))] + { + winit_window_builder = winit::platform::wayland::WindowBuilderExtWayland::with_name( + winit_window_builder, + name.clone(), + "", + ); + } + + #[cfg(all( + feature = "x11", + any( + target_os = "linux", + target_os = "dragonfly", + target_os = "freebsd", + target_os = "netbsd", + target_os = "openbsd" + ) + ))] + { + winit_window_builder = winit::platform::x11::WindowBuilderExtX11::with_name( + winit_window_builder, + name.clone(), + "", + ); + } + #[cfg(target_os = "windows")] + { + winit_window_builder = + winit::platform::windows::WindowBuilderExtWindows::with_class_name( + winit_window_builder, + name.clone(), + ); + } + } + let constraints = window.resize_constraints.check_constraints(); let min_inner_size = LogicalSize { width: constraints.min_width, diff --git a/examples/window/window_settings.rs b/examples/window/window_settings.rs index 77e24cef1f..31ea347e64 100644 --- a/examples/window/window_settings.rs +++ b/examples/window/window_settings.rs @@ -14,6 +14,7 @@ fn main() { DefaultPlugins.set(WindowPlugin { primary_window: Some(Window { title: "I am a window!".into(), + name: Some("bevy.app".into()), resolution: (500., 300.).into(), present_mode: PresentMode::AutoVsync, // Tells wasm not to override default event handling, like F5, Ctrl+R etc.