aboutsummaryrefslogtreecommitdiffstats
path: root/src/api/win32
diff options
context:
space:
mode:
Diffstat (limited to 'src/api/win32')
-rw-r--r--src/api/win32/callback.rs6
-rw-r--r--src/api/win32/mod.rs42
-rw-r--r--src/api/win32/monitor.rs5
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 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
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
}