mirror of
https://github.com/rust-windowing/winit.git
synced 2026-09-02 06:40:06 -04:00
[macos] Remove Window from EventsLoop's Window list on close and drop
Previously, a Window was only removed from the list when dropped.
This commit is contained in:
@@ -217,6 +217,18 @@ impl EventsLoop {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Removes the window with the given `Id` from the `windows` list.
|
||||||
|
//
|
||||||
|
// This is called when a window is either `Closed` or `Drop`ped.
|
||||||
|
pub fn find_and_remove_window(&self, id: super::window::Id) {
|
||||||
|
if let Ok(mut windows) = self.windows.lock() {
|
||||||
|
windows.retain(|w| match w.upgrade() {
|
||||||
|
Some(w) => w.id() != id,
|
||||||
|
None => true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn call_user_callback_with_pending_events(&self) {
|
fn call_user_callback_with_pending_events(&self) {
|
||||||
loop {
|
loop {
|
||||||
let event = match self.pending_events.lock().unwrap().pop_front() {
|
let event = match self.pending_events.lock().unwrap().pop_front() {
|
||||||
|
|||||||
@@ -66,6 +66,12 @@ impl WindowDelegate {
|
|||||||
let state: *mut c_void = *this.get_ivar("winitState");
|
let state: *mut c_void = *this.get_ivar("winitState");
|
||||||
let state = &mut *(state as *mut DelegateState);
|
let state = &mut *(state as *mut DelegateState);
|
||||||
emit_event(state, WindowEvent::Closed);
|
emit_event(state, WindowEvent::Closed);
|
||||||
|
|
||||||
|
// Remove the window from the events_loop.
|
||||||
|
if let Some(events_loop) = state.events_loop.upgrade() {
|
||||||
|
let window_id = get_window_id(*state.window);
|
||||||
|
events_loop.find_and_remove_window(window_id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
YES
|
YES
|
||||||
}
|
}
|
||||||
@@ -173,11 +179,7 @@ impl Drop for Window {
|
|||||||
// Remove this window from the `EventLoop`s list of windows.
|
// Remove this window from the `EventLoop`s list of windows.
|
||||||
let id = self.id();
|
let id = self.id();
|
||||||
if let Some(ev) = self.delegate.state.events_loop.upgrade() {
|
if let Some(ev) = self.delegate.state.events_loop.upgrade() {
|
||||||
let mut windows = ev.windows.lock().unwrap();
|
ev.find_and_remove_window(id);
|
||||||
windows.retain(|w| match w.upgrade() {
|
|
||||||
Some(w) => w.id() != id,
|
|
||||||
None => true,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user