@@ -93,6 +93,7 @@ impl fmt::Debug for CosmicStack {
9393#[ derive( Debug , Clone ) ]
9494pub struct CosmicStackInternal {
9595 windows : Arc < Mutex < Vec < CosmicSurface > > > ,
96+ tab_models : Arc < [ tab:: Model ] > ,
9697 active : Arc < AtomicUsize > ,
9798 activated : Arc < AtomicBool > ,
9899 group_focused : Arc < AtomicBool > ,
@@ -133,7 +134,11 @@ impl CosmicStack {
133134 handle : LoopHandle < ' static , crate :: state:: State > ,
134135 theme : cosmic:: Theme ,
135136 ) -> CosmicStack {
136- let windows = windows. map ( Into :: into) . collect :: < Vec < _ > > ( ) ;
137+ let ( tab_models, windows) = windows
138+ . map ( Into :: into)
139+ . map ( |window| ( tab:: Model :: from ( & window) , window) )
140+ . collect :: < ( Vec < _ > , Vec < _ > ) > ( ) ;
141+
137142 assert ! ( !windows. is_empty( ) ) ;
138143
139144 for window in & windows {
@@ -146,6 +151,7 @@ impl CosmicStack {
146151 CosmicStack ( IcedElement :: new (
147152 CosmicStackInternal {
148153 windows : Arc :: new ( Mutex :: new ( windows) ) ,
154+ tab_models : Arc :: from ( tab_models) ,
149155 active : Arc :: new ( AtomicUsize :: new ( 0 ) ) ,
150156 activated : Arc :: new ( AtomicBool :: new ( false ) ) ,
151157 group_focused : Arc :: new ( AtomicBool :: new ( false ) ) ,
@@ -791,6 +797,7 @@ pub enum Message {
791797 PotentialTabDragStart ( usize ) ,
792798 Activate ( usize ) ,
793799 Close ( usize ) ,
800+ Refresh ,
794801 ScrollForward ,
795802 ScrollBack ,
796803 Scrolled ,
@@ -838,6 +845,15 @@ impl Program for CosmicStackInternal {
838845 last_seat : Option < & ( Seat < State > , Serial ) > ,
839846 ) -> Task < Self :: Message > {
840847 match message {
848+ Message :: Refresh => {
849+ self . tab_models = self
850+ . windows
851+ . lock ( )
852+ . unwrap ( )
853+ . iter ( )
854+ . map ( tab:: Model :: from)
855+ . collect ( ) ;
856+ }
841857 Message :: DragStart => {
842858 if let Some ( ( seat, serial) ) = last_seat. cloned ( ) {
843859 let active = self . active . load ( Ordering :: SeqCst ) ;
@@ -997,12 +1013,14 @@ impl Program for CosmicStackInternal {
9971013 }
9981014
9991015 fn view ( & self ) -> CosmicElement < ' _ , Self :: Message > {
1000- let windows = self . windows . lock ( ) . unwrap ( ) ;
10011016 if self . geometry . lock ( ) . unwrap ( ) . is_none ( ) {
10021017 return iced_widget:: row ( Vec :: new ( ) ) . into ( ) ;
10031018 } ;
1019+
10041020 let active = self . active . load ( Ordering :: SeqCst ) ;
1021+ let activated = self . activated . load ( Ordering :: SeqCst ) ;
10051022 let group_focused = self . group_focused . load ( Ordering :: SeqCst ) ;
1023+ let maximized = self . windows . lock ( ) . unwrap ( ) [ active] . is_maximized ( false ) ;
10061024
10071025 let elements = vec ! [
10081026 cosmic_widget:: icon:: from_name( "window-stack-symbolic" )
@@ -1029,20 +1047,14 @@ impl Program for CosmicStackInternal {
10291047 . into( ) ,
10301048 CosmicElement :: new(
10311049 Tabs :: new(
1032- windows. iter( ) . enumerate( ) . map( |( i, w) | {
1033- let user_data = w. user_data( ) ;
1034- user_data. insert_if_missing( Id :: unique) ;
1035- Tab :: new(
1036- w. title( ) ,
1037- w. app_id( ) ,
1038- user_data. get:: <Id >( ) . unwrap( ) . clone( ) ,
1039- )
1040- . on_press( Message :: PotentialTabDragStart ( i) )
1041- . on_right_click( Message :: TabMenu ( i) )
1042- . on_close( Message :: Close ( i) )
1050+ self . tab_models. iter( ) . enumerate( ) . map( |( i, tab) | {
1051+ Tab :: new( tab)
1052+ . on_press( Message :: PotentialTabDragStart ( i) )
1053+ . on_right_click( Message :: TabMenu ( i) )
1054+ . on_close( Message :: Close ( i) )
10431055 } ) ,
10441056 active,
1045- windows [ active ] . is_activated ( false ) ,
1057+ activated ,
10461058 group_focused,
10471059 )
10481060 . id( SCROLLABLE_ID . clone( ) )
@@ -1064,7 +1076,7 @@ impl Program for CosmicStackInternal {
10641076 . into( ) ,
10651077 ] ;
10661078
1067- let radius = if windows [ active ] . is_maximized ( false ) {
1079+ let radius = if maximized {
10681080 Radius :: from ( 0.0 )
10691081 } else {
10701082 Radius :: from ( [ 8.0 , 8.0 , 0.0 , 0.0 ] )
@@ -1251,6 +1263,8 @@ impl SpaceElement for CosmicStack {
12511263 SpaceElement :: refresh ( w)
12521264 } ) ;
12531265 } ) ;
1266+
1267+ self . 0 . queue_message ( Message :: Refresh ) ;
12541268 SpaceElement :: refresh ( & self . 0 ) ;
12551269 }
12561270}
0 commit comments