@@ -53,6 +53,7 @@ pub const MINIMIZE_ANIMATION_DURATION: Duration = Duration::from_millis(320);
5353#[ derive( Debug , Default ) ]
5454pub struct FloatingLayout {
5555 pub ( crate ) space : Space < CosmicMapped > ,
56+ last_output_size : Size < i32 , Local > ,
5657 spawn_order : Vec < CosmicMapped > ,
5758 animations : HashMap < CosmicMapped , Animation > ,
5859 hovered_stack : Option < ( CosmicMapped , Rectangle < i32 , Local > ) > ,
@@ -265,6 +266,7 @@ impl FloatingLayout {
265266 pub fn new ( theme : cosmic:: Theme , output : & Output ) -> FloatingLayout {
266267 let mut layout = Self {
267268 theme,
269+ last_output_size : output. geometry ( ) . size . as_local ( ) ,
268270 ..Default :: default ( )
269271 } ;
270272 layout. space . map_output ( output, ( 0 , 0 ) ) ;
@@ -320,6 +322,7 @@ impl FloatingLayout {
320322 }
321323 }
322324
325+ self . last_output_size = output. geometry ( ) . size . as_local ( ) ;
323326 self . recalculate ( ) ;
324327 }
325328
@@ -1289,11 +1292,14 @@ impl FloatingLayout {
12891292
12901293 pub fn recalculate ( & mut self ) {
12911294 let output = self . space . outputs ( ) . next ( ) . unwrap ( ) . clone ( ) ;
1295+ let output_size = output. geometry ( ) . size . as_local ( ) ;
1296+ let old_output_size = Some ( self . last_output_size ) . filter ( |size| * size != output_size) ;
1297+
12921298 let geometry = layer_map_for_output ( & output)
12931299 . non_exclusive_zone ( )
12941300 . as_local ( ) ;
12951301
1296- // update maximized elements
1302+ // update elements
12971303 for mapped in self
12981304 . space
12991305 . elements ( )
@@ -1304,21 +1310,42 @@ impl FloatingLayout {
13041310 mapped. set_bounds ( geometry. size . as_logical ( ) ) ;
13051311 let prev = self . space . element_geometry ( & mapped) . map ( RectExt :: as_local) ;
13061312
1307- let position = if mapped. is_maximized ( false ) {
1308- mapped. set_geometry ( geometry. to_global ( & output) ) ;
1309- geometry. loc
1313+ let window_geometry = if mapped. is_maximized ( false ) {
1314+ geometry
13101315 } else {
13111316 prev. clone ( )
1312- . map ( |rect| rect. loc . constrain ( geometry) )
1313- . unwrap_or ( Point :: from ( ( 0 , 0 ) ) )
1317+ . map ( |mut rect| {
1318+ if let Some ( old_size) = old_output_size {
1319+ rect = Rectangle :: new (
1320+ Point :: new (
1321+ ( rect. loc . x as f64 + rect. size . w as f64 / 2. )
1322+ / old_size. w as f64
1323+ * output_size. w as f64
1324+ - rect. size . w as f64 / 2. ,
1325+ ( rect. loc . y as f64 + rect. size . h as f64 / 2. )
1326+ / old_size. h as f64
1327+ * output_size. h as f64
1328+ - rect. size . h as f64 / 2. ,
1329+ ) ,
1330+ rect. size . to_f64 ( ) ,
1331+ )
1332+ . to_i32_round ( ) ;
1333+ }
1334+ Rectangle :: new ( rect. loc . constrain ( geometry) , rect. size )
1335+ } )
1336+ . unwrap_or_else ( || {
1337+ Rectangle :: new ( Point :: from ( ( 0 , 0 ) ) , mapped. geometry ( ) . size . as_local ( ) )
1338+ } )
13141339 } ;
1340+ mapped. set_geometry ( window_geometry. to_global ( & output) ) ;
13151341
13161342 let is_activated = mapped. is_activated ( false ) ;
13171343 mapped. configure ( ) ;
13181344 self . space
1319- . map_element ( mapped, position . as_logical ( ) , is_activated) ;
1345+ . map_element ( mapped, window_geometry . loc . as_logical ( ) , is_activated) ;
13201346 }
13211347
1348+ self . last_output_size = output_size;
13221349 self . refresh ( ) ;
13231350 }
13241351
0 commit comments