diff options
-rw-r--r-- | src/api/cocoa/mod.rs | 2 | ||||
-rw-r--r-- | src/api/wgl/mod.rs | 10 | ||||
-rw-r--r-- | src/api/x11/window.rs | 31 | ||||
-rw-r--r-- | src/os/macos.rs | 19 | ||||
-rw-r--r-- | src/os/mod.rs | 2 |
5 files changed, 49 insertions, 15 deletions
diff --git a/src/api/cocoa/mod.rs b/src/api/cocoa/mod.rs index 28cbb55..138a448 100644 --- a/src/api/cocoa/mod.rs +++ b/src/api/cocoa/mod.rs @@ -619,7 +619,7 @@ impl Window { #[inline] pub fn platform_window(&self) -> *mut libc::c_void { - unimplemented!() + *self.window as *mut libc::c_void } #[inline] diff --git a/src/api/wgl/mod.rs b/src/api/wgl/mod.rs index dcd16b6..a0fce27 100644 --- a/src/api/wgl/mod.rs +++ b/src/api/wgl/mod.rs @@ -383,7 +383,7 @@ unsafe fn choose_native_pixel_format(hdc: winapi::HDC, reqs: &PixelFormatRequire nVersion: 1, dwFlags: { let f1 = match reqs.double_buffer { - None => winapi::PFD_DOUBLEBUFFER_DONTCARE, + None => winapi::PFD_DOUBLEBUFFER, // Should be PFD_DOUBLEBUFFER_DONTCARE after you can choose Some(true) => winapi::PFD_DOUBLEBUFFER, Some(false) => 0, }; @@ -541,10 +541,10 @@ unsafe fn choose_arb_pixel_format(extra: &gl::wgl_extra::Wgl, extensions: &str, out.push(stencil as c_int); } - if let Some(double_buffer) = reqs.double_buffer { - out.push(gl::wgl_extra::DOUBLE_BUFFER_ARB as c_int); - out.push(if double_buffer { 1 } else { 0 }); - } + // Prefer double buffering if unspecified (probably shouldn't once you can choose) + let double_buffer = reqs.double_buffer.unwrap_or(true); + out.push(gl::wgl_extra::DOUBLE_BUFFER_ARB as c_int); + out.push(if double_buffer { 1 } else { 0 }); if let Some(multisampling) = reqs.multisampling { if extensions.split(' ').find(|&i| i == "WGL_ARB_multisample").is_some() { diff --git a/src/api/x11/window.rs b/src/api/x11/window.rs index 2f700ce..de9cfb6 100644 --- a/src/api/x11/window.rs +++ b/src/api/x11/window.rs @@ -9,6 +9,8 @@ use std::sync::atomic::AtomicBool; use std::collections::VecDeque; use std::sync::{Arc, Mutex}; use std::os::raw::c_long; +use std::thread; +use std::time::Duration; use Api; use ContextError; @@ -642,15 +644,26 @@ impl Window { let ref x_window: &XWindow = window.x.borrow(); // XSetInputFocus generates an error if the window is not visible, - // therefore we call XSync before to make sure it's the case - (display.xlib.XSync)(display.display, 0); - (display.xlib.XSetInputFocus)( - display.display, - x_window.window, - ffi::RevertToParent, - ffi::CurrentTime - ); - display.check_errors().expect("Failed to call XSetInputFocus"); + // therefore we wait until it's the case. + loop { + let mut window_attributes = mem::uninitialized(); + (display.xlib.XGetWindowAttributes)(display.display, x_window.window, &mut window_attributes); + display.check_errors().expect("Failed to call XGetWindowAttributes"); + + if window_attributes.map_state == ffi::IsViewable { + (display.xlib.XSetInputFocus)( + display.display, + x_window.window, + ffi::RevertToParent, + ffi::CurrentTime + ); + display.check_errors().expect("Failed to call XSetInputFocus"); + break; + } + + // Wait about a frame to avoid too-busy waiting + thread::sleep(Duration::from_millis(16)); + } } } diff --git a/src/os/macos.rs b/src/os/macos.rs new file mode 100644 index 0000000..16ffe33 --- /dev/null +++ b/src/os/macos.rs @@ -0,0 +1,19 @@ +#![cfg(target_os = "macos")] + +use std::os::raw::c_void; +use Window; + +/// Additional methods on `Window` that are specific to MacOS. +pub trait WindowExt { + /// Returns a pointer to the cocoa `NSWindow` that is used by this window. + /// + /// The pointer will become invalid when the glutin `Window` is destroyed. + fn get_nswindow(&self) -> *mut c_void; +} + +impl WindowExt for Window { + #[inline] + fn get_nswindow(&self) -> *mut c_void { + self.window.platform_window() as *mut c_void + } +} diff --git a/src/os/mod.rs b/src/os/mod.rs index 251a8d4..04e82c2 100644 --- a/src/os/mod.rs +++ b/src/os/mod.rs @@ -2,8 +2,10 @@ //! //! Contains the follow modules: //! +//! - `macos` //! - `unix` //! - `windows` //! +pub mod macos; pub mod unix; pub mod windows; |