Skip to content

Commit 4bb1d05

Browse files
timon-schellingTrueDoctor
authored andcommitted
Desktop: Add taskbar icon on Windows (#3225)
* include icon as resource on windows * load icon
1 parent d06c816 commit 4bb1d05

File tree

5 files changed

+42
-3
lines changed

5 files changed

+42
-3
lines changed

Cargo.lock

Lines changed: 21 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

desktop/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ serde = { workspace = true }
4848
ash = { version = "0.38", optional = true }
4949

5050
# Windows-specific dependencies
51-
[target.'cfg(windows)'.dependencies]
51+
[target.'cfg(target_os = "windows")'.dependencies]
5252
windows = { version = "0.58.0", features = [
5353
"Win32_Foundation",
5454
"Win32_Graphics_Direct3D11",
@@ -72,3 +72,6 @@ core-foundation = { version = "0.9", optional = true }
7272
# Linux-specific dependencies
7373
[target.'cfg(target_os = "linux")'.dependencies]
7474
libc = { version = "0.2", optional = true }
75+
76+
[target.'cfg(target_os = "windows")'.build-dependencies]
77+
winres = "0.1"
310 KB
Binary file not shown.

desktop/build.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
fn main() {
2+
#[cfg(target_os = "windows")]
3+
{
4+
let mut res = winres::WindowsResource::new();
5+
res.set_icon("assets/graphite-icon-color.ico");
6+
res.compile().expect("Failed to compile Windows resources");
7+
}
8+
}

desktop/src/native_window.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,17 @@ impl NativeWindowHandle {
3939
} else {
4040
let x11_window = WindowAttributesX11::default().with_name(APP_ID, APP_NAME);
4141
window.with_platform_attributes(Box::new(x11_window))
42+
};
43+
}
44+
45+
#[cfg(target_os = "windows")]
46+
{
47+
if let Ok(win_icon) = winit::platform::windows::WinIcon::from_resource(1, None) {
48+
let icon = winit::icon::Icon(std::sync::Arc::new(win_icon));
49+
window = window.with_window_icon(Some(icon));
4250
}
4351
}
52+
4453
window
4554
}
4655
#[allow(unused_variables)]

0 commit comments

Comments
 (0)