# HG changeset patch # User John Tsiombikas # Date 1309659810 -10800 # Node ID fc2dba4c5a5f134bd461ead650874a3360cd2d5b # Parent 124195562f7ebe5244048a7d8c1db8ce0410a0d0 fuck yeah, I fixed the motherfucker, now let's roll diff -r 124195562f7e -r fc2dba4c5a5f src/wsys_cocoa.m --- a/src/wsys_cocoa.m Sun Jul 03 04:33:32 2011 +0300 +++ b/src/wsys_cocoa.m Sun Jul 03 05:23:30 2011 +0300 @@ -39,18 +39,27 @@ @interface AppDelegate : NSObject { - int foo; } -(void) applicationWillFinishLaunching: (NSNotification*) notification; -(void) applicationDidFinishLaunching: (NSNotification*) notification; --(void) windowDidExpose: (NSNotification*) notification; --(void) windowDidResize: (NSNotification*) notification; - -(BOOL) applicationShouldTerminate: (NSApplication*) app; -(BOOL) applicationShouldTerminateAfterLastWindowClosed: (NSApplication*) app; -(void) applicationWillTerminate: (NSNotification*) notification; +@end + +struct window; + +@interface WinDelegate : NSObject +{ + struct window *win; +} +-(id) init; +-(void) dealloc; + +-(void) windowDidExpose: (NSNotification*) notification; +-(void) windowDidResize: (NSNotification*) notification; -(BOOL) windowShouldClose: (id) win; -(void) windowWillClose: (NSNotification*) notification; @end @@ -176,16 +185,6 @@ APPLE_SUCKS(); } --(void) windowDidExpose: (NSNotification*) notification -{ - APPLE_SUCKS(); -} - --(void) windowDidResize: (NSNotification*) notification -{ - APPLE_SUCKS(); -} - -(BOOL) applicationShouldTerminate: (NSApplication*) app { APPLE_SUCKS(); @@ -201,11 +200,40 @@ -(void) applicationWillTerminate: (NSNotification*) notification { APPLE_SUCKS(); + /*[NSApp setDelegate: nil]; + [global_pool drain];*/ +} +@end + +@implementation WinDelegate +-(id) init +{ + APPLE_SUCKS(); + self = [super init]; + return self; +} + +-(void) dealloc +{ + APPLE_SUCKS(); + [super dealloc]; +} + +-(void) windowDidExpose: (NSNotification*) notification +{ + APPLE_SUCKS(); +} + +-(void) windowDidResize: (NSNotification*) notification +{ + APPLE_SUCKS(); } -(BOOL) windowShouldClose: (id) win { APPLE_SUCKS(); + assert(self->win); + close_window(self->win->wid); return YES; } @@ -238,8 +266,7 @@ } quit_main_loop = 1; - [NSApp setDelegate: nil]; - [global_pool drain]; + [NSApp terminate: nil]; } @@ -260,6 +287,7 @@ { APPLE_SUCKS(); NSAutoreleasePool *pool; + WinDelegate *delegate; NSWindow *nswin; NSRect rect; OpenGLView *view; @@ -291,6 +319,9 @@ nswin = [[NSWindow alloc] initWithContentRect: rect styleMask: style backing: NSBackingStoreBuffered defer: YES]; + delegate = [[WinDelegate alloc] init]; + + [nswin setDelegate: delegate]; [nswin setTitle: @"OpenGL/Cocoa"]; [nswin setReleasedWhenClosed: YES]; [nswin setContentView: view]; @@ -306,6 +337,8 @@ win->next = winlist; winlist = win; + delegate->win = win; + if(!active_win) { activate_window(win); } @@ -325,7 +358,7 @@ while(win) { if(win->wid == wid) { - if(!(close_func = sgl_get_callback(SGL_CLOSE))) { + if((close_func = sgl_get_callback(SGL_CLOSE))) { close_func(wid); } [win->win close]; @@ -346,7 +379,8 @@ win = win->next; } - if(!winlist) { + if(!dummy.next) { + winlist = 0; shutdown(); } }