@@ -6,6 +6,7 @@ use crate::render::RenderConfig;
6
6
use crate :: selected_frame:: SelectableFrame ;
7
7
use crate :: ui:: CustomUi ;
8
8
use crate :: widget:: BarWidget ;
9
+ use crate :: ICON_CACHE ;
9
10
use crate :: MAX_LABEL_WIDTH ;
10
11
use crate :: MONITOR_INDEX ;
11
12
use crossbeam_channel:: Receiver ;
@@ -611,27 +612,69 @@ impl From<&Workspace> for KomorebiNotificationStateContainerInformation {
611
612
612
613
impl From < & Container > for KomorebiNotificationStateContainerInformation {
613
614
fn from ( value : & Container ) -> Self {
615
+ let windows = value. windows ( ) . iter ( ) . collect :: < Vec < _ > > ( ) ;
616
+ let mut icons = vec ! [ ] ;
617
+
618
+ for window in windows {
619
+ let mut icon_cache = ICON_CACHE . lock ( ) . unwrap ( ) ;
620
+ let mut update_cache = false ;
621
+ let exe = window. exe ( ) . unwrap_or_default ( ) ;
622
+
623
+ match icon_cache. get ( & exe) {
624
+ None => {
625
+ icons. push ( windows_icons:: get_icon_by_process_id ( window. process_id ( ) ) ) ;
626
+ update_cache = true ;
627
+ }
628
+ Some ( icon) => {
629
+ icons. push ( Some ( icon. clone ( ) ) ) ;
630
+ }
631
+ }
632
+
633
+ if update_cache {
634
+ if let Some ( Some ( icon) ) = icons. last ( ) {
635
+ icon_cache. insert ( exe, icon. clone ( ) ) ;
636
+ }
637
+ }
638
+ }
639
+
614
640
Self {
615
641
titles : value
616
642
. windows ( )
617
643
. iter ( )
618
644
. map ( |w| w. title ( ) . unwrap_or_default ( ) )
619
645
. collect :: < Vec < _ > > ( ) ,
620
- icons : value
621
- . windows ( )
622
- . iter ( )
623
- . map ( |w| windows_icons:: get_icon_by_process_id ( w. process_id ( ) ) )
624
- . collect :: < Vec < _ > > ( ) ,
646
+ icons,
625
647
focused_window_idx : value. focused_window_idx ( ) ,
626
648
}
627
649
}
628
650
}
629
651
630
652
impl From < & Window > for KomorebiNotificationStateContainerInformation {
631
653
fn from ( value : & Window ) -> Self {
654
+ let mut icon_cache = ICON_CACHE . lock ( ) . unwrap ( ) ;
655
+ let mut update_cache = false ;
656
+ let mut icons = vec ! [ ] ;
657
+ let exe = value. exe ( ) . unwrap_or_default ( ) ;
658
+
659
+ match icon_cache. get ( & exe) {
660
+ None => {
661
+ icons. push ( windows_icons:: get_icon_by_process_id ( value. process_id ( ) ) ) ;
662
+ update_cache = true ;
663
+ }
664
+ Some ( icon) => {
665
+ icons. push ( Some ( icon. clone ( ) ) ) ;
666
+ }
667
+ }
668
+
669
+ if update_cache {
670
+ if let Some ( Some ( icon) ) = icons. last ( ) {
671
+ icon_cache. insert ( exe, icon. clone ( ) ) ;
672
+ }
673
+ }
674
+
632
675
Self {
633
676
titles : vec ! [ value. title( ) . unwrap_or_default( ) ] ,
634
- icons : vec ! [ windows_icons :: get_icon_by_process_id ( value . process_id ( ) ) ] ,
677
+ icons,
635
678
focused_window_idx : 0 ,
636
679
}
637
680
}
0 commit comments