Ignore pen input on Web

This commit is contained in:
dAxpeDDa 2023-06-02 13:16:04 +02:00 committed by daxpedda
parent 642ce2bfa7
commit 82d0380ea6
2 changed files with 41 additions and 30 deletions

View file

@ -62,6 +62,7 @@ And please only add new entries to the top of this list, right below the `# Unre
- On Web, handle coalesced pointer events, which increases the resolution of pointer inputs. - On Web, handle coalesced pointer events, which increases the resolution of pointer inputs.
- **Breaking:** On Web, `instant` is now replaced by `web_time`. - **Breaking:** On Web, `instant` is now replaced by `web_time`.
- On Windows, port to `windows-sys` version 0.48.0. - On Windows, port to `windows-sys` version 0.48.0.
- On Web, fix pen treated as mouse input.
# 0.28.6 # 0.28.6

View file

@ -41,7 +41,7 @@ impl PointerHandler {
// touch events are handled separately // touch events are handled separately
// handling them here would produce duplicate mouse events, inconsistent with // handling them here would produce duplicate mouse events, inconsistent with
// other platforms. // other platforms.
if event.pointer_type() == "touch" { if event.pointer_type() != "mouse" {
return; return;
} }
@ -60,7 +60,7 @@ impl PointerHandler {
// touch events are handled separately // touch events are handled separately
// handling them here would produce duplicate mouse events, inconsistent with // handling them here would produce duplicate mouse events, inconsistent with
// other platforms. // other platforms.
if event.pointer_type() == "touch" { if event.pointer_type() != "mouse" {
return; return;
} }
@ -82,19 +82,19 @@ impl PointerHandler {
self.on_pointer_release = Some(canvas_common.add_user_event( self.on_pointer_release = Some(canvas_common.add_user_event(
"pointerup", "pointerup",
move |event: PointerEvent| { move |event: PointerEvent| {
if event.pointer_type() == "touch" { match event.pointer_type().as_str() {
touch_handler( "touch" => touch_handler(
event.pointer_id(), event.pointer_id(),
event::touch_position(&event, &canvas) event::touch_position(&event, &canvas)
.to_physical(super::super::scale_factor()), .to_physical(super::super::scale_factor()),
Force::Normalized(event.pressure() as f64), Force::Normalized(event.pressure() as f64),
); ),
} else { "mouse" => mouse_handler(
mouse_handler(
event.pointer_id(), event.pointer_id(),
event::mouse_button(&event).expect("no mouse button released"), event::mouse_button(&event).expect("no mouse button released"),
event::mouse_modifiers(&event), event::mouse_modifiers(&event),
); ),
_ => (),
} }
}, },
)); ));
@ -113,25 +113,29 @@ impl PointerHandler {
self.on_pointer_press = Some(canvas_common.add_user_event( self.on_pointer_press = Some(canvas_common.add_user_event(
"pointerdown", "pointerdown",
move |event: PointerEvent| { move |event: PointerEvent| {
if event.pointer_type() == "touch" { match event.pointer_type().as_str() {
touch_handler( "touch" => {
event.pointer_id(), touch_handler(
event::touch_position(&event, &canvas) event.pointer_id(),
.to_physical(super::super::scale_factor()), event::touch_position(&event, &canvas)
Force::Normalized(event.pressure() as f64), .to_physical(super::super::scale_factor()),
); Force::Normalized(event.pressure() as f64),
} else { );
mouse_handler( }
event.pointer_id(), "mouse" => {
event::mouse_position(&event).to_physical(super::super::scale_factor()), mouse_handler(
event::mouse_button(&event).expect("no mouse button pressed"), event.pointer_id(),
event::mouse_modifiers(&event), event::mouse_position(&event).to_physical(super::super::scale_factor()),
); event::mouse_button(&event).expect("no mouse button pressed"),
event::mouse_modifiers(&event),
);
// Error is swallowed here since the error would occur every time the mouse is // Error is swallowed here since the error would occur every time the mouse is
// clicked when the cursor is grabbed, and there is probably not a situation where // clicked when the cursor is grabbed, and there is probably not a situation where
// this could fail, that we care if it fails. // this could fail, that we care if it fails.
let _e = canvas.set_pointer_capture(event.pointer_id()); let _e = canvas.set_pointer_capture(event.pointer_id());
}
_ => (),
} }
}, },
)); ));
@ -169,16 +173,22 @@ impl PointerHandler {
fn has_get_coalesced_events(this: &PointerEventExt) -> JsValue; fn has_get_coalesced_events(this: &PointerEventExt) -> JsValue;
} }
if event.pointer_type() == "touch" && prevent_default { match event.pointer_type().as_str() {
// prevent scroll on mobile web "touch" => {
event.prevent_default(); if prevent_default {
// prevent scroll on mobile web
event.prevent_default();
}
}
"mouse" => (),
_ => return,
} }
let event: PointerEventExt = event.unchecked_into(); let event: PointerEventExt = event.unchecked_into();
let id = event.pointer_id(); let id = event.pointer_id();
// cache buttons if the pointer is a mouse // cache buttons if the pointer is a mouse
let mouse = (event.pointer_type() != "touch").then(|| { let mouse = (event.pointer_type() == "mouse").then(|| {
( (
event::mouse_modifiers(&event), event::mouse_modifiers(&event),
event::mouse_buttons(&event), event::mouse_buttons(&event),