On Windows, fix MT safety when starting drag

This commit is contained in:
Jasper Bekkers
2023-10-31 16:20:34 +01:00
committed by Kirill Chibisov
parent 525219716c
commit fc9c78cb56
2 changed files with 35 additions and 19 deletions

View File

@@ -11,6 +11,8 @@ Unreleased` header.
# Unreleased # Unreleased
- On Windows, fix so `drag_window` and `drag_resize_window` can be called from another thread.
# 0.29.3 # 0.29.3
- On Wayland, apply correct scale to `PhysicalSize` passed in `WindowBuilder::with_inner_size` when possible. - On Wayland, apply correct scale to `PhysicalSize` passed in `WindowBuilder::with_inner_size` when possible.

View File

@@ -472,6 +472,19 @@ impl Window {
} }
unsafe fn handle_os_dragging(&self, wparam: WPARAM) { unsafe fn handle_os_dragging(&self, wparam: WPARAM) {
let window = self.window.clone();
let window_state = self.window_state.clone();
self.thread_executor.execute_in_thread(move || {
{
let mut guard = window_state.lock().unwrap();
if !guard.dragging {
guard.dragging = true;
} else {
return;
}
}
let points = { let points = {
let mut pos = unsafe { mem::zeroed() }; let mut pos = unsafe { mem::zeroed() };
unsafe { GetCursorPos(&mut pos) }; unsafe { GetCursorPos(&mut pos) };
@@ -481,18 +494,19 @@ impl Window {
x: points.x as i16, x: points.x as i16,
y: points.y as i16, y: points.y as i16,
}; };
unsafe { ReleaseCapture() };
self.window_state_lock().dragging = true; // ReleaseCapture needs to execute on the main thread
unsafe { ReleaseCapture() };
unsafe { unsafe {
PostMessageW( PostMessageW(
self.hwnd(), window.0,
WM_NCLBUTTONDOWN, WM_NCLBUTTONDOWN,
wparam, wparam,
&points as *const _ as LPARAM, &points as *const _ as LPARAM,
) )
}; };
});
} }
#[inline] #[inline]