diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d91573..43bb757 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## [Unreleased] - ReleaseDate +### Added + +- Add missing window icon. Note for package maintainers: On Wayland, the name of the `.desktop` file entries needs to match RustyPoB's `app_id`. `app_id` is set to either `rusty-path-of-building-1` or `rusty-path-of-building-2`, depending on the game argument. + ### Fixed - Fix missing window title during installation step diff --git a/assets/icon.png b/assets/icon.png new file mode 100644 index 0000000..d8e769a Binary files /dev/null and b/assets/icon.png differ diff --git a/src/app.rs b/src/app.rs index 7708b7a..012501b 100644 --- a/src/app.rs +++ b/src/app.rs @@ -18,6 +18,7 @@ use winit::{ event::*, event_loop::ActiveEventLoop, keyboard::{ModifiersState, PhysicalKey}, + platform::wayland::WindowAttributesExtWayland, window::Window, }; @@ -124,7 +125,19 @@ impl App { impl ApplicationHandler for App { fn resumed(&mut self, event_loop: &ActiveEventLoop) { - let window = match event_loop.create_window(Window::default_attributes()) { + let (title, app_id) = match Game::current() { + Game::Poe1 => ("Path of Building 1", "rusty-path-of-building-1"), + Game::Poe2 => ("Path of Building 2", "rusty-path-of-building-2"), + }; + + let window_attributes = Window::default_attributes() + .with_title(title) + .with_window_icon(load_icon()) // only works on windows and x11 + // on wayland we need an `app_id` that matches the name of a `.desktop` entry to load + // the icon + .with_name(app_id, app_id); + + let window = match event_loop.create_window(window_attributes) { Ok(window) => Arc::new(window), Err(err) => { log::error!("{err}"); @@ -133,11 +146,6 @@ impl ApplicationHandler for App { } }; - match Game::current() { - Game::Poe1 => window.set_title("Rusty Path of Building 1"), - Game::Poe2 => window.set_title("Rusty Path of Building 2"), - } - self.state.window.set_window(Arc::clone(&window)); self.gfx_context = match pollster::block_on(GraphicsContext::new(window)) { @@ -348,3 +356,10 @@ fn pob_font_definitions() -> FontDefinitions { definitions } + +fn load_icon() -> Option { + let image_data = include_bytes!("../assets/icon.png"); + let image = image::load_from_memory(image_data).ok()?.into_rgba8(); + let (width, height) = image.dimensions(); + winit::window::Icon::from_rgba(image.into_raw(), width, height).ok() +}