refactor(corner-radius): corner_radius method for CosmicSurface

This commit is contained in:
Ashley Wulber 2025-09-25 11:00:57 -04:00 committed by Victoria Brekenfeld
parent 4e30513673
commit f01ebf2f6f
4 changed files with 33 additions and 113 deletions

View file

@ -1,3 +1,5 @@
use crate::wayland::protocols::corner_radius::CornerRadiusData;
use smithay::reexports::wayland_server::Resource;
use std::{
borrow::Cow,
sync::{
@ -7,6 +9,7 @@ use std::{
time::Duration,
};
use cosmic_protocols::corner_radius::v1::server::cosmic_corner_radius_toplevel_v1::CosmicCornerRadiusToplevelV1;
use smithay::{
backend::renderer::{
element::{
@ -34,7 +37,7 @@ use smithay::{
},
},
wayland_protocols_misc::server_decoration::server::org_kde_kwin_server_decoration::Mode as KdeMode,
wayland_server::protocol::wl_surface::WlSurface,
wayland_server::{protocol::wl_surface::WlSurface, Weak},
},
utils::{
user_data::UserDataMap, IsAlive, Logical, Physical, Point, Rectangle, Scale, Serial, Size,
@ -124,6 +127,30 @@ impl CosmicSurface {
}
}
pub fn corner_radius(&self) -> Option<[u8; 4]> {
self.wl_surface().and_then(|surface| {
with_states(&surface, |s| {
let d = s
.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();
Some([
guard.top_right,
guard.bottom_right,
guard.top_left,
guard.bottom_left,
])
})
})
}
pub fn app_id(&self) -> String {
match self.0.underlying_surface() {
WindowSurface::Wayland(toplevel) => with_states(toplevel.wl_surface(), |states| {

View file

@ -119,28 +119,7 @@ impl MoveGrabState {
let active_window_hint = crate::theme::active_window_hint(theme);
let radius = self
.window()
.wl_surface()
.and_then(|surface| {
with_states(&surface, |s| {
let d = s
.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();
Some([
guard.top_right,
guard.bottom_right,
guard.top_left,
guard.bottom_left,
])
})
})
.corner_radius()
.unwrap_or([self.indicator_thickness; 4]);
let focus_element = if self.indicator_thickness > 0 {

View file

@ -1600,28 +1600,7 @@ impl FloatingLayout {
let active_window_hint = crate::theme::active_window_hint(theme);
let radius = elem
.active_window()
.wl_surface()
.and_then(|surface| {
with_states(&surface, |s| {
let d = s
.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();
Some([
guard.top_right,
guard.bottom_right,
guard.top_left,
guard.bottom_left,
])
})
})
.corner_radius()
.unwrap_or([indicator_thickness; 4]);
if indicator_thickness > 0 {
let element = IndicatorShader::focus_element(

View file

@ -5020,28 +5020,7 @@ where
}));
let radius = mapped
.active_window()
.wl_surface()
.and_then(|surface| {
with_states(&surface, |s| {
let d = s
.data_map
.get::<Mutex<WsWeak<CosmicCornerRadiusToplevelV1>>>()?;
let guard = d.lock().unwrap();
let weak_data = guard.upgrade().ok()?;
let corners = weak_data.data::<CornerRadiusData>()?;
let guard = corners.lock().unwrap();
Some([
guard.top_right,
guard.bottom_right,
guard.top_left,
guard.bottom_left,
])
})
})
.corner_radius()
.unwrap_or([indicator_thickness; 4]);
if is_minimizing && indicator_thickness > 0 {
elements.push(CosmicMappedRenderElement::FocusIndicator(
@ -5312,30 +5291,7 @@ where
)
.unwrap();
let radius = window
.wl_surface()
.and_then(|surface| {
with_states(&surface, |s| {
let d = s
.data_map
.get::<Mutex<WsWeak<CosmicCornerRadiusToplevelV1>>>()?;
let guard = d.lock().unwrap();
let weak_data = guard.upgrade().ok()?;
let corners = weak_data.data::<CornerRadiusData>()?;
let guard = corners.lock().unwrap();
Some([
guard.top_right,
guard.bottom_right,
guard.top_left,
guard.bottom_left,
])
})
})
.unwrap_or([indicator_thickness; 4]);
let radius = window.corner_radius().unwrap_or([indicator_thickness; 4]);
swap_elements.push(CosmicMappedRenderElement::FocusIndicator(
IndicatorShader::focus_element(
renderer,
@ -5416,28 +5372,7 @@ where
let radius = match data {
Data::Mapped { mapped, .. } => mapped
.active_window()
.wl_surface()
.and_then(|surface| {
with_states(&surface, |s| {
let d = s
.data_map
.get::<Mutex<WsWeak<CosmicCornerRadiusToplevelV1>>>()?;
let guard = d.lock().unwrap();
let weak_data = guard.upgrade().ok()?;
let corners = weak_data.data::<CornerRadiusData>()?;
let guard = corners.lock().unwrap();
Some([
guard.top_right,
guard.bottom_right,
guard.top_left,
guard.bottom_left,
])
})
})
.corner_radius()
.unwrap_or([indicator_thickness; 4]),
_ => [1; 4],
};