Skip to content

Commit 4e30513

Browse files
wash2Drakulix
authored andcommitted
fix(corner-radius): force redraw after corner radius change
1 parent ce655d2 commit 4e30513

File tree

2 files changed

+35
-25
lines changed

2 files changed

+35
-25
lines changed

src/wayland/handlers/corner_radius.rs

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,37 @@ impl CornerRadiusHandler for State {
2222

2323
fn set_corner_radius(
2424
&mut self,
25-
_toplevel: &cosmic_corner_radius_toplevel_v1::CosmicCornerRadiusToplevelV1,
26-
_data: &CornerRadiusData,
27-
_top_left: u32,
28-
_top_right: u32,
29-
_bottom_right: u32,
30-
_bottom_left: u32,
25+
_: &cosmic_corner_radius_toplevel_v1::CosmicCornerRadiusToplevelV1,
26+
data: &CornerRadiusData,
3127
) {
32-
// TODO force redraw? of focus element?
28+
if force_redraw(self, data).is_none() {
29+
tracing::warn!("Failed to force redraw for corner radius change.");
30+
}
3331
}
3432

3533
fn unset_corner_radius(
3634
&mut self,
37-
_toplevel: &cosmic_corner_radius_toplevel_v1::CosmicCornerRadiusToplevelV1,
38-
_data: &CornerRadiusData,
35+
_: &cosmic_corner_radius_toplevel_v1::CosmicCornerRadiusToplevelV1,
36+
data: &CornerRadiusData,
3937
) {
40-
// TODO force redraw?
38+
if force_redraw(self, data).is_none() {
39+
tracing::warn!("Failed to force redraw for corner radius reset.");
40+
}
4141
}
4242
}
4343

44+
fn force_redraw(state: &mut State, data: &CornerRadiusData) -> Option<()> {
45+
let guard = data.lock().unwrap();
46+
47+
let toplevel = guard.toplevel.upgrade().ok()?;
48+
49+
let surface = state.common.xdg_shell_state.get_toplevel(&toplevel)?;
50+
51+
let guard = state.common.shell.read();
52+
let output = guard.visible_output_for_surface(surface.wl_surface())?;
53+
54+
state.backend.schedule_render(output);
55+
Some(())
56+
}
57+
4458
delegate_corner_radius!(State);

src/wayland/protocols/corner_radius.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use cosmic_protocols::corner_radius::v1::server::{
33
};
44
use smithay::reexports::{
55
wayland_protocols::xdg::shell::server::xdg_toplevel::XdgToplevel,
6-
wayland_server::{Client, Dispatch, DisplayHandle, GlobalDispatch, Resource},
6+
wayland_server::{Client, Dispatch, DisplayHandle, GlobalDispatch, Resource, Weak},
77
};
88
use smithay::wayland::compositor::with_states;
99
use smithay::wayland::shell::xdg::ToplevelSurface;
@@ -50,10 +50,6 @@ pub trait CornerRadiusHandler {
5050
&mut self,
5151
toplevel: &cosmic_corner_radius_toplevel_v1::CosmicCornerRadiusToplevelV1,
5252
data: &CornerRadiusData,
53-
top_left: u32,
54-
top_right: u32,
55-
bottom_right: u32,
56-
bottom_left: u32,
5753
);
5854
fn unset_corner_radius(
5955
&mut self,
@@ -110,7 +106,13 @@ where
110106
corner_radius_state.instances.retain(|i| i != _resource);
111107
}
112108
cosmic_corner_radius_manager_v1::Request::GetCornerRadius { id, toplevel } => {
113-
let data = CornerRadiusData::default();
109+
let data = Mutex::new(CornerRadiusInternal {
110+
toplevel: toplevel.downgrade(),
111+
top_left: 0,
112+
top_right: 0,
113+
bottom_right: 0,
114+
bottom_left: 0,
115+
});
114116
let instance = data_init.init(id, data);
115117

116118
if let Some(surface) = state.toplevel_from_resource(&toplevel) {
@@ -178,14 +180,7 @@ where
178180
);
179181
}
180182

181-
_state.set_corner_radius(
182-
resource,
183-
data,
184-
top_left,
185-
top_right,
186-
bottom_right,
187-
bottom_left,
188-
);
183+
_state.set_corner_radius(resource, data);
189184
}
190185
cosmic_corner_radius_toplevel_v1::Request::UnsetRadius => {
191186
_state.unset_corner_radius(resource, data);
@@ -197,8 +192,9 @@ where
197192

198193
pub type CornerRadiusData = Mutex<CornerRadiusInternal>;
199194

200-
#[derive(Debug, Default)]
195+
#[derive(Debug)]
201196
pub struct CornerRadiusInternal {
197+
pub toplevel: Weak<XdgToplevel>,
202198
pub top_left: u8,
203199
pub top_right: u8,
204200
pub bottom_right: u8,

0 commit comments

Comments
 (0)