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
|
# 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.
|
||||||
|
|
|
||||||
|
|
@ -472,27 +472,41 @@ impl Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn handle_os_dragging(&self, wparam: WPARAM) {
|
unsafe fn handle_os_dragging(&self, wparam: WPARAM) {
|
||||||
let points = {
|
let window = self.window.clone();
|
||||||
let mut pos = unsafe { mem::zeroed() };
|
let window_state = self.window_state.clone();
|
||||||
unsafe { GetCursorPos(&mut pos) };
|
|
||||||
pos
|
|
||||||
};
|
|
||||||
let points = POINTS {
|
|
||||||
x: points.x as i16,
|
|
||||||
y: points.y as i16,
|
|
||||||
};
|
|
||||||
unsafe { ReleaseCapture() };
|
|
||||||
|
|
||||||
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 {
|
let points = {
|
||||||
PostMessageW(
|
let mut pos = unsafe { mem::zeroed() };
|
||||||
self.hwnd(),
|
unsafe { GetCursorPos(&mut pos) };
|
||||||
WM_NCLBUTTONDOWN,
|
pos
|
||||||
wparam,
|
};
|
||||||
&points as *const _ as LPARAM,
|
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]
|
#[inline]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue