Skip to content
Open
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
23 changes: 23 additions & 0 deletions winit-win32/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,12 @@ pub trait WindowExtWindows {
/// and <https://docs.microsoft.com/en-us/windows/win32/winmsg/window-features#disabled-windows>
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<Icon>);

Expand Down Expand Up @@ -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::<Window>().unwrap();
window.set_cloaked(cloaked)
}

unsafe fn window_handle_any_thread(
&self,
) -> Result<rwh_06::WindowHandle<'_>, rwh_06::HandleError> {
Expand Down Expand Up @@ -474,6 +486,7 @@ pub struct WindowAttributesWindows {
pub(crate) title_text_color: Option<Color>,
pub(crate) corner_preference: Option<CornerPreference>,
pub(crate) use_system_wheel_speed: bool,
pub(crate) cloaked: bool,
}

impl Default for WindowAttributesWindows {
Expand All @@ -494,6 +507,7 @@ impl Default for WindowAttributesWindows {
title_text_color: None,
corner_preference: None,
use_system_wheel_speed: true,
cloaked: false,
}
}
}
Expand Down Expand Up @@ -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.
///
Expand Down
16 changes: 15 additions & 1 deletion winit-win32/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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::<bool>() as u32,
);
}
}
}

impl Drop for Window {
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 2 additions & 0 deletions winit/src/changelog/unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading