From 409b3fea6d45ae6833c0526a70ec5cf61bd6efba Mon Sep 17 00:00:00 2001 From: kappaOne Date: Thu, 7 Feb 2013 21:55:53 +0000 Subject: [PATCH] Correctly catch quit events instead of manually catching OS X hotkeys --- src/native/macosx/org_lwjgl_opengl_Display.m | 21 ++++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/native/macosx/org_lwjgl_opengl_Display.m b/src/native/macosx/org_lwjgl_opengl_Display.m index e20e1057..81c9b5fa 100644 --- a/src/native/macosx/org_lwjgl_opengl_Display.m +++ b/src/native/macosx/org_lwjgl_opengl_Display.m @@ -85,6 +85,11 @@ static NSAutoreleasePool *pool; return NO; } +- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender { + [self windowShouldClose:nil]; + return NSTerminateCancel; +} + - (id)initWithFrame:(NSRect)frameRect pixelFormat:(NSOpenGLPixelFormat*)format { self = [super initWithFrame:frameRect]; if (self != nil) { @@ -178,19 +183,6 @@ static NSAutoreleasePool *pool; (*env)->CallVoidMethod(env, _parent->jkeyboard, keyup, [event keyCode], charcode, time); } -- (BOOL)performKeyEquivalent:(NSEvent *)event { - // if command key down - if (([event modifierFlags] & NSDeviceIndependentModifierFlagsMask) == NSCommandKeyMask) { - // and if q key down - if ([[event charactersIgnoringModifiers] isEqualToString:@"q"]) { - [self windowShouldClose:nil]; - return YES; - } - } - - return NO; -} - - (void)flagsChanged:(NSEvent *)event { JNIEnv *env = attachCurrentThread(); if (env == nil || event == nil || _parent == nil || _parent->jkeyboard == nil) { @@ -490,6 +482,9 @@ JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_MacOSXDisplay_nCreateWindow(JNIE window_info->view = [[MacOSXOpenGLView alloc] initWithFrame:view_rect pixelFormat:peer_info->pixel_format]; [window_info->view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; + // set nsapp delegate for catching app quit events + [NSApp setDelegate:window_info->view]; + if (window_info->context != nil) { [window_info->view setOpenGLContext:window_info->context]; }