diff --git a/src/platform_impl/stdweb/event_loop.rs b/src/platform_impl/stdweb/event_loop.rs index ea2b9acd..0602c197 100644 --- a/src/platform_impl/stdweb/event_loop.rs +++ b/src/platform_impl/stdweb/event_loop.rs @@ -67,6 +67,7 @@ pub struct ELRShared { struct EventLoopRunner { control: ControlFlow, + handling: bool, event_handler: Box, &mut ControlFlow)>, } @@ -89,13 +90,9 @@ impl EventLoop { } pub fn run(self, mut event_handler: F) -> ! - where F: 'static + FnMut(Event, &RootELW, &mut ControlFlow) - { - // TODO: how to handle request redraw? - // TODO: onclose (stdweb PR) - // TODO: file dropping, PathBuf isn't useful for web + where F: 'static + FnMut(Event, &RootELW, &mut ControlFlow) { let runner = self.elw.p.runner; - + let relw = RootELW { p: EventLoopWindowTarget::new(), _marker: PhantomData @@ -130,7 +127,6 @@ impl EventLoop { elrs.send_event(Event::WindowEvent { window_id: RootWI(WindowId), event: WindowEvent::KeyboardInput { - // TODO: is there a way to get keyboard device? device_id: RootDI(unsafe { DeviceId::dummy() }), input: KeyboardInput { scancode: scancode(&event), @@ -145,7 +141,6 @@ impl EventLoop { elrs.send_event(Event::WindowEvent { window_id: RootWI(WindowId), event: WindowEvent::KeyboardInput { - // TODO: is there a way to get keyboard device? device_id: RootDI(unsafe { DeviceId::dummy() }), input: KeyboardInput { scancode: scancode(&event), @@ -248,6 +243,7 @@ impl ELRShared { fn set_listener(&self, event_handler: Box, &mut ControlFlow)>) { *self.runner.borrow_mut() = Some(EventLoopRunner { control: ControlFlow::Poll, + handling: false event_handler }); } @@ -256,11 +252,17 @@ impl ELRShared { // TODO: handle event buffer pub fn send_event(&self, event: Event) { match *self.runner.borrow_mut() { - Some(ref mut runner) => { + Some(ref mut runner) if !runner.handling => { + runner.handling = true; + let closed = runner.control == ControlFlow::Exit; // TODO: bracket this in control flow events? (runner.event_handler)(event, &mut runner.control); + if closed { + runner.control = ControlFlow::Exit; + } + runner.handling = false; } - None => () + _ => self.events.borrow_mut().push_back(event) } }