Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions winit-appkit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
13 changes: 0 additions & 13 deletions winit-appkit/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);

Expand Down
34 changes: 23 additions & 11 deletions winit-appkit/src/window_delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,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;
Expand Down Expand Up @@ -1101,17 +1100,30 @@ impl WindowDelegate {
}

pub fn set_blur(&self, blur: bool) {
// 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,
);
#[cfg(feature = "private-apple-apis")]
{
#[link(name = "CoreGraphics", kind = "framework")]
unsafe extern "C" {
Comment thread
tronical marked this conversation as resolved.
// 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 {
CGSSetWindowBackgroundBlurRadius(CGSMainConnectionID(), window_number, radius)
};
}

// TODO: Implement blur using public methods somehow?
let _ = blur;
Comment thread
tronical marked this conversation as resolved.
}

pub fn set_visible(&self, visible: bool) {
Expand Down
1 change: 1 addition & 0 deletions winit-core/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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` or
/// `ext_background_effect_manager_v1` protocol.
Expand Down
1 change: 1 addition & 0 deletions winit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions winit/src/changelog/unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,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

Expand Down
3 changes: 3 additions & 0 deletions winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down