Add Window::set_content_protected on macOS and Windows (#2525)

* Add `Window::set_content_protect` on macOS and Windows

* Update window.rs

* Add builder variant

* fix import

* fix argument type

* fix import

* fix always visible window on Windows

* update docs
This commit is contained in:
Amr Bashir 2022-11-23 15:51:34 +02:00 committed by GitHub
parent 418cc44e93
commit 65baae75c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 89 additions and 7 deletions

View file

@ -136,6 +136,7 @@ pub(crate) struct WindowAttributes {
pub window_icon: Option<Icon>,
pub preferred_theme: Option<Theme>,
pub resize_increments: Option<Size>,
pub content_protected: bool,
}
impl Default for WindowAttributes {
@ -157,6 +158,7 @@ impl Default for WindowAttributes {
window_icon: None,
preferred_theme: None,
resize_increments: None,
content_protected: false,
}
}
}
@ -365,6 +367,23 @@ impl WindowBuilder {
self
}
/// Prevents the window contents from being captured by other apps.
///
/// The default is `false`.
///
/// ## Platform-specific
///
/// - **macOS**: if `false`, [`NSWindowSharingNone`] is used but doesn't completely
/// prevent all apps from reading the window content, for instance, QuickTime.
/// - **iOS / Android / Web / x11:** Ignored.
///
/// [`NSWindowSharingNone`]: https://developer.apple.com/documentation/appkit/nswindowsharingtype/nswindowsharingnone
#[inline]
pub fn with_content_protected(mut self, protected: bool) -> Self {
self.window.content_protected = protected;
self
}
/// Builds the window.
///
/// Possible causes of error include denied permission, incompatible system, and lack of memory.
@ -953,6 +972,20 @@ impl Window {
self.window.theme()
}
/// Prevents the window contents from being captured by other apps.
///
/// ## Platform-specific
///
/// - **macOS**: if `false`, [`NSWindowSharingNone`] is used but doesn't completely
/// prevent all apps from reading the window content, for instance, QuickTime.
/// - **iOS / Android / x11 / Wayland / Web:** Unsupported.
///
/// [`NSWindowSharingNone`]: https://developer.apple.com/documentation/appkit/nswindowsharingtype/nswindowsharingnone
pub fn set_content_protected(&self, _protected: bool) {
#[cfg(any(target_os = "macos", target_os = "windows"))]
self.window.set_content_protected(_protected);
}
/// Gets the current title of the window.
///
/// ## Platform-specific