Implement WindowID on the web platform (#1177)

* Use actual numeric IDs to differentiate Windows

This is generally important to identifying which window should
recieve which event, but is also specifically crucial for fixing
RedrawRequested on web.

* Cargo fmt
This commit is contained in:
Ryan G 2019-09-19 18:40:18 -04:00 committed by GitHub
parent e87bc3db20
commit 2c47c43f47
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 19 deletions

View file

@ -16,6 +16,7 @@ impl<T> Clone for Shared<T> {
pub struct Execution<T> {
runner: RefCell<Option<Runner<T>>>,
events: RefCell<VecDeque<Event<T>>>,
id: RefCell<u32>,
}
struct Runner<T> {
@ -39,6 +40,7 @@ impl<T: 'static> Shared<T> {
Shared(Rc::new(Execution {
runner: RefCell::new(None),
events: RefCell::new(VecDeque::new()),
id: RefCell::new(0),
}))
}
@ -53,6 +55,15 @@ impl<T: 'static> Shared<T> {
backend::on_unload(move || close_instance.handle_unload());
}
// Generate a strictly increasing ID
// This is used to differentiate windows when handling events
pub fn generate_id(&self) -> u32 {
let mut id = self.0.id.borrow_mut();
*id += 1;
*id
}
// Add an event to the event loop runner
//
// It will determine if the event should be immediately sent to the user or buffered for later