Skip to content

Commit 37a3198

Browse files
authored
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.
1 parent f016a20 commit 37a3198

File tree

6 files changed

+22
-78
lines changed

6 files changed

+22
-78
lines changed

Diff for: Cargo.lock

+3-66
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: alacritty/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ gl_generator = "0.14.0"
3939
xdg = "2"
4040

4141
[target.'cfg(not(target_os = "macos"))'.dependencies]
42-
image = { version = "0.23.3", default-features = false, features = ["ico"], optional = true }
42+
png = { version = "0.16.8", default-features = false, optional = true }
4343

4444
[target.'cfg(target_os = "macos")'.dependencies]
4545
objc = "0.2.2"
@@ -56,7 +56,7 @@ embed-resource = "1.3"
5656

5757
[features]
5858
default = ["wayland", "x11"]
59-
x11 = ["copypasta/x11", "glutin/x11", "x11-dl", "image"]
59+
x11 = ["copypasta/x11", "glutin/x11", "x11-dl", "png"]
6060
wayland = ["copypasta/wayland", "glutin/wayland", "wayland-client"]
6161
winpty = ["alacritty_terminal/winpty"]
6262
nightly = []

Diff for: alacritty/alacritty.ico

-1
This file was deleted.

Diff for: alacritty/alacritty.png

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../extra/logo/compat/alacritty-term.png

Diff for: alacritty/src/window.rs

+16-9
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,15 @@ use {
1919
crate::wayland_theme::AlacrittyWaylandTheme,
2020
};
2121

22+
#[rustfmt::skip]
2223
#[cfg(all(feature = "x11", not(any(target_os = "macos", windows))))]
23-
use x11_dl::xlib::{Display as XDisplay, PropModeReplace, XErrorEvent, Xlib};
24+
use {
25+
std::io::Cursor,
26+
27+
x11_dl::xlib::{Display as XDisplay, PropModeReplace, XErrorEvent, Xlib},
28+
glutin::window::Icon,
29+
png::Decoder,
30+
};
2431

2532
use std::fmt::{self, Display, Formatter};
2633

@@ -44,11 +51,11 @@ use crate::config::window::{Decorations, WindowConfig};
4451
use crate::config::Config;
4552
use crate::gl;
4653

47-
// It's required to be in this directory due to the `windows.rc` file.
54+
/// Window icon for `_NET_WM_ICON` property.
4855
#[cfg(all(feature = "x11", not(any(target_os = "macos", windows))))]
49-
static WINDOW_ICON: &[u8] = include_bytes!("../alacritty.ico");
56+
static WINDOW_ICON: &[u8] = include_bytes!("../alacritty.png");
5057

51-
// This should match the definition of IDI_ICON from `windows.rc`.
58+
/// This should match the definition of IDI_ICON from `windows.rc`.
5259
#[cfg(windows)]
5360
const IDI_ICON: WORD = 0x101;
5461

@@ -257,11 +264,11 @@ impl Window {
257264
pub fn get_platform_window(title: &str, window_config: &WindowConfig) -> WindowBuilder {
258265
#[cfg(feature = "x11")]
259266
let icon = {
260-
let image = image::load_from_memory_with_format(WINDOW_ICON, image::ImageFormat::Ico)
261-
.expect("loading icon")
262-
.to_rgba();
263-
let (width, height) = image.dimensions();
264-
glutin::window::Icon::from_rgba(image.into_raw(), width, height)
267+
let decoder = Decoder::new(Cursor::new(WINDOW_ICON));
268+
let (info, mut reader) = decoder.read_info().expect("invalid embedded icon");
269+
let mut buf = vec![0; info.buffer_size()];
270+
let _ = reader.next_frame(&mut buf);
271+
Icon::from_rgba(buf, info.width, info.height)
265272
};
266273

267274
let class = &window_config.class;

Diff for: extra/logo/compat/alacritty-term.png

3.53 KB
Loading

0 commit comments

Comments
 (0)