mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2025-01-11 21:31:29 +11:00
Merge pull request #12 from Osspial/master
Fix win32 bug where window resize cursors would not show
This commit is contained in:
commit
614276eb0b
|
@ -6,7 +6,6 @@ use std::sync::{Arc, Mutex};
|
||||||
use std::ffi::OsString;
|
use std::ffi::OsString;
|
||||||
use std::os::windows::ffi::OsStringExt;
|
use std::os::windows::ffi::OsStringExt;
|
||||||
|
|
||||||
use WindowAttributes;
|
|
||||||
use CursorState;
|
use CursorState;
|
||||||
use Event;
|
use Event;
|
||||||
use super::event;
|
use super::event;
|
||||||
|
@ -24,9 +23,14 @@ thread_local!(pub static CONTEXT_STASH: RefCell<Option<ThreadLocalData>> = RefCe
|
||||||
pub struct ThreadLocalData {
|
pub struct ThreadLocalData {
|
||||||
pub win: winapi::HWND,
|
pub win: winapi::HWND,
|
||||||
pub sender: Sender<Event>,
|
pub sender: Sender<Event>,
|
||||||
pub window_state: Arc<Mutex<WindowState>>
|
pub window_state: Arc<Mutex<WindowState>>,
|
||||||
|
pub mouse_in_window: bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Equivalent to the windows api [MINMAXINFO](https://msdn.microsoft.com/en-us/library/windows/desktop/ms632605%28v=vs.85%29.aspx)
|
||||||
|
/// struct. Used because winapi-rs doesn't have this declared.
|
||||||
|
#[repr(C)]
|
||||||
|
#[allow(dead_code)]
|
||||||
struct MinMaxInfo {
|
struct MinMaxInfo {
|
||||||
reserved: winapi::POINT, // Do not use/change
|
reserved: winapi::POINT, // Do not use/change
|
||||||
max_size: winapi::POINT,
|
max_size: winapi::POINT,
|
||||||
|
@ -122,15 +126,40 @@ pub unsafe extern "system" fn callback(window: winapi::HWND, msg: winapi::UINT,
|
||||||
|
|
||||||
winapi::WM_MOUSEMOVE => {
|
winapi::WM_MOUSEMOVE => {
|
||||||
use events::Event::MouseMoved;
|
use events::Event::MouseMoved;
|
||||||
|
CONTEXT_STASH.with(|context_stash| {
|
||||||
|
let mut context_stash = context_stash.borrow_mut();
|
||||||
|
if let Some(context_stash) = context_stash.as_mut() {
|
||||||
|
context_stash.mouse_in_window = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
let x = winapi::GET_X_LPARAM(lparam) as i32;
|
let x = winapi::GET_X_LPARAM(lparam) as i32;
|
||||||
let y = winapi::GET_Y_LPARAM(lparam) as i32;
|
let y = winapi::GET_Y_LPARAM(lparam) as i32;
|
||||||
|
|
||||||
|
let mut mouse_track = winapi::TRACKMOUSEEVENT {
|
||||||
|
cbSize: mem::size_of::<winapi::TRACKMOUSEEVENT>() as winapi::DWORD,
|
||||||
|
dwFlags: winapi::TME_HOVER | winapi::TME_LEAVE,
|
||||||
|
hwndTrack: window,
|
||||||
|
dwHoverTime: winapi::HOVER_DEFAULT
|
||||||
|
};
|
||||||
|
user32::TrackMouseEvent(&mut mouse_track);
|
||||||
|
|
||||||
send_event(window, MouseMoved((x, y)));
|
send_event(window, MouseMoved((x, y)));
|
||||||
|
|
||||||
0
|
0
|
||||||
},
|
},
|
||||||
|
|
||||||
|
winapi::WM_MOUSELEAVE => {
|
||||||
|
CONTEXT_STASH.with(|context_stash| {
|
||||||
|
let mut context_stash = context_stash.borrow_mut();
|
||||||
|
if let Some(context_stash) = context_stash.as_mut() {
|
||||||
|
context_stash.mouse_in_window = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
0
|
||||||
|
},
|
||||||
|
|
||||||
winapi::WM_MOUSEWHEEL => {
|
winapi::WM_MOUSEWHEEL => {
|
||||||
use events::Event::MouseWheel;
|
use events::Event::MouseWheel;
|
||||||
use events::MouseScrollDelta::LineDelta;
|
use events::MouseScrollDelta::LineDelta;
|
||||||
|
@ -264,31 +293,36 @@ pub unsafe extern "system" fn callback(window: winapi::HWND, msg: winapi::UINT,
|
||||||
},
|
},
|
||||||
|
|
||||||
winapi::WM_SETCURSOR => {
|
winapi::WM_SETCURSOR => {
|
||||||
CONTEXT_STASH.with(|context_stash| {
|
let call_def_window_proc = CONTEXT_STASH.with(|context_stash| {
|
||||||
let cstash = context_stash.borrow();
|
let cstash = context_stash.borrow();
|
||||||
let cstash = cstash.as_ref();
|
let mut call_def_window_proc = false;
|
||||||
// there's a very bizarre borrow checker bug
|
if let Some(cstash) = cstash.as_ref() {
|
||||||
// possibly related to rust-lang/rust/#23338
|
|
||||||
let _cursor_state = if let Some(cstash) = cstash {
|
|
||||||
if let Ok(window_state) = cstash.window_state.lock() {
|
if let Ok(window_state) = cstash.window_state.lock() {
|
||||||
match window_state.cursor_state {
|
if cstash.mouse_in_window {
|
||||||
CursorState::Normal => {
|
match window_state.cursor_state {
|
||||||
user32::SetCursor(user32::LoadCursorW(
|
CursorState::Normal => {
|
||||||
ptr::null_mut(),
|
user32::SetCursor(user32::LoadCursorW(
|
||||||
window_state.cursor));
|
ptr::null_mut(),
|
||||||
},
|
window_state.cursor));
|
||||||
CursorState::Grab | CursorState::Hide => {
|
},
|
||||||
user32::SetCursor(ptr::null_mut());
|
CursorState::Grab | CursorState::Hide => {
|
||||||
|
user32::SetCursor(ptr::null_mut());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
call_def_window_proc = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
return
|
|
||||||
};
|
|
||||||
|
|
||||||
// let &ThreadLocalData { ref cursor_state, .. } = stored;
|
call_def_window_proc
|
||||||
});
|
});
|
||||||
0
|
|
||||||
|
if call_def_window_proc {
|
||||||
|
user32::DefWindowProcW(window, msg, wparam, lparam)
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
winapi::WM_DROPFILES => {
|
winapi::WM_DROPFILES => {
|
||||||
|
@ -311,7 +345,7 @@ pub unsafe extern "system" fn callback(window: winapi::HWND, msg: winapi::UINT,
|
||||||
},
|
},
|
||||||
|
|
||||||
winapi::WM_GETMINMAXINFO => {
|
winapi::WM_GETMINMAXINFO => {
|
||||||
let mut mmi = lparam as *mut MinMaxInfo;
|
let 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_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: .., y: .. }; // The dimensions of the primary monitor.
|
//(*mmi).max_size = winapi::POINT { x: .., y: .. }; // The dimensions of the primary monitor.
|
||||||
|
|
||||||
|
|
|
@ -169,7 +169,8 @@ unsafe fn init(title: Vec<u16>, window: &WindowAttributes) -> Result<Window, Cre
|
||||||
let data = callback::ThreadLocalData {
|
let data = callback::ThreadLocalData {
|
||||||
win: real_window.0,
|
win: real_window.0,
|
||||||
sender: tx.take().unwrap(),
|
sender: tx.take().unwrap(),
|
||||||
window_state: window_state.clone()
|
window_state: window_state.clone(),
|
||||||
|
mouse_in_window: false
|
||||||
};
|
};
|
||||||
(*context_stash.borrow_mut()) = Some(data);
|
(*context_stash.borrow_mut()) = Some(data);
|
||||||
});
|
});
|
||||||
|
|
|
@ -65,10 +65,6 @@ pub use window::{WindowBuilder, WindowProxy, PollEventsIterator, WaitEventsItera
|
||||||
pub use window::{AvailableMonitorsIter, MonitorId, get_available_monitors, get_primary_monitor};
|
pub use window::{AvailableMonitorsIter, MonitorId, get_available_monitors, get_primary_monitor};
|
||||||
pub use native_monitor::NativeMonitorId;
|
pub use native_monitor::NativeMonitorId;
|
||||||
|
|
||||||
use std::io;
|
|
||||||
#[cfg(not(target_os = "macos"))]
|
|
||||||
use std::cmp::Ordering;
|
|
||||||
|
|
||||||
mod api;
|
mod api;
|
||||||
mod platform;
|
mod platform;
|
||||||
mod events;
|
mod events;
|
||||||
|
|
|
@ -7,9 +7,7 @@ pub use api::win32::{WindowProxy, PollEventsIterator, WaitEventsIterator};
|
||||||
use CreationError;
|
use CreationError;
|
||||||
use WindowAttributes;
|
use WindowAttributes;
|
||||||
|
|
||||||
use std::ffi::CString;
|
|
||||||
use std::ops::{Deref, DerefMut};
|
use std::ops::{Deref, DerefMut};
|
||||||
use kernel32;
|
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct PlatformSpecificWindowBuilderAttributes;
|
pub struct PlatformSpecificWindowBuilderAttributes;
|
||||||
|
|
Loading…
Reference in a new issue