Skip to content

Commit

Permalink
fix(tray): icon colour channels are being incorrectly rendered
Browse files Browse the repository at this point in the history
Converts from ARGB32 to RGBA32 formats when rendering tray Pixmaps

Fixes #546
  • Loading branch information
rdnelson authored Apr 24, 2024
1 parent 4854a5c commit 188abc3
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/modules/tray/icon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Image> {
const BITS_PER_SAMPLE: i32 = 8;

Expand All @@ -88,8 +90,18 @@ fn get_image_from_pixmap(item: &TrayMenu, size: u32) -> Result<Image> {
.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,
Expand Down

0 comments on commit 188abc3

Please sign in to comment.