-
Notifications
You must be signed in to change notification settings - Fork 920
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pen/Stylus support #3810
base: master
Are you sure you want to change the base?
Pen/Stylus support #3810
Conversation
|
||
#[derive(Clone, Copy, Debug, PartialEq)] | ||
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] | ||
pub struct ToolState { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would be glad for an alternative to the term "Tool" or "State".
Originally got the idea from Linux, because we need a term that applies to all sorts of different tools.
But honestly I think "Pen" would have been fine as well?
Maybe "Stylus" would fit all the possible tools:
- Pen
- Eraser
- Brush
- Pencil
- Airbrush
This aligns with the future Std type name and allows us to introduce `LazyCell`.
aac4f31
to
c3b84f8
Compare
event: WindowEvent::CursorMoved { | ||
device_id: mkdid(util::VIRTUAL_CORE_POINTER), | ||
position: location.cast(), | ||
r#type: CursorType::Mouse, | ||
}, | ||
}; | ||
callback(&self.target, event); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mouse cursor position changes when touch events are received.
Only the first concurrently active touch ID moves the mouse cursor.
This is a bit confusing to me, especially because I believe it doesn't map to other backends. Why do we tell the user that the mouse moves if the cursor moves with touch input?
Mouse input is cursor movement, but not all cursor movement is mouse input.
I'm really not sure what the purpose of this is.
@@ -262,12 +266,12 @@ pub enum WindowEvent { | |||
/// [`transform`]: https://developer.mozilla.org/en-US/docs/Web/CSS/transform | |||
CursorLeft { device_id: DeviceId }, | |||
|
|||
/// A cursor button press has been received. | |||
CursorInput { device_id: DeviceId, state: ElementState, button: CursorButton }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point we should probably rename "Cursor" to "Pointer".
"Cursor" commonly refers to the visual representation of an input device on the screen.
But "Pointer" is a broader category that can include any device and is not specific to its visual representation on the screen.
I couldn't really find anything concrete on this online.
WDYT?
@@ -1121,7 +1125,7 @@ impl EventProcessor { | |||
|
|||
let event = Event::WindowEvent { | |||
window_id, | |||
event: WindowEvent::CursorMoved { device_id, position }, | |||
event: WindowEvent::CursorMoved { device_id, position, r#type: CursorType::Mouse }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know how to ask X11 what kind of device this is.
Right now it reports my pen as a mouse.
Same in CursorEntered
and CursorLeft
.
Same issue in DeviceEvent
s.
Interestingly MouseWheel
contains the pen angles, but MouseMotion
should probably be excluded for pens as well, unless we want to rename it to CursorMotion
(or PointerMotion
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay I figured this one out as well.
After digging around in Chromium for a while I found how they determined if this was a stylus or not.
After some digging, I also found that Glazier was doing something quite similar, in addition to detecting erasers (in a hacky way, but it works). There is a lot to learn from them when actually implementing the backends for Pens/Stylus's.
Additionally, after some more digging into X11, I found that there is an alternative to figuring out the type: XListInputDevices
. That's right, using the old XInput version and no way to query individual devices. This exposes what they call "Device Types", which unfortunately don't include pens, but they let you recognize the drawing tablet, which works as well.
I found that Chromium was doing something similar for touchpads, but not for pens (and a comment in a much older revision explaining this as well). So maybe this will be useful for us in the future.
let event = Event::WindowEvent { | ||
window_id, | ||
event: WindowEvent::CursorMoved { device_id: mkdid(pointer_id as _), position }, | ||
event: WindowEvent::CursorMoved { | ||
device_id: mkdid(pointer_id as _), | ||
position, | ||
r#type: CursorType::Mouse, | ||
}, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also a bit confusing to me.
AFAIU focusing the window is not a mouse event and the mouse didn't move.
let Some(DeviceType::Mouse) = self | ||
.devices | ||
.borrow() | ||
.get(&DeviceId(event.sourceid as xinput::DeviceId)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This came as a surprise to me, but I had to spend quite some time to figure out why this wasn't working for me.
deviceId
here uses the cursor, but sourceId
actually uses the device that moved the cursor. Shouldn't we use that to send DeviceId
to the user?
- This adds pen/stylus support. - Move `Force::Calibrated::altitude_angle` to `ToolAngle::altitude`. - `Force::normalized()` now takes a `Option<ToolAngle>` to calculate the perpendicular force. - Just introducing types, no implementation yet!
Add a new `CursorButton` and `ToolButton` type.
Fixed: device events are emitted regardless of cursor type.
Waiting for #3833.
This implements Pen/Stylus support inspired by the Web Pointer API.
CursorMoved
andMouseInput
(now renamed toCursorInput
.DeviceEvent::MouseWheel
,DeviceEvent::MouseMotion
,WindowEvent::CursorMoved
,WindowEvent::MouseInput
, which I disabled, because users would think all these inputs are mouse. This is also in line with all the other backends, X11 and iOS were the only ones emitting any pen events.Force::Calibrated::altitude_angle
when a pen is used. I removed this and disabled pen events as well, as this information is now part of theToolState
, which can be used withForce::normalized()
to get the old behavior back.Open questions:
DeviceEvent::MouseMotion
toDeviceEvent::CursorMotion
?Follow-up:
Public API changes
Fixes #99.