On Windows, expose DWM attributes (#3409)
This commit is contained in:
parent
d7c7ba1d6c
commit
b0c59c8416
5 changed files with 222 additions and 1 deletions
|
|
@ -25,6 +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};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct PlatformSpecificWindowBuilderAttributes {
|
||||
|
|
@ -36,6 +37,10 @@ pub struct PlatformSpecificWindowBuilderAttributes {
|
|||
pub skip_taskbar: bool,
|
||||
pub class_name: String,
|
||||
pub decoration_shadow: bool,
|
||||
pub border_color: Option<Color>,
|
||||
pub title_background_color: Option<Color>,
|
||||
pub title_text_color: Option<Color>,
|
||||
pub corner_preference: Option<CornerPreference>,
|
||||
}
|
||||
|
||||
impl Default for PlatformSpecificWindowBuilderAttributes {
|
||||
|
|
@ -49,6 +54,10 @@ impl Default for PlatformSpecificWindowBuilderAttributes {
|
|||
skip_taskbar: false,
|
||||
class_name: "Window Class".to_string(),
|
||||
decoration_shadow: false,
|
||||
border_color: None,
|
||||
title_background_color: None,
|
||||
title_text_color: None,
|
||||
corner_preference: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,11 @@ use windows_sys::Win32::{
|
|||
HWND, LPARAM, OLE_E_WRONGCOMPOBJ, POINT, POINTS, RECT, RPC_E_CHANGED_MODE, S_OK, WPARAM,
|
||||
},
|
||||
Graphics::{
|
||||
Dwm::{DwmEnableBlurBehindWindow, DWM_BB_BLURREGION, DWM_BB_ENABLE, DWM_BLURBEHIND},
|
||||
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,
|
||||
},
|
||||
Gdi::{
|
||||
ChangeDisplaySettingsExW, ClientToScreen, CreateRectRgn, DeleteObject, InvalidateRgn,
|
||||
RedrawWindow, CDS_FULLSCREEN, DISP_CHANGE_BADFLAGS, DISP_CHANGE_BADMODE,
|
||||
|
|
@ -56,6 +60,7 @@ use windows_sys::Win32::{
|
|||
|
||||
use log::warn;
|
||||
|
||||
use crate::platform::windows::{Color, CornerPreference};
|
||||
use crate::{
|
||||
cursor::Cursor,
|
||||
dpi::{PhysicalPosition, PhysicalSize, Position, Size},
|
||||
|
|
@ -1060,6 +1065,54 @@ impl Window {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_border_color(&self, color: Color) {
|
||||
unsafe {
|
||||
DwmSetWindowAttribute(
|
||||
self.hwnd(),
|
||||
DWMWA_BORDER_COLOR,
|
||||
&color as *const _ as _,
|
||||
mem::size_of::<Color>() as _,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_title_background_color(&self, color: Color) {
|
||||
unsafe {
|
||||
DwmSetWindowAttribute(
|
||||
self.hwnd(),
|
||||
DWMWA_CAPTION_COLOR,
|
||||
&color as *const _ as _,
|
||||
mem::size_of::<Color>() as _,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_title_text_color(&self, color: Color) {
|
||||
unsafe {
|
||||
DwmSetWindowAttribute(
|
||||
self.hwnd(),
|
||||
DWMWA_TEXT_COLOR,
|
||||
&color as *const _ as _,
|
||||
mem::size_of::<Color>() as _,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_corner_preference(&self, preference: CornerPreference) {
|
||||
unsafe {
|
||||
DwmSetWindowAttribute(
|
||||
self.hwnd(),
|
||||
DWMWA_WINDOW_CORNER_PREFERENCE,
|
||||
&(preference as DWM_WINDOW_CORNER_PREFERENCE) as *const _ as _,
|
||||
mem::size_of::<DWM_WINDOW_CORNER_PREFERENCE>() as _,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Window {
|
||||
|
|
@ -1265,6 +1318,19 @@ impl<'a> InitData<'a> {
|
|||
if let Some(position) = attributes.position {
|
||||
win.set_outer_position(position);
|
||||
}
|
||||
|
||||
if let Some(color) = self.attributes.platform_specific.border_color {
|
||||
win.set_border_color(color);
|
||||
}
|
||||
if let Some(color) = self.attributes.platform_specific.title_background_color {
|
||||
win.set_title_background_color(color);
|
||||
}
|
||||
if let Some(color) = self.attributes.platform_specific.title_text_color {
|
||||
win.set_title_text_color(color);
|
||||
}
|
||||
if let Some(corner) = self.attributes.platform_specific.corner_preference {
|
||||
win.set_corner_preference(corner);
|
||||
}
|
||||
}
|
||||
}
|
||||
unsafe fn init(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue