hex/src/desktop/tray_icon.rs
Dax 3e6b47df4c
linux: dark tray mark on light panels (#1481)
* linux: dark tray mark on light panels

Read the desktop's color-scheme from the settings portal when the tray is
created, and draw the mark black when it explicitly prefers light. Move the
shared recolor from the Windows tray beside the shared tray menu.

* docs: note linux tray mark check and limitation
2026-11-07 05:02:25 -05:00

36 lines
1.1 KiB
Rust
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//! The tray mark Linux and Windows share: the white Hex mark, drawn in black
//! on a light panel or taskbar, where white would vanish.
/// The mark's edge, in pixels.
pub(crate) const SIZE: u32 = 32;
/// The white Hex mark, raw 32×32 RGBA.
const RGBA: &[u8] = include_bytes!("../../resources/windows/tray-32.rgba");
/// The tray mark for a light panel or taskbar: the white mark on a dark one,
/// the same shape in black on a light one.
pub(crate) fn pixels(light: bool) -> Vec<u8> {
let mut pixels = RGBA.to_vec();
if light {
for pixel in pixels.as_chunks_mut::<4>().0 {
pixel[..3].fill(0);
}
}
pixels
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn a_light_tray_gets_a_dark_mark_with_the_same_shape() {
let dark = pixels(false);
let light = pixels(true);
assert_eq!(dark, RGBA);
assert_eq!(light.len(), (SIZE * SIZE * 4) as usize);
for (shown, mark) in light.as_chunks::<4>().0.iter().zip(dark.as_chunks::<4>().0) {
assert_eq!(&shown[..3], &[0, 0, 0]);
assert_eq!(shown[3], mark[3]);
}
}
}