web: Manually emit focused event on mouse click (#2202)

* Manually emit focused event on mouse click

* Update CHANGELOG.md

Co-authored-by: Markus Røyset <maroider@protonmail.com>

Co-authored-by: Markus Røyset <maroider@protonmail.com>
This commit is contained in:
Lucas Kent 2022-07-13 08:46:15 +10:00 committed by GitHub
parent 2d2ce70edc
commit cdd9b1e1eb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View file

@ -27,6 +27,7 @@ And please only add new entries to the top of this list, right below the `# Unre
- On X11, fix for repeated event loop iteration when `ControlFlow` was `Wait` - On X11, fix for repeated event loop iteration when `ControlFlow` was `Wait`
- On X11, fix scale factor calculation when the only monitor is reconnected - On X11, fix scale factor calculation when the only monitor is reconnected
- On Wayland, report unaccelerated mouse deltas in `DeviceEvent::MouseMotion`. - On Wayland, report unaccelerated mouse deltas in `DeviceEvent::MouseMotion`.
- On Web, a focused event is manually generated when a click occurs to emulate behaviour of other backends.
- **Breaking:** Bump `ndk` version to 0.6, ndk-sys to `v0.3`, `ndk-glue` to `0.6`. - **Breaking:** Bump `ndk` version to 0.6, ndk-sys to `v0.3`, `ndk-glue` to `0.6`.
- Remove no longer needed `WINIT_LINK_COLORSYNC` environment variable. - Remove no longer needed `WINIT_LINK_COLORSYNC` environment variable.
- **Breaking:** Rename the `Exit` variant of `ControlFlow` to `ExitWithCode`, which holds a value to control the exit code after running. Add an `Exit` constant which aliases to `ExitWithCode(0)` instead to avoid major breakage. This shouldn't affect most existing programs. - **Breaking:** Rename the `Exit` variant of `ControlFlow` to `ExitWithCode`, which holds a value to control the exit code after running. Add an `Exit` constant which aliases to `ExitWithCode(0)` instead to avoid major breakage. This shouldn't affect most existing programs.

View file

@ -160,13 +160,17 @@ impl<T> EventLoopWindowTarget<T> {
// user code has the correct cursor position. // user code has the correct cursor position.
runner.send_events( runner.send_events(
std::iter::once(Event::WindowEvent { std::iter::once(Event::WindowEvent {
window_id: RootWindowId(id),
event: WindowEvent::Focused(true),
})
.chain(std::iter::once(Event::WindowEvent {
window_id: RootWindowId(id), window_id: RootWindowId(id),
event: WindowEvent::CursorMoved { event: WindowEvent::CursorMoved {
device_id: RootDeviceId(DeviceId(pointer_id)), device_id: RootDeviceId(DeviceId(pointer_id)),
position, position,
modifiers, modifiers,
}, },
}) }))
.chain(std::iter::once(Event::WindowEvent { .chain(std::iter::once(Event::WindowEvent {
window_id: RootWindowId(id), window_id: RootWindowId(id),
event: WindowEvent::MouseInput { event: WindowEvent::MouseInput {