mirror of
https://github.com/rust-windowing/winit.git
synced 2026-08-29 04:40:04 -04:00
macOS: Feature-gate CGSSetWindowBackgroundBlurRadius
Behind the Cargo feature `private-apple-apis`.
This commit is contained in:
committed by
Simon Hausmann
parent
6b113977d8
commit
0ea5f3c875
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
@@ -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" {
|
||||
// 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;
|
||||
}
|
||||
|
||||
pub fn set_visible(&self, visible: bool) {
|
||||
|
||||
Reference in New Issue
Block a user