diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/api/cocoa/mod.rs | 23 | ||||
-rw-r--r-- | src/api/glx/mod.rs | 6 | ||||
-rw-r--r-- | src/lib.rs | 2 |
3 files changed, 28 insertions, 3 deletions
diff --git a/src/api/cocoa/mod.rs b/src/api/cocoa/mod.rs index aa408ff..5cb7edb 100644 --- a/src/api/cocoa/mod.rs +++ b/src/api/cocoa/mod.rs @@ -18,6 +18,10 @@ use native_monitor::NativeMonitorId; use objc::runtime::{Class, Object, Sel, BOOL, YES, NO}; use objc::declare::ClassDecl; +use cgl; +use cgl::{CGLEnable, kCGLCECrashOnRemovedFunctions, CGLSetParameter, kCGLCPSurfaceOpacity}; +use cgl::CGLContextObj as CGL_CGLContextObj; + use cocoa::base::{id, nil}; use cocoa::foundation::{NSAutoreleasePool, NSDate, NSDefaultRunLoopMode, NSPoint, NSRect, NSSize, NSString, NSUInteger}; @@ -354,6 +358,21 @@ impl Window { }; unsafe { + if builder.transparent { + let clear_col = { + let cls = Class::get("NSColor").unwrap(); + + msg_send![cls, clearColor] + }; + window.setOpaque_(NO); + window.setBackgroundColor_(clear_col); + + let obj = context.CGLContextObj(); + + let mut opacity = 0; + CGLSetParameter(obj, kCGLCPSurfaceOpacity, &mut opacity); + } + app.activateIgnoringOtherApps_(YES); if builder.visible { window.makeKeyAndOrderFront_(nil); @@ -434,7 +453,7 @@ impl Window { } }; - let masks = if screen.is_some() { + let masks = if screen.is_some() || !builder.decorations { NSBorderlessWindowMask as NSUInteger } else { NSTitledWindowMask as NSUInteger | @@ -573,6 +592,8 @@ impl Window { let value = if builder.vsync { 1 } else { 0 }; cxt.setValues_forParameter_(&value, NSOpenGLContextParameter::NSOpenGLCPSwapInterval); + CGLEnable(cxt.CGLContextObj(), kCGLCECrashOnRemovedFunctions); + Ok((cxt, pf)) } else { Err(CreationError::NotSupported) diff --git a/src/api/glx/mod.rs b/src/api/glx/mod.rs index 4ba99ca..455f6a5 100644 --- a/src/api/glx/mod.rs +++ b/src/api/glx/mod.rs @@ -182,8 +182,10 @@ unsafe impl Sync for Context {} impl Drop for Context { fn drop(&mut self) { unsafe { - // we don't call MakeCurrent(0, 0) because we are not sure that the context - // is still the current one + if self.is_current() { + self.glx.MakeCurrent(self.display as *mut _, 0, ptr::null_mut()); + } + self.glx.DestroyContext(self.display as *mut _, self.context); } } @@ -46,6 +46,8 @@ extern crate dwmapi; #[macro_use] extern crate objc; #[cfg(target_os = "macos")] +extern crate cgl; +#[cfg(target_os = "macos")] extern crate cocoa; #[cfg(target_os = "macos")] extern crate core_foundation; |