From 01f013c63f72d503c931ad4081d1f64294583d71 Mon Sep 17 00:00:00 2001 From: Kevin King Date: Sun, 8 May 2022 21:59:47 -0700 Subject: [PATCH] remove old dialog fix that seems to be superceded by https://github.com/rust-windowing/winit/pull/2027/files this fixes the run_return loop never returning on macos when using multiple windows --- CHANGELOG.md | 1 + src/platform_impl/macos/app_state.rs | 37 ++-------------------- src/platform_impl/macos/window.rs | 5 +-- src/platform_impl/macos/window_delegate.rs | 10 +----- 4 files changed, 6 insertions(+), 47 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa4571088a..5cf9f338eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,7 @@ And please only add new entries to the top of this list, right below the `# Unre - **Breaking:** Added new `WindowEvent::Ime` supported on desktop platforms. - Added `Window::set_ime_allowed` supported on desktop platforms. - **Breaking:** IME input on desktop platforms won't be received unless it's explicitly allowed via `Window::set_ime_allowed` and new `WindowEvent::Ime` events are handled. +- On macOS, fixed an issue where having multiple windows would prevent run_return from ever returning. # 0.26.1 (2022-01-05) diff --git a/src/platform_impl/macos/app_state.rs b/src/platform_impl/macos/app_state.rs index 7b392a4124..48c91cde1c 100644 --- a/src/platform_impl/macos/app_state.rs +++ b/src/platform_impl/macos/app_state.rs @@ -127,7 +127,6 @@ impl EventHandler for EventLoopHandler { struct Handler { ready: AtomicBool, in_callback: AtomicBool, - dialog_is_closing: AtomicBool, control_flow: Mutex, control_flow_prev: Mutex, start_time: Mutex>, @@ -262,8 +261,6 @@ impl Handler { } } -pub static INTERRUPT_EVENT_LOOP_EXIT: AtomicBool = AtomicBool::new(false); - pub enum AppState {} impl AppState { @@ -403,40 +400,12 @@ impl AppState { if HANDLER.should_exit() { unsafe { let app: id = NSApp(); - let windows: id = msg_send![app, windows]; - let window_count: usize = msg_send![windows, count]; - - let dialog_open = if window_count > 1 { - let dialog: id = msg_send![windows, lastObject]; - let is_main_window: BOOL = msg_send![dialog, isMainWindow]; - let is_visible: BOOL = msg_send![dialog, isVisible]; - is_visible != NO && is_main_window == NO - } else { - false - }; - let dialog_is_closing = HANDLER.dialog_is_closing.load(Ordering::SeqCst); autoreleasepool(|| { - if !INTERRUPT_EVENT_LOOP_EXIT.load(Ordering::SeqCst) - && !dialog_open - && !dialog_is_closing - { - let () = msg_send![app, stop: nil]; - // To stop event loop immediately, we need to post some event here. - post_dummy_event(app); - } + let () = msg_send![app, stop: nil]; + // To stop event loop immediately, we need to post some event here. + post_dummy_event(app); }); - - if window_count > 0 { - let window: id = msg_send![windows, firstObject]; - let window_has_focus: BOOL = msg_send![window, isKeyWindow]; - if !dialog_open && window_has_focus != NO && dialog_is_closing { - HANDLER.dialog_is_closing.store(false, Ordering::SeqCst); - } - if dialog_open { - HANDLER.dialog_is_closing.store(true, Ordering::SeqCst); - } - } }; } HANDLER.update_start_time(); diff --git a/src/platform_impl/macos/window.rs b/src/platform_impl/macos/window.rs index d4856cb91b..6526629ec5 100644 --- a/src/platform_impl/macos/window.rs +++ b/src/platform_impl/macos/window.rs @@ -20,7 +20,6 @@ use crate::{ platform::macos::WindowExtMacOS, platform_impl::platform::{ app_state::AppState, - app_state::INTERRUPT_EVENT_LOOP_EXIT, ffi, monitor::{self, MonitorHandle, VideoMode}, util::{self, IdRef}, @@ -907,8 +906,6 @@ impl UnownedWindow { let mut shared_state_lock = self.lock_shared_state("set_fullscreen"); shared_state_lock.fullscreen = fullscreen.clone(); - INTERRUPT_EVENT_LOOP_EXIT.store(true, Ordering::SeqCst); - match (&old_fullscreen, &fullscreen) { (&None, &Some(_)) => unsafe { util::toggle_full_screen_async( @@ -978,7 +975,7 @@ impl UnownedWindow { setLevel: ffi::NSWindowLevel::NSNormalWindowLevel ]; }, - _ => INTERRUPT_EVENT_LOOP_EXIT.store(false, Ordering::SeqCst), + _ => {} }; } diff --git a/src/platform_impl/macos/window_delegate.rs b/src/platform_impl/macos/window_delegate.rs index 55ea8a07ec..608a648ad8 100644 --- a/src/platform_impl/macos/window_delegate.rs +++ b/src/platform_impl/macos/window_delegate.rs @@ -1,7 +1,7 @@ use std::{ f64, os::raw::c_void, - sync::{atomic::Ordering, Arc, Weak}, + sync::{Arc, Weak}, }; use cocoa::{ @@ -20,7 +20,6 @@ use crate::{ event::{Event, ModifiersState, WindowEvent}, platform_impl::platform::{ app_state::AppState, - app_state::INTERRUPT_EVENT_LOOP_EXIT, event::{EventProxy, EventWrapper}, util::{self, IdRef}, view::ViewState, @@ -422,8 +421,6 @@ extern "C" fn dragging_exited(this: &Object, _: Sel, _: id) { extern "C" fn window_will_enter_fullscreen(this: &Object, _: Sel, _: id) { trace_scope!("windowWillEnterFullscreen:"); - INTERRUPT_EVENT_LOOP_EXIT.store(true, Ordering::SeqCst); - with_state(this, |state| { state.with_window(|window| { let mut shared_state = window.lock_shared_state("window_will_enter_fullscreen"); @@ -453,8 +450,6 @@ extern "C" fn window_will_enter_fullscreen(this: &Object, _: Sel, _: id) { extern "C" fn window_will_exit_fullscreen(this: &Object, _: Sel, _: id) { trace_scope!("windowWillExitFullScreen:"); - INTERRUPT_EVENT_LOOP_EXIT.store(true, Ordering::SeqCst); - with_state(this, |state| { state.with_window(|window| { let mut shared_state = window.lock_shared_state("window_will_exit_fullscreen"); @@ -498,8 +493,6 @@ extern "C" fn window_will_use_fullscreen_presentation_options( /// Invoked when entered fullscreen extern "C" fn window_did_enter_fullscreen(this: &Object, _: Sel, _: id) { trace_scope!("windowDidEnterFullscreen:"); - INTERRUPT_EVENT_LOOP_EXIT.store(false, Ordering::SeqCst); - with_state(this, |state| { state.initial_fullscreen = false; state.with_window(|window| { @@ -517,7 +510,6 @@ extern "C" fn window_did_enter_fullscreen(this: &Object, _: Sel, _: id) { /// Invoked when exited fullscreen extern "C" fn window_did_exit_fullscreen(this: &Object, _: Sel, _: id) { trace_scope!("windowDidExitFullscreen:"); - INTERRUPT_EVENT_LOOP_EXIT.store(false, Ordering::SeqCst); with_state(this, |state| { state.with_window(|window| {