aboutsummaryrefslogtreecommitdiffstats
path: root/src/api/cocoa/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/api/cocoa/mod.rs')
-rw-r--r--src/api/cocoa/mod.rs56
1 files changed, 44 insertions, 12 deletions
diff --git a/src/api/cocoa/mod.rs b/src/api/cocoa/mod.rs
index 511148b..332244e 100644
--- a/src/api/cocoa/mod.rs
+++ b/src/api/cocoa/mod.rs
@@ -8,15 +8,21 @@ use libc;
use Api;
use BuilderAttribs;
+use ContextError;
use GlContext;
use GlProfile;
use GlRequest;
use PixelFormat;
+use Robustness;
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};
@@ -55,7 +61,6 @@ static mut win_pressed: bool = false;
static mut alt_pressed: bool = false;
struct DelegateState {
- is_closed: bool,
context: IdRef,
view: IdRef,
window: IdRef,
@@ -79,8 +84,6 @@ impl WindowDelegate {
unsafe {
let state: *mut libc::c_void = *this.get_ivar("glutinState");
let state = state as *mut DelegateState;
- (*state).is_closed = true;
-
(*state).pending_events.lock().unwrap().push_back(Closed);
}
YES
@@ -275,7 +278,15 @@ impl<'a> Iterator for PollEventsIterator<'a> {
self.window.delegate.state.pending_events.lock().unwrap().extend(events.into_iter());
event
},
- NSScrollWheel => { Some(MouseWheel(event.scrollingDeltaX() as f64, event.scrollingDeltaY() as f64)) },
+ NSScrollWheel => {
+ use events::MouseScrollDelta::{LineDelta, PixelDelta};
+ let delta = if event.hasPreciseScrollingDeltas() == YES {
+ PixelDelta(event.scrollingDeltaX() as f32, event.scrollingDeltaY() as f32)
+ } else {
+ LineDelta(event.scrollingDeltaX() as f32, event.scrollingDeltaY() as f32)
+ };
+ Some(MouseWheel(delta))
+ },
_ => { None },
};
@@ -322,6 +333,13 @@ impl Window {
unimplemented!()
}
+ match builder.gl_robustness {
+ Robustness::RobustNoResetNotification | Robustness::RobustLoseContextOnReset => {
+ return Err(CreationError::NotSupported);
+ },
+ _ => ()
+ }
+
let app = match Window::create_app() {
Some(app) => app,
None => { return Err(OsError(format!("Couldn't create NSApplication"))); },
@@ -345,6 +363,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);
@@ -354,7 +387,6 @@ impl Window {
}
let ds = DelegateState {
- is_closed: false,
context: context.clone(),
view: view.clone(),
window: window.clone(),
@@ -425,7 +457,7 @@ impl Window {
}
};
- let masks = if screen.is_some() {
+ let masks = if screen.is_some() || !builder.decorations {
NSBorderlessWindowMask as NSUInteger
} else {
NSTitledWindowMask as NSUInteger |
@@ -564,6 +596,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)
@@ -574,10 +608,6 @@ impl Window {
}
}
- pub fn is_closed(&self) -> bool {
- self.delegate.state.is_closed
- }
-
pub fn set_title(&self, title: &str) {
unsafe {
let title = IdRef::new(NSString::alloc(nil).init_str(title));
@@ -752,9 +782,10 @@ impl Window {
}
impl GlContext for Window {
- unsafe fn make_current(&self) {
+ unsafe fn make_current(&self) -> Result<(), ContextError> {
let _: () = msg_send![*self.context, update];
self.context.makeCurrentContext();
+ Ok(())
}
fn is_current(&self) -> bool {
@@ -781,8 +812,9 @@ impl GlContext for Window {
symbol as *const _
}
- fn swap_buffers(&self) {
+ fn swap_buffers(&self) -> Result<(), ContextError> {
unsafe { self.context.flushBuffer(); }
+ Ok(())
}
fn get_api(&self) -> ::Api {