From 188abc33e910a708061517b13e36125f9d7736d3 Mon Sep 17 00:00:00 2001 From: Robert Nelson Date: Wed, 24 Apr 2024 15:52:17 -0400 Subject: [PATCH] fix(tray): icon colour channels are being incorrectly rendered Converts from ARGB32 to RGBA32 formats when rendering tray Pixmaps Fixes #546 --- src/modules/tray/icon.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/modules/tray/icon.rs b/src/modules/tray/icon.rs index 3918dfb..c42ff4a 100644 --- a/src/modules/tray/icon.rs +++ b/src/modules/tray/icon.rs @@ -79,6 +79,8 @@ fn get_image_from_icon_name(item: &TrayMenu, icon_theme: &IconTheme, size: u32) /// /// The pixmap is supplied in ARGB32 format, /// which has 8 bits per sample and a bit stride of `4*width`. +/// The Pixbuf expects RGBA32 format, so some channel shuffling +/// is required. fn get_image_from_pixmap(item: &TrayMenu, size: u32) -> Result { const BITS_PER_SAMPLE: i32 = 8; @@ -88,8 +90,18 @@ fn get_image_from_pixmap(item: &TrayMenu, size: u32) -> Result { .and_then(|pixmap| pixmap.first()) .ok_or_else(|| Report::msg("Failed to get pixmap from tray icon"))?; - let bytes = glib::Bytes::from(&pixmap.pixels); + let mut pixels = pixmap.pixels.to_vec(); + + for i in (0..pixels.len()).step_by(4) { + let alpha = pixels[i]; + pixels[i] = pixels[i + 1]; + pixels[i + 1] = pixels[i + 2]; + pixels[i + 2] = pixels[i + 3]; + pixels[i + 3] = alpha; + } + let row_stride = pixmap.width * 4; + let bytes = glib::Bytes::from(&pixels); let pixbuf = Pixbuf::from_bytes( &bytes,