aboutsummaryrefslogtreecommitdiffstats
path: root/src/api/win32/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/api/win32/mod.rs')
-rw-r--r--src/api/win32/mod.rs42
1 files changed, 38 insertions, 4 deletions
diff --git a/src/api/win32/mod.rs b/src/api/win32/mod.rs
index f580950..0bc36a7 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() };
@@ -188,11 +202,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,
@@ -200,23 +216,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!()
}
@@ -286,6 +310,7 @@ impl Window {
res
}
+ #[inline]
pub fn hidpi_factor(&self) -> f32 {
1.0
}
@@ -311,6 +336,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(),
@@ -318,6 +344,7 @@ impl GlContext for Window {
}
}
+ #[inline]
fn is_current(&self) -> bool {
match self.context {
Context::Wgl(ref c) => c.is_current(),
@@ -325,6 +352,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),
@@ -332,6 +360,7 @@ impl GlContext for Window {
}
}
+ #[inline]
fn swap_buffers(&self) -> Result<(), ContextError> {
match self.context {
Context::Wgl(ref c) => c.swap_buffers(),
@@ -339,6 +368,7 @@ impl GlContext for Window {
}
}
+ #[inline]
fn get_api(&self) -> Api {
match self.context {
Context::Wgl(ref c) => c.get_api(),
@@ -346,6 +376,7 @@ impl GlContext for Window {
}
}
+ #[inline]
fn get_pixel_format(&self) -> PixelFormat {
match self.context {
Context::Wgl(ref c) => c.get_pixel_format(),
@@ -361,6 +392,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()
}
@@ -373,12 +405,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