Skip to content

Commit af1e3c2

Browse files
committed
Fix window_icon_plugin
1 parent c463466 commit af1e3c2

File tree

1 file changed

+58
-59
lines changed

1 file changed

+58
-59
lines changed

src/engine/window_icon_plugin.rs

Lines changed: 58 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -72,63 +72,62 @@ fn set_window_icon(
7272
if events.p0().is_empty() {
7373
return;
7474
}
75-
WINIT_WINDOWS.with_borrow_mut(|windows| { info!("Ahoy!") });
76-
// let outgoing = WINIT_WINDOWS.with_borrow_mut(|windows| {
77-
// let mut outgoing = Vec::new();
78-
// for event in events.p0().read() {
79-
// debug!(?event.window, ?windows, "Handling {}", type_name::<AddWindowIconWithRetry>());
80-
81-
// // Identify window
82-
// let target_window = windows.get_window(event.window);
83-
// let Some(window) = target_window else {
84-
// warn!(
85-
// ?windows,
86-
// "Window {:?} does not exist, retrying later...",
87-
// event.window
88-
// );
89-
// outgoing.push(event.clone());
90-
// continue;
91-
// };
92-
93-
// // Fetch the image asset
94-
// let Some(image) = assets.get(&event.image) else {
95-
// error!(
96-
// "Image handle {:?} not found in assets, the window will not have our custom icon",
97-
// event.image
98-
// );
99-
// continue;
100-
// };
101-
102-
// // Acquire pixel data from the image
103-
// let Some(image_data) = image.data.clone() else {
104-
// error!(
105-
// "Image handle {:?} has no data, the window will not have our custom icon",
106-
// event.image
107-
// );
108-
// continue;
109-
// };
110-
111-
// // Convert between formats
112-
// let icon = match winit::window::Icon::from_rgba(
113-
// image_data,
114-
// image.texture_descriptor.size.width,
115-
// image.texture_descriptor.size.height,
116-
// ) {
117-
// Ok(icon) => icon,
118-
// Err(e) => {
119-
// error!("Failed to construct window icon: {:?}", e);
120-
// continue;
121-
// }
122-
// };
123-
124-
// // Set the window icon
125-
// info!(image_size = ?image.size(), "Setting window icon");
126-
// window.set_window_icon(Some(icon));
127-
// }
128-
// outgoing
129-
// });
130-
131-
// for event in outgoing {
132-
// events.p1().write(event);
133-
// }
75+
let outgoing = WINIT_WINDOWS.with_borrow(|windows| {
76+
let mut outgoing = Vec::new();
77+
for event in events.p0().read() {
78+
debug!(?event.window, ?windows, "Handling {}", type_name::<AddWindowIconWithRetry>());
79+
80+
// Identify window
81+
let target_window = windows.get_window(event.window);
82+
let Some(window) = target_window else {
83+
warn!(
84+
?windows,
85+
"Window {:?} does not exist, retrying later...",
86+
event.window
87+
);
88+
outgoing.push(event.clone());
89+
continue;
90+
};
91+
92+
// Fetch the image asset
93+
let Some(image) = assets.get(&event.image) else {
94+
error!(
95+
"Image handle {:?} not found in assets, the window will not have our custom icon",
96+
event.image
97+
);
98+
continue;
99+
};
100+
101+
// Acquire pixel data from the image
102+
let Some(image_data) = image.data.clone() else {
103+
error!(
104+
"Image handle {:?} has no data, the window will not have our custom icon",
105+
event.image
106+
);
107+
continue;
108+
};
109+
110+
// Convert between formats
111+
let icon = match winit::window::Icon::from_rgba(
112+
image_data,
113+
image.texture_descriptor.size.width,
114+
image.texture_descriptor.size.height,
115+
) {
116+
Ok(icon) => icon,
117+
Err(e) => {
118+
error!("Failed to construct window icon: {:?}", e);
119+
continue;
120+
}
121+
};
122+
123+
// Set the window icon
124+
info!(image_size = ?image.size(), "Setting window icon");
125+
window.set_window_icon(Some(icon));
126+
}
127+
outgoing
128+
});
129+
130+
for event in outgoing {
131+
events.p1().write(event);
132+
}
134133
}

0 commit comments

Comments
 (0)