@@ -2,7 +2,6 @@ use cosmic_protocols::corner_radius::v1::server::cosmic_corner_radius_toplevel_v
22use cosmic_protocols:: corner_radius:: v1:: server:: {
33 cosmic_corner_radius_manager_v1, cosmic_corner_radius_toplevel_v1,
44} ;
5- use smithay:: reexports:: wayland_server:: protocol:: wl_surface:: WlSurface ;
65use smithay:: utils:: HookId ;
76use smithay:: wayland:: compositor:: add_pre_commit_hook;
87use smithay:: wayland:: compositor:: with_states;
@@ -15,10 +14,11 @@ use smithay::{
1514 } ,
1615 wayland:: shell:: xdg:: XdgShellHandler ,
1716} ;
18- use std:: collections:: HashMap ;
1917use std:: sync:: Mutex ;
2018use wayland_backend:: server:: GlobalId ;
2119
20+ type ToplevelHookId = Mutex < Option < ( HookId , Weak < CosmicCornerRadiusToplevelV1 > ) > > ;
21+
2222#[ derive( Debug ) ]
2323pub struct CornerRadiusState {
2424 instances : Vec < cosmic_corner_radius_manager_v1:: CosmicCornerRadiusManagerV1 > ,
@@ -116,16 +116,11 @@ where
116116 cosmic_corner_radius_manager_v1:: Request :: GetCornerRadius { id, toplevel } => {
117117 if let Some ( surface) = state. xdg_shell_state ( ) . get_toplevel ( & toplevel) {
118118 let radius_exists = with_states ( surface. wl_surface ( ) , |surface_data| {
119- let hook_ids = surface_data. data_map . get_or_insert_threadsafe ( || {
120- Mutex :: new ( HashMap :: <
121- WlSurface ,
122- ( HookId , Weak < CosmicCornerRadiusToplevelV1 > ) ,
123- > :: new ( ) )
124- } ) ;
125- let guard = hook_ids. lock ( ) . unwrap ( ) ;
126- guard
127- . get ( surface. wl_surface ( ) )
128- . map ( |( _, t) | t. upgrade ( ) . is_ok ( ) )
119+ let hook_id = surface_data
120+ . data_map
121+ . get_or_insert_threadsafe ( || ToplevelHookId :: new ( None ) ) ;
122+ let guard = hook_id. lock ( ) . unwrap ( ) ;
123+ guard. as_ref ( ) . map ( |( _, t) | t. upgrade ( ) . is_ok ( ) )
129124 } ) ;
130125 if radius_exists. unwrap_or_default ( ) {
131126 resource. post_error (
@@ -179,14 +174,11 @@ where
179174 ) ;
180175
181176 with_states ( surface. wl_surface ( ) , |surface_data| {
182- let hook_ids = surface_data. data_map . get_or_insert_threadsafe ( || {
183- Mutex :: new ( HashMap :: <
184- WlSurface ,
185- ( HookId , Weak < CosmicCornerRadiusToplevelV1 > ) ,
186- > :: new ( ) )
187- } ) ;
177+ let hook_ids = surface_data
178+ . data_map
179+ . get_or_insert_threadsafe ( || ToplevelHookId :: new ( None ) ) ;
188180 let mut guard = hook_ids. lock ( ) . unwrap ( ) ;
189- guard. insert ( surface . wl_surface ( ) . clone ( ) , ( hook_id, obj_downgrade) ) ;
181+ * guard = Some ( ( hook_id, obj_downgrade) ) ;
190182 } ) ;
191183 }
192184 }
@@ -231,22 +223,15 @@ where
231223 guard. corners = None ;
232224
233225 let Ok ( toplevel) = guard. toplevel . upgrade ( ) else {
234- resource. post_error (
235- cosmic_corner_radius_toplevel_v1:: Error :: ToplevelDestroyed as u32 ,
236- format ! ( "{:?} No toplevel found" , resource) ,
237- ) ;
238226 return ;
239227 } ;
240228
241229 if let Some ( surface) = state. xdg_shell_state ( ) . get_toplevel ( & toplevel) {
242230 with_states ( surface. wl_surface ( ) , |surface_data| {
243- if let Some ( hook_ids_mutex) =
244- surface_data. data_map . get :: < Mutex <
245- HashMap < WlSurface , ( HookId , Weak < CosmicCornerRadiusToplevelV1 > ) > ,
246- > > ( )
231+ if let Some ( hook_ids_mutex) = surface_data. data_map . get :: < ToplevelHookId > ( )
247232 {
248- let mut hook_ids = hook_ids_mutex. lock ( ) . unwrap ( ) ;
249- hook_ids . remove ( surface . wl_surface ( ) ) ;
233+ let mut hook_id = hook_ids_mutex. lock ( ) . unwrap ( ) ;
234+ * hook_id = None ;
250235 }
251236 } ) ;
252237 }
0 commit comments