From 2784e317bd8123534b2a52e38f3f4c24c22d2f63 Mon Sep 17 00:00:00 2001 From: fcfangcc Date: Wed, 24 May 2023 15:50:12 +0800 Subject: [PATCH 1/2] Add binding for ScreenCaptureAccess --- core-graphics/src/access.rs | 8 ++++++++ core-graphics/src/lib.rs | 2 ++ 2 files changed, 10 insertions(+) create mode 100644 core-graphics/src/access.rs diff --git a/core-graphics/src/access.rs b/core-graphics/src/access.rs new file mode 100644 index 0000000..5cadf28 --- /dev/null +++ b/core-graphics/src/access.rs @@ -0,0 +1,8 @@ +pub use base::boolean_t; + +#[link(name = "CoreGraphics", kind = "framework")] +extern "C" { + // Screen Capture Access + pub fn CGRequestScreenCaptureAccess() -> boolean_t; + pub fn CGPreflightScreenCaptureAccess() -> boolean_t; +} diff --git a/core-graphics/src/lib.rs b/core-graphics/src/lib.rs index 5238774..514558f 100644 --- a/core-graphics/src/lib.rs +++ b/core-graphics/src/lib.rs @@ -41,3 +41,5 @@ pub mod private; pub mod image; pub mod path; pub mod sys; +#[cfg(target_os = "macos")] +pub mod access; \ No newline at end of file From d8b6ff1723d28123b2aaa61d3e7c1db5129dabcc Mon Sep 17 00:00:00 2001 From: fcfangcc Date: Wed, 24 May 2023 21:23:55 +0800 Subject: [PATCH 2/2] Add ScreenCaptureAccess struct --- core-graphics/src/access.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/core-graphics/src/access.rs b/core-graphics/src/access.rs index 5cadf28..4e852c8 100644 --- a/core-graphics/src/access.rs +++ b/core-graphics/src/access.rs @@ -1,8 +1,26 @@ pub use base::boolean_t; +#[derive(Default)] +pub struct ScreenCaptureAccess; + +impl ScreenCaptureAccess { + /// If current app not in list, will open window. + /// Return the same result as preflight. + #[inline] + pub fn request(&self) -> bool { + unsafe { CGRequestScreenCaptureAccess() == 1 } + } + + /// Return true if has access + #[inline] + pub fn preflight(&self) -> bool { + unsafe { CGPreflightScreenCaptureAccess() == 1 } + } +} + #[link(name = "CoreGraphics", kind = "framework")] extern "C" { // Screen Capture Access - pub fn CGRequestScreenCaptureAccess() -> boolean_t; - pub fn CGPreflightScreenCaptureAccess() -> boolean_t; + fn CGRequestScreenCaptureAccess() -> boolean_t; + fn CGPreflightScreenCaptureAccess() -> boolean_t; }