Skip to content

Commit 44c5547

Browse files
committed
fix: NewIcon update event send both icon_name and icon_pixmap
1 parent e107d45 commit 44c5547

File tree

2 files changed

+45
-34
lines changed

2 files changed

+45
-34
lines changed

src/client.rs

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::dbus::notifier_watcher_proxy::StatusNotifierWatcherProxy;
55
use crate::dbus::status_notifier_watcher::StatusNotifierWatcher;
66
use crate::dbus::{self, OwnedValueExt};
77
use crate::error::{Error, Result};
8-
use crate::item::{self, Status, StatusNotifierItem, Tooltip};
8+
use crate::item::{self, IconPixmap, Status, StatusNotifierItem, Tooltip};
99
use crate::menu::{MenuDiff, TrayMenu};
1010
use crate::names;
1111
use dbus::DBusProps;
@@ -17,7 +17,7 @@ use tokio::time::timeout;
1717
use tracing::{debug, error, trace, warn};
1818
use zbus::fdo::{DBusProxy, PropertiesProxy};
1919
use zbus::names::InterfaceName;
20-
use zbus::zvariant::{Structure, Value};
20+
use zbus::zvariant::{Array, Structure, Value};
2121
use zbus::{Connection, Message};
2222

2323
use self::names::ITEM_OBJECT;
@@ -41,7 +41,10 @@ pub enum Event {
4141
#[derive(Debug, Clone)]
4242
pub enum UpdateEvent {
4343
AttentionIcon(Option<String>),
44-
Icon(Option<String>),
44+
Icon {
45+
icon_name: Option<String>,
46+
icon_pixmap: Vec<IconPixmap>,
47+
},
4548
OverlayIcon(Option<String>),
4649
Status(Status),
4750
Title(Option<String>),
@@ -409,47 +412,55 @@ impl Client {
409412
.member()
410413
.ok_or(Error::InvalidData("Update message header missing `member`"))?;
411414

412-
let property_name = match member.as_str() {
413-
"NewAttentionIcon" => "AttentionIconName",
414-
"NewIcon" => "IconName",
415-
"NewOverlayIcon" => "OverlayIconName",
416-
"NewStatus" => "Status",
417-
"NewTitle" => "Title",
418-
"NewToolTip" => "ToolTip",
419-
_ => &member.as_str()["New".len()..],
420-
};
421-
422-
let property = properties_proxy
423-
.get(
424-
InterfaceName::from_static_str(PROPERTIES_INTERFACE)
425-
.expect("to be valid interface name"),
426-
property_name,
427-
)
428-
.await?;
429-
430-
debug!("received tray item update: {member} -> {property:?}");
415+
macro_rules! get_property {
416+
($name:expr) => {
417+
properties_proxy
418+
.get(
419+
InterfaceName::from_static_str(PROPERTIES_INTERFACE)
420+
.expect("to be valid interface name"),
421+
$name,
422+
)
423+
.await?
424+
};
425+
}
431426

432427
use UpdateEvent::*;
433-
Ok(match member.as_str() {
434-
"NewAttentionIcon" => Some(AttentionIcon(property.to_string().ok())),
435-
"NewIcon" => Some(Icon(property.to_string().ok())),
436-
"NewOverlayIcon" => Some(OverlayIcon(property.to_string().ok())),
428+
let property = match member.as_str() {
429+
"NewAttentionIcon" => Some(AttentionIcon(
430+
get_property!("AttentionIconName").to_string().ok(),
431+
)),
432+
"NewIcon" => Some(Icon {
433+
icon_name: get_property!("IconName").to_string().ok(),
434+
icon_pixmap: get_property!("IconPixmap")
435+
.downcast_ref::<&Array>()
436+
.map_err(Into::into)
437+
.and_then(IconPixmap::from_array)?,
438+
}),
439+
"NewOverlayIcon" => Some(OverlayIcon(
440+
get_property!("OverlayIconName").to_string().ok(),
441+
)),
437442
"NewStatus" => Some(Status(
438-
property.downcast_ref::<&str>().map(item::Status::from)?,
443+
get_property!("Status")
444+
.downcast_ref::<&str>()
445+
.map(item::Status::from)?,
439446
)),
440-
"NewTitle" => Some(Title(property.to_string().ok())),
441-
"NewToolTip" => Some(Tooltip({
442-
property
447+
"NewTitle" => Some(Title(get_property!("Title").to_string().ok())),
448+
"NewToolTip" => Some(Tooltip(
449+
get_property!("ToolTip")
443450
.downcast_ref::<&Structure>()
444451
.ok()
445452
.map(crate::item::Tooltip::try_from)
446-
.transpose()?
447-
})),
453+
.transpose()?,
454+
)),
448455
_ => {
449456
warn!("received unhandled update event: {member}");
450457
None
451458
}
452-
})
459+
};
460+
461+
debug!("received tray item update: {member} -> {property:?}");
462+
463+
Ok(property)
453464
}
454465

455466
/// Watches the `DBusMenu` associated with an SNI item.

src/item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl Debug for IconPixmap {
146146
}
147147

148148
impl IconPixmap {
149-
fn from_array(array: &Array) -> Result<Vec<Self>> {
149+
pub fn from_array(array: &Array) -> Result<Vec<Self>> {
150150
array
151151
.iter()
152152
.map(|pixmap| {

0 commit comments

Comments
 (0)