Extended NSWindow with ability to exit application upon closing by user

This commit is contained in:
alexey.lysiuk 2015-12-28 13:05:07 +02:00
parent 3676a42512
commit 15a269db9d
2 changed files with 18 additions and 4 deletions

View file

@ -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;

View file

@ -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)