Skip to content

Commit dc9a7f4

Browse files
Kalmar Robertfelixrabe
authored andcommitted
Handle WM_POINTER* events in favor of WM_TOUCH
Fixes rust-windowing#975.
1 parent ac08601 commit dc9a7f4

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

src/platform_impl/windows/event_loop.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,6 +1433,64 @@ unsafe extern "system" fn public_window_callback<T>(
14331433
0
14341434
}
14351435

1436+
winuser::WM_POINTERDOWN | winuser::WM_POINTERUPDATE | winuser::WM_POINTERUP => {
1437+
let pointer_id = LOWORD(wparam as DWORD) as UINT;
1438+
let mut entries_count = 0 as UINT;
1439+
let mut pointers_count = 0 as UINT;
1440+
if winuser::GetPointerFrameInfoHistory(
1441+
pointer_id,
1442+
&mut entries_count as *mut _,
1443+
&mut pointers_count as *mut _,
1444+
std::ptr::null_mut(),
1445+
) == 0
1446+
{
1447+
return 0;
1448+
}
1449+
1450+
let pointer_info_count = (entries_count * pointers_count) as usize;
1451+
let mut pointer_infos = Vec::with_capacity(pointer_info_count);
1452+
pointer_infos.set_len(pointer_info_count);
1453+
if winuser::GetPointerFrameInfoHistory(
1454+
pointer_id,
1455+
&mut entries_count as *mut _,
1456+
&mut pointers_count as *mut _,
1457+
pointer_infos.as_mut_ptr(),
1458+
) == 0
1459+
{
1460+
return 0;
1461+
}
1462+
1463+
let dpi_factor = hwnd_scale_factor(window);
1464+
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getpointerframeinfohistory
1465+
// The information retrieved appears in reverse chronological order, with the most recent entry in the first
1466+
// row of the returned array
1467+
for pointer_info in pointer_infos.iter().rev() {
1468+
let x = pointer_info.ptPixelLocation.x as f64;
1469+
let y = pointer_info.ptPixelLocation.y as f64;
1470+
let location = LogicalPosition::from_physical((x, y), dpi_factor);
1471+
subclass_input.send_event(Event::WindowEvent {
1472+
window_id: RootWindowId(WindowId(window)),
1473+
event: WindowEvent::Touch(Touch {
1474+
phase: if pointer_info.pointerFlags & winuser::POINTER_FLAG_DOWN != 0 {
1475+
TouchPhase::Started
1476+
} else if pointer_info.pointerFlags & winuser::POINTER_FLAG_UP != 0 {
1477+
TouchPhase::Ended
1478+
} else if pointer_info.pointerFlags & winuser::POINTER_FLAG_UPDATE != 0 {
1479+
TouchPhase::Moved
1480+
} else {
1481+
continue;
1482+
},
1483+
location,
1484+
id: pointer_info.pointerId as u64,
1485+
device_id: DEVICE_ID,
1486+
}),
1487+
});
1488+
}
1489+
1490+
winuser::SkipPointerFrameMessages(pointer_id);
1491+
0
1492+
}
1493+
14361494
winuser::WM_SETFOCUS => {
14371495
use crate::event::WindowEvent::Focused;
14381496
subclass_input.send_event(Event::WindowEvent {

0 commit comments

Comments
 (0)