From 37a3198d8882463c9873011c1d18c325ea46d7c8 Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Sun, 20 Dec 2020 07:57:03 +0000 Subject: Fix embedded _NET_WM_ICON on X11 Previously the _NET_WM_ICON would use the .ico which was also used for the Windows icon. This icon used the dimensions 256x256, but the maximum supported image size is 192x192, so a new image with the dimensions 64x64 has been added. Since we know the image format anyways, the `image` dependency could also be easily replaced with `png`, which cuts out a few extra unused dependencies. --- alacritty/src/window.rs | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'alacritty/src') diff --git a/alacritty/src/window.rs b/alacritty/src/window.rs index e43e5c95..1b9e7731 100644 --- a/alacritty/src/window.rs +++ b/alacritty/src/window.rs @@ -19,8 +19,15 @@ use { crate::wayland_theme::AlacrittyWaylandTheme, }; +#[rustfmt::skip] #[cfg(all(feature = "x11", not(any(target_os = "macos", windows))))] -use x11_dl::xlib::{Display as XDisplay, PropModeReplace, XErrorEvent, Xlib}; +use { + std::io::Cursor, + + x11_dl::xlib::{Display as XDisplay, PropModeReplace, XErrorEvent, Xlib}, + glutin::window::Icon, + png::Decoder, +}; use std::fmt::{self, Display, Formatter}; @@ -44,11 +51,11 @@ use crate::config::window::{Decorations, WindowConfig}; use crate::config::Config; use crate::gl; -// It's required to be in this directory due to the `windows.rc` file. +/// Window icon for `_NET_WM_ICON` property. #[cfg(all(feature = "x11", not(any(target_os = "macos", windows))))] -static WINDOW_ICON: &[u8] = include_bytes!("../alacritty.ico"); +static WINDOW_ICON: &[u8] = include_bytes!("../alacritty.png"); -// This should match the definition of IDI_ICON from `windows.rc`. +/// This should match the definition of IDI_ICON from `windows.rc`. #[cfg(windows)] const IDI_ICON: WORD = 0x101; @@ -257,11 +264,11 @@ impl Window { pub fn get_platform_window(title: &str, window_config: &WindowConfig) -> WindowBuilder { #[cfg(feature = "x11")] let icon = { - let image = image::load_from_memory_with_format(WINDOW_ICON, image::ImageFormat::Ico) - .expect("loading icon") - .to_rgba(); - let (width, height) = image.dimensions(); - glutin::window::Icon::from_rgba(image.into_raw(), width, height) + let decoder = Decoder::new(Cursor::new(WINDOW_ICON)); + let (info, mut reader) = decoder.read_info().expect("invalid embedded icon"); + let mut buf = vec![0; info.buffer_size()]; + let _ = reader.next_frame(&mut buf); + Icon::from_rgba(buf, info.width, info.height) }; let class = &window_config.class; -- cgit