aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Weissflog <floooh@gmail.com>2021-05-04 20:16:53 +0200
committerAndre Weissflog <floooh@gmail.com>2021-05-04 20:16:53 +0200
commitf79edaf562ce4901cbbddc65a3ef75a50f5dfdde (patch)
tree3553ea6d885d6cba6e2d154b4c87e773281e31b4
parenta35bea524ffafe6bd1f399a25a6cda6332c0752a (diff)
sokol_app.h metal: start to fix window close and shutdown behaviour
-rw-r--r--sokol_app.h67
1 files changed, 43 insertions, 24 deletions
diff --git a/sokol_app.h b/sokol_app.h
index a06a8331..bca9ea34 100644
--- a/sokol_app.h
+++ b/sokol_app.h
@@ -3775,10 +3775,15 @@ _SOKOL_PRIVATE CVReturn _sapp_macos_displaylink_callback(
}
}
_sapp_frame();
- // FIXME FIXME FIXME
- // if (_sapp.quit_requested || _sapp.quit_ordered) {
- // [win->macos.window performClose:nil];
- // }
+ if (_sapp.quit_requested && !_sapp.quit_ordered) {
+ _sapp_window_t* win = _sapp_lookup_window(_sapp.main_window_id);
+ if (win) {
+ [win->macos.window performClose:nil];
+ }
+ }
+ if (_sapp.quit_ordered) {
+ [NSApp terminate:self];
+ }
}
- (void)applicationDidFinishLaunching:(NSNotification*)aNotification {
@@ -3814,11 +3819,6 @@ _SOKOL_PRIVATE CVReturn _sapp_macos_displaylink_callback(
_sapp.valid = true;
}
-- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication*)sender {
- _SOKOL_UNUSED(sender);
- return YES;
-}
-
- (void)applicationWillTerminate:(NSNotification*)notification {
_SOKOL_UNUSED(notification);
_sapp_discard_state();
@@ -3830,25 +3830,44 @@ _SOKOL_PRIVATE CVReturn _sapp_macos_displaylink_callback(
- (BOOL)windowShouldClose:(id)sender {
_SOKOL_UNUSED(sender);
- /* only give user-code a chance to intervene when sapp_quit() wasn't already called */
- if (!_sapp.quit_ordered) {
- /* if window should be closed and event handling is enabled, give user code
- a chance to intervene via sapp_cancel_quit()
- */
- _sapp.quit_requested = true;
- _sapp_window_t* win = _sapp_lookup_window(self.win_id);
- SOKOL_ASSERT(win);
- _sapp_macos_app_event(win, SAPP_EVENTTYPE_QUIT_REQUESTED);
- /* user code hasn't intervened, quit the app */
- if (_sapp.quit_requested) {
- _sapp.quit_ordered = true;
+ if (self.win_id == _sapp.main_window_id) {
+ /* only give user-code a chance to intervene when sapp_quit() wasn't already called */
+ if (!_sapp.quit_ordered) {
+ /* if window should be closed and event handling is enabled, give user code
+ a chance to intervene via sapp_cancel_quit()
+ */
+ _sapp.quit_requested = true;
+ _sapp_window_t* win = _sapp_lookup_window(self.win_id);
+ SOKOL_ASSERT(win);
+ _sapp_macos_app_event(win, SAPP_EVENTTYPE_QUIT_REQUESTED);
+ /* user code hasn't intervened, quit the app */
+ if (_sapp.quit_requested) {
+ _sapp.quit_ordered = true;
+ }
+ }
+ if (_sapp.quit_ordered) {
+ return YES;
+ }
+ else {
+ return NO;
}
}
- if (_sapp.quit_ordered) {
+ else {
+ // not the main window
return YES;
}
- else {
- return NO;
+}
+
+- (void)windowWillClose:(id)sender {
+ _SOKOL_UNUSED(sender);
+ // the main window will be closed when the application closes
+ if (self.win_id != _sapp.main_window_id) {
+ _sapp_window_t* win = _sapp_lookup_window(self.win_id);
+ if (win) {
+ // FIXME: send window close event
+ // destroy state associated with the window
+ _sapp_destroy_window(self.win_id);
+ }
}
}