JFLib

plat/win_pen.rs (Windows)#

Source: lib/plat/win_pen.rs

win_pen -- (PN1) pen input on Windows: WM_POINTER* of pen pointers (Windows 8+)
                                                   [src/plat/win/win_pen.s; PEN_INPUT.md]

  win_pointer(hwnd, msg, wparam, w) -> true handled (the window procedure returns 0), false
       = on to DefWindowProc.  Called by the window procedure (win_api.rs) for
       WM_POINTERUPDATE .. WM_POINTERCAPTURECHANGED with the event window = w.
  pen_devices() -> pens / pen tablets attached (GetPointerDevices; -1 = the API is missing)
  pen_api_set(Some(api))   (test aid) the pointer API through the given functions instead
       of user32's (plattest's fakes); None = back to user32 (loaded again on first use)

Pointers of type PT_PEN are handled here, fingers (PT_TOUCH) in win_touch.rs.  EnableMouseInPointer
is never called, so the mouse keeps sending WM_MOUSEMOVE / WM_*BUTTON*; every pointer the API cannot
describe goes on to DefWindowProc, which turns it into mouse messages as before.  A handled
pen message produces no mouse message.  With pen input off (pen_enable(false)) no pen is
handled: pens arrive as the system's mouse emulation.
  WM_POINTERUPDATE   every coalesced sample since the last message (GetPointerPenInfoHistory,
                     oldest first, at most PEN_HIST) -> E_MOVE with pen data
  WM_POINTERDOWN     tip contact -> E_DOWN BTN_LEFT, or BTN_RIGHT while the barrel button is
                     held (PEN_FLAG_BARREL / POINTER_FLAG_SECONDBUTTON), like paint.net
  WM_POINTERUP       E_UP of the button of the press
  WM_POINTERLEAVE    E_LEAVE (no button held)    WM_POINTERCAPTURECHANGED  E_UP if held
Pen data (evq_pen_data): pressure 0..1024 -> 1..PRESSURE_ONE (PEN_MASK_PRESSURE, else none),
PEN_FLAG_INVERTED / PEN_FLAG_ERASER -> PTR_ERASER, tilt x / y in degrees.  The API's results
are not trusted: counts are clamped, positions go through ScreenToClient.
PEN_HIST: usize = 16  // samples per WM_POINTERUPDATE
  • struct PenInfo one sample of the pointer API: the POINTER_PEN_INFO fields the pen path reads

    • flags: u32 -- POINTER_INFO.pointerFlags
    • x: i32 -- ptPixelLocation (screen px)
    • y: i32
    • pen_flags: u32 -- PEN_FLAG_*
    • pen_mask: u32 -- PEN_MASK_*
    • pressure: u32 -- 0..1024
    • tilt_x: i32 -- -90..90 degrees
    • tilt_y: i32
  • struct PenApi the pointer API (functions that are missing are None)

    • ptype: Option<fn(u32) -> Option<u32>> -- GetPointerType(id) -> the POINTER_INPUT_TYPE (None: failed)
    • info: Option<fn(u32) -> Option<PenInfo>> -- GetPointerPenInfo(id) -> the newest sample
    • hist: Option<fn(u32, &mut u32, &mut [PenInfo]) -> bool> -- GetPointerPenInfoHistory(id, &count, out): newest first, at most *count (the room) records; *count = the samples available -> false: failed
    • devs: Option<fn(&mut u32, Option<&mut [u32]>) -> bool> -- GetPointerDevices(&count, types): *count = the devices; with Some(types) (*count of them) their POINTER_DEVICE_TYPEs -> false: failed
  • fn pen_api_set(api: Option<PenApi>) (test aid) the pointer API through api (None: user32's again, loaded on first use)

  • fn pen_devices() -> i32 pens / pen tablets attached, -1 = no pointer API [plat_pen_devices]

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