@@ -43,7 +43,9 @@ use smithay::{
4343 wayland:: {
4444 compositor:: { SurfaceData , TraversalAction , with_states, with_surface_tree_downward} ,
4545 seat:: WaylandFocus ,
46- shell:: xdg:: { SurfaceCachedState , ToplevelSurface , XdgToplevelSurfaceData } ,
46+ shell:: xdg:: {
47+ SurfaceCachedState , ToplevelCachedState , ToplevelSurface , XdgToplevelSurfaceData ,
48+ } ,
4749 } ,
4850 xwayland:: { X11Surface , xwm:: X11Relatable } ,
4951} ;
@@ -215,7 +217,7 @@ impl CosmicSurface {
215217 pub fn is_activated ( & self , pending : bool ) -> bool {
216218 match self . 0 . underlying_surface ( ) {
217219 WindowSurface :: Wayland ( toplevel) => with_toplevel_state ( toplevel, pending, |state| {
218- state. states . contains ( ToplevelState :: Activated )
220+ state. is_some_and ( |state| state . states . contains ( ToplevelState :: Activated ) )
219221 } ) ,
220222 WindowSurface :: X11 ( surface) => surface. is_activated ( ) ,
221223 }
@@ -247,9 +249,11 @@ impl CosmicSurface {
247249 } ) ;
248250
249251 let xdg_state = with_toplevel_state ( toplevel, pending, |state| {
250- state
251- . decoration_mode
252- . map ( |mode| mode == DecorationMode :: ClientSide )
252+ state. and_then ( |state| {
253+ state
254+ . decoration_mode
255+ . map ( |mode| mode == DecorationMode :: ClientSide )
256+ } )
253257 } ) ;
254258
255259 kde_state. or ( xdg_state) . unwrap_or ( true )
@@ -262,7 +266,9 @@ impl CosmicSurface {
262266 match self . 0 . underlying_surface ( ) {
263267 WindowSurface :: Wayland ( toplevel) => {
264268 if enable {
265- let previous_decoration_state = toplevel. current_state ( ) . decoration_mode ;
269+ let previous_decoration_state = toplevel. with_committed_state ( |state| {
270+ state. map_or_else ( Default :: default, |state| state. decoration_mode )
271+ } ) ;
266272 if PreferredDecorationMode :: is_unset ( & self . 0 ) {
267273 PreferredDecorationMode :: update ( & self . 0 , previous_decoration_state) ;
268274 }
@@ -298,7 +304,7 @@ impl CosmicSurface {
298304 match self . 0 . underlying_surface ( ) {
299305 WindowSurface :: Wayland ( toplevel) => {
300306 Some ( with_toplevel_state ( toplevel, pending, |state| {
301- state. states . contains ( ToplevelState :: Resizing )
307+ state. is_some_and ( |state| state . states . contains ( ToplevelState :: Resizing ) )
302308 } ) )
303309 }
304310 WindowSurface :: X11 ( _surface) => None ,
@@ -322,7 +328,7 @@ impl CosmicSurface {
322328 match self . 0 . underlying_surface ( ) {
323329 WindowSurface :: Wayland ( toplevel) => {
324330 Some ( with_toplevel_state ( toplevel, pending, |state| {
325- state. states . contains ( ToplevelState :: TiledLeft )
331+ state. is_some_and ( |state| state . states . contains ( ToplevelState :: TiledLeft ) )
326332 } ) )
327333 }
328334 WindowSurface :: X11 ( _surface) => None ,
@@ -351,7 +357,7 @@ impl CosmicSurface {
351357 pub fn is_fullscreen ( & self , pending : bool ) -> bool {
352358 match self . 0 . underlying_surface ( ) {
353359 WindowSurface :: Wayland ( toplevel) => with_toplevel_state ( toplevel, pending, |state| {
354- state. states . contains ( ToplevelState :: Fullscreen )
360+ state. is_some_and ( |state| state . states . contains ( ToplevelState :: Fullscreen ) )
355361 } ) ,
356362 WindowSurface :: X11 ( surface) => surface. is_fullscreen ( ) ,
357363 }
@@ -375,7 +381,7 @@ impl CosmicSurface {
375381 pub fn is_maximized ( & self , pending : bool ) -> bool {
376382 match self . 0 . underlying_surface ( ) {
377383 WindowSurface :: Wayland ( toplevel) => with_toplevel_state ( toplevel, pending, |state| {
378- state. states . contains ( ToplevelState :: Maximized )
384+ state. is_some_and ( |state| state . states . contains ( ToplevelState :: Maximized ) )
379385 } ) ,
380386 WindowSurface :: X11 ( surface) => surface. is_maximized ( ) ,
381387 }
@@ -491,10 +497,9 @@ impl CosmicSurface {
491497 . lock ( )
492498 . unwrap ( ) ;
493499 attrs
494- . configure_serial
500+ . last_acked
495501 . as_ref ( )
496- . map ( |s| s >= serial)
497- . unwrap_or ( false )
502+ . is_some_and ( |configure| configure. serial >= * serial)
498503 } ) ,
499504 WindowSurface :: X11 ( _surface) => true ,
500505 }
@@ -503,17 +508,12 @@ impl CosmicSurface {
503508 pub fn serial_past ( & self , serial : & Serial ) -> bool {
504509 match self . 0 . underlying_surface ( ) {
505510 WindowSurface :: Wayland ( toplevel) => with_states ( toplevel. wl_surface ( ) , |states| {
506- let attrs = states
507- . data_map
508- . get :: < XdgToplevelSurfaceData > ( )
509- . unwrap ( )
510- . lock ( )
511- . unwrap ( ) ;
512- attrs
513- . current_serial
511+ let mut guard = states. cached_state . get :: < ToplevelCachedState > ( ) ;
512+ guard
513+ . current ( )
514+ . last_acked
514515 . as_ref ( )
515- . map ( |s| s >= serial)
516- . unwrap_or ( false )
516+ . is_some_and ( |configure| configure. serial >= * serial)
517517 } ) ,
518518 WindowSurface :: X11 ( _surface) => true ,
519519 }
@@ -531,12 +531,18 @@ impl CosmicSurface {
531531 . unwrap ( ) ;
532532
533533 let current_server = attributes. current_server_state ( ) ;
534- if attributes. current . size == current_server. size {
534+ let mut guard = states. cached_state . get :: < ToplevelCachedState > ( ) ;
535+ if guard
536+ . current ( )
537+ . last_acked
538+ . as_ref ( )
539+ . is_some_and ( |configure| configure. state . size == current_server. size )
540+ {
535541 // The window had committed for our previous size change, so we can
536542 // change the size again.
537543 trace ! (
538544 "current size matches server size: {:?}" ,
539- attributes . current. size
545+ guard . current( ) . last_acked . as_ref ( ) . unwrap ( ) . state . size
540546 ) ;
541547 true
542548 } else {
@@ -927,15 +933,14 @@ where
927933 }
928934}
929935
930- fn with_toplevel_state < T , F : FnOnce ( & smithay:: wayland:: shell:: xdg:: ToplevelState ) -> T > (
936+ fn with_toplevel_state < T , F : FnOnce ( Option < & smithay:: wayland:: shell:: xdg:: ToplevelState > ) -> T > (
931937 toplevel : & ToplevelSurface ,
932938 pending : bool ,
933939 cb : F ,
934940) -> T {
935941 if pending {
936- toplevel. with_pending_state ( |pending| cb ( pending) )
942+ toplevel. with_pending_state ( |pending| cb ( Some ( pending) ) )
937943 } else {
938- let current = toplevel. current_state ( ) ;
939- cb ( & current)
944+ toplevel. with_committed_state ( |committed| cb ( committed) )
940945 }
941946}
0 commit comments