mirror of
https://github.com/rust-windowing/winit.git
synced 2026-08-29 04:40:04 -04:00
Web: don't block pen input (#3813)
This commit is contained in:
committed by
Kirill Chibisov
parent
4b1aa51094
commit
9ca8c09208
@@ -47,3 +47,4 @@ changelog entry.
|
|||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- On MacOS, fix building with `feature = "rwh_04"`.
|
- On MacOS, fix building with `feature = "rwh_04"`.
|
||||||
|
- On Web, pen events are now routed through to `WindowEvent::Cursor*`.
|
||||||
|
|||||||
@@ -245,21 +245,10 @@ impl Shared {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let pointer_type = event.pointer_type();
|
|
||||||
|
|
||||||
if pointer_type != "mouse" {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// chorded button event
|
// chorded button event
|
||||||
let device_id = RootDeviceId(DeviceId(event.pointer_id()));
|
let device_id = RootDeviceId(DeviceId(event.pointer_id()));
|
||||||
|
|
||||||
if let Some(button) = backend::event::mouse_button(&event) {
|
if let Some(button) = backend::event::mouse_button(&event) {
|
||||||
debug_assert_eq!(
|
|
||||||
pointer_type, "mouse",
|
|
||||||
"expect pointer type of a chorded button event to be a mouse"
|
|
||||||
);
|
|
||||||
|
|
||||||
let state = if backend::event::mouse_buttons(&event).contains(button.into()) {
|
let state = if backend::event::mouse_buttons(&event).contains(button.into()) {
|
||||||
ElementState::Pressed
|
ElementState::Pressed
|
||||||
} else {
|
} else {
|
||||||
@@ -323,10 +312,6 @@ impl Shared {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if event.pointer_type() != "mouse" {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let button = backend::event::mouse_button(&event).expect("no mouse button pressed");
|
let button = backend::event::mouse_button(&event).expect("no mouse button pressed");
|
||||||
runner.send_event(Event::DeviceEvent {
|
runner.send_event(Event::DeviceEvent {
|
||||||
device_id: RootDeviceId(DeviceId(event.pointer_id())),
|
device_id: RootDeviceId(DeviceId(event.pointer_id())),
|
||||||
@@ -346,10 +331,6 @@ impl Shared {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if event.pointer_type() != "mouse" {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let button = backend::event::mouse_button(&event).expect("no mouse button pressed");
|
let button = backend::event::mouse_button(&event).expect("no mouse button pressed");
|
||||||
runner.send_event(Event::DeviceEvent {
|
runner.send_event(Event::DeviceEvent {
|
||||||
device_id: RootDeviceId(DeviceId(event.pointer_id())),
|
device_id: RootDeviceId(DeviceId(event.pointer_id())),
|
||||||
|
|||||||
@@ -258,21 +258,6 @@ impl ActiveEventLoop {
|
|||||||
});
|
});
|
||||||
|
|
||||||
canvas.on_cursor_move(
|
canvas.on_cursor_move(
|
||||||
{
|
|
||||||
let runner = self.runner.clone();
|
|
||||||
let has_focus = has_focus.clone();
|
|
||||||
let modifiers = self.modifiers.clone();
|
|
||||||
|
|
||||||
move |active_modifiers| {
|
|
||||||
if has_focus.get() && modifiers.get() != active_modifiers {
|
|
||||||
modifiers.set(active_modifiers);
|
|
||||||
runner.send_event(Event::WindowEvent {
|
|
||||||
window_id: RootWindowId(id),
|
|
||||||
event: WindowEvent::ModifiersChanged(active_modifiers.into()),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
let runner = self.runner.clone();
|
let runner = self.runner.clone();
|
||||||
let has_focus = has_focus.clone();
|
let has_focus = has_focus.clone();
|
||||||
@@ -372,20 +357,6 @@ impl ActiveEventLoop {
|
|||||||
);
|
);
|
||||||
|
|
||||||
canvas.on_mouse_press(
|
canvas.on_mouse_press(
|
||||||
{
|
|
||||||
let runner = self.runner.clone();
|
|
||||||
let modifiers = self.modifiers.clone();
|
|
||||||
|
|
||||||
move |active_modifiers| {
|
|
||||||
if modifiers.get() != active_modifiers {
|
|
||||||
modifiers.set(active_modifiers);
|
|
||||||
runner.send_event(Event::WindowEvent {
|
|
||||||
window_id: RootWindowId(id),
|
|
||||||
event: WindowEvent::ModifiersChanged(active_modifiers.into()),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
let runner = self.runner.clone();
|
let runner = self.runner.clone();
|
||||||
let modifiers = self.modifiers.clone();
|
let modifiers = self.modifiers.clone();
|
||||||
@@ -450,21 +421,6 @@ impl ActiveEventLoop {
|
|||||||
);
|
);
|
||||||
|
|
||||||
canvas.on_mouse_release(
|
canvas.on_mouse_release(
|
||||||
{
|
|
||||||
let runner = self.runner.clone();
|
|
||||||
let has_focus = has_focus.clone();
|
|
||||||
let modifiers = self.modifiers.clone();
|
|
||||||
|
|
||||||
move |active_modifiers| {
|
|
||||||
if has_focus.get() && modifiers.get() != active_modifiers {
|
|
||||||
modifiers.set(active_modifiers);
|
|
||||||
runner.send_event(Event::WindowEvent {
|
|
||||||
window_id: RootWindowId(id),
|
|
||||||
event: WindowEvent::ModifiersChanged(active_modifiers.into()),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
let runner = self.runner.clone();
|
let runner = self.runner.clone();
|
||||||
let has_focus = has_focus.clone();
|
let has_focus = has_focus.clone();
|
||||||
|
|||||||
@@ -329,51 +329,29 @@ impl Canvas {
|
|||||||
self.pointer_handler.on_cursor_enter(&self.common, handler)
|
self.pointer_handler.on_cursor_enter(&self.common, handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn on_mouse_release<MOD, M, T>(
|
pub fn on_mouse_release<M, T>(&mut self, mouse_handler: M, touch_handler: T)
|
||||||
&mut self,
|
where
|
||||||
modifier_handler: MOD,
|
|
||||||
mouse_handler: M,
|
|
||||||
touch_handler: T,
|
|
||||||
) where
|
|
||||||
MOD: 'static + FnMut(ModifiersState),
|
|
||||||
M: 'static + FnMut(ModifiersState, i32, PhysicalPosition<f64>, MouseButton),
|
M: 'static + FnMut(ModifiersState, i32, PhysicalPosition<f64>, MouseButton),
|
||||||
T: 'static + FnMut(ModifiersState, i32, PhysicalPosition<f64>, Force),
|
T: 'static + FnMut(ModifiersState, i32, PhysicalPosition<f64>, Force),
|
||||||
{
|
{
|
||||||
self.pointer_handler.on_mouse_release(
|
self.pointer_handler.on_mouse_release(&self.common, mouse_handler, touch_handler)
|
||||||
&self.common,
|
|
||||||
modifier_handler,
|
|
||||||
mouse_handler,
|
|
||||||
touch_handler,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn on_mouse_press<MOD, M, T>(
|
pub fn on_mouse_press<M, T>(&mut self, mouse_handler: M, touch_handler: T)
|
||||||
&mut self,
|
where
|
||||||
modifier_handler: MOD,
|
|
||||||
mouse_handler: M,
|
|
||||||
touch_handler: T,
|
|
||||||
) where
|
|
||||||
MOD: 'static + FnMut(ModifiersState),
|
|
||||||
M: 'static + FnMut(ModifiersState, i32, PhysicalPosition<f64>, MouseButton),
|
M: 'static + FnMut(ModifiersState, i32, PhysicalPosition<f64>, MouseButton),
|
||||||
T: 'static + FnMut(ModifiersState, i32, PhysicalPosition<f64>, Force),
|
T: 'static + FnMut(ModifiersState, i32, PhysicalPosition<f64>, Force),
|
||||||
{
|
{
|
||||||
self.pointer_handler.on_mouse_press(
|
self.pointer_handler.on_mouse_press(
|
||||||
&self.common,
|
&self.common,
|
||||||
modifier_handler,
|
|
||||||
mouse_handler,
|
mouse_handler,
|
||||||
touch_handler,
|
touch_handler,
|
||||||
Rc::clone(&self.prevent_default),
|
Rc::clone(&self.prevent_default),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn on_cursor_move<MOD, M, T, B>(
|
pub fn on_cursor_move<M, T, B>(&mut self, mouse_handler: M, touch_handler: T, button_handler: B)
|
||||||
&mut self,
|
where
|
||||||
modifier_handler: MOD,
|
|
||||||
mouse_handler: M,
|
|
||||||
touch_handler: T,
|
|
||||||
button_handler: B,
|
|
||||||
) where
|
|
||||||
MOD: 'static + FnMut(ModifiersState),
|
|
||||||
M: 'static + FnMut(ModifiersState, i32, &mut dyn Iterator<Item = PhysicalPosition<f64>>),
|
M: 'static + FnMut(ModifiersState, i32, &mut dyn Iterator<Item = PhysicalPosition<f64>>),
|
||||||
T: 'static
|
T: 'static
|
||||||
+ FnMut(ModifiersState, i32, &mut dyn Iterator<Item = (PhysicalPosition<f64>, Force)>),
|
+ FnMut(ModifiersState, i32, &mut dyn Iterator<Item = (PhysicalPosition<f64>, Force)>),
|
||||||
@@ -381,7 +359,6 @@ impl Canvas {
|
|||||||
{
|
{
|
||||||
self.pointer_handler.on_cursor_move(
|
self.pointer_handler.on_cursor_move(
|
||||||
&self.common,
|
&self.common,
|
||||||
modifier_handler,
|
|
||||||
mouse_handler,
|
mouse_handler,
|
||||||
touch_handler,
|
touch_handler,
|
||||||
button_handler,
|
button_handler,
|
||||||
|
|||||||
@@ -44,7 +44,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.
|
||||||
let pointer_id = (event.pointer_type() == "mouse").then(|| event.pointer_id());
|
let pointer_id = (event.pointer_type() != "touch").then(|| event.pointer_id());
|
||||||
|
|
||||||
handler(modifiers, pointer_id);
|
handler(modifiers, pointer_id);
|
||||||
}));
|
}));
|
||||||
@@ -61,20 +61,18 @@ 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.
|
||||||
let pointer_id = (event.pointer_type() == "mouse").then(|| event.pointer_id());
|
let pointer_id = (event.pointer_type() != "touch").then(|| event.pointer_id());
|
||||||
|
|
||||||
handler(modifiers, pointer_id);
|
handler(modifiers, pointer_id);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn on_mouse_release<MOD, M, T>(
|
pub fn on_mouse_release<M, T>(
|
||||||
&mut self,
|
&mut self,
|
||||||
canvas_common: &Common,
|
canvas_common: &Common,
|
||||||
mut modifier_handler: MOD,
|
|
||||||
mut mouse_handler: M,
|
mut mouse_handler: M,
|
||||||
mut touch_handler: T,
|
mut touch_handler: T,
|
||||||
) where
|
) where
|
||||||
MOD: 'static + FnMut(ModifiersState),
|
|
||||||
M: 'static + FnMut(ModifiersState, i32, PhysicalPosition<f64>, MouseButton),
|
M: 'static + FnMut(ModifiersState, i32, PhysicalPosition<f64>, MouseButton),
|
||||||
T: 'static + FnMut(ModifiersState, i32, PhysicalPosition<f64>, Force),
|
T: 'static + FnMut(ModifiersState, i32, PhysicalPosition<f64>, Force),
|
||||||
{
|
{
|
||||||
@@ -90,26 +88,23 @@ impl PointerHandler {
|
|||||||
event::mouse_position(&event).to_physical(super::scale_factor(&window)),
|
event::mouse_position(&event).to_physical(super::scale_factor(&window)),
|
||||||
Force::Normalized(event.pressure() as f64),
|
Force::Normalized(event.pressure() as f64),
|
||||||
),
|
),
|
||||||
"mouse" => mouse_handler(
|
_ => mouse_handler(
|
||||||
modifiers,
|
modifiers,
|
||||||
event.pointer_id(),
|
event.pointer_id(),
|
||||||
event::mouse_position(&event).to_physical(super::scale_factor(&window)),
|
event::mouse_position(&event).to_physical(super::scale_factor(&window)),
|
||||||
event::mouse_button(&event).expect("no mouse button released"),
|
event::mouse_button(&event).expect("no mouse button released"),
|
||||||
),
|
),
|
||||||
_ => modifier_handler(modifiers),
|
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn on_mouse_press<MOD, M, T>(
|
pub fn on_mouse_press<M, T>(
|
||||||
&mut self,
|
&mut self,
|
||||||
canvas_common: &Common,
|
canvas_common: &Common,
|
||||||
mut modifier_handler: MOD,
|
|
||||||
mut mouse_handler: M,
|
mut mouse_handler: M,
|
||||||
mut touch_handler: T,
|
mut touch_handler: T,
|
||||||
prevent_default: Rc<Cell<bool>>,
|
prevent_default: Rc<Cell<bool>>,
|
||||||
) where
|
) where
|
||||||
MOD: 'static + FnMut(ModifiersState),
|
|
||||||
M: 'static + FnMut(ModifiersState, i32, PhysicalPosition<f64>, MouseButton),
|
M: 'static + FnMut(ModifiersState, i32, PhysicalPosition<f64>, MouseButton),
|
||||||
T: 'static + FnMut(ModifiersState, i32, PhysicalPosition<f64>, Force),
|
T: 'static + FnMut(ModifiersState, i32, PhysicalPosition<f64>, Force),
|
||||||
{
|
{
|
||||||
@@ -125,8 +120,9 @@ impl PointerHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let modifiers = event::mouse_modifiers(&event);
|
let modifiers = event::mouse_modifiers(&event);
|
||||||
|
let pointer_type = &event.pointer_type();
|
||||||
|
|
||||||
match event.pointer_type().as_str() {
|
match pointer_type.as_str() {
|
||||||
"touch" => {
|
"touch" => {
|
||||||
touch_handler(
|
touch_handler(
|
||||||
modifiers,
|
modifiers,
|
||||||
@@ -135,7 +131,7 @@ impl PointerHandler {
|
|||||||
Force::Normalized(event.pressure() as f64),
|
Force::Normalized(event.pressure() as f64),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
"mouse" => {
|
_ => {
|
||||||
mouse_handler(
|
mouse_handler(
|
||||||
modifiers,
|
modifiers,
|
||||||
event.pointer_id(),
|
event.pointer_id(),
|
||||||
@@ -143,27 +139,27 @@ impl PointerHandler {
|
|||||||
event::mouse_button(&event).expect("no mouse button pressed"),
|
event::mouse_button(&event).expect("no mouse button pressed"),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Error is swallowed here since the error would occur every time the mouse
|
if pointer_type == "mouse" {
|
||||||
// is clicked when the cursor is grabbed, and there
|
// Error is swallowed here since the error would occur every time the
|
||||||
// is probably not a situation where this could
|
// mouse is clicked when the cursor is
|
||||||
// fail, that we care if it fails.
|
// grabbed, and there is probably not a
|
||||||
let _e = canvas.set_pointer_capture(event.pointer_id());
|
// situation where this could fail, that we
|
||||||
|
// care if it fails.
|
||||||
|
let _e = canvas.set_pointer_capture(event.pointer_id());
|
||||||
|
}
|
||||||
},
|
},
|
||||||
_ => modifier_handler(modifiers),
|
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn on_cursor_move<MOD, M, T, B>(
|
pub fn on_cursor_move<M, T, B>(
|
||||||
&mut self,
|
&mut self,
|
||||||
canvas_common: &Common,
|
canvas_common: &Common,
|
||||||
mut modifier_handler: MOD,
|
|
||||||
mut mouse_handler: M,
|
mut mouse_handler: M,
|
||||||
mut touch_handler: T,
|
mut touch_handler: T,
|
||||||
mut button_handler: B,
|
mut button_handler: B,
|
||||||
prevent_default: Rc<Cell<bool>>,
|
prevent_default: Rc<Cell<bool>>,
|
||||||
) where
|
) where
|
||||||
MOD: 'static + FnMut(ModifiersState),
|
|
||||||
M: 'static + FnMut(ModifiersState, i32, &mut dyn Iterator<Item = PhysicalPosition<f64>>),
|
M: 'static + FnMut(ModifiersState, i32, &mut dyn Iterator<Item = PhysicalPosition<f64>>),
|
||||||
T: 'static
|
T: 'static
|
||||||
+ FnMut(ModifiersState, i32, &mut dyn Iterator<Item = (PhysicalPosition<f64>, Force)>),
|
+ FnMut(ModifiersState, i32, &mut dyn Iterator<Item = (PhysicalPosition<f64>, Force)>),
|
||||||
@@ -175,23 +171,10 @@ impl PointerHandler {
|
|||||||
Some(canvas_common.add_event("pointermove", move |event: PointerEvent| {
|
Some(canvas_common.add_event("pointermove", move |event: PointerEvent| {
|
||||||
let modifiers = event::mouse_modifiers(&event);
|
let modifiers = event::mouse_modifiers(&event);
|
||||||
|
|
||||||
let pointer_type = event.pointer_type();
|
|
||||||
|
|
||||||
if let "touch" | "mouse" = pointer_type.as_str() {
|
|
||||||
} else {
|
|
||||||
modifier_handler(modifiers);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let id = event.pointer_id();
|
let id = event.pointer_id();
|
||||||
|
|
||||||
// chorded button event
|
// chorded button event
|
||||||
if let Some(button) = event::mouse_button(&event) {
|
if let Some(button) = event::mouse_button(&event) {
|
||||||
debug_assert_eq!(
|
|
||||||
pointer_type, "mouse",
|
|
||||||
"expect pointer type of a chorded button event to be a mouse"
|
|
||||||
);
|
|
||||||
|
|
||||||
if prevent_default.get() {
|
if prevent_default.get() {
|
||||||
// prevent text selection
|
// prevent text selection
|
||||||
event.prevent_default();
|
event.prevent_default();
|
||||||
@@ -212,13 +195,7 @@ impl PointerHandler {
|
|||||||
|
|
||||||
// pointer move event
|
// pointer move event
|
||||||
let scale = super::scale_factor(&window);
|
let scale = super::scale_factor(&window);
|
||||||
match pointer_type.as_str() {
|
match event.pointer_type().as_str() {
|
||||||
"mouse" => mouse_handler(
|
|
||||||
modifiers,
|
|
||||||
id,
|
|
||||||
&mut event::pointer_move_event(event)
|
|
||||||
.map(|event| event::mouse_position(&event).to_physical(scale)),
|
|
||||||
),
|
|
||||||
"touch" => touch_handler(
|
"touch" => touch_handler(
|
||||||
modifiers,
|
modifiers,
|
||||||
id,
|
id,
|
||||||
@@ -229,7 +206,12 @@ impl PointerHandler {
|
|||||||
)
|
)
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
_ => unreachable!("didn't return early before"),
|
_ => mouse_handler(
|
||||||
|
modifiers,
|
||||||
|
id,
|
||||||
|
&mut event::pointer_move_event(event)
|
||||||
|
.map(|event| event::mouse_position(&event).to_physical(scale)),
|
||||||
|
),
|
||||||
};
|
};
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user