mirror of
https://github.com/rust-windowing/winit.git
synced 2026-06-26 14:49:07 -04:00
macOS: Feature-gate CGSSetWindowBackgroundBlurRadius
Behind the Cargo feature `private-apple-apis`.
This commit is contained in:
@@ -9,6 +9,7 @@ rust-version.workspace = true
|
||||
version.workspace = true
|
||||
|
||||
[features]
|
||||
private-apple-apis = []
|
||||
serde = ["dep:serde", "bitflags/serde", "smol_str/serde", "dpi/serde"]
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
|
||||
use std::ffi::c_void;
|
||||
|
||||
use objc2::ffi::NSInteger;
|
||||
use objc2::runtime::AnyObject;
|
||||
use objc2_core_foundation::{CFString, CFUUID, cf_type};
|
||||
use objc2_core_graphics::CGDirectDisplayID;
|
||||
|
||||
@@ -28,17 +26,6 @@ unsafe extern "C" {
|
||||
pub fn CGDisplayGetDisplayIDFromUUID(uuid: &CFUUID) -> CGDirectDisplayID;
|
||||
}
|
||||
|
||||
#[link(name = "CoreGraphics", kind = "framework")]
|
||||
unsafe extern "C" {
|
||||
// Wildly used private APIs; Apple uses them for their Terminal.app.
|
||||
pub fn CGSMainConnectionID() -> *mut AnyObject;
|
||||
pub fn CGSSetWindowBackgroundBlurRadius(
|
||||
connection_id: *mut AnyObject,
|
||||
window_id: NSInteger,
|
||||
radius: i64,
|
||||
) -> i32;
|
||||
}
|
||||
|
||||
#[repr(transparent)]
|
||||
pub struct TISInputSource(std::ffi::c_void);
|
||||
|
||||
|
||||
@@ -55,7 +55,6 @@ use winit_core::window::{
|
||||
|
||||
use super::app_state::AppState;
|
||||
use super::cursor::{CustomCursor, cursor_from_icon};
|
||||
use super::ffi;
|
||||
use super::monitor::{self, MonitorHandle, flip_window_screen_coordinates, get_display_id};
|
||||
use super::util::cgerr;
|
||||
use super::view::WinitView;
|
||||
@@ -973,17 +972,30 @@ impl WindowDelegate {
|
||||
}
|
||||
|
||||
pub fn set_blur(&self, blur: bool) {
|
||||
#[cfg(feature = "private-apple-apis")]
|
||||
{
|
||||
#[link(name = "CoreGraphics", kind = "framework")]
|
||||
unsafe extern "C" {
|
||||
// Wildly used private APIs; Apple uses them for their Terminal.app.
|
||||
pub fn CGSMainConnectionID() -> *mut objc2::runtime::AnyObject;
|
||||
pub fn CGSSetWindowBackgroundBlurRadius(
|
||||
connection_id: *mut objc2::runtime::AnyObject,
|
||||
window_id: objc2_foundation::NSInteger,
|
||||
radius: i64,
|
||||
) -> i32;
|
||||
}
|
||||
|
||||
// NOTE: in general we want to specify the blur radius, but the choice of 80
|
||||
// should be a reasonable default.
|
||||
let radius = if blur { 80 } else { 0 };
|
||||
let window_number = self.window().windowNumber();
|
||||
unsafe {
|
||||
ffi::CGSSetWindowBackgroundBlurRadius(
|
||||
ffi::CGSMainConnectionID(),
|
||||
window_number,
|
||||
radius,
|
||||
);
|
||||
CGSSetWindowBackgroundBlurRadius(CGSMainConnectionID(), window_number, radius)
|
||||
};
|
||||
}
|
||||
|
||||
// TODO: Implement blur using public methods somehow?
|
||||
let _ = blur;
|
||||
}
|
||||
|
||||
pub fn set_visible(&self, visible: bool) {
|
||||
|
||||
@@ -879,6 +879,7 @@ pub trait Window: AsAny + Send + Sync + fmt::Debug {
|
||||
///
|
||||
/// ## Platform-specific
|
||||
///
|
||||
/// - **macOS**: Must enable the `private-apple-apis` Cargo feature.
|
||||
/// - **Android / iOS / X11 / Web / Windows:** Unsupported.
|
||||
/// - **Wayland:** Only works with org_kde_kwin_blur_manager protocol.
|
||||
fn set_blur(&self, blur: bool);
|
||||
|
||||
@@ -44,6 +44,7 @@ default = ["x11", "wayland", "wayland-dlopen", "wayland-csd-adwaita"]
|
||||
android-game-activity = ["winit-android/game-activity"]
|
||||
android-native-activity = ["winit-android/native-activity"]
|
||||
mint = ["dpi/mint"]
|
||||
private-apple-apis = ["winit-appkit/private-apple-apis"]
|
||||
serde = [
|
||||
"dep:serde",
|
||||
"cursor-icon/serde",
|
||||
|
||||
@@ -53,6 +53,7 @@ changelog entry.
|
||||
|
||||
- Updated `windows-sys` to `v0.61`.
|
||||
- On older macOS versions (tested up to 12.7.6), applications now receive mouse movement events for unfocused windows, matching the behavior on other platforms.
|
||||
- On macOS, using the private API `CGSSetWindowBackgroundBlurRadius` for `Window::set_blur` is now disabled by default. It can be re-enabled using the Cargo feature `private-apple-apis`.
|
||||
|
||||
### Fixed
|
||||
|
||||
|
||||
@@ -195,6 +195,9 @@
|
||||
//! * `rwh_06`: Implement `raw-window-handle v0.6` traits.
|
||||
//! * `serde`: Enables serialization/deserialization of certain types with [Serde](https://crates.io/crates/serde).
|
||||
//! * `mint`: Enables mint (math interoperability standard types) conversions.
|
||||
//! * `private-apple-apis`: Enables private APIs whose usage might cause rejections from the App
|
||||
//! Store. Currently enables the use of `CGSSetWindowBackgroundBlurRadius`, commonly used for
|
||||
//! terminal emulators.
|
||||
//!
|
||||
//! See the [`platform`] module for documentation on platform-specific cargo
|
||||
//! features.
|
||||
|
||||
Reference in New Issue
Block a user