@@ -5,7 +5,7 @@ use crate::dbus::notifier_watcher_proxy::StatusNotifierWatcherProxy;
55use crate :: dbus:: status_notifier_watcher:: StatusNotifierWatcher ;
66use crate :: dbus:: { self , OwnedValueExt } ;
77use crate :: error:: { Error , Result } ;
8- use crate :: item:: { self , Status , StatusNotifierItem , Tooltip } ;
8+ use crate :: item:: { self , IconPixmap , Status , StatusNotifierItem , Tooltip } ;
99use crate :: menu:: { MenuDiff , TrayMenu } ;
1010use crate :: names;
1111use dbus:: DBusProps ;
@@ -17,7 +17,7 @@ use tokio::time::timeout;
1717use tracing:: { debug, error, trace, warn} ;
1818use zbus:: fdo:: { DBusProxy , PropertiesProxy } ;
1919use zbus:: names:: InterfaceName ;
20- use zbus:: zvariant:: { Structure , Value } ;
20+ use zbus:: zvariant:: { Array , Structure , Value } ;
2121use zbus:: { Connection , Message } ;
2222
2323use self :: names:: ITEM_OBJECT ;
@@ -41,7 +41,10 @@ pub enum Event {
4141#[ derive( Debug , Clone ) ]
4242pub 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.
0 commit comments