fix: sharp corners & window state handling

This commit is contained in:
Ashley Wulber 2025-09-25 15:41:16 -04:00 committed by Ashley Wulber
parent 27f591e5aa
commit 03f07d2f1e
5 changed files with 56 additions and 9 deletions

View file

@ -426,6 +426,12 @@ where
) => {
return Some(Action::SuggestedBounds(b));
}
#[cfg(feature = "wayland")]
wayland::Event::Window(iced::event::wayland::WindowEvent::WindowState(
s,
)) => {
return Some(Action::WindowState(id, s));
}
_ => (),
}
}
@ -588,6 +594,7 @@ impl<T: Application> Cosmic<T> {
fn cosmic_update(&mut self, message: Action) -> iced::Task<crate::Action<T::Message>> {
match message {
Action::WindowMaximized(id, maximized) => {
#[cfg(not(feature = "wayland"))]
if self
.app
.core()
@ -635,6 +642,24 @@ impl<T: Application> Cosmic<T> {
| WindowState::TILED_BOTTOM,
);
}
if self.app.core().sync_window_border_radii_to_theme() {
use iced_runtime::platform_specific::wayland::CornerRadius;
use iced_winit::platform_specific::commands::corner_radius::corner_radius;
let theme = THEME.lock().unwrap();
let t = theme.cosmic();
let radii = t.radius_s().map(|x| if x < 4.0 { x } else { x + 4.0 });
let cur_rad = CornerRadius {
top_left: radii[0].round() as u32,
top_right: radii[1].round() as u32,
bottom_right: radii[2].round() as u32,
bottom_left: radii[3].round() as u32,
};
let rounded = !self.app.core().window.sharp_corners;
return Task::batch(vec![
corner_radius(id, rounded.then_some(cur_rad)).discard(),
]);
}
}
#[cfg(feature = "wayland")]

View file

@ -759,16 +759,25 @@ impl<App: Application> ApplicationExt for App {
header
.apply(container)
.class(crate::theme::Container::custom(move |theme| {
let cosmic = theme.cosmic();
container::Style {
background: Some(iced::Background::Color(
theme.cosmic().background.base.into(),
cosmic.background.base.into(),
)),
border: iced::Border {
radius: [
window_corner_radius[0] - 1.0,
window_corner_radius[1] - 1.0,
theme.cosmic().radius_0()[2],
theme.cosmic().radius_0()[3],
if sharp_corners {
cosmic.radius_0()[0]
} else {
window_corner_radius[0] - 1.0
},
if sharp_corners {
cosmic.radius_0()[1]
} else {
window_corner_radius[1] - 1.0
},
cosmic.radius_0()[2],
cosmic.radius_0()[3],
]
.into(),
..Default::default()