Skip to content

Commit

Permalink
Web: account for canvas being focused already (#3369)
Browse files Browse the repository at this point in the history
  • Loading branch information
daxpedda authored Jan 6, 2024
1 parent 787b2d7 commit d39528a
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/platform_impl/web/event_loop/window_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use std::iter;
use std::marker::PhantomData;
use std::rc::{Rc, Weak};

use web_sys::Element;

use super::runner::{EventWrapper, Execution};
use super::{
super::{monitor::MonitorHandle, KeyEventExtra},
Expand Down Expand Up @@ -118,6 +120,25 @@ impl<T> EventLoopWindowTarget<T> {
}
});

// It is possible that at this point the canvas has
// been focused before the callback can be called.
let focused = canvas
.document()
.active_element()
.filter(|element| {
let canvas: &Element = canvas.raw();
element == canvas
})
.is_some();

if focused {
canvas.has_focus.set(true);
self.runner.send_event(Event::WindowEvent {
window_id: RootWindowId(id),
event: WindowEvent::Focused(true),
})
}

let runner = self.runner.clone();
let modifiers = self.modifiers.clone();
canvas.on_keyboard_press(
Expand Down

0 comments on commit d39528a

Please sign in to comment.