@@ -6,6 +6,7 @@ use smithay::reexports::{
66 wayland_server:: { Client , Dispatch , DisplayHandle , GlobalDispatch , Resource , Weak } ,
77} ;
88use smithay:: wayland:: compositor:: with_states;
9+ use smithay:: wayland:: compositor:: Cacheable ;
910use smithay:: wayland:: shell:: xdg:: ToplevelSurface ;
1011use std:: sync:: Mutex ;
1112use wayland_backend:: server:: GlobalId ;
@@ -110,17 +111,7 @@ where
110111 toplevel : toplevel. downgrade ( ) ,
111112 corners : None ,
112113 } ) ;
113- let instance = data_init. init ( id, data) ;
114-
115- if let Some ( surface) = state. toplevel_from_resource ( & toplevel) {
116- with_states ( surface. wl_surface ( ) , |s| {
117- let data = s
118- . data_map
119- . get_or_insert_threadsafe ( || Mutex :: new ( instance. downgrade ( ) ) ) ;
120- let mut guard = data. lock ( ) . unwrap ( ) ;
121- * guard = instance. downgrade ( ) ;
122- } ) ;
123- }
114+ let _ = data_init. init ( id, data) ;
124115 }
125116 _ => unimplemented ! ( ) ,
126117 }
@@ -160,6 +151,18 @@ where
160151 cosmic_corner_radius_toplevel_v1:: Request :: Destroy => {
161152 let mut guard = data. lock ( ) . unwrap ( ) ;
162153 guard. corners = None ;
154+ if let Some ( surface) = guard
155+ . toplevel
156+ . upgrade ( )
157+ . ok ( )
158+ . and_then ( |toplevel| state. toplevel_from_resource ( & toplevel) )
159+ {
160+ with_states ( surface. wl_surface ( ) , |s| {
161+ let mut cached = s. cached_state . get :: < CacheableCorners > ( ) ;
162+ let pending = cached. pending ( ) ;
163+ * pending = CacheableCorners ( None ) ;
164+ } ) ;
165+ }
163166 drop ( guard) ;
164167
165168 state. unset_corner_radius ( resource, data) ;
@@ -172,13 +175,37 @@ where
172175 } => {
173176 let mut guard = data. lock ( ) . unwrap ( ) ;
174177 guard. set_corner_radius ( top_left, top_right, bottom_right, bottom_left) ;
178+ if let Some ( surface) = guard
179+ . toplevel
180+ . upgrade ( )
181+ . ok ( )
182+ . and_then ( |toplevel| state. toplevel_from_resource ( & toplevel) )
183+ {
184+ with_states ( surface. wl_surface ( ) , |s| {
185+ let mut cached = s. cached_state . get :: < CacheableCorners > ( ) ;
186+ let pending = cached. pending ( ) ;
187+ * pending = CacheableCorners ( guard. corners ) ;
188+ } ) ;
189+ }
175190 drop ( guard) ;
176191
177192 state. set_corner_radius ( resource, data) ;
178193 }
179194 cosmic_corner_radius_toplevel_v1:: Request :: UnsetRadius => {
180195 let mut guard = data. lock ( ) . unwrap ( ) ;
181196 guard. corners = None ;
197+ if let Some ( surface) = guard
198+ . toplevel
199+ . upgrade ( )
200+ . ok ( )
201+ . and_then ( |toplevel| state. toplevel_from_resource ( & toplevel) )
202+ {
203+ with_states ( surface. wl_surface ( ) , |s| {
204+ let mut cached = s. cached_state . get :: < CacheableCorners > ( ) ;
205+ let pending = cached. pending ( ) ;
206+ * pending = CacheableCorners ( None ) ;
207+ } ) ;
208+ }
182209 drop ( guard) ;
183210
184211 state. unset_corner_radius ( resource, data) ;
@@ -204,6 +231,18 @@ pub struct Corners {
204231 pub bottom_left : u8 ,
205232}
206233
234+ #[ derive( Default , Debug , Copy , Clone ) ]
235+ pub struct CacheableCorners ( pub Option < Corners > ) ;
236+
237+ impl Cacheable for CacheableCorners {
238+ fn commit ( & mut self , _dh : & DisplayHandle ) -> Self {
239+ * self
240+ }
241+ fn merge_into ( self , into : & mut Self , _dh : & DisplayHandle ) {
242+ * into = self ;
243+ }
244+ }
245+
207246impl CornerRadiusInternal {
208247 fn set_corner_radius (
209248 & mut self ,
0 commit comments