From: Mikko Rasa Date: Sat, 11 Oct 2014 13:26:06 +0000 (+0300) Subject: Subclass NSWindow to eat keyDown events so they won't beep X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;ds=sidebyside;h=97707c9f57234bf7992bac03bd52cb3fdd00fcfa;hp=0775bf72fa8debd94b050e201469957e62c4bfe3;p=libs%2Fgui.git Subclass NSWindow to eat keyDown events so they won't beep --- 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