AppKit: Add tablet tool support#4593
Conversation
kchibisov
left a comment
There was a problem hiding this comment.
Just by looking into docs for tablet, it seems that tablet events has a property of
NSTabletPointEventSubtype or NSTabletPoint
Also, how handling works if you hover with tablet over window and also use mouse? is mouse treated as tablet in such case?
| if device == NSPointingDeviceType::Eraser { | ||
| TabletToolKind::Eraser | ||
| } else if device == NSPointingDeviceType::Cursor { | ||
| // AppKit's `Cursor` is the tablet puck; winit's closest tool kind is `Mouse`. | ||
| TabletToolKind::Mouse | ||
| } else { | ||
| // `Pen` and `Unknown` both map to a pen; it is the most common tool and a | ||
| // reasonable default for hardware that does not report a specific type. | ||
| TabletToolKind::Pen | ||
| } |
| Some((kind, data)) => ButtonSource::TabletTool { | ||
| kind, | ||
| button: match button { | ||
| // Mirror winit-core's `TabletToolButton` to `MouseButton` conversion table. | ||
| MouseButton::Left => TabletToolButton::Contact, | ||
| MouseButton::Right => TabletToolButton::Barrel, | ||
| MouseButton::Middle => TabletToolButton::Other(1), | ||
| MouseButton::Back => TabletToolButton::Other(3), | ||
| MouseButton::Forward => TabletToolButton::Other(4), | ||
| other => TabletToolButton::Other(other as u16), | ||
| }, | ||
| data, | ||
| }, |
There was a problem hiding this comment.
maybe extract all of that to tablet button?
|
Thank you for the review!
Good catch. I changed it to kind=unknown for now, because that seems to be the only 100% correct option and winit is a foundation library. Besides
Right, and I think we need the subtype one here. The tablet NSEvents look the same as mouse events if you only look at .type (NSEventType) but the .subtype field (NSEventSubtype) has the tablet details we want. I think the logs make it a little clearer. Inline comments addressedI also addressed the inline comments. The device-type chain is now a match, and the button mapping is extracted into a Here are summarized logs of
|
Add support to winit-appkit for tablet tools (pen/eraser) with rich inputs like pressure and tilt.
Apple documents that tool type is only available in proximity events (pointingDeviceType is "valid for mouse events with subtype NSTabletProximityEventSubtype and for NSTabletProximity events") so we keep that information cached in the ViewState.
Tilt gets converted from -1,1 to -90,90.
yis negated, since AppKit is y-up and winit documents positive y as toward the user.Tested with a toy app that tracks a Wacom tablet pressure (sphere size) and tilt (the vector)
changelogmodule if knowledge of this change could be valuable to users