diff --git a/.changes/content-protection-builder.md b/.changes/content-protection-builder.md new file mode 100644 index 000000000..5cb2979b4 --- /dev/null +++ b/.changes/content-protection-builder.md @@ -0,0 +1,5 @@ +--- +"tao": "patch" +--- + +Add `WindowBuilder::with_content_protection`. \ No newline at end of file diff --git a/src/platform_impl/macos/window.rs b/src/platform_impl/macos/window.rs index 5d5923101..cafe6c24e 100644 --- a/src/platform_impl/macos/window.rs +++ b/src/platform_impl/macos/window.rs @@ -259,6 +259,10 @@ fn create_window( ]; } + if attrs.content_protection { + let _: () = msg_send![*ns_window, setSharingType: 0]; + } + if !attrs.maximizable { let button = ns_window.standardWindowButton_(NSWindowButton::NSWindowZoomButton); let _: () = msg_send![button, setEnabled: NO]; diff --git a/src/platform_impl/windows/window.rs b/src/platform_impl/windows/window.rs index 71e2af2f9..da8011f77 100644 --- a/src/platform_impl/windows/window.rs +++ b/src/platform_impl/windows/window.rs @@ -1076,6 +1076,7 @@ unsafe fn init( win.set_visible(attributes.visible); win.set_closable(attributes.closable); + win.set_content_protection(attributes.content_protection); if let Some(position) = attributes.position { win.set_outer_position(position); diff --git a/src/window.rs b/src/window.rs index 26813e345..955d76eea 100644 --- a/src/window.rs +++ b/src/window.rs @@ -236,6 +236,13 @@ pub struct WindowAttributes { /// /// **Android / iOS:** Unsupported. pub focused: bool, + + /// Prevents the window contents from being captured by other apps. + /// + /// ## Platform-specific + /// + /// - **iOS / Android / Linux:** Unsupported. + pub content_protection: bool, } impl Default for WindowAttributes { @@ -262,6 +269,7 @@ impl Default for WindowAttributes { window_menu: None, preferred_theme: None, focused: false, + content_protection: false, } } } @@ -486,6 +494,16 @@ impl WindowBuilder { self.window.focused = focused; self } + /// Prevents the window contents from being captured by other apps. + /// + /// ## Platform-specific + /// + /// - **iOS / Android / Linux:** Unsupported. + #[inline] + pub fn with_content_protection(mut self, protected: bool) -> WindowBuilder { + self.window.content_protection = protected; + self + } /// Builds the window. ///