Skip to content

Commit 2873d6b

Browse files
wash2Drakulix
authored andcommitted
fix(corner-radius): properly handle no value, and use geometry
1 parent 6f93b87 commit 2873d6b

File tree

5 files changed

+53
-43
lines changed

5 files changed

+53
-43
lines changed

src/shell/element/surface.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,10 @@ impl CosmicSurface {
127127
}
128128
}
129129

130-
pub fn corner_radius(&self) -> Option<[u8; 4]> {
130+
pub fn corner_radius(&self, geometry_size: Size<i32, Logical>) -> Option<[u8; 4]> {
131131
self.wl_surface().and_then(|surface| {
132-
with_states(&surface, |s| {
133-
let d = s
132+
with_states(&surface, |states| {
133+
let d = states
134134
.data_map
135135
.get::<Mutex<Weak<CosmicCornerRadiusToplevelV1>>>()?;
136136
let guard = d.lock().unwrap();
@@ -141,16 +141,18 @@ impl CosmicSurface {
141141

142142
let guard = corners.lock().unwrap();
143143

144-
let size = <CosmicSurface as SpaceElement>::geometry(self).size;
145144
// guard against corner radius being too large, potentially disconnecting the outline
146-
let half_min_dim = u8::try_from(size.w.min(size.h) / 2).unwrap_or(u8::MAX);
147-
148-
Some([
149-
guard.top_right.min(half_min_dim),
150-
guard.bottom_right.min(half_min_dim),
151-
guard.top_left.min(half_min_dim),
152-
guard.bottom_left.min(half_min_dim),
153-
])
145+
let half_min_dim =
146+
u8::try_from(geometry_size.w.min(geometry_size.h) / 2).unwrap_or(u8::MAX);
147+
148+
guard.corners.map(|corners| {
149+
[
150+
corners.top_right.min(half_min_dim),
151+
corners.bottom_right.min(half_min_dim),
152+
corners.top_left.min(half_min_dim),
153+
corners.bottom_left.min(half_min_dim),
154+
]
155+
})
154156
})
155157
})
156158
}

src/shell/grabs/moving.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ impl MoveGrabState {
111111
let active_window_hint = crate::theme::active_window_hint(theme);
112112
let radius = self
113113
.window()
114-
.corner_radius()
114+
.corner_radius(window_geo.size)
115115
.unwrap_or([self.indicator_thickness; 4]);
116116

117117
let focus_element = if self.indicator_thickness > 0 {

src/shell/layout/floating/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1591,7 +1591,7 @@ impl FloatingLayout {
15911591
let active_window_hint = crate::theme::active_window_hint(theme);
15921592
let radius = elem
15931593
.active_window()
1594-
.corner_radius()
1594+
.corner_radius(geometry.size.as_logical())
15951595
.unwrap_or([indicator_thickness; 4]);
15961596
if indicator_thickness > 0 {
15971597
let element = IndicatorShader::focus_element(

src/shell/layout/tiling/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5017,7 +5017,7 @@ where
50175017
}));
50185018
let radius = mapped
50195019
.active_window()
5020-
.corner_radius()
5020+
.corner_radius(geo.size.as_logical())
50215021
.unwrap_or([indicator_thickness; 4]);
50225022
if is_minimizing && indicator_thickness > 0 {
50235023
elements.push(CosmicMappedRenderElement::FocusIndicator(
@@ -5288,7 +5288,9 @@ where
52885288
)
52895289
.unwrap();
52905290

5291-
let radius = window.corner_radius().unwrap_or([indicator_thickness; 4]);
5291+
let radius = window
5292+
.corner_radius(swap_geo.size.as_logical())
5293+
.unwrap_or([indicator_thickness; 4]);
52925294
swap_elements.push(CosmicMappedRenderElement::FocusIndicator(
52935295
IndicatorShader::focus_element(
52945296
renderer,
@@ -5369,7 +5371,7 @@ where
53695371
let radius = match data {
53705372
Data::Mapped { mapped, .. } => mapped
53715373
.active_window()
5372-
.corner_radius()
5374+
.corner_radius(geo.size.as_logical())
53735375
.unwrap_or([indicator_thickness; 4]),
53745376
_ => [1; 4],
53755377
};

src/wayland/protocols/corner_radius.rs

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,7 @@ where
108108
cosmic_corner_radius_manager_v1::Request::GetCornerRadius { id, toplevel } => {
109109
let data = Mutex::new(CornerRadiusInternal {
110110
toplevel: toplevel.downgrade(),
111-
top_left: 0,
112-
top_right: 0,
113-
bottom_right: 0,
114-
bottom_left: 0,
111+
corners: None,
115112
});
116113
let instance = data_init.init(id, data);
117114

@@ -151,7 +148,7 @@ where
151148
+ 'static,
152149
{
153150
fn request(
154-
_state: &mut D,
151+
state: &mut D,
155152
_client: &Client,
156153
resource: &cosmic_corner_radius_toplevel_v1::CosmicCornerRadiusToplevelV1,
157154
request: <cosmic_corner_radius_toplevel_v1::CosmicCornerRadiusToplevelV1 as Resource>::Request,
@@ -161,29 +158,30 @@ where
161158
) {
162159
match request {
163160
cosmic_corner_radius_toplevel_v1::Request::Destroy => {
164-
// TODO do we want to unset it after it is destroyed or just leave it?
165-
_state.unset_corner_radius(resource, data);
161+
let mut guard = data.lock().unwrap();
162+
guard.corners = None;
163+
drop(guard);
164+
165+
state.unset_corner_radius(resource, data);
166166
}
167167
cosmic_corner_radius_toplevel_v1::Request::SetRadius {
168168
top_left,
169169
top_right,
170170
bottom_right,
171171
bottom_left,
172172
} => {
173-
{
174-
let mut guard = data.lock().unwrap();
175-
guard.set_corner_radius(
176-
top_left as u8,
177-
top_right as u8,
178-
bottom_right as u8,
179-
bottom_left as u8,
180-
);
181-
}
173+
let mut guard = data.lock().unwrap();
174+
guard.set_corner_radius(top_left, top_right, bottom_right, bottom_left);
175+
drop(guard);
182176

183-
_state.set_corner_radius(resource, data);
177+
state.set_corner_radius(resource, data);
184178
}
185179
cosmic_corner_radius_toplevel_v1::Request::UnsetRadius => {
186-
_state.unset_corner_radius(resource, data);
180+
let mut guard = data.lock().unwrap();
181+
guard.corners = None;
182+
drop(guard);
183+
184+
state.unset_corner_radius(resource, data);
187185
}
188186
_ => unimplemented!(),
189187
}
@@ -195,6 +193,11 @@ pub type CornerRadiusData = Mutex<CornerRadiusInternal>;
195193
#[derive(Debug)]
196194
pub struct CornerRadiusInternal {
197195
pub toplevel: Weak<XdgToplevel>,
196+
pub corners: Option<Corners>,
197+
}
198+
199+
#[derive(Debug, Copy, Clone)]
200+
pub struct Corners {
198201
pub top_left: u8,
199202
pub top_right: u8,
200203
pub bottom_right: u8,
@@ -204,15 +207,18 @@ pub struct CornerRadiusInternal {
204207
impl CornerRadiusInternal {
205208
fn set_corner_radius(
206209
&mut self,
207-
top_left: u8,
208-
top_right: u8,
209-
bottom_right: u8,
210-
bottom_left: u8,
210+
top_left: u32,
211+
top_right: u32,
212+
bottom_right: u32,
213+
bottom_left: u32,
211214
) {
212-
self.top_left = top_left;
213-
self.top_right = top_right;
214-
self.bottom_right = bottom_right;
215-
self.bottom_left = bottom_left;
215+
let corners = Corners {
216+
top_left: top_left.clamp(u8::MIN as u32, u8::MAX as u32) as u8,
217+
top_right: top_right.clamp(u8::MIN as u32, u8::MAX as u32) as u8,
218+
bottom_right: bottom_right.clamp(u8::MIN as u32, u8::MAX as u32) as u8,
219+
bottom_left: bottom_left.clamp(u8::MIN as u32, u8::MAX as u32) as u8,
220+
};
221+
self.corners = Some(corners);
216222
}
217223
}
218224

0 commit comments

Comments
 (0)