diff --git a/Cargo.lock b/Cargo.lock index 3f517be116..428bcb48ea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1350,7 +1350,7 @@ dependencies = [ [[package]] name = "dpi" version = "0.1.1" -source = "git+https://github.com/iced-rs/winit.git?rev=11414b6aa45699f038114e61b4ddf5102b2d3b4b#11414b6aa45699f038114e61b4ddf5102b2d3b4b" +source = "git+https://github.com/pml68/winit.git?rev=30deb1b4641b9ec0d4568bd8b521c7419d3a172a#30deb1b4641b9ec0d4568bd8b521c7419d3a172a" [[package]] name = "drm" @@ -7357,7 +7357,7 @@ checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486" [[package]] name = "winit" version = "0.30.8" -source = "git+https://github.com/iced-rs/winit.git?rev=11414b6aa45699f038114e61b4ddf5102b2d3b4b#11414b6aa45699f038114e61b4ddf5102b2d3b4b" +source = "git+https://github.com/pml68/winit.git?rev=30deb1b4641b9ec0d4568bd8b521c7419d3a172a#30deb1b4641b9ec0d4568bd8b521c7419d3a172a" dependencies = [ "ahash", "android-activity", diff --git a/Cargo.toml b/Cargo.toml index c9a3eea0de..d4d0f60dfd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -213,7 +213,8 @@ web-sys = "0.3.69" web-time = "1.1" wgpu = "24.0" window_clipboard = "0.4.1" -winit = { git = "https://github.com/iced-rs/winit.git", rev = "11414b6aa45699f038114e61b4ddf5102b2d3b4b" } +# TODO: switch back to iced-rs/winit if merged +winit = { git = "https://github.com/pml68/winit.git", rev = "30deb1b4641b9ec0d4568bd8b521c7419d3a172a" } [workspace.lints.rust] rust_2018_idioms = { level = "deny", priority = -1 } diff --git a/core/src/window/settings.rs b/core/src/window/settings.rs index 94bcfd78b4..4708a9bcfb 100644 --- a/core/src/window/settings.rs +++ b/core/src/window/settings.rs @@ -62,6 +62,21 @@ pub struct Settings { /// Whether the window should be transparent. pub transparent: bool, + /// Whether the window should have a blurred background. + /// + /// Note that the blurry effect is only applied to transparent windows. You need to enable + /// [`Settings::transparent`] and set a proper opacity value to the background color with + /// `Application::style`. + /// + /// On Windows, it sets the [backdrop][winit_backdrop] to `TransientWindow`, making the window [acrylic][acrylic]. + /// + /// On MacOS and Linux, it uses `set_blur`. For more details, please refer to the [winit documentation][winit_set_blur]. + /// + /// [winit_backdrop]: https://docs.rs/winit/latest/winit/platform/windows/enum.BackdropType.html + /// [winit_set_blur]: https://docs.rs/winit/latest/winit/window/struct.Window.html#method.set_blur + /// [acrylic]: https://learn.microsoft.com/en-us/windows/apps/design/style/acrylic + pub blur: bool, + /// The window [`Level`]. pub level: Level, @@ -95,6 +110,7 @@ impl Default for Settings { resizable: true, decorations: true, transparent: false, + blur: false, level: Level::default(), icon: None, exit_on_close_request: true, diff --git a/core/src/window/settings/macos.rs b/core/src/window/settings/macos.rs index f86e63ad05..a748126995 100644 --- a/core/src/window/settings/macos.rs +++ b/core/src/window/settings/macos.rs @@ -1,7 +1,7 @@ //! Platform specific settings for macOS. /// The platform specific window settings of an application. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct PlatformSpecific { /// Hides the window title. pub title_hidden: bool, @@ -9,4 +9,17 @@ pub struct PlatformSpecific { pub titlebar_transparent: bool, /// Makes the window content appear behind the titlebar. pub fullsize_content_view: bool, + /// Sets the window's blur radius. + pub blur_radius: i64, +} + +impl Default for PlatformSpecific { + fn default() -> Self { + Self { + title_hidden: false, + titlebar_transparent: false, + fullsize_content_view: false, + blur_radius: 80, + } + } } diff --git a/src/application.rs b/src/application.rs index e735218b53..6c0a0d67d7 100644 --- a/src/application.rs +++ b/src/application.rs @@ -309,6 +309,17 @@ impl Application

{ } } + /// Sets the [`window::Settings::blur`] of the [`Application`]. + pub fn blur(self, blur: bool) -> Self { + Self { + window: window::Settings { + blur, + ..self.window + }, + ..self + } + } + /// Sets the [`window::Settings::level`] of the [`Application`]. pub fn level(self, level: window::Level) -> Self { Self { diff --git a/winit/src/conversion.rs b/winit/src/conversion.rs index ab84afff27..5718c27119 100644 --- a/winit/src/conversion.rs +++ b/winit/src/conversion.rs @@ -40,6 +40,7 @@ pub fn window_attributes( .with_decorations(settings.decorations) .with_transparent(settings.transparent) .with_window_icon(settings.icon.and_then(icon)) + .with_blur(settings.blur) .with_window_level(window_level(settings.level)) .with_visible(settings.visible); @@ -79,6 +80,7 @@ pub fn window_attributes( #[cfg(target_os = "windows")] { + use winit::platform::windows::BackdropType; use winit::platform::windows::WindowAttributesExtWindows; attributes = attributes @@ -90,6 +92,11 @@ pub fn window_attributes( attributes = attributes.with_undecorated_shadow( settings.platform_specific.undecorated_shadow, ); + + if settings.blur { + attributes = + attributes.with_system_backdrop(BackdropType::TransientWindow) + } } #[cfg(target_os = "macos")] @@ -103,7 +110,8 @@ pub fn window_attributes( ) .with_fullsize_content_view( settings.platform_specific.fullsize_content_view, - ); + ) + .with_blur_radius(settings.platform_specific.blur_radius); } #[cfg(target_os = "linux")]