]> git.tdb.fi Git - libs/gui.git/commitdiff
Subclass NSWindow to eat keyDown events so they won't beep
authorMikko Rasa <tdb@tdb.fi>
Sat, 11 Oct 2014 13:26:06 +0000 (16:26 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 11 Oct 2014 10:41:01 +0000 (13:41 +0300)
source/graphics/cocoa/cocoawindow.m

index 745488bfd3dfc89863d2bf895ee4648cfd3c52fe..11181269b5faa9432e09d55644bbb4f337cb7d98 100644 (file)
@@ -4,15 +4,12 @@
 #include "cocoadisplay.h"
 #include "cocoawindow.h"
 
-#if __MAC_OS_X_VERSION_MAX_ALLOWED < 1060
-@protocol NSWindowDelegate <NSObject> @end
-#endif
-
-@interface WindowDelegate: NSObject <NSWindowDelegate> {
+@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