2026-04-17 17:57:48 +02:00
|
|
|
use smithay::utils::{Logical, Rectangle, Size};
|
|
|
|
|
use smithay::wayland::compositor::SurfaceData;
|
2025-09-24 15:11:16 -04:00
|
|
|
|
|
|
|
|
use crate::wayland::protocols::corner_radius::{
|
2026-04-17 17:57:48 +02:00
|
|
|
CacheableCorners, CacheablePadding, CornerRadiusData, CornerRadiusHandler, CornerRadiusState,
|
2026-07-17 16:11:49 +02:00
|
|
|
delegate_corner_radius,
|
2025-09-24 15:11:16 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
use crate::state::State;
|
|
|
|
|
|
|
|
|
|
impl CornerRadiusHandler for State {
|
2025-09-25 09:10:00 -04:00
|
|
|
fn corner_radius_state(&mut self) -> &mut CornerRadiusState {
|
2025-09-24 15:11:16 -04:00
|
|
|
&mut self.common.corner_radius_state
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-10 13:46:56 -04:00
|
|
|
fn set_corner_radius(&mut self, _data: &CornerRadiusData) {}
|
2025-09-24 15:11:16 -04:00
|
|
|
|
2026-07-10 13:46:56 -04:00
|
|
|
fn unset_corner_radius(&mut self, _data: &CornerRadiusData) {}
|
2025-09-25 09:57:08 -04:00
|
|
|
|
2026-07-10 13:46:56 -04:00
|
|
|
fn set_padding(&mut self, _data: &CornerRadiusData) {}
|
2025-09-25 09:57:08 -04:00
|
|
|
|
2026-07-10 13:46:56 -04:00
|
|
|
fn unset_padding(&mut self, _data: &CornerRadiusData) {}
|
2025-09-25 09:57:08 -04:00
|
|
|
}
|
|
|
|
|
|
2026-04-17 17:57:48 +02:00
|
|
|
pub fn surface_corners(states: &SurfaceData, size: Size<i32, Logical>) -> Option<[u8; 4]> {
|
|
|
|
|
let mut guard = states.cached_state.get::<CacheableCorners>();
|
|
|
|
|
|
|
|
|
|
// guard against corner radius being too large, potentially disconnecting the outline
|
|
|
|
|
let half_min_dim = u8::try_from(size.w.min(size.h) / 2).unwrap_or(u8::MAX);
|
|
|
|
|
let corners = guard.current().0?;
|
|
|
|
|
|
|
|
|
|
Some([
|
|
|
|
|
u8::try_from(corners.top_left)
|
|
|
|
|
.unwrap_or(u8::MAX)
|
|
|
|
|
.min(half_min_dim),
|
|
|
|
|
u8::try_from(corners.top_right)
|
|
|
|
|
.unwrap_or(u8::MAX)
|
|
|
|
|
.min(half_min_dim),
|
|
|
|
|
u8::try_from(corners.bottom_right)
|
|
|
|
|
.unwrap_or(u8::MAX)
|
|
|
|
|
.min(half_min_dim),
|
|
|
|
|
u8::try_from(corners.bottom_left)
|
|
|
|
|
.unwrap_or(u8::MAX)
|
|
|
|
|
.min(half_min_dim),
|
|
|
|
|
])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn surface_padding(states: &SurfaceData, size: Size<i32, Logical>) -> Option<[i32; 4]> {
|
|
|
|
|
let mut guard = states.cached_state.get::<CacheablePadding>();
|
|
|
|
|
|
|
|
|
|
let padding = guard.current().0?;
|
|
|
|
|
|
2026-04-27 18:58:19 -04:00
|
|
|
// guard against padding being too large
|
2026-04-17 17:57:48 +02:00
|
|
|
Some([
|
2026-04-27 18:58:19 -04:00
|
|
|
padding.top.min(size.h / 2),
|
|
|
|
|
padding.right.min(size.w / 2),
|
|
|
|
|
padding.bottom.min(size.h / 2),
|
|
|
|
|
padding.left.min(size.w / 2),
|
2026-04-17 17:57:48 +02:00
|
|
|
])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn pad_rect(
|
|
|
|
|
mut rect: Rectangle<i32, Logical>,
|
|
|
|
|
padding: &[i32; 4],
|
|
|
|
|
) -> Option<Rectangle<i32, Logical>> {
|
|
|
|
|
rect.size.h = rect.size.h.checked_sub(padding[0])?;
|
2026-04-27 18:57:48 -04:00
|
|
|
rect.loc.x += padding[3];
|
2026-04-17 17:57:48 +02:00
|
|
|
rect.size.w = rect.size.w.checked_sub(padding[1])?;
|
|
|
|
|
rect.size.h = rect.size.h.checked_sub(padding[2])?;
|
|
|
|
|
rect.size.w = rect.size.w.checked_sub(padding[3])?;
|
2026-04-27 18:57:48 -04:00
|
|
|
rect.loc.y += padding[0];
|
2026-04-17 17:57:48 +02:00
|
|
|
Some(rect)
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-24 15:11:16 -04:00
|
|
|
delegate_corner_radius!(State);
|