From 50bbc85dc36659e5bf8e1c535180dc34a9bbe222 Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Sun, 6 Nov 2022 22:30:55 +0200 Subject: [PATCH] On Windows, fix icons specified on `WindowBuilder` not taking effect for windows created after the first one (#2530) --- CHANGELOG.md | 1 + src/platform_impl/windows/window.rs | 23 ++++++----------------- src/platform_impl/windows/window_state.rs | 3 +-- 3 files changed, 8 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d538d3d..b3e90880 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, fix icons specified on `WindowBuilder` not taking effect for windows created after the first one. - On Windows and macOS, add `Window::title` to query the current window title. - On Windows, fix focusing menubar when pressing `Alt`. - On MacOS, made `accepts_first_mouse` configurable. diff --git a/src/platform_impl/windows/window.rs b/src/platform_impl/windows/window.rs index 1361176a..e2515961 100644 --- a/src/platform_impl/windows/window.rs +++ b/src/platform_impl/windows/window.rs @@ -794,7 +794,6 @@ impl<'a, T: 'static> InitData<'a, T> { let window_state = { let window_state = WindowState::new( &self.attributes, - self.pl_attribs.taskbar_icon.clone(), scale_factor, current_theme, self.attributes.preferred_theme, @@ -904,6 +903,8 @@ impl<'a, T: 'static> InitData<'a, T> { } win.set_skip_taskbar(self.pl_attribs.skip_taskbar); + win.set_window_icon(self.attributes.window_icon.clone()); + win.set_taskbar_icon(self.pl_attribs.taskbar_icon.clone()); let attributes = self.attributes.clone(); @@ -957,7 +958,7 @@ where { let title = util::encode_wide(&attributes.title); - let class_name = register_window_class::(&attributes.window_icon, &pl_attribs.taskbar_icon); + let class_name = register_window_class::(); let mut window_flags = WindowFlags::empty(); window_flags.set(WindowFlags::MARKER_DECORATIONS, attributes.decorations); @@ -1030,21 +1031,9 @@ where Ok(initdata.window.unwrap()) } -unsafe fn register_window_class( - window_icon: &Option, - taskbar_icon: &Option, -) -> Vec { +unsafe fn register_window_class() -> Vec { let class_name = util::encode_wide("Window Class"); - let h_icon = taskbar_icon - .as_ref() - .map(|icon| icon.inner.as_raw_handle()) - .unwrap_or(0); - let h_icon_small = window_icon - .as_ref() - .map(|icon| icon.inner.as_raw_handle()) - .unwrap_or(0); - use windows_sys::Win32::Graphics::Gdi::COLOR_WINDOWFRAME; let class = WNDCLASSEXW { cbSize: mem::size_of::() as u32, @@ -1053,12 +1042,12 @@ unsafe fn register_window_class( cbClsExtra: 0, cbWndExtra: 0, hInstance: util::get_instance_handle(), - hIcon: h_icon, + hIcon: 0, hCursor: 0, // must be null in order for cursor state to work properly hbrBackground: COLOR_WINDOWFRAME as _, lpszMenuName: ptr::null(), lpszClassName: class_name.as_ptr(), - hIconSm: h_icon_small, + hIconSm: 0, }; // We ignore errors because registering the same window class twice would trigger diff --git a/src/platform_impl/windows/window_state.rs b/src/platform_impl/windows/window_state.rs index 4f3e8888..1f7ac631 100644 --- a/src/platform_impl/windows/window_state.rs +++ b/src/platform_impl/windows/window_state.rs @@ -123,7 +123,6 @@ pub enum ImeState { impl WindowState { pub(crate) fn new( attributes: &WindowAttributes, - taskbar_icon: Option, scale_factor: f64, current_theme: Theme, preferred_theme: Option, @@ -140,7 +139,7 @@ impl WindowState { max_size: attributes.max_inner_size, window_icon: attributes.window_icon.clone(), - taskbar_icon, + taskbar_icon: None, saved_window: None, scale_factor,