fix(corner-radius): properly handle no value, and use geometry
This commit is contained in:
parent
6f93b8774d
commit
2873d6b27e
5 changed files with 52 additions and 42 deletions
|
|
@ -108,10 +108,7 @@ where
|
|||
cosmic_corner_radius_manager_v1::Request::GetCornerRadius { id, toplevel } => {
|
||||
let data = Mutex::new(CornerRadiusInternal {
|
||||
toplevel: toplevel.downgrade(),
|
||||
top_left: 0,
|
||||
top_right: 0,
|
||||
bottom_right: 0,
|
||||
bottom_left: 0,
|
||||
corners: None,
|
||||
});
|
||||
let instance = data_init.init(id, data);
|
||||
|
||||
|
|
@ -151,7 +148,7 @@ where
|
|||
+ 'static,
|
||||
{
|
||||
fn request(
|
||||
_state: &mut D,
|
||||
state: &mut D,
|
||||
_client: &Client,
|
||||
resource: &cosmic_corner_radius_toplevel_v1::CosmicCornerRadiusToplevelV1,
|
||||
request: <cosmic_corner_radius_toplevel_v1::CosmicCornerRadiusToplevelV1 as Resource>::Request,
|
||||
|
|
@ -161,8 +158,11 @@ where
|
|||
) {
|
||||
match request {
|
||||
cosmic_corner_radius_toplevel_v1::Request::Destroy => {
|
||||
// TODO do we want to unset it after it is destroyed or just leave it?
|
||||
_state.unset_corner_radius(resource, data);
|
||||
let mut guard = data.lock().unwrap();
|
||||
guard.corners = None;
|
||||
drop(guard);
|
||||
|
||||
state.unset_corner_radius(resource, data);
|
||||
}
|
||||
cosmic_corner_radius_toplevel_v1::Request::SetRadius {
|
||||
top_left,
|
||||
|
|
@ -170,20 +170,18 @@ where
|
|||
bottom_right,
|
||||
bottom_left,
|
||||
} => {
|
||||
{
|
||||
let mut guard = data.lock().unwrap();
|
||||
guard.set_corner_radius(
|
||||
top_left as u8,
|
||||
top_right as u8,
|
||||
bottom_right as u8,
|
||||
bottom_left as u8,
|
||||
);
|
||||
}
|
||||
let mut guard = data.lock().unwrap();
|
||||
guard.set_corner_radius(top_left, top_right, bottom_right, bottom_left);
|
||||
drop(guard);
|
||||
|
||||
_state.set_corner_radius(resource, data);
|
||||
state.set_corner_radius(resource, data);
|
||||
}
|
||||
cosmic_corner_radius_toplevel_v1::Request::UnsetRadius => {
|
||||
_state.unset_corner_radius(resource, data);
|
||||
let mut guard = data.lock().unwrap();
|
||||
guard.corners = None;
|
||||
drop(guard);
|
||||
|
||||
state.unset_corner_radius(resource, data);
|
||||
}
|
||||
_ => unimplemented!(),
|
||||
}
|
||||
|
|
@ -195,6 +193,11 @@ pub type CornerRadiusData = Mutex<CornerRadiusInternal>;
|
|||
#[derive(Debug)]
|
||||
pub struct CornerRadiusInternal {
|
||||
pub toplevel: Weak<XdgToplevel>,
|
||||
pub corners: Option<Corners>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct Corners {
|
||||
pub top_left: u8,
|
||||
pub top_right: u8,
|
||||
pub bottom_right: u8,
|
||||
|
|
@ -204,15 +207,18 @@ pub struct CornerRadiusInternal {
|
|||
impl CornerRadiusInternal {
|
||||
fn set_corner_radius(
|
||||
&mut self,
|
||||
top_left: u8,
|
||||
top_right: u8,
|
||||
bottom_right: u8,
|
||||
bottom_left: u8,
|
||||
top_left: u32,
|
||||
top_right: u32,
|
||||
bottom_right: u32,
|
||||
bottom_left: u32,
|
||||
) {
|
||||
self.top_left = top_left;
|
||||
self.top_right = top_right;
|
||||
self.bottom_right = bottom_right;
|
||||
self.bottom_left = bottom_left;
|
||||
let corners = Corners {
|
||||
top_left: top_left.clamp(u8::MIN as u32, u8::MAX as u32) as u8,
|
||||
top_right: top_right.clamp(u8::MIN as u32, u8::MAX as u32) as u8,
|
||||
bottom_right: bottom_right.clamp(u8::MIN as u32, u8::MAX as u32) as u8,
|
||||
bottom_left: bottom_left.clamp(u8::MIN as u32, u8::MAX as u32) as u8,
|
||||
};
|
||||
self.corners = Some(corners);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue