From 97707c9f57234bf7992bac03bd52cb3fdd00fcfa Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 11 Oct 2014 16:26:06 +0300 Subject: [PATCH] Subclass NSWindow to eat keyDown events so they won't beep --- source/graphics/cocoa/cocoawindow.m | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/source/graphics/cocoa/cocoawindow.m b/source/graphics/cocoa/cocoawindow.m index 745488b..1118126 100644 --- a/source/graphics/cocoa/cocoawindow.m +++ b/source/graphics/cocoa/cocoawindow.m @@ -4,15 +4,12 @@ #include "cocoadisplay.h" #include "cocoawindow.h" -#if __MAC_OS_X_VERSION_MAX_ALLOWED < 1060 -@protocol NSWindowDelegate @end -#endif - -@interface WindowDelegate: NSObject { +@interface MspWindow: NSWindow { int dummy_member; } - (BOOL)windowShouldClose:(id)sender; +- (void)keyDown:(NSEvent *)event; @end @@ -20,7 +17,6 @@ struct _CocoaWindow { CocoaDisplay *display; __strong NSWindow *window; - __strong WindowDelegate *delegate; NSUInteger style; }; @@ -32,7 +28,7 @@ CocoaWindow *create_window(CocoaDisplay *display, unsigned width, unsigned heigh NSUInteger style = NSTitledWindowMask|NSClosableWindowMask; if(resizable) style |= NSResizableWindowMask; - NSWindow *window = [NSWindow alloc]; + NSWindow *window = [MspWindow alloc]; window = [window initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:NO]; [window setAcceptsMouseMovedEvents:YES]; @@ -43,9 +39,6 @@ CocoaWindow *create_window(CocoaDisplay *display, unsigned width, unsigned heigh wrapper->window = window; wrapper->style = style; - wrapper->delegate = [[WindowDelegate alloc] init]; - [window setDelegate:wrapper->delegate]; - if(!windows) windows = CFDictionaryCreateMutable(NULL, 0, NULL, NULL); CFDictionaryAddValue(windows, window, wrapper); @@ -63,7 +56,6 @@ void destroy_window(CocoaWindow *window) } [window->window release]; - [window->delegate release]; free(window); } @@ -100,7 +92,7 @@ void hide_window(CocoaWindow *window) (void)window; } -@implementation WindowDelegate +@implementation MspWindow - (BOOL)windowShouldClose:(id)sender { @@ -116,4 +108,10 @@ void hide_window(CocoaWindow *window) return YES; } +- (void)keyDown:(NSEvent *)event +{ + // Eat the event to avoid beeping + (void)event; +} + @end -- 2.43.0