feat(blur): better align with designs and remove transparency from theme when not on wayland

This commit is contained in:
Ashley Wulber 2026-04-14 23:44:01 -04:00 committed by Ashley Wulber
parent 439109db04
commit d0b164d216
7 changed files with 222 additions and 41 deletions

View file

@ -115,8 +115,8 @@ where
(
Self::new(model),
Task::batch([
command,
iced_runtime::window::run_with_handle(id, init_windowing_system),
command,
]),
)
}
@ -776,7 +776,17 @@ impl<T: Application> Cosmic<T> {
}
}
let new_blur = theme.cosmic().frosted.is_some();
let new_blur = WINDOWING_SYSTEM.get() == Some(&WindowingSystem::Wayland) && {
let t = theme.cosmic();
match self.app.core().app_type() {
crate::core::AppType::Window => t.frosted_windows,
crate::core::AppType::System => t.frosted_system_interface,
crate::core::AppType::Applet => t.frosted_applets,
}
};
if !new_blur {
theme = theme.into_opaque();
}
THEME.lock().unwrap().set_theme(theme.theme_type);
let core = self.app.core();
@ -979,9 +989,19 @@ impl<T: Application> Cosmic<T> {
// Only apply update if the theme is set to load a system theme
if let ThemeType::System { .. } = cosmic_theme.theme_type {
// TODO adjust theme container alphas to remove transparency?
// if auto-blur is disabled & theme is frosted, should we make container colors in theme opaque?
let new_blur = new_theme.cosmic().frosted.is_some();
let new_blur =
WINDOWING_SYSTEM.get() == Some(&WindowingSystem::Wayland) && {
let t = new_theme.cosmic();
match self.app.core().app_type() {
crate::core::AppType::Window => t.frosted_windows,
crate::core::AppType::System => t.frosted_system_interface,
crate::core::AppType::Applet => t.frosted_applets,
}
};
if !new_blur {
new_theme = new_theme.into_opaque();
}
cosmic_theme.set_theme(new_theme.theme_type);
#[cfg(all(feature = "wayland", target_os = "linux"))]
if self.app.core().sync_window_border_radii_to_theme() {
@ -1181,7 +1201,7 @@ impl<T: Application> Cosmic<T> {
if changed {
core.theme_sub_counter += 1;
let new_theme = if is_dark {
let mut new_theme = if is_dark {
crate::theme::system_dark()
} else {
crate::theme::system_light()
@ -1195,7 +1215,21 @@ impl<T: Application> Cosmic<T> {
let mut cmds = Vec::with_capacity(1 + self.tracked_windows.len());
if core.auto_blur {
let blur = if new_theme.cosmic().frosted.is_some() {
let new_blur =
WINDOWING_SYSTEM.get() == Some(&WindowingSystem::Wayland) && {
let t = new_theme.cosmic();
match self.app.core().app_type() {
crate::core::AppType::Window => t.frosted_windows,
crate::core::AppType::System => {
t.frosted_system_interface
}
crate::core::AppType::Applet => t.frosted_applets,
}
};
if !new_blur {
new_theme = new_theme.into_opaque();
}
let blur = if new_blur {
iced::window::enable_blur
} else {
iced::window::disable_blur
@ -1316,7 +1350,7 @@ impl<T: Application> Cosmic<T> {
use iced_runtime::platform_specific::wayland::CornerRadius;
use iced_winit::platform_specific::commands::corner_radius::corner_radius;
let theme = THEME.lock().unwrap();
let mut 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 {
@ -1328,8 +1362,19 @@ impl<T: Application> Cosmic<T> {
// TODO do we need per window sharp corners?
let rounded = !self.app.core().window.sharp_corners;
let core = self.app.core();
let new_blur = WINDOWING_SYSTEM.get() == Some(&WindowingSystem::Wayland) && {
let t = theme.cosmic();
match self.app.core().app_type() {
crate::core::AppType::Window => t.frosted_windows,
crate::core::AppType::System => t.frosted_system_interface,
crate::core::AppType::Applet => t.frosted_applets,
}
};
if !new_blur {
*theme = theme.into_opaque();
}
let blur_cmd = if core.auto_blur {
let blur = if t.frosted.is_some() {
let blur = if new_blur {
iced::window::enable_blur
} else {
iced::window::disable_blur
@ -1343,6 +1388,7 @@ impl<T: Application> Cosmic<T> {
} else {
Task::none()
};
let t = theme.cosmic();
return Task::batch([
blur_cmd,
corner_radius(
@ -1365,7 +1411,45 @@ impl<T: Application> Cosmic<T> {
}
return iced_runtime::window::run_with_handle(id, init_windowing_system);
}
_ => {}
Action::WindowingSystemInitialized => {
let core = self.app.core();
let new_blur = WINDOWING_SYSTEM.get() == Some(&WindowingSystem::Wayland) && {
let t = core.system_theme.cosmic();
match self.app.core().app_type() {
crate::core::AppType::Window => t.frosted_windows,
crate::core::AppType::System => t.frosted_system_interface,
crate::core::AppType::Applet => t.frosted_applets,
}
};
let mut t = THEME.lock().unwrap();
if let ThemeType::System { prefer_dark, theme } = &t.theme_type
&& new_blur
{
let mut reloaded = if theme.is_dark {
crate::theme::system_dark()
} else {
crate::theme::system_light()
};
reloaded.theme_type.prefer_dark(*prefer_dark);
*t = reloaded;
}
if core.auto_blur {
let blur = if new_blur {
iced::window::enable_blur
} else {
iced::window::disable_blur
};
let mut cmds = Vec::with_capacity(1 + self.tracked_windows.len());
if let Some(main_id) = core.main_window_id() {
cmds.push(blur(main_id));
}
for id in &self.tracked_windows {
cmds.push(blur(*id));
}
return Task::batch(cmds);
}
}
}
iced::Task::none()

View file

@ -372,9 +372,11 @@ impl Context {
Container::<Message, _, Renderer>::new(content).style(|theme| {
let cosmic = theme.cosmic();
let corners = cosmic.corner_radii;
let mut bg = cosmic.background.base;
bg.alpha = (bg.alpha + if cosmic.is_dark { 0.6 } else { 0.5 }).min(1.);
iced_widget::container::Style {
text_color: Some(cosmic.background.on.into()),
background: Some(Color::from(cosmic.background.base).into()),
background: Some(Color::from(bg).into()),
border: iced::Border {
radius: corners.radius_m.into(),
width: 1.0,
@ -559,6 +561,7 @@ pub fn run<App: Application>(flags: App::Flags) -> iced::Result {
core.window.show_maximize = false;
core.window.show_minimize = false;
core.window.use_template = false;
core.app_type = crate::core::AppType::Applet;
window_settings.decorations = false;
window_settings.exit_on_close_request = true;

View file

@ -103,6 +103,18 @@ pub struct Core {
pub(crate) sync_window_border_radii_to_theme: bool,
pub(crate) auto_blur: bool,
pub(crate) app_type: AppType,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum AppType {
/// A regular application
Window,
/// A system application
System,
/// An applet
Applet,
}
impl Default for Core {
@ -164,6 +176,7 @@ impl Default for Core {
#[cfg(all(feature = "wayland", target_os = "linux"))]
sync_window_border_radii_to_theme: true,
auto_blur: true,
app_type: AppType::Window,
}
}
}
@ -509,4 +522,16 @@ impl Core {
pub fn set_auto_blur(&mut self, auto_blur: bool) {
self.auto_blur = auto_blur;
}
pub fn auto_blur(&self) -> bool {
self.auto_blur
}
pub fn set_app_type(&mut self, app_type: AppType) {
self.app_type = app_type;
}
pub fn app_type(&self) -> AppType {
self.app_type
}
}

View file

@ -290,6 +290,29 @@ impl Theme {
pub fn set_theme(&mut self, theme: ThemeType) {
self.theme_type = theme;
}
pub fn into_opaque(&self) -> Self {
let mut new_theme = Theme {
theme_type: match &self.theme_type {
ThemeType::System { theme, prefer_dark } => {
let mut new_t = (**theme).clone();
new_t.background.base.alpha = 1.0;
new_t.primary.base.alpha = 1.0;
new_t.secondary.base.alpha = 1.0;
ThemeType::System {
theme: Arc::new(new_t),
prefer_dark: *prefer_dark,
}
}
other => other.clone(),
},
layer: self.layer,
};
let cosmic = new_theme.cosmic();
// copy theme but make all container colors opaque
new_theme
}
}
impl LayeredTheme for Theme {

View file

@ -477,7 +477,21 @@ impl iced_container::Catalog for Theme {
let window_corner_radius = cosmic.radius_s().map(|x| if x < 4.0 { x } else { x + 4.0 });
match class {
Container::Transparent => iced_container::Style::default(),
Container::Transparent => {
let component = &self.current_container().component;
iced_container::Style {
icon_color: Some(component.on.into()),
text_color: Some(component.on.into()),
background: None,
border: Border {
radius: 0.into(),
..Default::default()
},
shadow: Shadow::default(),
snap: true,
}
}
Container::Custom(f) => f(self),
@ -565,7 +579,7 @@ impl iced_container::Catalog for Theme {
Container::ContextDrawer => {
let mut a = Container::primary(cosmic);
if let Some(Background::Color(ref mut color)) = a.background {
color.a = 1.;
color.a = (color.a + if cosmic.is_dark { 0.60 } else { 0.5 }).min(1.);
}
if cosmic.is_high_contrast {

View file

@ -65,10 +65,12 @@ impl StyleSheet for Theme {
fn appearance(&self, style: &Self::Style) -> Appearance {
let cosmic = self.cosmic();
let component = &cosmic.background.component;
let mut bg = component.base;
bg.alpha = (bg.alpha + if cosmic.is_dark { 0.6 } else { 0.5 }).min(1.);
match style {
MenuBarStyle::Default => Appearance {
background: component.base.into(),
background: bg.into(),
border_width: 1.0,
bar_border_radius: cosmic.corner_radii.radius_xl,
menu_border_radius: cosmic.corner_radii.radius_s,