diff --git a/CHANGELOG.md b/CHANGELOG.md index e6e138db..0ec68f6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - 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. - Fixed thread safety issues with input methods on X11. +- Add support for `Touch` for win32 backend. # Version 0.11.3 (2018-03-28) diff --git a/src/platform/windows/events_loop.rs b/src/platform/windows/events_loop.rs index 1a62c6ab..e9bbc3cd 100644 --- a/src/platform/windows/events_loop.rs +++ b/src/platform/windows/events_loop.rs @@ -26,7 +26,7 @@ use std::sync::Mutex; use std::sync::Condvar; 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::windowsx; use winapi::um::{winuser, shellapi, processthreadsapi}; @@ -44,6 +44,8 @@ use KeyboardInput; use WindowAttributes; use WindowEvent; use WindowId as SuperWindowId; +use events::{Touch, TouchPhase}; + /// Contains information about states and the window that the callback is going to use. #[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::() 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 => { use events::WindowEvent::{Focused, CursorMoved}; send_event(Event::WindowEvent { diff --git a/src/platform/windows/window.rs b/src/platform/windows/window.rs index 2211e763..7aab3fca 100644 --- a/src/platform/windows/window.rs +++ b/src/platform/windows/window.rs @@ -473,6 +473,15 @@ unsafe fn init(window: WindowAttributes, pl_attribs: PlatformSpecificWindowBuild winuser::RegisterRawInputDevices(&rid, 1, mem::size_of::() 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 let window_state = Arc::new(Mutex::new(events_loop::WindowState { cursor: winuser::IDC_ARROW, // use arrow by default