diff --git a/Cargo.lock b/Cargo.lock index 0bce5ae..ae54749 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3348,10 +3348,11 @@ dependencies = [ [[package]] name = "system-tray" -version = "0.7.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3397841ed755bf361606a845779e0f7333d35fb4e39627ef6f656d7cdad4c73" +checksum = "90d5d024b1573d22079347055d817863c21ea0903df404668095499c08800e4a" dependencies = [ + "cfg-if", "dbusmenu-gtk3-sys", "futures-lite", "gtk", diff --git a/Cargo.toml b/Cargo.toml index fc6c1cb..55fe78a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -177,7 +177,7 @@ futures-signals = { version = "0.3.34", optional = true } sysinfo = { version = "0.36.0", optional = true } # tray -system-tray = { version = "0.7.0", features = ["dbusmenu-gtk3"], optional = true } +system-tray = { version = "0.8.1", features = ["dbusmenu-gtk3"], optional = true } # volume libpulse-binding = { version = "2.30.1", optional = true } diff --git a/src/modules/tray/icon.rs b/src/modules/tray/icon.rs index 4586f23..e7932dd 100644 --- a/src/modules/tray/icon.rs +++ b/src/modules/tray/icon.rs @@ -11,6 +11,7 @@ use std::collections::HashSet; use std::ffi::CStr; use std::os::raw::{c_char, c_int}; use std::ptr; +use system_tray::item::IconPixmap; /// Gets the GTK icon theme search paths by calling the FFI function. /// Conveniently returns the result as a `HashSet`. @@ -45,10 +46,10 @@ pub fn get_image( icon_theme: &IconTheme, ) -> Result { if !prefer_icons && item.icon_pixmap.is_some() { - get_image_from_pixmap(item, size) + get_image_from_pixmap(item.icon_pixmap.as_deref(), size) } else { get_image_from_icon_name(item, size, icon_theme) - .or_else(|_| get_image_from_pixmap(item, size)) + .or_else(|_| get_image_from_pixmap(item.icon_pixmap.as_deref(), size)) } } @@ -81,12 +82,10 @@ fn get_image_from_icon_name(item: &TrayMenu, size: u32, icon_theme: &IconTheme) /// 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 { +fn get_image_from_pixmap(item: Option<&[IconPixmap]>, size: u32) -> Result { const BITS_PER_SAMPLE: i32 = 8; let pixmap = item - .icon_pixmap - .as_ref() .and_then(|pixmap| pixmap.first()) .ok_or_else(|| Report::msg("Failed to get pixmap from tray icon"))?; diff --git a/src/modules/tray/mod.rs b/src/modules/tray/mod.rs index b0159f1..d42f7cb 100644 --- a/src/modules/tray/mod.rs +++ b/src/modules/tray/mod.rs @@ -181,9 +181,11 @@ fn on_update( UpdateEvent::AttentionIcon(_icon) => { warn!("received unimplemented NewAttentionIcon event"); } - UpdateEvent::Icon(icon) => { - if icon.as_ref() != menu_item.icon_name() { - menu_item.set_icon_name(icon); + UpdateEvent::Icon { icon_name, icon_pixmap} => { + menu_item.icon_pixmap = icon_pixmap; + + if icon_name.as_ref() != menu_item.icon_name() { + menu_item.set_icon_name(icon_name); match icon::get_image(menu_item, icon_size, prefer_icons, icon_theme) { Ok(image) => menu_item.set_image(&image), Err(_) => menu_item.show_label(),