Add an icon to the SDL2 window (#462)

* Add an icon to the SDL2 window

* Use the native endian RGBA32 so we don't have wrong icons on BE
macos-click-through
Jade 4 years ago committed by GitHub
parent 008528d272
commit 6d5d632c96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -7,6 +7,7 @@ use crate::{
redraw_scheduler::REDRAW_SCHEDULER, renderer::Renderer, settings::SETTINGS,
};
use crossfire::mpsc::TxUnbounded;
use image::load_from_memory_with_format;
use layouts::handle_qwerty_layout;
use skulpin::{
ash::prelude::VkResult,
@ -391,6 +392,28 @@ fn allow_compositing() {
sdl2::hint::set(name, "0");
}
fn set_icon(win: &mut sdl2::video::Window) {
let icon_data = Asset::get("nvim.ico").expect("Failed to read icon data");
let icon = load_from_memory_with_format(&icon_data, image::ImageFormat::ICO)
.expect("Failed to parse icon data");
let icon = icon.into_rgba();
let width = icon.width();
let height = icon.height();
let mut icon = icon.into_raw();
let surf = sdl2::surface::Surface::from_data(
&mut icon,
width,
height,
4 * width,
sdl2::pixels::PixelFormatEnum::RGBA32,
)
.expect("Failed to create icon surface");
win.set_icon(surf);
}
pub fn start_loop(
window_command_receiver: Receiver<WindowCommand>,
ui_command_sender: TxUnbounded<UiCommand>,
@ -419,6 +442,8 @@ pub fn start_loop(
.expect("Failed to create window");
log::info!("window created");
set_icon(&mut sdl_window);
if std::env::args().any(|arg| arg == "--maximized") {
sdl_window.maximize();
}

Loading…
Cancel
Save