]> 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 692952002f7c6be6f5d60be10266ba2d5e03b58a..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;
+}
 
-- (void)windowWillClose:(NSNotification *)notification;
+- (BOOL)windowShouldClose:(id)sender;
+- (void)keyDown:(NSEvent *)event;
 
 @end
 
@@ -17,7 +21,6 @@ struct _CocoaWindow
 };
 
 CFMutableDictionaryRef windows = NULL;
-CFMutableArrayRef event_queue = NULL;
 
 CocoaWindow *create_window(CocoaDisplay *display, unsigned width, unsigned height, bool fullscreen, bool resizable)
 {
@@ -25,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];
 
@@ -36,8 +39,6 @@ CocoaWindow *create_window(CocoaDisplay *display, unsigned width, unsigned heigh
        wrapper->window = window;
        wrapper->style = style;
 
-       [window setDelegate:[[WindowDelegate alloc] init]];
-
        if(!windows)
                windows = CFDictionaryCreateMutable(NULL, 0, NULL, NULL);
        CFDictionaryAddValue(windows, window, wrapper);
@@ -91,18 +92,26 @@ void hide_window(CocoaWindow *window)
        (void)window;
 }
 
-@implementation WindowDelegate
+@implementation MspWindow
 
-- (void)windowWillClose:(NSNotification *)notification
+- (BOOL)windowShouldClose:(id)sender
 {
-       CocoaWindow *window = lookup_window((NSWindow *)[notification object]);
+       CocoaWindow *window = lookup_window((NSWindow *)sender);
        if(window)
        {
                CocoaEvent event;
                event.any.type = WINDOW_CLOSED;
                event.any.window = window;
                queue_event(window->display, &event);
+               return NO;
        }
+       return YES;
+}
+
+- (void)keyDown:(NSEvent *)event
+{
+       // Eat the event to avoid beeping
+       (void)event;
 }
 
 @end