From 15a269db9df6c2454c4b11bb474eef750a492900 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Mon, 28 Dec 2015 13:05:07 +0200 Subject: [PATCH] Extended NSWindow with ability to exit application upon closing by user --- src/posix/cocoa/i_common.h | 5 +++++ src/posix/cocoa/i_video.mm | 17 +++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/posix/cocoa/i_common.h b/src/posix/cocoa/i_common.h index 63377bb36..cf2fffbdc 100644 --- a/src/posix/cocoa/i_common.h +++ b/src/posix/cocoa/i_common.h @@ -62,6 +62,11 @@ extern RenderBufferOptions rbOpts; #define AppKit10_7 1138 +@interface NSWindow(ExitAppOnClose) +- (void)exitAppOnClose; +@end + + inline bool I_IsHiDPISupported() { return NSAppKitVersionNumber >= AppKit10_7; diff --git a/src/posix/cocoa/i_video.mm b/src/posix/cocoa/i_video.mm index a47a1f1a8..768d147a9 100644 --- a/src/posix/cocoa/i_video.mm +++ b/src/posix/cocoa/i_video.mm @@ -58,6 +58,18 @@ #undef Class +@implementation NSWindow(ExitAppOnClose) + +- (void)exitAppOnClose +{ + NSButton* closeButton = [self standardWindowButton:NSWindowCloseButton]; + [closeButton setAction:@selector(terminate:)]; + [closeButton setTarget:NSApp]; +} + +@end + + EXTERN_CVAR(Bool, ticker ) EXTERN_CVAR(Bool, vid_vsync) EXTERN_CVAR(Bool, vid_hidpi) @@ -659,10 +671,7 @@ void CocoaVideo::SetWindowedMode(const int width, const int height) [m_window setContentSize:windowSize]; [m_window center]; - - NSButton* closeButton = [m_window standardWindowButton:NSWindowCloseButton]; - [closeButton setAction:@selector(terminate:)]; - [closeButton setTarget:NSApp]; + [m_window exitAppOnClose]; } void CocoaVideo::SetMode(const int width, const int height, const bool fullscreen, const bool hiDPI)