Add Touch events for win32. (#377)

* Add Touch events for win32.

* Add entry to CHANGELOG.md
This commit is contained in:
cpardotortosa 2018-04-05 21:25:37 +02:00 committed by Francesca Frangipane
parent 1c4973d5b7
commit 580321b56f
3 changed files with 47 additions and 1 deletions

View file

@ -4,6 +4,7 @@
- Dead keys now work properly on X11, no longer resulting in a panic. - Dead keys now work properly on X11, no longer resulting in a panic.
- On X11, input method creation first tries to use the value from the user's `XMODIFIERS` environment variable, so application developers should no longer need to manually call `XSetLocaleModifiers`. If that fails, fallbacks are tried, which should prevent input method initialization from ever outright failing. - On X11, input method creation first tries to use the value from the user's `XMODIFIERS` environment variable, so application developers should no longer need to manually call `XSetLocaleModifiers`. If that fails, fallbacks are tried, which should prevent input method initialization from ever outright failing.
- Fixed thread safety issues with input methods on X11. - Fixed thread safety issues with input methods on X11.
- Add support for `Touch` for win32 backend.
# Version 0.11.3 (2018-03-28) # Version 0.11.3 (2018-03-28)

View file

@ -26,7 +26,7 @@ use std::sync::Mutex;
use std::sync::Condvar; use std::sync::Condvar;
use std::thread; use std::thread;
use winapi::shared::minwindef::{LOWORD, HIWORD, DWORD, WPARAM, LPARAM, UINT, LRESULT, MAX_PATH}; use winapi::shared::minwindef::{LOWORD, HIWORD, DWORD, WPARAM, LPARAM, INT, UINT, LRESULT, MAX_PATH};
use winapi::shared::windef::{HWND, POINT}; use winapi::shared::windef::{HWND, POINT};
use winapi::shared::windowsx; use winapi::shared::windowsx;
use winapi::um::{winuser, shellapi, processthreadsapi}; use winapi::um::{winuser, shellapi, processthreadsapi};
@ -44,6 +44,8 @@ use KeyboardInput;
use WindowAttributes; use WindowAttributes;
use WindowEvent; use WindowEvent;
use WindowId as SuperWindowId; use WindowId as SuperWindowId;
use events::{Touch, TouchPhase};
/// 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)]
@ -730,6 +732,40 @@ pub unsafe extern "system" fn callback(window: HWND, msg: UINT,
} }
}, },
winuser::WM_TOUCH => {
let pcount = LOWORD( wparam as DWORD ) as usize;
let mut inputs = Vec::with_capacity( pcount );
inputs.set_len( pcount );
let htouch = lparam as winuser::HTOUCHINPUT;
if winuser::GetTouchInputInfo( htouch, pcount as UINT,
inputs.as_mut_ptr(),
mem::size_of::<winuser::TOUCHINPUT>() as INT ) > 0 {
for input in &inputs {
send_event( Event::WindowEvent {
window_id: SuperWindowId(WindowId(window)),
event: WindowEvent::Touch(Touch {
phase:
if input.dwFlags & winuser::TOUCHEVENTF_DOWN != 0 {
TouchPhase::Started
} else if input.dwFlags & winuser::TOUCHEVENTF_UP != 0 {
TouchPhase::Ended
} else if input.dwFlags & winuser::TOUCHEVENTF_MOVE != 0 {
TouchPhase::Moved
} else {
continue;
},
location: ((input.x as f64) / 100f64,
(input.y as f64) / 100f64),
id: input.dwID as u64,
device_id: DEVICE_ID,
})
});
}
}
winuser::CloseTouchInputHandle( htouch );
0
}
winuser::WM_SETFOCUS => { winuser::WM_SETFOCUS => {
use events::WindowEvent::{Focused, CursorMoved}; use events::WindowEvent::{Focused, CursorMoved};
send_event(Event::WindowEvent { send_event(Event::WindowEvent {

View file

@ -473,6 +473,15 @@ unsafe fn init(window: WindowAttributes, pl_attribs: PlatformSpecificWindowBuild
winuser::RegisterRawInputDevices(&rid, 1, mem::size_of::<winuser::RAWINPUTDEVICE>() as u32); winuser::RegisterRawInputDevices(&rid, 1, mem::size_of::<winuser::RAWINPUTDEVICE>() as u32);
} }
// Register for touch events if applicable
{
let digitizer = winuser::GetSystemMetrics( winuser::SM_DIGITIZER ) as u32;
if digitizer & winuser::NID_READY != 0 {
winuser::RegisterTouchWindow( real_window.0, winuser::TWF_WANTPALM );
}
}
// 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: winuser::IDC_ARROW, // use arrow by default cursor: winuser::IDC_ARROW, // use arrow by default