Fix run_return does not return on macOS unless it receives a message (#1380)

* On MacOS, fix `run_return` not exit immediately

* Add CHANGELOG
This commit is contained in:
hatoo 2020-01-11 00:25:55 +09:00 committed by Bogaevsky
parent 9e3844ddd9
commit 633d0deeae
2 changed files with 21 additions and 17 deletions

View file

@ -1,5 +1,6 @@
# Unreleased # Unreleased
- On macOS, fix `run_return` does not return unless it receives a message.
- On Windows, fix bug where `RedrawRequested` would only get emitted every other iteration of the event loop. - On Windows, fix bug where `RedrawRequested` would only get emitted every other iteration of the event loop.
- On X11, fix deadlock on window state when handling certain window events. - On X11, fix deadlock on window state when handling certain window events.
- `WindowBuilder` now implements `Default`. - `WindowBuilder` now implements `Default`.

View file

@ -12,11 +12,13 @@ use std::{
}; };
use cocoa::{ use cocoa::{
appkit::{NSApp, NSWindow}, appkit::{NSApp, NSEventType::NSApplicationDefined, NSWindow},
base::nil, base::{id, nil},
foundation::{NSAutoreleasePool, NSSize, NSString}, foundation::{NSAutoreleasePool, NSPoint, NSSize},
}; };
use objc::runtime::YES;
use crate::{ use crate::{
dpi::LogicalSize, dpi::LogicalSize,
event::{Event, StartCause, WindowEvent}, event::{Event, StartCause, WindowEvent},
@ -29,7 +31,6 @@ use crate::{
}, },
window::WindowId, window::WindowId,
}; };
use objc::runtime::Object;
lazy_static! { lazy_static! {
static ref HANDLER: Handler = Default::default(); static ref HANDLER: Handler = Default::default();
@ -339,21 +340,23 @@ impl AppState {
let pool = NSAutoreleasePool::new(nil); let pool = NSAutoreleasePool::new(nil);
let windows: *const Object = msg_send![NSApp(), windows]; let windows: id = msg_send![NSApp(), windows];
let window: *const Object = msg_send![windows, objectAtIndex:0]; let window: id = msg_send![windows, objectAtIndex:0];
assert_ne!(window, nil); assert_ne!(window, nil);
let title: *const Object = msg_send![window, title]; let dummy_event: id = msg_send![class!(NSEvent),
assert_ne!(title, nil); otherEventWithType: NSApplicationDefined
let postfix = NSString::alloc(nil).init_str("*"); location: NSPoint::new(0.0, 0.0)
let some_unique_title: *const Object = modifierFlags: 0
msg_send![title, stringByAppendingString: postfix]; timestamp: 0
assert_ne!(some_unique_title, nil); windowNumber: 0
context: nil
// To stop event loop immediately, we need to send some UI event here. subtype: 0
let _: () = msg_send![window, setTitle: some_unique_title]; data1: 0
// And restore it. data2: 0
let _: () = msg_send![window, setTitle: title]; ];
// To stop event loop immediately, we need to post some event here.
let _: () = msg_send![window, postEvent: dummy_event atStart: YES];
pool.drain(); pool.drain();
}; };