From 026be10b8be3b6dc6583732e6528710d991c9537 Mon Sep 17 00:00:00 2001 From: Daniel Collin Date: Sat, 19 Dec 2015 11:44:36 +0100 Subject: [PATCH] Finally a visible window! --- examples/noise.rs | 3 ++- src/macos.rs | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/examples/noise.rs b/examples/noise.rs index 55131b0..e0286db 100644 --- a/examples/noise.rs +++ b/examples/noise.rs @@ -10,7 +10,7 @@ fn main() { //let mut carry; //let mut seed = 0xbeefu32; - //let mut buffer: [u32; WIDTH * HEIGHT] = [0; WIDTH * HEIGHT]; + let mut buffer: [u32; WIDTH * HEIGHT] = [0; WIDTH * HEIGHT]; let window = match macos::Window::new("Noise Test - Press ESC to exit", WIDTH, @@ -25,6 +25,7 @@ fn main() { }; loop { + window.update(&buffer); /* for i in buffer.iter_mut() { noise = seed; diff --git a/src/macos.rs b/src/macos.rs index 7c1150f..d315991 100644 --- a/src/macos.rs +++ b/src/macos.rs @@ -59,6 +59,8 @@ impl WindowDelegate { let state: *mut libc::c_void = *this.get_ivar("glutinState"); let state = &mut *(state as *mut DelegateState); + println!("did_resize"); + //let _: () = msg_send![*state.context, update]; if let Some(handler) = state.resize_handler { @@ -75,6 +77,7 @@ impl WindowDelegate { // TODO: center the cursor if the window had mouse grab when it // lost focus + println!("became key window"); let state: *mut libc::c_void = *this.get_ivar("glutinState"); let state = state as *mut DelegateState; //(*state).pending_events.lock().unwrap().push_back(Focused(true)); @@ -93,7 +96,7 @@ impl WindowDelegate { static INIT: Once = ONCE_INIT; INIT.call_once(|| unsafe { - // Create new NSWindowDelegate + println!("Create new NSWindowDelegate"); let superclass = Class::get("NSObject").unwrap(); let mut decl = ClassDecl::new(superclass, "GlutinWindowDelegate").unwrap(); @@ -167,8 +170,9 @@ impl Window { return Err("Unable to create NSView"); } }; - + app.activateIgnoringOtherApps_(YES); + window.makeKeyAndOrderFront_(nil); let ds = DelegateState { view: view.clone(), @@ -202,6 +206,7 @@ impl Window { window.non_nil().map(|window| { let title = IdRef::new(NSString::alloc(nil).init_str(name)); + window.setLevel_(NSMainMenuWindowLevel as i64 + 1); window.setTitle_(*title); window.center(); window @@ -216,7 +221,14 @@ impl Window { }) } - pub fn update(_: &[u32]) { + pub fn update(&self, _: &[u32]) { + unsafe { + NSApp().nextEventMatchingMask_untilDate_inMode_dequeue_( + NSAnyEventMask.bits(), + NSDate::distantPast(nil), + NSDefaultRunLoopMode, + YES); + } } pub fn get_keys() -> Option> {