From f01ebf2f6f37535393d88b1527d9605712f062da Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Thu, 25 Sep 2025 11:00:57 -0400 Subject: [PATCH] refactor(corner-radius): corner_radius method for CosmicSurface --- src/shell/element/surface.rs | 29 ++++++++++++- src/shell/grabs/moving.rs | 23 +---------- src/shell/layout/floating/mod.rs | 23 +---------- src/shell/layout/tiling/mod.rs | 71 ++------------------------------ 4 files changed, 33 insertions(+), 113 deletions(-) diff --git a/src/shell/element/surface.rs b/src/shell/element/surface.rs index b9785603..204dc4e9 100644 --- a/src/shell/element/surface.rs +++ b/src/shell/element/surface.rs @@ -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::>>()?; + let guard = d.lock().unwrap(); + + let weak_data = guard.upgrade().ok()?; + + let corners = weak_data.data::()?; + + 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| { diff --git a/src/shell/grabs/moving.rs b/src/shell/grabs/moving.rs index 94e28a3e..d26fd03e 100644 --- a/src/shell/grabs/moving.rs +++ b/src/shell/grabs/moving.rs @@ -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::>>()?; - let guard = d.lock().unwrap(); - - let weak_data = guard.upgrade().ok()?; - - let corners = weak_data.data::()?; - - 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 { diff --git a/src/shell/layout/floating/mod.rs b/src/shell/layout/floating/mod.rs index b1b9401b..cedbf6e9 100644 --- a/src/shell/layout/floating/mod.rs +++ b/src/shell/layout/floating/mod.rs @@ -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::>>()?; - let guard = d.lock().unwrap(); - - let weak_data = guard.upgrade().ok()?; - - let corners = weak_data.data::()?; - - 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( diff --git a/src/shell/layout/tiling/mod.rs b/src/shell/layout/tiling/mod.rs index 25c86d5b..1f4b241b 100644 --- a/src/shell/layout/tiling/mod.rs +++ b/src/shell/layout/tiling/mod.rs @@ -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::>>()?; - let guard = d.lock().unwrap(); - - let weak_data = guard.upgrade().ok()?; - - let corners = weak_data.data::()?; - - 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::>>()?; - let guard = d.lock().unwrap(); - - let weak_data = guard.upgrade().ok()?; - - let corners = weak_data.data::()?; - - 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::>>()?; - let guard = d.lock().unwrap(); - - let weak_data = guard.upgrade().ok()?; - - let corners = weak_data.data::()?; - - 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], };