@@ -108,10 +108,7 @@ where
108108 cosmic_corner_radius_manager_v1:: Request :: GetCornerRadius { id, toplevel } => {
109109 let data = Mutex :: new ( CornerRadiusInternal {
110110 toplevel : toplevel. downgrade ( ) ,
111- top_left : 0 ,
112- top_right : 0 ,
113- bottom_right : 0 ,
114- bottom_left : 0 ,
111+ corners : None ,
115112 } ) ;
116113 let instance = data_init. init ( id, data) ;
117114
@@ -151,7 +148,7 @@ where
151148 + ' static ,
152149{
153150 fn request (
154- _state : & mut D ,
151+ state : & mut D ,
155152 _client : & Client ,
156153 resource : & cosmic_corner_radius_toplevel_v1:: CosmicCornerRadiusToplevelV1 ,
157154 request : <cosmic_corner_radius_toplevel_v1:: CosmicCornerRadiusToplevelV1 as Resource >:: Request ,
@@ -161,29 +158,30 @@ where
161158 ) {
162159 match request {
163160 cosmic_corner_radius_toplevel_v1:: Request :: Destroy => {
164- // TODO do we want to unset it after it is destroyed or just leave it?
165- _state. unset_corner_radius ( resource, data) ;
161+ let mut guard = data. lock ( ) . unwrap ( ) ;
162+ guard. corners = None ;
163+ drop ( guard) ;
164+
165+ state. unset_corner_radius ( resource, data) ;
166166 }
167167 cosmic_corner_radius_toplevel_v1:: Request :: SetRadius {
168168 top_left,
169169 top_right,
170170 bottom_right,
171171 bottom_left,
172172 } => {
173- {
174- let mut guard = data. lock ( ) . unwrap ( ) ;
175- guard. set_corner_radius (
176- top_left as u8 ,
177- top_right as u8 ,
178- bottom_right as u8 ,
179- bottom_left as u8 ,
180- ) ;
181- }
173+ let mut guard = data. lock ( ) . unwrap ( ) ;
174+ guard. set_corner_radius ( top_left, top_right, bottom_right, bottom_left) ;
175+ drop ( guard) ;
182176
183- _state . set_corner_radius ( resource, data) ;
177+ state . set_corner_radius ( resource, data) ;
184178 }
185179 cosmic_corner_radius_toplevel_v1:: Request :: UnsetRadius => {
186- _state. unset_corner_radius ( resource, data) ;
180+ let mut guard = data. lock ( ) . unwrap ( ) ;
181+ guard. corners = None ;
182+ drop ( guard) ;
183+
184+ state. unset_corner_radius ( resource, data) ;
187185 }
188186 _ => unimplemented ! ( ) ,
189187 }
@@ -195,6 +193,11 @@ pub type CornerRadiusData = Mutex<CornerRadiusInternal>;
195193#[ derive( Debug ) ]
196194pub struct CornerRadiusInternal {
197195 pub toplevel : Weak < XdgToplevel > ,
196+ pub corners : Option < Corners > ,
197+ }
198+
199+ #[ derive( Debug , Copy , Clone ) ]
200+ pub struct Corners {
198201 pub top_left : u8 ,
199202 pub top_right : u8 ,
200203 pub bottom_right : u8 ,
@@ -204,15 +207,18 @@ pub struct CornerRadiusInternal {
204207impl CornerRadiusInternal {
205208 fn set_corner_radius (
206209 & mut self ,
207- top_left : u8 ,
208- top_right : u8 ,
209- bottom_right : u8 ,
210- bottom_left : u8 ,
210+ top_left : u32 ,
211+ top_right : u32 ,
212+ bottom_right : u32 ,
213+ bottom_left : u32 ,
211214 ) {
212- self . top_left = top_left;
213- self . top_right = top_right;
214- self . bottom_right = bottom_right;
215- self . bottom_left = bottom_left;
215+ let corners = Corners {
216+ top_left : top_left. clamp ( u8:: MIN as u32 , u8:: MAX as u32 ) as u8 ,
217+ top_right : top_right. clamp ( u8:: MIN as u32 , u8:: MAX as u32 ) as u8 ,
218+ bottom_right : bottom_right. clamp ( u8:: MIN as u32 , u8:: MAX as u32 ) as u8 ,
219+ bottom_left : bottom_left. clamp ( u8:: MIN as u32 , u8:: MAX as u32 ) as u8 ,
220+ } ;
221+ self . corners = Some ( corners) ;
216222 }
217223}
218224
0 commit comments