@@ -43,7 +43,9 @@ use smithay::{
4343 wayland:: {
4444 compositor:: { with_states, with_surface_tree_downward, SurfaceData , TraversalAction } ,
4545 seat:: WaylandFocus ,
46- shell:: xdg:: { SurfaceCachedState , ToplevelSurface , XdgToplevelSurfaceData } ,
46+ shell:: xdg:: {
47+ SurfaceCachedState , ToplevelCachedState , ToplevelSurface , XdgToplevelSurfaceData ,
48+ } ,
4749 } ,
4850 xwayland:: { xwm:: X11Relatable , X11Surface } ,
4951} ;
@@ -216,7 +218,7 @@ impl CosmicSurface {
216218 pub fn is_activated ( & self , pending : bool ) -> bool {
217219 match self . 0 . underlying_surface ( ) {
218220 WindowSurface :: Wayland ( toplevel) => with_toplevel_state ( toplevel, pending, |state| {
219- state. states . contains ( ToplevelState :: Activated )
221+ state. is_some_and ( |state| state . states . contains ( ToplevelState :: Activated ) )
220222 } ) ,
221223 WindowSurface :: X11 ( surface) => surface. is_activated ( ) ,
222224 }
@@ -248,9 +250,11 @@ impl CosmicSurface {
248250 } ) ;
249251
250252 let xdg_state = with_toplevel_state ( toplevel, pending, |state| {
251- state
252- . decoration_mode
253- . map ( |mode| mode == DecorationMode :: ClientSide )
253+ state. and_then ( |state| {
254+ state
255+ . decoration_mode
256+ . map ( |mode| mode == DecorationMode :: ClientSide )
257+ } )
254258 } ) ;
255259
256260 kde_state. or ( xdg_state) . unwrap_or ( true )
@@ -263,8 +267,9 @@ impl CosmicSurface {
263267 match self . 0 . underlying_surface ( ) {
264268 WindowSurface :: Wayland ( toplevel) => {
265269 if enable {
266- let previous_decoration_state =
267- toplevel. current_state ( ) . decoration_mode . clone ( ) ;
270+ let previous_decoration_state = toplevel. with_committed_state ( |state| {
271+ state. map_or_else ( Default :: default, |state| state. decoration_mode . clone ( ) )
272+ } ) ;
268273 if PreferredDecorationMode :: is_unset ( & self . 0 ) {
269274 PreferredDecorationMode :: update ( & self . 0 , previous_decoration_state) ;
270275 }
@@ -300,7 +305,7 @@ impl CosmicSurface {
300305 match self . 0 . underlying_surface ( ) {
301306 WindowSurface :: Wayland ( toplevel) => {
302307 Some ( with_toplevel_state ( toplevel, pending, |state| {
303- state. states . contains ( ToplevelState :: Resizing )
308+ state. is_some_and ( |state| state . states . contains ( ToplevelState :: Resizing ) )
304309 } ) )
305310 }
306311 WindowSurface :: X11 ( _surface) => None ,
@@ -324,7 +329,7 @@ impl CosmicSurface {
324329 match self . 0 . underlying_surface ( ) {
325330 WindowSurface :: Wayland ( toplevel) => {
326331 Some ( with_toplevel_state ( toplevel, pending, |state| {
327- state. states . contains ( ToplevelState :: TiledLeft )
332+ state. is_some_and ( |state| state . states . contains ( ToplevelState :: TiledLeft ) )
328333 } ) )
329334 }
330335 WindowSurface :: X11 ( _surface) => None ,
@@ -353,7 +358,7 @@ impl CosmicSurface {
353358 pub fn is_fullscreen ( & self , pending : bool ) -> bool {
354359 match self . 0 . underlying_surface ( ) {
355360 WindowSurface :: Wayland ( toplevel) => with_toplevel_state ( toplevel, pending, |state| {
356- state. states . contains ( ToplevelState :: Fullscreen )
361+ state. is_some_and ( |state| state . states . contains ( ToplevelState :: Fullscreen ) )
357362 } ) ,
358363 WindowSurface :: X11 ( surface) => surface. is_fullscreen ( ) ,
359364 }
@@ -377,7 +382,7 @@ impl CosmicSurface {
377382 pub fn is_maximized ( & self , pending : bool ) -> bool {
378383 match self . 0 . underlying_surface ( ) {
379384 WindowSurface :: Wayland ( toplevel) => with_toplevel_state ( toplevel, pending, |state| {
380- state. states . contains ( ToplevelState :: Maximized )
385+ state. is_some_and ( |state| state . states . contains ( ToplevelState :: Maximized ) )
381386 } ) ,
382387 WindowSurface :: X11 ( surface) => surface. is_maximized ( ) ,
383388 }
@@ -493,10 +498,9 @@ impl CosmicSurface {
493498 . lock ( )
494499 . unwrap ( ) ;
495500 attrs
496- . configure_serial
501+ . last_acked
497502 . as_ref ( )
498- . map ( |s| s >= serial)
499- . unwrap_or ( false )
503+ . is_some_and ( |configure| configure. serial >= * serial)
500504 } ) ,
501505 WindowSurface :: X11 ( _surface) => true ,
502506 }
@@ -505,17 +509,12 @@ impl CosmicSurface {
505509 pub fn serial_past ( & self , serial : & Serial ) -> bool {
506510 match self . 0 . underlying_surface ( ) {
507511 WindowSurface :: Wayland ( toplevel) => with_states ( toplevel. wl_surface ( ) , |states| {
508- let attrs = states
509- . data_map
510- . get :: < XdgToplevelSurfaceData > ( )
511- . unwrap ( )
512- . lock ( )
513- . unwrap ( ) ;
514- attrs
515- . current_serial
512+ let mut guard = states. cached_state . get :: < ToplevelCachedState > ( ) ;
513+ guard
514+ . current ( )
515+ . last_acked
516516 . as_ref ( )
517- . map ( |s| s >= serial)
518- . unwrap_or ( false )
517+ . is_some_and ( |configure| configure. serial >= * serial)
519518 } ) ,
520519 WindowSurface :: X11 ( _surface) => true ,
521520 }
@@ -533,12 +532,18 @@ impl CosmicSurface {
533532 . unwrap ( ) ;
534533
535534 let current_server = attributes. current_server_state ( ) ;
536- if attributes. current . size == current_server. size {
535+ let mut guard = states. cached_state . get :: < ToplevelCachedState > ( ) ;
536+ if guard
537+ . current ( )
538+ . last_acked
539+ . as_ref ( )
540+ . is_some_and ( |configure| configure. state . size == current_server. size )
541+ {
537542 // The window had committed for our previous size change, so we can
538543 // change the size again.
539544 trace ! (
540545 "current size matches server size: {:?}" ,
541- attributes . current. size
546+ guard . current( ) . last_acked . as_ref ( ) . unwrap ( ) . state . size
542547 ) ;
543548 true
544549 } else {
@@ -931,15 +936,14 @@ where
931936 }
932937}
933938
934- fn with_toplevel_state < T , F : FnOnce ( & smithay:: wayland:: shell:: xdg:: ToplevelState ) -> T > (
939+ fn with_toplevel_state < T , F : FnOnce ( Option < & smithay:: wayland:: shell:: xdg:: ToplevelState > ) -> T > (
935940 toplevel : & ToplevelSurface ,
936941 pending : bool ,
937942 cb : F ,
938943) -> T {
939944 if pending {
940- toplevel. with_pending_state ( |pending| cb ( pending) )
945+ toplevel. with_pending_state ( |pending| cb ( Some ( pending) ) )
941946 } else {
942- let current = toplevel. current_state ( ) ;
943- cb ( & current)
947+ toplevel. with_committed_state ( |committed| cb ( committed) )
944948 }
945949}
0 commit comments