Fix run_return in MacOS (#1321)

* Fix run_return in MacOS

* MacOS: Fix the way of getting a window in run_return

* Fix CHANGELOG.md
This commit is contained in:
hatoo 2019-12-19 18:10:47 +09:00 committed by Bogaevsky
parent 3e1d169160
commit 01203b247b
2 changed files with 22 additions and 3 deletions

View file

@ -1,5 +1,6 @@
# Unreleased # Unreleased
- On macOS, fix application not to terminate on `run_return`.
- On Wayland, fix cursor icon updates on window borders when using CSD. - On Wayland, fix cursor icon updates on window borders when using CSD.
# # 0.20.0 Alpha 5 (2019-12-09) # # 0.20.0 Alpha 5 (2019-12-09)

View file

@ -11,7 +11,7 @@ use std::{
time::Instant, time::Instant,
}; };
use cocoa::{appkit::NSApp, base::nil}; use cocoa::{appkit::NSApp, base::nil, foundation::NSString};
use crate::{ use crate::{
event::{Event, StartCause, WindowEvent}, event::{Event, StartCause, WindowEvent},
@ -19,6 +19,7 @@ use crate::{
platform_impl::platform::{observer::EventLoopWaker, util::Never}, platform_impl::platform::{observer::EventLoopWaker, util::Never},
window::WindowId, window::WindowId,
}; };
use objc::runtime::Object;
lazy_static! { lazy_static! {
static ref HANDLER: Handler = Default::default(); static ref HANDLER: Handler = Default::default();
@ -275,8 +276,25 @@ impl AppState {
HANDLER.set_in_callback(false); HANDLER.set_in_callback(false);
} }
if HANDLER.should_exit() { if HANDLER.should_exit() {
let _: () = unsafe { msg_send![NSApp(), terminate: nil] }; unsafe {
return; let _: () = msg_send![NSApp(), stop: nil];
let windows: *const Object = msg_send![NSApp(), windows];
let window: *const Object = msg_send![windows, objectAtIndex:0];
assert_ne!(window, nil);
let title: *const Object = msg_send![window, title];
assert_ne!(title, nil);
let postfix = NSString::alloc(nil).init_str("*");
let some_unique_title: *const Object =
msg_send![title, stringByAppendingString: postfix];
assert_ne!(some_unique_title, nil);
// To stop event loop immediately, we need to send some UI event here.
let _: () = msg_send![window, setTitle: some_unique_title];
// And restore it.
let _: () = msg_send![window, setTitle: title];
};
} }
HANDLER.update_start_time(); HANDLER.update_start_time();
match HANDLER.get_old_and_new_control_flow() { match HANDLER.get_old_and_new_control_flow() {