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.rs23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/api/win32/mod.rs b/src/api/win32/mod.rs
index d85ef09..7a7f42a 100644
--- a/src/api/win32/mod.rs
+++ b/src/api/win32/mod.rs
@@ -42,6 +42,13 @@ lazy_static! {
static ref WAKEUP_MSG_ID: u32 = unsafe { user32::RegisterWindowMessageA("Glutin::EventID".as_ptr() as *const i8) };
}
+/// Contains information about states and the window for the callback.
+#[derive(Clone)]
+pub struct WindowState {
+ pub cursor_state: CursorState,
+ pub attributes: WindowAttributes
+}
+
/// The Win32 implementation of the main `Window` object.
pub struct Window {
/// Main handle for the window.
@@ -53,8 +60,8 @@ pub struct Window {
/// Receiver for the events dispatched by the window callback.
events_receiver: Receiver<Event>,
- /// The current cursor state.
- cursor_state: Arc<Mutex<CursorState>>,
+ /// The current window state.
+ window_state: Arc<Mutex<WindowState>>,
}
unsafe impl Send for Window {}
@@ -258,14 +265,14 @@ impl Window {
}
pub fn set_cursor_state(&self, state: CursorState) -> Result<(), String> {
- let mut current_state = self.cursor_state.lock().unwrap();
+ let mut current_state = self.window_state.lock().unwrap().cursor_state;
let foreground_thread_id = unsafe { user32::GetWindowThreadProcessId(self.window.0, ptr::null_mut()) };
let current_thread_id = unsafe { kernel32::GetCurrentThreadId() };
unsafe { user32::AttachThreadInput(foreground_thread_id, current_thread_id, 1) };
- let res = match (state, *current_state) {
+ let res = match (state, current_state) {
(CursorState::Normal, CursorState::Normal) => Ok(()),
(CursorState::Hide, CursorState::Hide) => Ok(()),
(CursorState::Grab, CursorState::Grab) => Ok(()),
@@ -273,7 +280,7 @@ impl Window {
(CursorState::Hide, CursorState::Normal) => {
unsafe {
user32::SetCursor(ptr::null_mut());
- *current_state = CursorState::Hide;
+ current_state = CursorState::Hide;
Ok(())
}
},
@@ -281,7 +288,7 @@ impl Window {
(CursorState::Normal, CursorState::Hide) => {
unsafe {
user32::SetCursor(user32::LoadCursorW(ptr::null_mut(), winapi::IDC_ARROW));
- *current_state = CursorState::Normal;
+ current_state = CursorState::Normal;
Ok(())
}
},
@@ -298,7 +305,7 @@ impl Window {
if user32::ClipCursor(&rect) == 0 {
return Err(format!("ClipCursor failed"));
}
- *current_state = CursorState::Grab;
+ current_state = CursorState::Grab;
Ok(())
}
},
@@ -309,7 +316,7 @@ impl Window {
if user32::ClipCursor(ptr::null()) == 0 {
return Err(format!("ClipCursor failed"));
}
- *current_state = CursorState::Normal;
+ current_state = CursorState::Normal;
Ok(())
}
},