From 08c311839f9c65faa358b0540a3ff6b2eb19ff14 Mon Sep 17 00:00:00 2001 From: Felix Kaaman Date: Wed, 2 Mar 2016 16:40:19 +0100 Subject: Fix memory leak while creating NSEvent and swapping buffers (Fixes #514) --- src/api/cocoa/mod.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/api/cocoa/mod.rs') diff --git a/src/api/cocoa/mod.rs b/src/api/cocoa/mod.rs index abcd735..ca77ce9 100644 --- a/src/api/cocoa/mod.rs +++ b/src/api/cocoa/mod.rs @@ -224,12 +224,16 @@ impl<'a> Iterator for PollEventsIterator<'a> { let event: Option; unsafe { + let pool = NSAutoreleasePool::new(nil); + let nsevent = NSApp().nextEventMatchingMask_untilDate_inMode_dequeue_( NSAnyEventMask.bits() | NSEventMaskPressure.bits(), NSDate::distantPast(nil), NSDefaultRunLoopMode, YES); event = NSEventToEvent(self.window, nsevent); + + let _: () = msg_send![pool, release]; } event } @@ -249,12 +253,16 @@ impl<'a> Iterator for WaitEventsIterator<'a> { let event: Option; unsafe { + let pool = NSAutoreleasePool::new(nil); + let nsevent = NSApp().nextEventMatchingMask_untilDate_inMode_dequeue_( NSAnyEventMask.bits() | NSEventMaskPressure.bits(), NSDate::distantFuture(nil), NSDefaultRunLoopMode, YES); event = NSEventToEvent(self.window, nsevent); + + let _: () = msg_send![pool, release]; } if event.is_none() { @@ -747,7 +755,11 @@ impl GlContext for Window { #[inline] fn swap_buffers(&self) -> Result<(), ContextError> { - unsafe { self.context.flushBuffer(); } + unsafe { + let pool = NSAutoreleasePool::new(nil); + self.context.flushBuffer(); + let _: () = msg_send![pool, release]; + } Ok(()) } -- cgit v1.2.3 From 7249529654afe4b3ac6628be45bd2d8bb15dcaf4 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 14 Mar 2016 15:51:10 -0700 Subject: Make Mac borderless windows resizable and draggable. Despite the fact that the style mask contains `NSTitledWindowMask`, the title doesn't show up for two reasons: (a) we draw over it; (b) we make it invisible with a call to `-[NSWindow setTitleVisibility:]`. Addresses servo/servo#9856 and servo/servo#9878. Partially addresses servo/servo#9812. --- src/api/cocoa/mod.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/api/cocoa/mod.rs') diff --git a/src/api/cocoa/mod.rs b/src/api/cocoa/mod.rs index db3f749..08fabdd 100644 --- a/src/api/cocoa/mod.rs +++ b/src/api/cocoa/mod.rs @@ -404,7 +404,9 @@ impl Window { let masks = if screen.is_some() || attrs.transparent { // Fullscreen or transparent window - NSBorderlessWindowMask as NSUInteger + NSBorderlessWindowMask as NSUInteger | + NSResizableWindowMask as NSUInteger | + NSTitledWindowMask as NSUInteger } else if attrs.decorations { // Classic opaque window with titlebar NSClosableWindowMask as NSUInteger | -- cgit v1.2.3 From c5268309c39933e13e86bd33a9fe0b7fa8c88b14 Mon Sep 17 00:00:00 2001 From: Steven Sheldon Date: Sun, 20 Mar 2016 16:04:11 -0700 Subject: Update objc to 0.2. --- Cargo.toml | 14 +++++++------- src/api/cocoa/mod.rs | 19 ++++++++++--------- 2 files changed, 17 insertions(+), 16 deletions(-) (limited to 'src/api/cocoa/mod.rs') diff --git a/Cargo.toml b/Cargo.toml index 294d55d..ddf8160 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,24 +23,24 @@ khronos_api = "1.0" version = "0.1" [target.i386-apple-ios.dependencies] -objc = "0.1.8" +objc = "0.2" [target.x86_64-apple-ios.dependencies] -objc = "0.1.8" +objc = "0.2" [target.aarch64-apple-ios.dependencies] -objc = "0.1.8" +objc = "0.2" [target.armv7s-apple-ios.dependencies] -objc = "0.1.8" +objc = "0.2" [target.armv7-apple-ios.dependencies] -objc = "0.1.8" +objc = "0.2" [target.x86_64-apple-darwin.dependencies] -objc = "0.1.8" +objc = "0.2" cgl = "0.1" -cocoa = "0.2.4" +cocoa = "0.3" core-foundation = "0" core-graphics = "0.3" diff --git a/src/api/cocoa/mod.rs b/src/api/cocoa/mod.rs index bec56d2..e935805 100644 --- a/src/api/cocoa/mod.rs +++ b/src/api/cocoa/mod.rs @@ -79,11 +79,12 @@ struct WindowDelegate { impl WindowDelegate { /// Get the delegate class, initiailizing it neccessary fn class() -> *const Class { + use std::os::raw::c_void; use std::sync::{Once, ONCE_INIT}; extern fn window_should_close(this: &Object, _: Sel, _: id) -> BOOL { unsafe { - let state: *mut libc::c_void = *this.get_ivar("glutinState"); + let state: *mut c_void = *this.get_ivar("glutinState"); let state = state as *mut DelegateState; (*state).pending_events.lock().unwrap().push_back(Closed); } @@ -92,7 +93,7 @@ impl WindowDelegate { extern fn window_did_resize(this: &Object, _: Sel, _: id) { unsafe { - let state: *mut libc::c_void = *this.get_ivar("glutinState"); + let state: *mut c_void = *this.get_ivar("glutinState"); let state = &mut *(state as *mut DelegateState); let _: () = msg_send![*state.context, update]; @@ -111,7 +112,7 @@ impl WindowDelegate { // TODO: center the cursor if the window had mouse grab when it // lost focus - let state: *mut libc::c_void = *this.get_ivar("glutinState"); + let state: *mut c_void = *this.get_ivar("glutinState"); let state = state as *mut DelegateState; (*state).pending_events.lock().unwrap().push_back(Focused(true)); } @@ -119,7 +120,7 @@ impl WindowDelegate { extern fn window_did_resign_key(this: &Object, _: Sel, _: id) { unsafe { - let state: *mut libc::c_void = *this.get_ivar("glutinState"); + let state: *mut c_void = *this.get_ivar("glutinState"); let state = state as *mut DelegateState; (*state).pending_events.lock().unwrap().push_back(Focused(false)); } @@ -131,7 +132,7 @@ impl WindowDelegate { INIT.call_once(|| unsafe { // Create new NSWindowDelegate let superclass = Class::get("NSObject").unwrap(); - let mut decl = ClassDecl::new(superclass, "GlutinWindowDelegate").unwrap(); + let mut decl = ClassDecl::new("GlutinWindowDelegate", superclass).unwrap(); // Add callback methods decl.add_method(sel!(windowShouldClose:), @@ -145,7 +146,7 @@ impl WindowDelegate { window_did_resign_key as extern fn(&Object, Sel, id)); // Store internal state as user data - decl.add_ivar::<*mut libc::c_void>("glutinState"); + decl.add_ivar::<*mut c_void>("glutinState"); delegate_class = decl.register(); }); @@ -162,7 +163,7 @@ impl WindowDelegate { unsafe { let delegate = IdRef::new(msg_send![WindowDelegate::class(), new]); - (&mut **delegate).set_ivar("glutinState", state_ptr as *mut libc::c_void); + (&mut **delegate).set_ivar("glutinState", state_ptr as *mut ::std::os::raw::c_void); let _: () = msg_send![*state.window, setDelegate:*delegate]; WindowDelegate { state: state, _this: delegate } @@ -673,8 +674,8 @@ impl Window { let sel = Sel::register(cursor_name); let cls = Class::get("NSCursor").unwrap(); unsafe { - use objc::MessageArguments; - let cursor: id = ().send(cls as *const _ as id, sel); + use objc::Message; + let cursor: id = cls.send_message(sel, ()).unwrap(); let _: () = msg_send![cursor, set]; } } -- cgit v1.2.3