Merge pull request #213 from LPGhatguy/windows-raw-mouse

Implement raw mouse motion for Windows
This commit is contained in:
tomaka 2017-07-05 09:38:09 +02:00 committed by GitHub
commit 601599eb0a
2 changed files with 31 additions and 5 deletions

View file

@ -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)
}

View file

@ -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