mirror of
https://github.com/rust-windowing/winit.git
synced 2026-08-29 21:00:04 -04:00
Make views explicitly layer-backed on macOS Mojave. (#685)
On Mojave, views automatically become layer-backed shortly after being added to a window. Changing the layer-backedness of a view breaks the association between the view and its associated OpenGL context. To work around this, on Mojave we explicitly make the view layer-backed up front so that AppKit doesn't do it itself and break the association with its context. This was breaking the `window` example in `glutin`.
This commit is contained in:
committed by
Francesca Plebani
parent
0fca8e8cb5
commit
d2d127a4c4
@@ -1,5 +1,6 @@
|
||||
use std;
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::f64;
|
||||
use std::ops::Deref;
|
||||
use std::os::raw::c_void;
|
||||
use std::sync::Weak;
|
||||
@@ -850,6 +851,16 @@ impl Window2 {
|
||||
let view = new_view(window, shared);
|
||||
view.non_nil().map(|view| {
|
||||
view.setWantsBestResolutionOpenGLSurface_(YES);
|
||||
|
||||
// On Mojave, views automatically become layer-backed shortly after being added to
|
||||
// a window. Changing the layer-backedness of a view breaks the association between
|
||||
// the view and its associated OpenGL context. To work around this, on Mojave we
|
||||
// explicitly make the view layer-backed up front so that AppKit doesn't do it
|
||||
// itself and break the association with its context.
|
||||
if f64::floor(appkit::NSAppKitVersionNumber) > appkit::NSAppKitVersionNumber10_12 {
|
||||
view.setWantsLayer(YES);
|
||||
}
|
||||
|
||||
window.setContentView_(*view);
|
||||
window.makeFirstResponder_(*view);
|
||||
view
|
||||
|
||||
Reference in New Issue
Block a user