Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
16 changes: 16 additions & 0 deletions core/src/window/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down Expand Up @@ -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,
Expand Down
15 changes: 14 additions & 1 deletion core/src/window/settings/macos.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
//! 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,
/// Makes the titlebar transparent and allows the content to appear behind it.
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,
}
}
}
11 changes: 11 additions & 0 deletions src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,17 @@ impl<P: Program> Application<P> {
}
}

/// 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 {
Expand Down
10 changes: 9 additions & 1 deletion winit/src/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
.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);

Expand Down Expand Up @@ -79,6 +80,7 @@

#[cfg(target_os = "windows")]
{
use winit::platform::windows::BackdropType;
use winit::platform::windows::WindowAttributesExtWindows;

attributes = attributes
Expand All @@ -90,6 +92,11 @@
attributes = attributes.with_undecorated_shadow(
settings.platform_specific.undecorated_shadow,
);

if settings.blur {
attributes =
attributes.with_system_backdrop(BackdropType::TransientWindow)
}
}

#[cfg(target_os = "macos")]
Expand All @@ -103,7 +110,8 @@
)
.with_fullsize_content_view(
settings.platform_specific.fullsize_content_view,
);
)
.with_blur_radius(settings.platform_specific.blur_radius);
}

#[cfg(target_os = "linux")]
Expand Down Expand Up @@ -289,7 +297,7 @@
Ime::Enabled => input_method::Event::Opened,
Ime::Preedit(content, size) => input_method::Event::Preedit(
content,
size.map(|(start, end)| (start..end)),

Check warning on line 300 in winit/src/conversion.rs

View workflow job for this annotation

GitHub Actions / all

unnecessary parentheses around closure body
),
Ime::Commit(content) => input_method::Event::Commit(content),
Ime::Disabled => input_method::Event::Closed,
Expand Down
Loading