From 9f938f351f6db442d289df90c0f33c9fce30ac23 Mon Sep 17 00:00:00 2001 From: Lucas Kent Date: Tue, 28 Dec 2021 11:45:17 +1100 Subject: [PATCH] Manually emit focused event on mouse click --- CHANGELOG.md | 1 + src/platform_impl/web/event_loop/window_target.rs | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 54f5a13bc86..3a7c72ae321 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ And please only add new entries to the top of this list, right below the `# Unre - Added `Window::is_decorated`. - On X11, fix for repeated event loop iteration when `ControlFlow` was `Wait` - 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`. - 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. diff --git a/src/platform_impl/web/event_loop/window_target.rs b/src/platform_impl/web/event_loop/window_target.rs index 367556a7a16..dfecd440be4 100644 --- a/src/platform_impl/web/event_loop/window_target.rs +++ b/src/platform_impl/web/event_loop/window_target.rs @@ -156,13 +156,17 @@ impl WindowTarget { // user code has the correct cursor position. runner.send_events( std::iter::once(Event::WindowEvent { + window_id: WindowId(id), + event: WindowEvent::Focused(true), + }) + .chain(std::iter::once(Event::WindowEvent { window_id: WindowId(id), event: WindowEvent::CursorMoved { device_id: DeviceId(device::Id(pointer_id)), position, modifiers, }, - }) + })) .chain(std::iter::once(Event::WindowEvent { window_id: WindowId(id), event: WindowEvent::MouseInput {