Focus window on touch press

This commit is contained in:
dAxpeDDa 2023-06-04 01:09:30 +02:00 committed by daxpedda
parent 61bd8b8254
commit fbba203c4a
2 changed files with 62 additions and 46 deletions

View file

@ -64,6 +64,7 @@ And please only add new entries to the top of this list, right below the `# Unre
- 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. - On Web, fix pen treated as mouse input.
- On Web, send mouse position on button release as well. - On Web, send mouse position on button release as well.
- On Web, fix touch input not gaining or loosing focus.
# 0.28.6 # 0.28.6

View file

@ -345,14 +345,15 @@ impl<T> EventLoopWindowTarget<T> {
prevent_default, prevent_default,
); );
let runner = self.runner.clone();
let runner_touch = self.runner.clone();
let modifiers = self.modifiers.clone();
let has_focus_clone = has_focus.clone();
canvas.on_mouse_press( canvas.on_mouse_press(
{
let runner = self.runner.clone();
let modifiers = self.modifiers.clone();
let has_focus = has_focus.clone();
move |pointer_id, position, button, active_modifiers| { move |pointer_id, position, button, active_modifiers| {
let focus_changed = let focus_changed =
(!has_focus_clone.replace(true)).then_some(Event::WindowEvent { (!has_focus.replace(true)).then_some(Event::WindowEvent {
window_id: RootWindowId(id), window_id: RootWindowId(id),
event: WindowEvent::Focused(true), event: WindowEvent::Focused(true),
}); });
@ -385,9 +386,21 @@ impl<T> EventLoopWindowTarget<T> {
}, },
}, },
])); ]));
}
}, },
{
let runner = self.runner.clone();
let has_focus = has_focus.clone();
move |device_id, location, force| { move |device_id, location, force| {
runner_touch.send_event(Event::WindowEvent { let focus_changed =
(!has_focus.replace(true)).then_some(Event::WindowEvent {
window_id: RootWindowId(id),
event: WindowEvent::Focused(true),
});
runner.send_events(focus_changed.into_iter().chain(iter::once(
Event::WindowEvent {
window_id: RootWindowId(id), window_id: RootWindowId(id),
event: WindowEvent::Touch(Touch { event: WindowEvent::Touch(Touch {
id: device_id as u64, id: device_id as u64,
@ -396,7 +409,9 @@ impl<T> EventLoopWindowTarget<T> {
force: Some(force), force: Some(force),
location, location,
}), }),
}); },
)));
}
}, },
); );