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

2
iced

@ -1 +1 @@
Subproject commit 788be2f7825b648ec3ce33697c6e675a7b7265ec Subproject commit f581f19f897e1ccc4393c8867d4ae3ed532742b4

View file

@ -426,6 +426,12 @@ where
) => { ) => {
return Some(Action::SuggestedBounds(b)); 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>> { fn cosmic_update(&mut self, message: Action) -> iced::Task<crate::Action<T::Message>> {
match message { match message {
Action::WindowMaximized(id, maximized) => { Action::WindowMaximized(id, maximized) => {
#[cfg(not(feature = "wayland"))]
if self if self
.app .app
.core() .core()
@ -635,6 +642,24 @@ impl<T: Application> Cosmic<T> {
| WindowState::TILED_BOTTOM, | 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")] #[cfg(feature = "wayland")]

View file

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

View file

@ -395,6 +395,7 @@ pub enum Container<'a> {
Dropdown, Dropdown,
HeaderBar { HeaderBar {
focused: bool, focused: bool,
sharp_corners: bool,
}, },
List, List,
Primary, Primary,
@ -507,7 +508,10 @@ impl iced_container::Catalog for Theme {
} }
} }
Container::HeaderBar { focused } => { Container::HeaderBar {
focused,
sharp_corners,
} => {
let (icon_color, text_color) = if *focused { let (icon_color, text_color) = if *focused {
( (
Color::from(cosmic.accent_text_color()), Color::from(cosmic.accent_text_color()),
@ -526,8 +530,16 @@ impl iced_container::Catalog for Theme {
background: Some(iced::Background::Color(cosmic.background.base.into())), background: Some(iced::Background::Color(cosmic.background.base.into())),
border: Border { border: Border {
radius: [ radius: [
window_corner_radius[0], if *sharp_corners {
window_corner_radius[1], cosmic.corner_radii.radius_0[0]
} else {
window_corner_radius[0]
},
if *sharp_corners {
cosmic.corner_radii.radius_0[1]
} else {
window_corner_radius[1]
},
cosmic.corner_radii.radius_0[2], cosmic.corner_radii.radius_0[2],
cosmic.corner_radii.radius_0[3], cosmic.corner_radii.radius_0[3],
] ]

View file

@ -409,6 +409,7 @@ impl<'a, Message: Clone + 'static> HeaderBar<'a, Message> {
.apply(widget::container) .apply(widget::container)
.class(crate::theme::Container::HeaderBar { .class(crate::theme::Container::HeaderBar {
focused: self.focused, focused: self.focused,
sharp_corners: self.maximized,
}) })
.center_y(Length::Shrink) .center_y(Length::Shrink)
.apply(widget::mouse_area); .apply(widget::mouse_area);