Add DWMWA_SYSTEMBACKDROP_TYPE support on Windows (#3257)

This commit is contained in:
Dubzer 2024-01-25 20:59:10 +03:00 committed by GitHub
parent d0a1917603
commit 98d3391f2d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 76 additions and 5 deletions

View file

@ -25,7 +25,7 @@ use crate::platform_impl::Fullscreen;
use crate::event::DeviceId as RootDeviceId;
use crate::icon::Icon;
use crate::keyboard::Key;
use crate::platform::windows::{Color, CornerPreference};
use crate::platform::windows::{BackdropType, Color, CornerPreference};
#[derive(Clone, Debug)]
pub struct PlatformSpecificWindowBuilderAttributes {
@ -37,6 +37,7 @@ pub struct PlatformSpecificWindowBuilderAttributes {
pub skip_taskbar: bool,
pub class_name: String,
pub decoration_shadow: bool,
pub backdrop_type: BackdropType,
pub clip_children: bool,
pub border_color: Option<Color>,
pub title_background_color: Option<Color>,
@ -55,6 +56,7 @@ impl Default for PlatformSpecificWindowBuilderAttributes {
skip_taskbar: false,
class_name: "Window Class".to_string(),
decoration_shadow: false,
backdrop_type: BackdropType::default(),
clip_children: true,
border_color: None,
title_background_color: None,

View file

@ -16,8 +16,9 @@ use windows_sys::Win32::{
Graphics::{
Dwm::{
DwmEnableBlurBehindWindow, DwmSetWindowAttribute, DWMWA_BORDER_COLOR,
DWMWA_CAPTION_COLOR, DWMWA_TEXT_COLOR, DWMWA_WINDOW_CORNER_PREFERENCE,
DWM_BB_BLURREGION, DWM_BB_ENABLE, DWM_BLURBEHIND, DWM_WINDOW_CORNER_PREFERENCE,
DWMWA_CAPTION_COLOR, DWMWA_SYSTEMBACKDROP_TYPE, DWMWA_TEXT_COLOR,
DWMWA_WINDOW_CORNER_PREFERENCE, DWM_BB_BLURREGION, DWM_BB_ENABLE, DWM_BLURBEHIND,
DWM_SYSTEMBACKDROP_TYPE, DWM_WINDOW_CORNER_PREFERENCE,
},
Gdi::{
ChangeDisplaySettingsExW, ClientToScreen, CreateRectRgn, DeleteObject, InvalidateRgn,
@ -60,12 +61,12 @@ use windows_sys::Win32::{
use log::warn;
use crate::platform::windows::{Color, CornerPreference};
use crate::{
cursor::Cursor,
dpi::{PhysicalPosition, PhysicalSize, Position, Size},
error::{ExternalError, NotSupportedError, OsError as RootOsError},
icon::Icon,
platform::windows::{BackdropType, Color, CornerPreference},
platform_impl::platform::{
dark_mode::try_theme,
definitions::{
@ -1019,6 +1020,18 @@ impl Window {
});
}
#[inline]
pub fn set_system_backdrop(&self, backdrop_type: BackdropType) {
unsafe {
DwmSetWindowAttribute(
self.hwnd(),
DWMWA_SYSTEMBACKDROP_TYPE,
&(backdrop_type as i32) as *const _ as _,
mem::size_of::<DWM_SYSTEMBACKDROP_TYPE>() as _,
);
}
}
#[inline]
pub fn focus_window(&self) {
let window_flags = self.window_state_lock().window_flags();
@ -1308,6 +1321,8 @@ impl<'a> InitData<'a> {
win.set_outer_position(position);
}
win.set_system_backdrop(self.attributes.platform_specific.backdrop_type);
if let Some(color) = self.attributes.platform_specific.border_color {
win.set_border_color(color);
}