From 856775815623684a78c7cad6f8f5c74c3a86a4bf Mon Sep 17 00:00:00 2001 From: dam4rus Date: Wed, 17 Jul 2019 18:25:35 +0200 Subject: [PATCH] Touch events emit screen coordinates instead of client coordinates on Windows (#1042) * Touch events emit screen coordinates instead of client coordinates on Windows Fixes #1002 * Don't lose precision of WM_TOUCH events when converting from screen space to client space * Updated CHANGELOG.md to reflect changes from issue: #1042 --- CHANGELOG.md | 1 + src/platform_impl/windows/event_loop.rs | 26 +++++++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 65555cf0..a4665ca5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ and `WindowEvent::HoveredFile`. - On Windows, fix the trail effect happening on transparent decorated windows. Borderless (or un-decorated) windows were not affected. - On Windows, fix `with_maximized` not properly setting window size to entire window. - On macOS, change `WindowExtMacOS::request_user_attention()` to take an `enum` instead of a `bool`. +- On Windows, location of `WindowEvent::Touch` are window client coordinates instead of screen coordinates. # 0.20.0 Alpha 1 (2019-06-21) diff --git a/src/platform_impl/windows/event_loop.rs b/src/platform_impl/windows/event_loop.rs index 0204747e..65380c0f 100644 --- a/src/platform_impl/windows/event_loop.rs +++ b/src/platform_impl/windows/event_loop.rs @@ -1448,8 +1448,17 @@ unsafe extern "system" fn public_window_callback( { let dpi_factor = hwnd_scale_factor(window); for input in &inputs { - let x = (input.x as f64) / 100f64; - let y = (input.y as f64) / 100f64; + let mut location = POINT { + x: input.x / 100, + y: input.y / 100, + }; + + if winuser::ScreenToClient(window, &mut location as *mut _) == 0 { + continue; + } + + let x = location.x as f64 + (input.x % 100) as f64 / 100f64; + let y = location.y as f64 + (input.y % 100) as f64 / 100f64; let location = LogicalPosition::from_physical((x, y), dpi_factor); subclass_input.send_event(Event::WindowEvent { window_id: RootWindowId(WindowId(window)), @@ -1510,8 +1519,17 @@ unsafe extern "system" fn public_window_callback( // The information retrieved appears in reverse chronological order, with the most recent entry in the first // row of the returned array for pointer_info in pointer_infos.iter().rev() { - let x = pointer_info.ptPixelLocation.x as f64; - let y = pointer_info.ptPixelLocation.y as f64; + let mut location = POINT { + x: pointer_info.ptPixelLocation.x, + y: pointer_info.ptPixelLocation.y, + }; + + if winuser::ScreenToClient(window, &mut location as *mut _) == 0 { + continue; + } + + let x = location.x as f64; + let y = location.y as f64; let location = LogicalPosition::from_physical((x, y), dpi_factor); subclass_input.send_event(Event::WindowEvent { window_id: RootWindowId(WindowId(window)),