Skip to content

Commit

Permalink
feat: add WindowBuilder::with_content_protection (#605)
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir committed Oct 30, 2022
1 parent d72b1e1 commit 8084c80
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changes/content-protection-builder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tao": "patch"
---

Add `WindowBuilder::with_content_protection`.
4 changes: 4 additions & 0 deletions src/platform_impl/macos/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
1 change: 1 addition & 0 deletions src/platform_impl/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,7 @@ unsafe fn init<T: 'static>(

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);
Expand Down
18 changes: 18 additions & 0 deletions src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -262,6 +269,7 @@ impl Default for WindowAttributes {
window_menu: None,
preferred_theme: None,
focused: false,
content_protection: false,
}
}
}
Expand Down Expand Up @@ -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.
///
Expand Down

0 comments on commit 8084c80

Please sign in to comment.