Correctly catch quit events instead of manually catching OS X hotkeys

This commit is contained in:
kappaOne 2013-02-07 21:55:53 +00:00
parent 93a169b27b
commit 409b3fea6d
1 changed files with 8 additions and 13 deletions

View File

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