Skip to content

Commit

Permalink
On Windows, fix icons specified on WindowBuilder not taking effect …
Browse files Browse the repository at this point in the history
…for windows created after the first one (rust-windowing#2530)
  • Loading branch information
amrbashir committed Nov 6, 2022
1 parent 8669c2e commit 50bbc85
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
23 changes: 6 additions & 17 deletions src/platform_impl/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -957,7 +958,7 @@ where
{
let title = util::encode_wide(&attributes.title);

let class_name = register_window_class::<T>(&attributes.window_icon, &pl_attribs.taskbar_icon);
let class_name = register_window_class::<T>();

let mut window_flags = WindowFlags::empty();
window_flags.set(WindowFlags::MARKER_DECORATIONS, attributes.decorations);
Expand Down Expand Up @@ -1030,21 +1031,9 @@ where
Ok(initdata.window.unwrap())
}

unsafe fn register_window_class<T: 'static>(
window_icon: &Option<Icon>,
taskbar_icon: &Option<Icon>,
) -> Vec<u16> {
unsafe fn register_window_class<T: 'static>() -> Vec<u16> {
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::<WNDCLASSEXW>() as u32,
Expand All @@ -1053,12 +1042,12 @@ unsafe fn register_window_class<T: 'static>(
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
Expand Down
3 changes: 1 addition & 2 deletions src/platform_impl/windows/window_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ pub enum ImeState {
impl WindowState {
pub(crate) fn new(
attributes: &WindowAttributes,
taskbar_icon: Option<Icon>,
scale_factor: f64,
current_theme: Theme,
preferred_theme: Option<Theme>,
Expand All @@ -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,
Expand Down

0 comments on commit 50bbc85

Please sign in to comment.