Skip to content

Commit 313475c

Browse files
committed
feat: add blurring capabilities (with_blur, set_blur) for Windows
1 parent 30deb1b commit 313475c

File tree

2 files changed

+34
-17
lines changed

2 files changed

+34
-17
lines changed

src/platform_impl/windows/window.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,16 @@ impl Window {
129129
});
130130
}
131131

132-
pub fn set_blur(&self, _blur: bool) {}
132+
pub fn set_blur(&self, blur: bool) {
133+
let window = self.window;
134+
let window_state = Arc::clone(&self.window_state);
135+
self.thread_executor.execute_in_thread(move || {
136+
let _ = &window;
137+
WindowState::set_window_flags(window_state.lock().unwrap(), window, |f| {
138+
f.set(WindowFlags::BLUR, blur)
139+
});
140+
});
141+
}
133142

134143
#[inline]
135144
pub fn set_visible(&self, visible: bool) {
@@ -1233,10 +1242,16 @@ impl InitData<'_> {
12331242
pub unsafe fn on_create(&mut self) {
12341243
let win = self.window.as_mut().expect("failed window creation");
12351244

1236-
// making the window transparent
1245+
// making the window transparent and optionally blurred
12371246
if self.attributes.transparent && !self.attributes.platform_specific.no_redirection_bitmap {
1238-
// Empty region for the blur effect, so the window is fully transparent
1239-
let region = unsafe { CreateRectRgn(0, 0, -1, -1) };
1247+
let region = unsafe {
1248+
if self.attributes.blur {
1249+
0
1250+
} else {
1251+
// Empty region for the blur effect, so the window is fully transparent
1252+
CreateRectRgn(0, 0, -1, -1)
1253+
}
1254+
};
12401255

12411256
let bb = DWM_BLURBEHIND {
12421257
dwFlags: DWM_BB_ENABLE | DWM_BB_BLURREGION,
@@ -1328,6 +1343,7 @@ unsafe fn init(
13281343
.set(WindowFlags::NO_BACK_BUFFER, attributes.platform_specific.no_redirection_bitmap);
13291344
window_flags.set(WindowFlags::MARKER_ACTIVATE, attributes.active);
13301345
window_flags.set(WindowFlags::TRANSPARENT, attributes.transparent);
1346+
window_flags.set(WindowFlags::BLUR, attributes.blur);
13311347
// WindowFlags::VISIBLE and MAXIMIZED are set down below after the window has been configured.
13321348
window_flags.set(WindowFlags::RESIZABLE, attributes.resizable);
13331349
// Will be changed later using `window.set_enabled_buttons` but we need to set a default here

src/platform_impl/windows/window_state.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92,36 +92,37 @@ bitflags! {
9292
const ALWAYS_ON_BOTTOM = 1 << 7;
9393
const NO_BACK_BUFFER = 1 << 8;
9494
const TRANSPARENT = 1 << 9;
95-
const CHILD = 1 << 10;
96-
const MAXIMIZED = 1 << 11;
97-
const POPUP = 1 << 12;
95+
const BLUR = 1 << 10;
96+
const CHILD = 1 << 11;
97+
const MAXIMIZED = 1 << 12;
98+
const POPUP = 1 << 13;
9899

99100
/// Marker flag for fullscreen. Should always match `WindowState::fullscreen`, but is
100101
/// included here to make masking easier.
101-
const MARKER_EXCLUSIVE_FULLSCREEN = 1 << 13;
102-
const MARKER_BORDERLESS_FULLSCREEN = 1 << 14;
102+
const MARKER_EXCLUSIVE_FULLSCREEN = 1 << 14;
103+
const MARKER_BORDERLESS_FULLSCREEN = 1 << 15;
103104

104105
/// The `WM_SIZE` event contains some parameters that can effect the state of `WindowFlags`.
105106
/// In most cases, it's okay to let those parameters change the state. However, when we're
106107
/// running the `WindowFlags::apply_diff` function, we *don't* want those parameters to
107108
/// effect our stored state, because the purpose of `apply_diff` is to update the actual
108109
/// window's state to match our stored state. This controls whether to accept those changes.
109-
const MARKER_RETAIN_STATE_ON_SIZE = 1 << 15;
110+
const MARKER_RETAIN_STATE_ON_SIZE = 1 << 16;
110111

111-
const MARKER_IN_SIZE_MOVE = 1 << 16;
112+
const MARKER_IN_SIZE_MOVE = 1 << 17;
112113

113-
const MINIMIZED = 1 << 17;
114+
const MINIMIZED = 1 << 18;
114115

115-
const IGNORE_CURSOR_EVENT = 1 << 18;
116+
const IGNORE_CURSOR_EVENT = 1 << 19;
116117

117118
/// Fully decorated window (incl. caption, border and drop shadow).
118-
const MARKER_DECORATIONS = 1 << 19;
119+
const MARKER_DECORATIONS = 1 << 20;
119120
/// Drop shadow for undecorated windows.
120-
const MARKER_UNDECORATED_SHADOW = 1 << 20;
121+
const MARKER_UNDECORATED_SHADOW = 1 << 21;
121122

122-
const MARKER_ACTIVATE = 1 << 21;
123+
const MARKER_ACTIVATE = 1 << 22;
123124

124-
const CLIP_CHILDREN = 1 << 22;
125+
const CLIP_CHILDREN = 1 << 23;
125126

126127
const EXCLUSIVE_FULLSCREEN_OR_MASK = WindowFlags::ALWAYS_ON_TOP.bits();
127128
}

0 commit comments

Comments
 (0)