aboutsummaryrefslogtreecommitdiffstats
path: root/src/api/win32
diff options
context:
space:
mode:
authorAceeri <conmcclusk@gmail.com>2015-11-09 01:42:54 -0800
committerAceeri <conmcclusk@gmail.com>2015-11-09 01:42:54 -0800
commit78eb4a5990dadb3402dd3e80d04e2cfd7f9dd6fd (patch)
tree106da761ef835dda393c736d0d33da9358290670 /src/api/win32
parent5ca4e89dd4427464a11417cd127c67ee96d5fae1 (diff)
downloadglutin-78eb4a5990dadb3402dd3e80d04e2cfd7f9dd6fd.tar.gz
glutin-78eb4a5990dadb3402dd3e80d04e2cfd7f9dd6fd.zip
Minimum/maximum dimensions for windows in win32 api
Diffstat (limited to 'src/api/win32')
-rw-r--r--src/api/win32/callback.rs59
-rw-r--r--src/api/win32/init.rs8
-rw-r--r--src/api/win32/mod.rs14
3 files changed, 68 insertions, 13 deletions
diff --git a/src/api/win32/callback.rs b/src/api/win32/callback.rs
index 45de907..a36320b 100644
--- a/src/api/win32/callback.rs
+++ b/src/api/win32/callback.rs
@@ -6,6 +6,7 @@ use std::sync::{Arc, Mutex};
use std::ffi::OsString;
use std::os::windows::ffi::OsStringExt;
+use WindowAttributes;
use CursorState;
use Event;
use super::event;
@@ -19,10 +20,26 @@ use winapi;
/// a thread-local variable.
thread_local!(pub static CONTEXT_STASH: RefCell<Option<ThreadLocalData>> = RefCell::new(None));
+/// Contains information about states and the window for the callback.
+#[derive(Clone)]
+pub struct WindowState {
+ pub cursor_state: CursorState,
+ pub attributes: WindowAttributes
+}
+
pub struct ThreadLocalData {
pub win: winapi::HWND,
pub sender: Sender<Event>,
- pub cursor_state: Arc<Mutex<CursorState>>
+ pub window_state: Arc<Mutex<WindowState>>
+ //pub cursor_state: Arc<Mutex<CursorState>>
+}
+
+struct MinMaxInfo {
+ reserved: winapi::POINT, // Do not use/change
+ max_size: winapi::POINT,
+ max_position: winapi::POINT,
+ min_track: winapi::POINT,
+ max_track: winapi::POINT
}
/// Checks that the window is the good one, and if so send the event to it.
@@ -240,9 +257,9 @@ pub unsafe extern "system" fn callback(window: winapi::HWND, msg: winapi::UINT,
let cstash = cstash.as_ref();
// there's a very bizarre borrow checker bug
// possibly related to rust-lang/rust/#23338
- let _cursor_state = if let Some(cstash) = cstash {
- if let Ok(cursor_state) = cstash.cursor_state.lock() {
- match *cursor_state {
+ let _window_state = if let Some(cstash) = cstash {
+ if let Ok(window_state) = cstash.window_state.lock() {
+ match window_state.cursor_state {
CursorState::Normal => {
user32::SetCursor(user32::LoadCursorW(
ptr::null_mut(),
@@ -281,6 +298,40 @@ pub unsafe extern "system" fn callback(window: winapi::HWND, msg: winapi::UINT,
0
},
+ winapi::WM_GETMINMAXINFO => {
+ let mut mmi = lparam as *mut MinMaxInfo;
+ //(*mmi).max_position = winapi::POINT { x: -8, y: -8 }; // The upper left corner of the window if it were maximized on the primary monitor.
+ //(*mmi).max_size = winapi::POINT { x: 200, y: 200 }; // The dimensions of the primary monitor.
+
+ CONTEXT_STASH.with(|context_stash| {
+ let cstash = context_stash.borrow();
+ let cstash = cstash.as_ref();
+
+ let _window_state = if let Some(cstash) = cstash {
+ if let Ok(window_state) = cstash.window_state.lock() {
+ match window_state.attributes.min_dimensions {
+ Some((width, height)) => {
+ (*mmi).min_track = winapi::POINT { x: width as i32, y: height as i32 };
+ },
+ None => {
+ (*mmi).min_track = winapi::POINT { x: 800, y: 600 };
+ }
+ }
+
+ match window_state.attributes.max_dimensions {
+ Some((width, height)) => {
+ (*mmi).max_track = winapi::POINT { x: width as i32, y: height as i32 };
+ },
+ None => { }
+ }
+ }
+ } else {
+ return
+ };
+ });
+ 0
+ },
+
x if x == *super::WAKEUP_MSG_ID => {
use events::Event::Awakened;
send_event(window, Awakened);
diff --git a/src/api/win32/init.rs b/src/api/win32/init.rs
index 67e4e4e..6b52660 100644
--- a/src/api/win32/init.rs
+++ b/src/api/win32/init.rs
@@ -5,6 +5,7 @@ use std::mem;
use std::thread;
use super::callback;
+use super::callback::WindowState;
use super::Window;
use super::MonitorId;
use super::WindowWrapper;
@@ -215,7 +216,7 @@ unsafe fn init(title: Vec<u16>, window: &WindowAttributes, pf_reqs: &PixelFormat
}
// Creating a mutex to track the current cursor state
- let cursor_state = Arc::new(Mutex::new(CursorState::Normal));
+ let cursor_state = CursorState::Normal;
// filling the CONTEXT_STASH task-local storage so that we can start receiving events
let events_receiver = {
@@ -225,7 +226,10 @@ unsafe fn init(title: Vec<u16>, window: &WindowAttributes, pf_reqs: &PixelFormat
let data = callback::ThreadLocalData {
win: real_window.0,
sender: tx.take().unwrap(),
- cursor_state: cursor_state.clone()
+ window_state: Arc::new(Mutex::new(WindowState {
+ cursor_state: cursor_state.clone(),
+ attributes: window.clone()
+ }))
};
(*context_stash.borrow_mut()) = Some(data);
});
diff --git a/src/api/win32/mod.rs b/src/api/win32/mod.rs
index d85ef09..760020c 100644
--- a/src/api/win32/mod.rs
+++ b/src/api/win32/mod.rs
@@ -54,7 +54,7 @@ pub struct Window {
events_receiver: Receiver<Event>,
/// The current cursor state.
- cursor_state: Arc<Mutex<CursorState>>,
+ cursor_state: CursorState,
}
unsafe impl Send for Window {}
@@ -258,14 +258,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.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 +273,7 @@ impl Window {
(CursorState::Hide, CursorState::Normal) => {
unsafe {
user32::SetCursor(ptr::null_mut());
- *current_state = CursorState::Hide;
+ current_state = CursorState::Hide;
Ok(())
}
},
@@ -281,7 +281,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 +298,7 @@ impl Window {
if user32::ClipCursor(&rect) == 0 {
return Err(format!("ClipCursor failed"));
}
- *current_state = CursorState::Grab;
+ current_state = CursorState::Grab;
Ok(())
}
},
@@ -309,7 +309,7 @@ impl Window {
if user32::ClipCursor(ptr::null()) == 0 {
return Err(format!("ClipCursor failed"));
}
- *current_state = CursorState::Normal;
+ current_state = CursorState::Normal;
Ok(())
}
},