diff --git a/winit-win32/src/lib.rs b/winit-win32/src/lib.rs index 569d1f32c1..030dae79e9 100644 --- a/winit-win32/src/lib.rs +++ b/winit-win32/src/lib.rs @@ -249,6 +249,12 @@ pub trait WindowExtWindows { /// and fn set_enable(&self, enabled: bool); + /// Cloaks the window such that it is not visible to the user. The window is still composed by + /// DWM. + /// + /// Not supported on Windows 7 and earlier. + fn set_cloaked(&self, cloaked: bool); + /// This sets `ICON_BIG`. A good ceiling here is 256x256. fn set_taskbar_icon(&self, taskbar_icon: Option); @@ -412,6 +418,12 @@ impl WindowExtWindows for dyn CoreWindow + '_ { window.set_use_system_scroll_speed(should_use) } + #[inline] + fn set_cloaked(&self, cloaked: bool) { + let window = self.cast_ref::().unwrap(); + window.set_cloaked(cloaked) + } + unsafe fn window_handle_any_thread( &self, ) -> Result, rwh_06::HandleError> { @@ -474,6 +486,7 @@ pub struct WindowAttributesWindows { pub(crate) title_text_color: Option, pub(crate) corner_preference: Option, pub(crate) use_system_wheel_speed: bool, + pub(crate) cloaked: bool, } impl Default for WindowAttributesWindows { @@ -494,6 +507,7 @@ impl Default for WindowAttributesWindows { title_text_color: None, corner_preference: None, use_system_wheel_speed: true, + cloaked: false, } } } @@ -627,6 +641,15 @@ impl WindowAttributesWindows { self } + /// Cloaks the window such that it is not visible to the user. The window is still composed by + /// DWM. + /// + /// Not supported on Windows 7 and earlier. + pub fn with_cloaked(mut self, cloaked: bool) -> Self { + self.cloaked = cloaked; + self + } + /// Sets if the reported [`winit_core::event::WindowEvent::MouseWheel`] event /// should account for scroll speed system settings. /// diff --git a/winit-win32/src/window.rs b/winit-win32/src/window.rs index dba95e9bd8..8d5dd39378 100644 --- a/winit-win32/src/window.rs +++ b/winit-win32/src/window.rs @@ -14,7 +14,7 @@ use windows_sys::Win32::Foundation::{ }; use windows_sys::Win32::Graphics::Dwm::{ DWM_BB_BLURREGION, DWM_BB_ENABLE, DWM_BLURBEHIND, DWM_SYSTEMBACKDROP_TYPE, - DWM_WINDOW_CORNER_PREFERENCE, DWMWA_BORDER_COLOR, DWMWA_CAPTION_COLOR, + DWM_WINDOW_CORNER_PREFERENCE, DWMWA_BORDER_COLOR, DWMWA_CAPTION_COLOR, DWMWA_CLOAK, DWMWA_SYSTEMBACKDROP_TYPE, DWMWA_TEXT_COLOR, DWMWA_WINDOW_CORNER_PREFERENCE, DwmEnableBlurBehindWindow, DwmSetWindowAttribute, }; @@ -384,6 +384,17 @@ impl Window { IconType::Big => self.window_state_lock().taskbar_icon = None, } } + + pub fn set_cloaked(&self, cloaked: bool) { + unsafe { + DwmSetWindowAttribute( + self.hwnd(), + DWMWA_CLOAK.try_into().unwrap(), + &cloaked as *const bool as *const _, + mem::size_of::() as u32, + ); + } + } } impl Drop for Window { @@ -1350,6 +1361,9 @@ impl InitData<'_> { if let Some(corner) = self.win_attributes.corner_preference { win.set_corner_preference(corner); } + if self.win_attributes.cloaked { + win.set_cloaked(true); + } } } unsafe fn init( diff --git a/winit/src/changelog/unreleased.md b/winit/src/changelog/unreleased.md index 1c58b725c0..c42080d402 100644 --- a/winit/src/changelog/unreleased.md +++ b/winit/src/changelog/unreleased.md @@ -50,6 +50,8 @@ changelog entry. - On Android, added scancode conversions for more obscure key codes. - On Wayland, added `HoldGesture` event for multi-finger hold gestures - On Wayland, added ext-background-effect-v1 support. +- On Windows, add `WindowExtWindows::set_cloaked` and + `WindowAttributesWindows::with_cloaked` to cloak a window via `DWMWA_CLOAK`. ### Changed