diff --git a/CHANGELOG.md b/CHANGELOG.md index 84b0cd5e..d3099b6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ And please only add new entries to the top of this list, right below the `# Unre # Unreleased +- On Windows, added `WindowBuilderExtWindows::with_class_name` to customize the internal class name. - On iOS, always wake the event loop when transitioning from `ControlFlow::Poll` to `ControlFlow::Poll`. - **Breaking:** `ActivationTokenDone` event which could be requested with the new `startup_notify` module, see its docs for more. - On Wayland, make double clicking and moving the CSD frame more reliable. diff --git a/FEATURES.md b/FEATURES.md index 9e859d89..fce88d50 100644 --- a/FEATURES.md +++ b/FEATURES.md @@ -119,6 +119,7 @@ If your PR makes notable changes to Winit's features, please update this section ## Platform ### Windows +* Setting the name of the internal window class * Setting the taskbar icon * Setting the parent window * Setting a menu bar diff --git a/src/platform/windows.rs b/src/platform/windows.rs index 626e2fba..55da29f7 100644 --- a/src/platform/windows.rs +++ b/src/platform/windows.rs @@ -223,6 +223,9 @@ pub trait WindowBuilderExtWindows { /// Whether show or hide the window icon in the taskbar. fn with_skip_taskbar(self, skip: bool) -> WindowBuilder; + /// Customize the window class name. + fn with_class_name>(self, class_name: S) -> WindowBuilder; + /// Shows or hides the background drop shadow for undecorated windows. /// /// The shadow is hidden by default. @@ -267,6 +270,12 @@ impl WindowBuilderExtWindows for WindowBuilder { self } + #[inline] + fn with_class_name>(mut self, class_name: S) -> WindowBuilder { + self.platform_specific.class_name = class_name.into(); + self + } + #[inline] fn with_undecorated_shadow(mut self, shadow: bool) -> WindowBuilder { self.platform_specific.decoration_shadow = shadow; diff --git a/src/platform_impl/windows/mod.rs b/src/platform_impl/windows/mod.rs index ee256694..3d5c02a7 100644 --- a/src/platform_impl/windows/mod.rs +++ b/src/platform_impl/windows/mod.rs @@ -30,6 +30,7 @@ pub struct PlatformSpecificWindowBuilderAttributes { pub no_redirection_bitmap: bool, pub drag_and_drop: bool, pub skip_taskbar: bool, + pub class_name: String, pub decoration_shadow: bool, } @@ -42,6 +43,7 @@ impl Default for PlatformSpecificWindowBuilderAttributes { no_redirection_bitmap: false, drag_and_drop: true, skip_taskbar: false, + class_name: "Window Class".to_string(), decoration_shadow: false, } } diff --git a/src/platform_impl/windows/window.rs b/src/platform_impl/windows/window.rs index 04bd78d3..bf27e8ec 100644 --- a/src/platform_impl/windows/window.rs +++ b/src/platform_impl/windows/window.rs @@ -1100,7 +1100,8 @@ where { let title = util::encode_wide(&attributes.title); - let class_name = register_window_class::(); + let class_name = util::encode_wide(&pl_attribs.class_name); + register_window_class::(&class_name); let mut window_flags = WindowFlags::empty(); window_flags.set(WindowFlags::MARKER_DECORATIONS, attributes.decorations); @@ -1187,9 +1188,7 @@ where Ok(initdata.window.unwrap()) } -unsafe fn register_window_class() -> Vec { - let class_name = util::encode_wide("Window Class"); - +unsafe fn register_window_class(class_name: &[u16]) { let class = WNDCLASSEXW { cbSize: mem::size_of::() as u32, style: CS_HREDRAW | CS_VREDRAW, @@ -1210,8 +1209,6 @@ unsafe fn register_window_class() -> Vec { // Also since there is no weird element in the struct, there is no reason for this // call to fail. RegisterClassExW(&class); - - class_name } struct ComInitialized(*mut ());