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 GitHub
parent 3c9f9da19e
commit 52af1b4a77
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 19 deletions

View file

@ -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]