mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-25 23:01:30 +11:00
Merge pull request #213 from LPGhatguy/windows-raw-mouse
Implement raw mouse motion for Windows
This commit is contained in:
commit
601599eb0a
|
@ -42,6 +42,7 @@ use KeyboardInput;
|
||||||
use WindowAttributes;
|
use WindowAttributes;
|
||||||
use WindowEvent;
|
use WindowEvent;
|
||||||
use WindowId as SuperWindowId;
|
use WindowId as SuperWindowId;
|
||||||
|
use AxisId;
|
||||||
|
|
||||||
/// Contains information about states and the window that the callback is going to use.
|
/// Contains information about states and the window that the callback is going to use.
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
@ -556,6 +557,7 @@ pub unsafe extern "system" fn callback(window: winapi::HWND, msg: winapi::UINT,
|
||||||
},
|
},
|
||||||
|
|
||||||
winapi::WM_INPUT => {
|
winapi::WM_INPUT => {
|
||||||
|
use events::DeviceEvent::Motion;
|
||||||
let mut data: winapi::RAWINPUT = mem::uninitialized();
|
let mut data: winapi::RAWINPUT = mem::uninitialized();
|
||||||
let mut data_size = mem::size_of::<winapi::RAWINPUT>() as winapi::UINT;
|
let mut data_size = mem::size_of::<winapi::RAWINPUT>() as winapi::UINT;
|
||||||
user32::GetRawInputData(mem::transmute(lparam), winapi::RID_INPUT,
|
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);
|
mem::size_of::<winapi::RAWINPUTHEADER>() as winapi::UINT);
|
||||||
|
|
||||||
if data.header.dwType == winapi::RIM_TYPEMOUSE {
|
if data.header.dwType == winapi::RIM_TYPEMOUSE {
|
||||||
let _x = data.mouse.lLastX; // FIXME: this is not always the relative movement
|
if data.mouse.usFlags & winapi::MOUSE_MOVE_RELATIVE == winapi::MOUSE_MOVE_RELATIVE {
|
||||||
let _y = data.mouse.lLastY;
|
let x = data.mouse.lLastX as f64;
|
||||||
// TODO:
|
let y = data.mouse.lLastY as f64;
|
||||||
//send_event(window, Event::MouseRawMovement { x: x, y: y });
|
|
||||||
|
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
|
0
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
user32::DefWindowProcW(window, msg, wparam, lparam)
|
user32::DefWindowProcW(window, msg, wparam, lparam)
|
||||||
}
|
}
|
||||||
|
|
|
@ -389,6 +389,17 @@ unsafe fn init(window: WindowAttributes, pl_attribs: PlatformSpecificWindowBuild
|
||||||
WindowWrapper(handle, hdc)
|
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
|
// Creating a mutex to track the current window state
|
||||||
let window_state = Arc::new(Mutex::new(events_loop::WindowState {
|
let window_state = Arc::new(Mutex::new(events_loop::WindowState {
|
||||||
cursor: winapi::IDC_ARROW, // use arrow by default
|
cursor: winapi::IDC_ARROW, // use arrow by default
|
||||||
|
|
Loading…
Reference in a new issue