On Windows, fix MT safety when starting drag
This commit is contained in:
parent
3c9f9da19e
commit
52af1b4a77
2 changed files with 35 additions and 19 deletions
|
|
@ -11,6 +11,8 @@ Unreleased` header.
|
|||
|
||||
# Unreleased
|
||||
|
||||
- On Windows, fix so `drag_window` and `drag_resize_window` can be called from another thread.
|
||||
|
||||
# 0.29.3
|
||||
|
||||
- On Wayland, apply correct scale to `PhysicalSize` passed in `WindowBuilder::with_inner_size` when possible.
|
||||
|
|
|
|||
|
|
@ -472,27 +472,41 @@ impl Window {
|
|||
}
|
||||
|
||||
unsafe fn handle_os_dragging(&self, wparam: WPARAM) {
|
||||
let points = {
|
||||
let mut pos = unsafe { mem::zeroed() };
|
||||
unsafe { GetCursorPos(&mut pos) };
|
||||
pos
|
||||
};
|
||||
let points = POINTS {
|
||||
x: points.x as i16,
|
||||
y: points.y as i16,
|
||||
};
|
||||
unsafe { ReleaseCapture() };
|
||||
let window = self.window.clone();
|
||||
let window_state = self.window_state.clone();
|
||||
|
||||
self.window_state_lock().dragging = true;
|
||||
self.thread_executor.execute_in_thread(move || {
|
||||
{
|
||||
let mut guard = window_state.lock().unwrap();
|
||||
if !guard.dragging {
|
||||
guard.dragging = true;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
unsafe {
|
||||
PostMessageW(
|
||||
self.hwnd(),
|
||||
WM_NCLBUTTONDOWN,
|
||||
wparam,
|
||||
&points as *const _ as LPARAM,
|
||||
)
|
||||
};
|
||||
let points = {
|
||||
let mut pos = unsafe { mem::zeroed() };
|
||||
unsafe { GetCursorPos(&mut pos) };
|
||||
pos
|
||||
};
|
||||
let points = POINTS {
|
||||
x: points.x as i16,
|
||||
y: points.y as i16,
|
||||
};
|
||||
|
||||
// ReleaseCapture needs to execute on the main thread
|
||||
unsafe { ReleaseCapture() };
|
||||
|
||||
unsafe {
|
||||
PostMessageW(
|
||||
window.0,
|
||||
WM_NCLBUTTONDOWN,
|
||||
wparam,
|
||||
&points as *const _ as LPARAM,
|
||||
)
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue