Skip to content

Commit 2cf941f

Browse files
authored
fix: NewIcon update event send both icon_name and icon_pixmap (#22)
2 parents 94719f3 + 44c5547 commit 2cf941f

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
@@ -7,7 +7,7 @@ use crate::dbus::notifier_watcher_proxy::StatusNotifierWatcherProxy;
77
use crate::dbus::status_notifier_watcher::StatusNotifierWatcher;
88
use crate::dbus::{self, OwnedValueExt};
99
use crate::error::{Error, Result};
10-
use crate::item::{self, Status, StatusNotifierItem, Tooltip};
10+
use crate::item::{self, IconPixmap, Status, StatusNotifierItem, Tooltip};
1111
use crate::menu::{MenuDiff, TrayMenu};
1212
use crate::names;
1313
use dbus::DBusProps;
@@ -19,7 +19,7 @@ use tokio::time::timeout;
1919
use tracing::{debug, error, trace, warn};
2020
use zbus::fdo::{DBusProxy, PropertiesProxy};
2121
use zbus::names::InterfaceName;
22-
use zbus::zvariant::{Structure, Value};
22+
use zbus::zvariant::{Array, Structure, Value};
2323
use zbus::{Connection, Message};
2424

2525
use self::names::ITEM_OBJECT;
@@ -43,7 +43,10 @@ pub enum Event {
4343
#[derive(Debug, Clone)]
4444
pub enum UpdateEvent {
4545
AttentionIcon(Option<String>),
46-
Icon(Option<String>),
46+
Icon {
47+
icon_name: Option<String>,
48+
icon_pixmap: Vec<IconPixmap>,
49+
},
4750
OverlayIcon(Option<String>),
4851
Status(Status),
4952
Title(Option<String>),
@@ -416,47 +419,55 @@ impl Client {
416419
.member()
417420
.ok_or(Error::InvalidData("Update message header missing `member`"))?;
418421

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

439434
use UpdateEvent::*;
440-
Ok(match member.as_str() {
441-
"NewAttentionIcon" => Some(AttentionIcon(property.to_string().ok())),
442-
"NewIcon" => Some(Icon(property.to_string().ok())),
443-
"NewOverlayIcon" => Some(OverlayIcon(property.to_string().ok())),
435+
let property = match member.as_str() {
436+
"NewAttentionIcon" => Some(AttentionIcon(
437+
get_property!("AttentionIconName").to_string().ok(),
438+
)),
439+
"NewIcon" => Some(Icon {
440+
icon_name: get_property!("IconName").to_string().ok(),
441+
icon_pixmap: get_property!("IconPixmap")
442+
.downcast_ref::<&Array>()
443+
.map_err(Into::into)
444+
.and_then(IconPixmap::from_array)?,
445+
}),
446+
"NewOverlayIcon" => Some(OverlayIcon(
447+
get_property!("OverlayIconName").to_string().ok(),
448+
)),
444449
"NewStatus" => Some(Status(
445-
property.downcast_ref::<&str>().map(item::Status::from)?,
450+
get_property!("Status")
451+
.downcast_ref::<&str>()
452+
.map(item::Status::from)?,
446453
)),
447-
"NewTitle" => Some(Title(property.to_string().ok())),
448-
"NewToolTip" => Some(Tooltip({
449-
property
454+
"NewTitle" => Some(Title(get_property!("Title").to_string().ok())),
455+
"NewToolTip" => Some(Tooltip(
456+
get_property!("ToolTip")
450457
.downcast_ref::<&Structure>()
451458
.ok()
452459
.map(crate::item::Tooltip::try_from)
453-
.transpose()?
454-
})),
460+
.transpose()?,
461+
)),
455462
_ => {
456463
warn!("received unhandled update event: {member}");
457464
None
458465
}
459-
})
466+
};
467+
468+
debug!("received tray item update: {member} -> {property:?}");
469+
470+
Ok(property)
460471
}
461472

462473
/// 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)