@@ -7,7 +7,7 @@ use crate::dbus::notifier_watcher_proxy::StatusNotifierWatcherProxy;
77use crate :: dbus:: status_notifier_watcher:: StatusNotifierWatcher ;
88use crate :: dbus:: { self , OwnedValueExt } ;
99use crate :: error:: { Error , Result } ;
10- use crate :: item:: { self , Status , StatusNotifierItem , Tooltip } ;
10+ use crate :: item:: { self , IconPixmap , Status , StatusNotifierItem , Tooltip } ;
1111use crate :: menu:: { MenuDiff , TrayMenu } ;
1212use crate :: names;
1313use dbus:: DBusProps ;
@@ -19,7 +19,7 @@ use tokio::time::timeout;
1919use tracing:: { debug, error, trace, warn} ;
2020use zbus:: fdo:: { DBusProxy , PropertiesProxy } ;
2121use zbus:: names:: InterfaceName ;
22- use zbus:: zvariant:: { Structure , Value } ;
22+ use zbus:: zvariant:: { Array , Structure , Value } ;
2323use zbus:: { Connection , Message } ;
2424
2525use self :: names:: ITEM_OBJECT ;
@@ -43,7 +43,10 @@ pub enum Event {
4343#[ derive( Debug , Clone ) ]
4444pub 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.
0 commit comments