RealTimeStylus touch contact width and height use different units on different touch screens
I'm building a native Win32 ink application that uses the RealTimeStylus (RTS) COM API (IRealTimeStylus + IStylusSyncPlugin, MultiTouchEnabled = TRUE, SetAllTabletsMode(TRUE)). We also support Windows 7, so we need the touch contact size from RTS itself, without relying on the WM_POINTER APIs.
I request GUID_PACKETPROPERTY_GUID_WIDTH and GUID_PACKETPROPERTY_GUID_HEIGHT in the packet description. The values arrive, but I can't find a documented way to convert them to pixels. On two devices, the same conversion is off by a factor of about 8 in area on one device and about 40 on the other. Each device needs a different formula.
I use the rcContactRaw from GetPointerTouchInfo on the same machine as the pixel reference, measured in a separate run without RTS (see below). On both devices, it equals the HID Width/Height usage (read with GetRawPointerDeviceData) * screen pixels / X-Y logical range, to within 1 px.
Notation
All values come from IRealTimeStylus::GetPacketDescriptionData and the PROPERTY_METRICS of each packet property.
- S:
pfInkToDeviceScaleX/Yof the first tablet context (the mouse context). Packet X * S gives client pixels on both devices, as expected. - C:
pfInkToDeviceScaleX/Yof the touch context that produced the packet. - spanToAxis: (X counts per cm) / (WIDTH counts per cm), from the declared
fResolutionandUnitsof each property. The same applies to Y and HEIGHT.
Device 1: Surface Pro 11, Windows 11 ARM64, 2880x1920 display
Touch context metrics (identical at every scale factor):
PropertyUnitsResolutionLogical maxXcm1000.2927388Ycm1000.4418258WIDTHcm1000.0027388HEIGHTcm1000.0018258The same finger touch, where HID Width = 1217 and rcContactRaw width = 127-128 px:
Display scaleSC (x)RTS packet WIDTHWIDTH * C100%0.0377950.35942333861217200%0.0755910.71884516931217300%0.1133861.07826811291217So on this device, the packet WIDTH changes with the DPI, like X/Y in ink space. raw * spanToAxis * S matches rcContactRaw at every scale (area ratio 0.995-1.010).
Device 2: large-format display with a four-side infrared touch frame, 3840x2160, 300% scale, Windows 10 64-bit
Touch context metrics:
PropertyUnitsResolutionLogical maxXcm377.195832767Ycm657.5757432767WIDTHcm10018950HEIGHTcm10010660S = 0.11338583, C = (0.9675294, 1.7200525), so S/C = (0.11719, 0.06592) = (3840/32767, 2160/32767).
In one press, the RTS packet was WIDTH * HEIGHT = 1270 * 2059 (median of the stable phase). A Pointer press in the same session had HID 1189 * 1987. The RTS value is about the raw HID count; it is not scaled the way device 1 is. Here raw * S / C, which treats the value as X/Y logical counts, matches rcContactRaw (area ratio 0.98). The formula that fits device 1 gives about 40x the area, because spanToAxis is 3.77 / 6.58 on this device.
Summary
Formula (area / rcContactRaw area)Surface 100%Surface 200%Surface 300%IR frame 300%raw * spanToAxis * S0.9971.0100.99540.4raw * S / C7.711.950.860.979raw * spanToAxis * S / C7.721.960.8624.3The declared WIDTH/HEIGHT range on device 2 (1895 * 1066 mm at 0.1 mm per count) is almost the same as the physical size that the mouse context reports for the whole screen (1900 * 1070 mm). It is very different from the X/Y range (868.7 * 498.3 mm). If the firmware really reported 0.1 mm per count, the true contact would be about 5x larger in area than rcContactRaw. Windows' own Pointer conversion seems to ignore the WIDTH/HEIGHT metrics and use the X/Y logical range.
WM_POINTER is not delivered while RTS is enabled
I first tried to read rcContactRaw for the same contacts on the same window, to calibrate the RTS values on Windows 8 and later. On the Surface Pro 11, once RTS is enabled on the window, the window receives no WM_POINTERDOWN / WM_POINTERUPDATE / WM_POINTERUP for touch at all. It only receives one WM_POINTERCAPTURECHANGED per contact, right after the RTS StylusUp of that contact. Without RTS, the same window receives the normal touch WM_POINTER messages. So the comparison above uses separate runs with similar presses.
Questions
- In an RTS packet from a touch tablet context, which unit or coordinate space are WIDTH and HEIGHT in? Ink space (HIMETRIC, like X/Y), the digitizer logical counts of the X/Y axes, or the units declared in the WIDTH/HEIGHT
PROPERTY_METRICS? - Why does the value scale with the window DPI on device 1 but not on device 2? Does this depend on the HID descriptor, the driver, or a Windows component, and can an application detect which case applies?
- Is there a supported way to convert RTS WIDTH/HEIGHT to pixels that works for any touch device, including on Windows 7?
- Is it by design that an HWND with RTS enabled stops receiving touch WM_POINTER messages? Is there a supported way to get both the RTS packets and the Pointer contact rectangle for the same touch contact, for example from another window or another API?
Minimal repro
A single-file console program (Windows SDK only). Build it from a Developer Command Prompt with cl /std:c++20 /EHsc /W4 rts_contact_repro.cpp, run it from that console, and touch the window with one finger.
-
rts_contact_repro.exe: enables RTS on the window. Prints the property metrics, the raw RTS WIDTH/HEIGHT of each touch packet with both candidate conversions, and every WM_POINTER message the window still receives. -
rts_contact_repro.exe pointer: does not create RTS. Prints thercContactRawsize of each touch frame.
Thanks for any pointers to documentation or to the component that defines this behavior.