JFLib

plat/win_touch.rs (Windows)#

Source: lib/plat/win_touch.rs

win_touch -- fingers on Windows: WM_POINTER* / WM_NCPOINTER* of touch pointers (Windows 8+)

  pointer(hwnd, msg, id, w) -> handled    (win_pen.rs, for a pointer of type PT_TOUCH): a finger
  nc_pointer(hwnd, msg, wp, w) -> handled (window procedure) a finger over the non-client area
  activate(hwnd, wp, w) -> the answer to WM_POINTERACTIVATE, None: the system's
  begin_drag(w, edges) -> true: a finger is down on window w and the window follows it from now on
       (win_begin_move / win_begin_resize: the system's move loop follows only a mouse)
  mouse_is_stale() -> true: this WM_MOUSEMOVE is no mouse (window procedure)
  feedback_off(hwnd)      no system visuals for a touch of this window
  touch_api_set(Some(api))   (test aid) the touch calls through the given functions (plattest's
       fakes, like pen_api_set); None = user32's again
  jfgui_TOUCH_LOG=1          stderr: where each finger came down and whose it became (for a device
       nobody at the desk has)
  win_touch_primary() -> a tablet in slate posture    win_touch_keyboard(w, show) the on-screen keyboard

Every finger goes to plat::finger: no gesture is decided here (ui/touch.rs).  A handled pointer
message never reaches DefWindowProc, and that is the point: DefWindowProc turns a finger into mouse
messages, a pinch into Ctrl + wheel (preset steps), a two-finger pan into nothing at all and a
press and hold into a right click.  EnableMouseInPointer stays off: the mouse keeps its messages.

Which window a finger belongs to: a contact is wide and the system gives it to a window frame it
touches (measured with InjectTouchInput, a contact 60 px wide): a finger on JFPainter's zoom slider
arrived as WM_NCPOINTERDOWN HTBOTTOM on the tool window above it, whose invisible resize border ends
at the status bar, and resized that window.  So a finger over a border belongs to the window whose
client area is under its centre (z-order, from the window that got it), also a contact the system
gives to a client area its centre is not in.  With no window there the main window's resize is the
system's; a tool window's frame never is, its resize band for a finger lies inside it (ui edge_grips).
The position of such a contact is not where the finger is: the system moves it onto the frame (17 px off
on the slider above, also ptPixelLocationRaw) and it stays off by that while the contact lives; only the
contact rectangle tells (Slot::adj).
HTCAPTION: a tool window's title bar is the UI's (press and hold, then begin_drag); the main
window's goes to the system (moves, snaps, double tap) unless a small widget is close (a finger that
misses the gear by a hair).

Coordinates come from the pointer's screen position, so the window that was moved under a finger or a
popup window (win_popup.rs: its input belongs to the owner, in the owner's client coordinates) need
nothing else.  The API's results are not trusted: counts are clamped, a finger without a free slot is
nobody's.  A palm is the recogniser's business (ui/touch.rs: the pen comes first); what the system
itself cancels comes through as FingerPhase::Cancel.
  • struct TouchInfo one sample of the pointer API: the POINTER_TOUCH_INFO fields the finger path reads

    • flags: u32 -- POINTER_INFO.pointerFlags
    • x: i32 -- ptPixelLocation (screen px)
    • y: i32
    • time: u32 -- dwTime (ms, 0: none)
    • middle: Option<[i32; 2]> -- the middle of rcContact, if it has one (screen px)
  • struct TouchApi the touch part of the pointer API (functions that are missing are None)

    • info: Option<fn(u32) -> Option<TouchInfo>> -- GetPointerTouchInfo(id) -> the newest sample
    • hist: Option<fn(u32, &mut u32, &mut [TouchInfo]) -> bool> -- GetPointerTouchInfoHistory(id, &count, out): newest first, at most *count records; *count = the samples available -> false: failed
    • now: Option<fn() -> u32> -- the clock of TouchInfo::time (GetTickCount)
  • fn touch_api_set(api: Option<TouchApi>) (test aid) the touch calls through api (None: user32's again, loaded on first use)

  • fn win_touch_primary() -> bool the main pointer of this machine is a finger right now: a tablet in slate posture

  • fn win_touch_keyboard(w: i32, show: bool) the on-screen keyboard for a text field that got a finger (show), or gone again. InputPane through its interop interface, which takes a desktop window (Windows 10 1809 and later; older ones and a machine without one: nothing happens)

Source: docs/API.md in the JFLib repository.