fix(corner-radius): use cached state
This commit is contained in:
parent
e476153086
commit
242e465d42
2 changed files with 61 additions and 33 deletions
|
|
@ -1,5 +1,4 @@
|
|||
use crate::wayland::protocols::corner_radius::CornerRadiusData;
|
||||
use smithay::reexports::wayland_server::Resource;
|
||||
use crate::wayland::protocols::corner_radius::CacheableCorners;
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
sync::{
|
||||
|
|
@ -9,7 +8,6 @@ use std::{
|
|||
time::Duration,
|
||||
};
|
||||
|
||||
use cosmic_protocols::corner_radius::v1::server::cosmic_corner_radius_toplevel_v1::CosmicCornerRadiusToplevelV1;
|
||||
use smithay::{
|
||||
backend::renderer::{
|
||||
element::{
|
||||
|
|
@ -37,7 +35,7 @@ use smithay::{
|
|||
},
|
||||
},
|
||||
wayland_protocols_misc::server_decoration::server::org_kde_kwin_server_decoration::Mode as KdeMode,
|
||||
wayland_server::{protocol::wl_surface::WlSurface, Weak},
|
||||
wayland_server::protocol::wl_surface::WlSurface,
|
||||
},
|
||||
utils::{
|
||||
user_data::UserDataMap, IsAlive, Logical, Physical, Point, Rectangle, Scale, Serial, Size,
|
||||
|
|
@ -130,29 +128,20 @@ impl CosmicSurface {
|
|||
pub fn corner_radius(&self, geometry_size: Size<i32, Logical>) -> Option<[u8; 4]> {
|
||||
self.wl_surface().and_then(|surface| {
|
||||
with_states(&surface, |states| {
|
||||
let d = states
|
||||
.data_map
|
||||
.get::<Mutex<Weak<CosmicCornerRadiusToplevelV1>>>()?;
|
||||
let guard = d.lock().unwrap();
|
||||
|
||||
let weak_data = guard.upgrade().ok()?;
|
||||
|
||||
let corners = weak_data.data::<CornerRadiusData>()?;
|
||||
|
||||
let guard = corners.lock().unwrap();
|
||||
let mut guard = states.cached_state.get::<CacheableCorners>();
|
||||
|
||||
// guard against corner radius being too large, potentially disconnecting the outline
|
||||
let half_min_dim =
|
||||
u8::try_from(geometry_size.w.min(geometry_size.h) / 2).unwrap_or(u8::MAX);
|
||||
|
||||
guard.corners.map(|corners| {
|
||||
[
|
||||
corners.bottom_right.min(half_min_dim),
|
||||
corners.top_right.min(half_min_dim),
|
||||
corners.bottom_left.min(half_min_dim),
|
||||
corners.top_left.min(half_min_dim),
|
||||
]
|
||||
})
|
||||
let corners = guard.current().0?;
|
||||
|
||||
Some([
|
||||
corners.bottom_right.min(half_min_dim),
|
||||
corners.top_right.min(half_min_dim),
|
||||
corners.bottom_left.min(half_min_dim),
|
||||
corners.top_left.min(half_min_dim),
|
||||
])
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue