Skip to content

Commit

Permalink
Remove old dialog fix that is superseded by #2027 (#2292)
Browse files Browse the repository at this point in the history
This fixes the run_return loop never returning on macos when using multiple windows
  • Loading branch information
kcking authored Jun 8, 2022
1 parent 224872c commit 4c39b31
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 47 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ And please only add new entries to the top of this list, right below the `# Unre

# Unreleased

- On macOS, fixed an issue where having multiple windows would prevent run_return from ever returning.
- On Wayland, fix bug where the cursor wouldn't hide in GNOME.
- On macOS, Windows, and Wayland, add `set_cursor_hittest` to let the window ignore mouse events.
- On Windows, added `WindowExtWindows::set_skip_taskbar` and `WindowBuilderExtWindows::with_skip_taskbar`.
Expand Down
37 changes: 3 additions & 34 deletions src/platform_impl/macos/app_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ impl<T> EventHandler for EventLoopHandler<T> {
struct Handler {
ready: AtomicBool,
in_callback: AtomicBool,
dialog_is_closing: AtomicBool,
control_flow: Mutex<ControlFlow>,
control_flow_prev: Mutex<ControlFlow>,
start_time: Mutex<Option<Instant>>,
Expand Down Expand Up @@ -262,8 +261,6 @@ impl Handler {
}
}

pub static INTERRUPT_EVENT_LOOP_EXIT: AtomicBool = AtomicBool::new(false);

pub enum AppState {}

impl AppState {
Expand Down Expand Up @@ -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();
Expand Down
5 changes: 1 addition & 4 deletions src/platform_impl/macos/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -978,7 +975,7 @@ impl UnownedWindow {
setLevel: ffi::NSWindowLevel::NSNormalWindowLevel
];
},
_ => INTERRUPT_EVENT_LOOP_EXIT.store(false, Ordering::SeqCst),
_ => {}
};
}

Expand Down
10 changes: 1 addition & 9 deletions src/platform_impl/macos/window_delegate.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{
f64,
os::raw::c_void,
sync::{atomic::Ordering, Arc, Weak},
sync::{Arc, Weak},
};

use cocoa::{
Expand All @@ -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,
Expand Down Expand Up @@ -414,8 +413,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");
Expand Down Expand Up @@ -445,8 +442,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");
Expand Down Expand Up @@ -490,8 +485,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| {
Expand All @@ -509,7 +502,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| {
Expand Down

0 comments on commit 4c39b31

Please sign in to comment.