From 4e305136737c128be2ec27111b8a53e85691961c Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Thu, 25 Sep 2025 09:57:08 -0400 Subject: [PATCH] fix(corner-radius): force redraw after corner radius change --- src/wayland/handlers/corner_radius.rs | 34 ++++++++++++++++++-------- src/wayland/protocols/corner_radius.rs | 26 +++++++++----------- 2 files changed, 35 insertions(+), 25 deletions(-) diff --git a/src/wayland/handlers/corner_radius.rs b/src/wayland/handlers/corner_radius.rs index d702bb23..7991d6b0 100644 --- a/src/wayland/handlers/corner_radius.rs +++ b/src/wayland/handlers/corner_radius.rs @@ -22,23 +22,37 @@ impl CornerRadiusHandler for State { fn set_corner_radius( &mut self, - _toplevel: &cosmic_corner_radius_toplevel_v1::CosmicCornerRadiusToplevelV1, - _data: &CornerRadiusData, - _top_left: u32, - _top_right: u32, - _bottom_right: u32, - _bottom_left: u32, + _: &cosmic_corner_radius_toplevel_v1::CosmicCornerRadiusToplevelV1, + data: &CornerRadiusData, ) { - // TODO force redraw? of focus element? + if force_redraw(self, data).is_none() { + tracing::warn!("Failed to force redraw for corner radius change."); + } } fn unset_corner_radius( &mut self, - _toplevel: &cosmic_corner_radius_toplevel_v1::CosmicCornerRadiusToplevelV1, - _data: &CornerRadiusData, + _: &cosmic_corner_radius_toplevel_v1::CosmicCornerRadiusToplevelV1, + data: &CornerRadiusData, ) { - // TODO force redraw? + if force_redraw(self, data).is_none() { + tracing::warn!("Failed to force redraw for corner radius reset."); + } } } +fn force_redraw(state: &mut State, data: &CornerRadiusData) -> Option<()> { + let guard = data.lock().unwrap(); + + let toplevel = guard.toplevel.upgrade().ok()?; + + let surface = state.common.xdg_shell_state.get_toplevel(&toplevel)?; + + let guard = state.common.shell.read(); + let output = guard.visible_output_for_surface(surface.wl_surface())?; + + state.backend.schedule_render(output); + Some(()) +} + delegate_corner_radius!(State); diff --git a/src/wayland/protocols/corner_radius.rs b/src/wayland/protocols/corner_radius.rs index 31e6cc0d..c732e824 100644 --- a/src/wayland/protocols/corner_radius.rs +++ b/src/wayland/protocols/corner_radius.rs @@ -3,7 +3,7 @@ use cosmic_protocols::corner_radius::v1::server::{ }; use smithay::reexports::{ wayland_protocols::xdg::shell::server::xdg_toplevel::XdgToplevel, - wayland_server::{Client, Dispatch, DisplayHandle, GlobalDispatch, Resource}, + wayland_server::{Client, Dispatch, DisplayHandle, GlobalDispatch, Resource, Weak}, }; use smithay::wayland::compositor::with_states; use smithay::wayland::shell::xdg::ToplevelSurface; @@ -50,10 +50,6 @@ pub trait CornerRadiusHandler { &mut self, toplevel: &cosmic_corner_radius_toplevel_v1::CosmicCornerRadiusToplevelV1, data: &CornerRadiusData, - top_left: u32, - top_right: u32, - bottom_right: u32, - bottom_left: u32, ); fn unset_corner_radius( &mut self, @@ -110,7 +106,13 @@ where corner_radius_state.instances.retain(|i| i != _resource); } cosmic_corner_radius_manager_v1::Request::GetCornerRadius { id, toplevel } => { - let data = CornerRadiusData::default(); + let data = Mutex::new(CornerRadiusInternal { + toplevel: toplevel.downgrade(), + top_left: 0, + top_right: 0, + bottom_right: 0, + bottom_left: 0, + }); let instance = data_init.init(id, data); if let Some(surface) = state.toplevel_from_resource(&toplevel) { @@ -178,14 +180,7 @@ where ); } - _state.set_corner_radius( - resource, - data, - top_left, - top_right, - bottom_right, - bottom_left, - ); + _state.set_corner_radius(resource, data); } cosmic_corner_radius_toplevel_v1::Request::UnsetRadius => { _state.unset_corner_radius(resource, data); @@ -197,8 +192,9 @@ where pub type CornerRadiusData = Mutex; -#[derive(Debug, Default)] +#[derive(Debug)] pub struct CornerRadiusInternal { + pub toplevel: Weak, pub top_left: u8, pub top_right: u8, pub bottom_right: u8,