@@ -92,6 +92,7 @@ impl fmt::Debug for CosmicStack {
9292#[ derive( Debug , Clone ) ]
9393pub struct CosmicStackInternal {
9494 windows : Arc < Mutex < Vec < CosmicSurface > > > ,
95+ tab_models : Arc < [ tab:: Model ] > ,
9596 active : Arc < AtomicUsize > ,
9697 activated : Arc < AtomicBool > ,
9798 group_focused : Arc < AtomicBool > ,
@@ -132,7 +133,11 @@ impl CosmicStack {
132133 handle : LoopHandle < ' static , crate :: state:: State > ,
133134 theme : cosmic:: Theme ,
134135 ) -> CosmicStack {
135- let windows = windows. map ( Into :: into) . collect :: < Vec < _ > > ( ) ;
136+ let ( tab_models, windows) = windows
137+ . map ( Into :: into)
138+ . map ( |window| ( tab:: Model :: from ( & window) , window) )
139+ . collect :: < ( Vec < _ > , Vec < _ > ) > ( ) ;
140+
136141 assert ! ( !windows. is_empty( ) ) ;
137142
138143 for window in & windows {
@@ -145,6 +150,7 @@ impl CosmicStack {
145150 CosmicStack ( IcedElement :: new (
146151 CosmicStackInternal {
147152 windows : Arc :: new ( Mutex :: new ( windows) ) ,
153+ tab_models : Arc :: from ( tab_models) ,
148154 active : Arc :: new ( AtomicUsize :: new ( 0 ) ) ,
149155 activated : Arc :: new ( AtomicBool :: new ( false ) ) ,
150156 group_focused : Arc :: new ( AtomicBool :: new ( false ) ) ,
@@ -795,6 +801,7 @@ pub enum Message {
795801 PotentialTabDragStart ( usize ) ,
796802 Activate ( usize ) ,
797803 Close ( usize ) ,
804+ Refresh ,
798805 ScrollForward ,
799806 ScrollBack ,
800807 Scrolled ,
@@ -842,6 +849,15 @@ impl Program for CosmicStackInternal {
842849 last_seat : Option < & ( Seat < State > , Serial ) > ,
843850 ) -> Task < Self :: Message > {
844851 match message {
852+ Message :: Refresh => {
853+ self . tab_models = self
854+ . windows
855+ . lock ( )
856+ . unwrap ( )
857+ . iter ( )
858+ . map ( tab:: Model :: from)
859+ . collect ( ) ;
860+ }
845861 Message :: DragStart => {
846862 if let Some ( ( seat, serial) ) = last_seat. cloned ( ) {
847863 let active = self . active . load ( Ordering :: SeqCst ) ;
@@ -1001,12 +1017,14 @@ impl Program for CosmicStackInternal {
10011017 }
10021018
10031019 fn view ( & self ) -> CosmicElement < ' _ , Self :: Message > {
1004- let windows = self . windows . lock ( ) . unwrap ( ) ;
10051020 if self . geometry . lock ( ) . unwrap ( ) . is_none ( ) {
10061021 return iced_widget:: row ( Vec :: new ( ) ) . into ( ) ;
10071022 } ;
1023+
10081024 let active = self . active . load ( Ordering :: SeqCst ) ;
1025+ let activated = self . activated . load ( Ordering :: SeqCst ) ;
10091026 let group_focused = self . group_focused . load ( Ordering :: SeqCst ) ;
1027+ let maximized = self . windows . lock ( ) . unwrap ( ) [ active] . is_maximized ( false ) ;
10101028
10111029 let elements = vec ! [
10121030 cosmic_widget:: icon:: from_name( "window-stack-symbolic" )
@@ -1033,20 +1051,14 @@ impl Program for CosmicStackInternal {
10331051 . into( ) ,
10341052 CosmicElement :: new(
10351053 Tabs :: new(
1036- windows. iter( ) . enumerate( ) . map( |( i, w) | {
1037- let user_data = w. user_data( ) ;
1038- user_data. insert_if_missing( Id :: unique) ;
1039- Tab :: new(
1040- w. title( ) ,
1041- w. app_id( ) ,
1042- user_data. get:: <Id >( ) . unwrap( ) . clone( ) ,
1043- )
1044- . on_press( Message :: PotentialTabDragStart ( i) )
1045- . on_right_click( Message :: TabMenu ( i) )
1046- . on_close( Message :: Close ( i) )
1054+ self . tab_models. iter( ) . enumerate( ) . map( |( i, tab) | {
1055+ Tab :: new( tab)
1056+ . on_press( Message :: PotentialTabDragStart ( i) )
1057+ . on_right_click( Message :: TabMenu ( i) )
1058+ . on_close( Message :: Close ( i) )
10471059 } ) ,
10481060 active,
1049- windows [ active ] . is_activated ( false ) ,
1061+ activated ,
10501062 group_focused,
10511063 )
10521064 . id( SCROLLABLE_ID . clone( ) )
@@ -1068,7 +1080,7 @@ impl Program for CosmicStackInternal {
10681080 . into( ) ,
10691081 ] ;
10701082
1071- let radius = if windows [ active ] . is_maximized ( false ) {
1083+ let radius = if maximized {
10721084 Radius :: from ( 0.0 )
10731085 } else {
10741086 Radius :: from ( [ 8.0 , 8.0 , 0.0 , 0.0 ] )
@@ -1255,6 +1267,8 @@ impl SpaceElement for CosmicStack {
12551267 SpaceElement :: refresh ( w)
12561268 } ) ;
12571269 } ) ;
1270+
1271+ self . 0 . queue_message ( Message :: Refresh ) ;
12581272 SpaceElement :: refresh ( & self . 0 ) ;
12591273 }
12601274}
0 commit comments