]> git.tdb.fi Git - libs/gui.git/blobdiff - source/graphics/cocoa/cocoawindow.m
Subclass NSWindow to eat keyDown events so they won't beep
[libs/gui.git] / source / graphics / cocoa / cocoawindow.m
index cbf67222d7b91a60371a9180686220e52a997a2b..11181269b5faa9432e09d55644bbb4f337cb7d98 100644 (file)
@@ -1,11 +1,15 @@
+#import <AppKit/NSApplication.h>
 #import <AppKit/NSWindow.h>
 #import <CoreFoundation/CFArray.h>
 #include "cocoadisplay.h"
 #include "cocoawindow.h"
 
-@interface WindowDelegate: NSObject <NSWindowDelegate>
+@interface MspWindow: NSWindow {
+       int dummy_member;
+}
 
 - (BOOL)windowShouldClose:(id)sender;
+- (void)keyDown:(NSEvent *)event;
 
 @end
 
@@ -13,12 +17,10 @@ struct _CocoaWindow
 {
        CocoaDisplay *display;
        __strong NSWindow *window;
-       __strong WindowDelegate *delegate;
        NSUInteger style;
 };
 
 CFMutableDictionaryRef windows = NULL;
-CFMutableArrayRef event_queue = NULL;
 
 CocoaWindow *create_window(CocoaDisplay *display, unsigned width, unsigned height, bool fullscreen, bool resizable)
 {
@@ -26,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];
 
@@ -37,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);
@@ -57,7 +56,6 @@ void destroy_window(CocoaWindow *window)
        }
 
        [window->window release];
-       [window->delegate release];
        free(window);
 }
 
@@ -94,7 +92,7 @@ void hide_window(CocoaWindow *window)
        (void)window;
 }
 
-@implementation WindowDelegate
+@implementation MspWindow
 
 - (BOOL)windowShouldClose:(id)sender
 {
@@ -110,4 +108,10 @@ void hide_window(CocoaWindow *window)
        return YES;
 }
 
+- (void)keyDown:(NSEvent *)event
+{
+       // Eat the event to avoid beeping
+       (void)event;
+}
+
 @end