Change linking of CGDisplayCreateUUIDFromDisplayID on macos (#1626)
* Link CGDisplayCreateUUIDFromDisplayID through ColorSync instead of CoreGraphics * Conditionally link through ColorSync only if WINIT_LINK_COLORSYNC is set to true * Document new macos env var in README
This commit is contained in:
parent
b1d353180b
commit
b9307a9967
3 changed files with 32 additions and 1 deletions
10
README.md
10
README.md
|
|
@ -110,3 +110,13 @@ fn main() {
|
||||||
```
|
```
|
||||||
|
|
||||||
And run the application with `cargo apk run --example request_redraw_threaded`
|
And run the application with `cargo apk run --example request_redraw_threaded`
|
||||||
|
|
||||||
|
#### MacOS
|
||||||
|
|
||||||
|
To ensure compatibility with older MacOS systems, winit links to
|
||||||
|
CGDisplayCreateUUIDFromDisplayID through the CoreGraphics framework.
|
||||||
|
However, under certain setups this function is only available to be linked
|
||||||
|
through the newer ColorSync framework. So, winit provides the
|
||||||
|
`WINIT_LINK_COLORSYNC` environment variable which can be set to `1` or `true`
|
||||||
|
while compiling to enable linking via ColorSync.
|
||||||
|
|
||||||
|
|
|
||||||
10
build.rs
Normal file
10
build.rs
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
fn main() {
|
||||||
|
// If building for macos and WINIT_LINK_COLORSYNC is set to true
|
||||||
|
// use CGDisplayCreateUUIDFromDisplayID from ColorSync instead of CoreGraphics
|
||||||
|
if std::env::var("CARGO_CFG_TARGET_OS").map_or(false, |os| os == "macos")
|
||||||
|
&& std::env::var("WINIT_LINK_COLORSYNC")
|
||||||
|
.map_or(false, |v| v == "1" || v.eq_ignore_ascii_case("true"))
|
||||||
|
{
|
||||||
|
println!("cargo:rustc-cfg=use_colorsync_cgdisplaycreateuuidfromdisplayid");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -161,6 +161,18 @@ pub const IO8BitOverlayPixels: &str = "O8";
|
||||||
pub type CGWindowLevel = i32;
|
pub type CGWindowLevel = i32;
|
||||||
pub type CGDisplayModeRef = *mut libc::c_void;
|
pub type CGDisplayModeRef = *mut libc::c_void;
|
||||||
|
|
||||||
|
#[cfg_attr(
|
||||||
|
not(use_colorsync_cgdisplaycreateuuidfromdisplayid),
|
||||||
|
link(name = "CoreGraphics", kind = "framework")
|
||||||
|
)]
|
||||||
|
#[cfg_attr(
|
||||||
|
use_colorsync_cgdisplaycreateuuidfromdisplayid,
|
||||||
|
link(name = "ColorSync", kind = "framework")
|
||||||
|
)]
|
||||||
|
extern "C" {
|
||||||
|
pub fn CGDisplayCreateUUIDFromDisplayID(display: CGDirectDisplayID) -> CFUUIDRef;
|
||||||
|
}
|
||||||
|
|
||||||
#[link(name = "CoreGraphics", kind = "framework")]
|
#[link(name = "CoreGraphics", kind = "framework")]
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn CGRestorePermanentDisplayConfiguration();
|
pub fn CGRestorePermanentDisplayConfiguration();
|
||||||
|
|
@ -189,7 +201,6 @@ extern "C" {
|
||||||
synchronous: Boolean,
|
synchronous: Boolean,
|
||||||
) -> CGError;
|
) -> CGError;
|
||||||
pub fn CGReleaseDisplayFadeReservation(token: CGDisplayFadeReservationToken) -> CGError;
|
pub fn CGReleaseDisplayFadeReservation(token: CGDisplayFadeReservationToken) -> CGError;
|
||||||
pub fn CGDisplayCreateUUIDFromDisplayID(display: CGDirectDisplayID) -> CFUUIDRef;
|
|
||||||
pub fn CGShieldingWindowLevel() -> CGWindowLevel;
|
pub fn CGShieldingWindowLevel() -> CGWindowLevel;
|
||||||
pub fn CGDisplaySetDisplayMode(
|
pub fn CGDisplaySetDisplayMode(
|
||||||
display: CGDirectDisplayID,
|
display: CGDirectDisplayID,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue