mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-25 14:51:30 +11:00
Implement raw mouse motion for Windows
This commit is contained in:
parent
e196f80e98
commit
0371b6573f
|
@ -42,6 +42,7 @@ use KeyboardInput;
|
|||
use WindowAttributes;
|
||||
use WindowEvent;
|
||||
use WindowId as SuperWindowId;
|
||||
use AxisId;
|
||||
|
||||
/// Contains information about states and the window that the callback is going to use.
|
||||
#[derive(Clone)]
|
||||
|
@ -556,6 +557,7 @@ pub unsafe extern "system" fn callback(window: winapi::HWND, msg: winapi::UINT,
|
|||
},
|
||||
|
||||
winapi::WM_INPUT => {
|
||||
use events::DeviceEvent::Motion;
|
||||
let mut data: winapi::RAWINPUT = mem::uninitialized();
|
||||
let mut data_size = mem::size_of::<winapi::RAWINPUT>() as winapi::UINT;
|
||||
user32::GetRawInputData(mem::transmute(lparam), winapi::RID_INPUT,
|
||||
|
@ -563,13 +565,26 @@ pub unsafe extern "system" fn callback(window: winapi::HWND, msg: winapi::UINT,
|
|||
mem::size_of::<winapi::RAWINPUTHEADER>() as winapi::UINT);
|
||||
|
||||
if data.header.dwType == winapi::RIM_TYPEMOUSE {
|
||||
let _x = data.mouse.lLastX; // FIXME: this is not always the relative movement
|
||||
let _y = data.mouse.lLastY;
|
||||
// TODO:
|
||||
//send_event(window, Event::MouseRawMovement { x: x, y: y });
|
||||
if data.mouse.usFlags & winapi::MOUSE_MOVE_RELATIVE == winapi::MOUSE_MOVE_RELATIVE {
|
||||
let x = data.mouse.lLastX as f64;
|
||||
let y = data.mouse.lLastY as f64;
|
||||
|
||||
if x != 0.0 {
|
||||
send_event(Event::DeviceEvent {
|
||||
device_id: DEVICE_ID,
|
||||
event: Motion { axis: AxisId(0), value: x }
|
||||
});
|
||||
}
|
||||
|
||||
if y != 0.0 {
|
||||
send_event(Event::DeviceEvent {
|
||||
device_id: DEVICE_ID,
|
||||
event: Motion { axis: AxisId(1), value: y }
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
0
|
||||
|
||||
} else {
|
||||
user32::DefWindowProcW(window, msg, wparam, lparam)
|
||||
}
|
||||
|
|
|
@ -389,6 +389,17 @@ unsafe fn init(window: WindowAttributes, pl_attribs: PlatformSpecificWindowBuild
|
|||
WindowWrapper(handle, hdc)
|
||||
};
|
||||
|
||||
// Set up raw mouse input
|
||||
{
|
||||
let mut rid: winapi::RAWINPUTDEVICE = mem::uninitialized();
|
||||
rid.usUsagePage = winapi::HID_USAGE_PAGE_GENERIC;
|
||||
rid.usUsage = winapi::HID_USAGE_GENERIC_MOUSE;
|
||||
rid.dwFlags = 0;
|
||||
rid.hwndTarget = real_window.0;
|
||||
|
||||
user32::RegisterRawInputDevices(&rid, 1, mem::size_of::<winapi::RAWINPUTDEVICE>() as u32);
|
||||
}
|
||||
|
||||
// Creating a mutex to track the current window state
|
||||
let window_state = Arc::new(Mutex::new(events_loop::WindowState {
|
||||
cursor: winapi::IDC_ARROW, // use arrow by default
|
||||
|
|
Loading…
Reference in a new issue