diff options
Diffstat (limited to 'src/api/win32')
| -rw-r--r-- | src/api/win32/callback.rs | 6 | ||||
| -rw-r--r-- | src/api/win32/mod.rs | 42 | ||||
| -rw-r--r-- | src/api/win32/monitor.rs | 5 | 
3 files changed, 49 insertions, 4 deletions
| diff --git a/src/api/win32/callback.rs b/src/api/win32/callback.rs index da8e1a6..45de907 100644 --- a/src/api/win32/callback.rs +++ b/src/api/win32/callback.rs @@ -281,6 +281,12 @@ pub unsafe extern "system" fn callback(window: winapi::HWND, msg: winapi::UINT,              0          }, +        x if x == *super::WAKEUP_MSG_ID => { +            use events::Event::Awakened; +            send_event(window, Awakened); +            0 +        }, +          _ => {              user32::DefWindowProcW(window, msg, wparam, lparam)          } diff --git a/src/api/win32/mod.rs b/src/api/win32/mod.rs index 59fdf5d..81e1c16 100644 --- a/src/api/win32/mod.rs +++ b/src/api/win32/mod.rs @@ -38,6 +38,10 @@ mod event;  mod init;  mod monitor; +lazy_static! { +    static ref WAKEUP_MSG_ID: u32 = unsafe { user32::RegisterWindowMessageA("Glutin::EventID".as_ptr() as *const i8) }; +} +  /// The Win32 implementation of the main `Window` object.  pub struct Window {      /// Main handle for the window. @@ -67,6 +71,7 @@ enum Context {  pub struct WindowWrapper(pub winapi::HWND, pub winapi::HDC);  impl Drop for WindowWrapper { +    #[inline]      fn drop(&mut self) {          unsafe {              user32::DestroyWindow(self.0); @@ -75,11 +80,16 @@ impl Drop for WindowWrapper {  }  #[derive(Clone)] -pub struct WindowProxy; +pub struct WindowProxy { +    hwnd: winapi::HWND, +}  impl WindowProxy { +    #[inline]      pub fn wakeup_event_loop(&self) { -        unimplemented!() +        unsafe { +            user32::PostMessageA(self.hwnd, *WAKEUP_MSG_ID, 0, 0); +        }      }  } @@ -111,12 +121,14 @@ impl Window {          }      } +    #[inline]      pub fn show(&self) {          unsafe {              user32::ShowWindow(self.window.0, winapi::SW_SHOW);          }      } +    #[inline]      pub fn hide(&self) {          unsafe {              user32::ShowWindow(self.window.0, winapi::SW_HIDE); @@ -150,6 +162,7 @@ impl Window {      }      /// See the docs in the crate root file. +    #[inline]      pub fn get_inner_size(&self) -> Option<(u32, u32)> {          let mut rect: winapi::RECT = unsafe { mem::uninitialized() }; @@ -164,6 +177,7 @@ impl Window {      }      /// See the docs in the crate root file. +    #[inline]      pub fn get_outer_size(&self) -> Option<(u32, u32)> {          let mut rect: winapi::RECT = unsafe { mem::uninitialized() }; @@ -197,11 +211,13 @@ impl Window {          }      } +    #[inline]      pub fn create_window_proxy(&self) -> WindowProxy { -        WindowProxy +        WindowProxy { hwnd: self.window.0 }      }      /// See the docs in the crate root file. +    #[inline]      pub fn poll_events(&self) -> PollEventsIterator {          PollEventsIterator {              window: self, @@ -209,23 +225,31 @@ impl Window {      }      /// See the docs in the crate root file. +    #[inline]      pub fn wait_events(&self) -> WaitEventsIterator {          WaitEventsIterator {              window: self,          }      } +    #[inline]      pub fn platform_display(&self) -> *mut libc::c_void { -        unimplemented!() +        // What should this return on win32? +        // It could be GetDC(NULL), but that requires a ReleaseDC() +        // to avoid leaking the DC. +        ptr::null_mut()      } +    #[inline]      pub fn platform_window(&self) -> *mut libc::c_void {          self.window.0 as *mut libc::c_void      } +    #[inline]      pub fn set_window_resize_callback(&mut self, _: Option<fn(u32, u32)>) {      } +    #[inline]      pub fn set_cursor(&self, _cursor: MouseCursor) {          unimplemented!()      } @@ -295,6 +319,7 @@ impl Window {          res      } +    #[inline]      pub fn hidpi_factor(&self) -> f32 {          1.0      } @@ -320,6 +345,7 @@ impl Window {  }  impl GlContext for Window { +    #[inline]      unsafe fn make_current(&self) -> Result<(), ContextError> {          match self.context {              Context::Wgl(ref c) => c.make_current(), @@ -327,6 +353,7 @@ impl GlContext for Window {          }      } +    #[inline]      fn is_current(&self) -> bool {          match self.context {              Context::Wgl(ref c) => c.is_current(), @@ -334,6 +361,7 @@ impl GlContext for Window {          }      } +    #[inline]      fn get_proc_address(&self, addr: &str) -> *const libc::c_void {          match self.context {              Context::Wgl(ref c) => c.get_proc_address(addr), @@ -341,6 +369,7 @@ impl GlContext for Window {          }      } +    #[inline]      fn swap_buffers(&self) -> Result<(), ContextError> {          match self.context {              Context::Wgl(ref c) => c.swap_buffers(), @@ -348,6 +377,7 @@ impl GlContext for Window {          }      } +    #[inline]      fn get_api(&self) -> Api {          match self.context {              Context::Wgl(ref c) => c.get_api(), @@ -355,6 +385,7 @@ impl GlContext for Window {          }      } +    #[inline]      fn get_pixel_format(&self) -> PixelFormat {          match self.context {              Context::Wgl(ref c) => c.get_pixel_format(), @@ -370,6 +401,7 @@ pub struct PollEventsIterator<'a> {  impl<'a> Iterator for PollEventsIterator<'a> {      type Item = Event; +    #[inline]      fn next(&mut self) -> Option<Event> {          self.window.events_receiver.try_recv().ok()      } @@ -382,12 +414,14 @@ pub struct WaitEventsIterator<'a> {  impl<'a> Iterator for WaitEventsIterator<'a> {      type Item = Event; +    #[inline]      fn next(&mut self) -> Option<Event> {          self.window.events_receiver.recv().ok()      }  }  impl Drop for Window { +    #[inline]      fn drop(&mut self) {          unsafe {              // we don't call MakeCurrent(0, 0) because we are not sure that the context diff --git a/src/api/win32/monitor.rs b/src/api/win32/monitor.rs index d87c928..2f2e2c1 100644 --- a/src/api/win32/monitor.rs +++ b/src/api/win32/monitor.rs @@ -151,16 +151,19 @@ pub fn get_primary_monitor() -> MonitorID {  impl MonitorID {      /// See the docs if the crate root file. +    #[inline]      pub fn get_name(&self) -> Option<String> {          Some(self.readable_name.clone())      }      /// See the docs of the crate root file. +    #[inline]      pub fn get_native_identifier(&self) -> NativeMonitorId {          NativeMonitorId::Name(self.monitor_name.clone())      }      /// See the docs if the crate root file. +    #[inline]      pub fn get_dimensions(&self) -> (u32, u32) {          // TODO: retreive the dimensions every time this is called          self.dimensions @@ -168,6 +171,7 @@ impl MonitorID {      /// This is a Win32-only function for `MonitorID` that returns the system name of the adapter      /// device. +    #[inline]      pub fn get_adapter_name(&self) -> &[winapi::WCHAR] {          &self.adapter_name      } @@ -175,6 +179,7 @@ impl MonitorID {      /// This is a Win32-only function for `MonitorID` that returns the position of the      ///  monitor on the desktop.      /// A window that is positionned at these coordinates will overlap the monitor. +    #[inline]      pub fn get_position(&self) -> (u32, u32) {          self.position      } | 
