mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-24 06:11:30 +11:00
De-duplicate resize events.
This tracks resizes separately, and synthesizes them for the event iterators as needed, so that OS X apps don't generate a whole set of resize events after each resize.
This commit is contained in:
parent
7d6b4c3fe5
commit
6f82ccfba9
|
@ -43,6 +43,7 @@ struct DelegateState {
|
|||
view: IdRef,
|
||||
window: IdRef,
|
||||
resize_handler: Option<fn(u32, u32)>,
|
||||
pending_resize: Mutex<Option<(u32, u32)>>,
|
||||
|
||||
/// Events that have been retreived with XLib but not dispatched with iterators yet
|
||||
pending_events: Mutex<VecDeque<Event>>,
|
||||
|
@ -83,7 +84,7 @@ impl WindowDelegate {
|
|||
if let Some(handler) = state.resize_handler {
|
||||
(handler)(width, height);
|
||||
}
|
||||
(*state).pending_events.lock().unwrap().push_back(Event::Resized(width, height));
|
||||
*state.pending_resize.lock().unwrap() = Some((width, height));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -211,6 +212,10 @@ impl<'a> Iterator for PollEventsIterator<'a> {
|
|||
type Item = Event;
|
||||
|
||||
fn next(&mut self) -> Option<Event> {
|
||||
if let Some((width, height)) = self.window.delegate.state.pending_resize.lock().unwrap().take() {
|
||||
return Some(Event::Resized(width, height));
|
||||
}
|
||||
|
||||
if let Some(ev) = self.window.delegate.state.pending_events.lock().unwrap().pop_front() {
|
||||
return Some(ev);
|
||||
}
|
||||
|
@ -240,6 +245,10 @@ impl<'a> Iterator for WaitEventsIterator<'a> {
|
|||
type Item = Event;
|
||||
|
||||
fn next(&mut self) -> Option<Event> {
|
||||
if let Some((width, height)) = self.window.delegate.state.pending_resize.lock().unwrap().take() {
|
||||
return Some(Event::Resized(width, height));
|
||||
}
|
||||
|
||||
if let Some(ev) = self.window.delegate.state.pending_events.lock().unwrap().pop_front() {
|
||||
return Some(ev);
|
||||
}
|
||||
|
@ -313,6 +322,7 @@ impl Window {
|
|||
view: view.clone(),
|
||||
window: window.clone(),
|
||||
resize_handler: None,
|
||||
pending_resize: Mutex::new(None),
|
||||
pending_events: Mutex::new(VecDeque::new()),
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue