sgl

diff src/wsys_cocoa.m @ 32:fc2dba4c5a5f

fuck yeah, I fixed the motherfucker, now let's roll
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 03 Jul 2011 05:23:30 +0300
parents 124195562f7e
children 46e90f9c1e0f
line diff
     1.1 --- a/src/wsys_cocoa.m	Sun Jul 03 04:33:32 2011 +0300
     1.2 +++ b/src/wsys_cocoa.m	Sun Jul 03 05:23:30 2011 +0300
     1.3 @@ -39,18 +39,27 @@
     1.4  
     1.5  @interface AppDelegate : NSObject
     1.6  {
     1.7 -	int foo;
     1.8  }
     1.9  
    1.10  -(void) applicationWillFinishLaunching: (NSNotification*) notification;
    1.11  -(void) applicationDidFinishLaunching: (NSNotification*) notification;
    1.12  
    1.13 --(void) windowDidExpose: (NSNotification*) notification;
    1.14 --(void) windowDidResize: (NSNotification*) notification;
    1.15 -
    1.16  -(BOOL) applicationShouldTerminate: (NSApplication*) app;
    1.17  -(BOOL) applicationShouldTerminateAfterLastWindowClosed: (NSApplication*) app;
    1.18  -(void) applicationWillTerminate: (NSNotification*) notification;
    1.19 +@end
    1.20 +
    1.21 +struct window;
    1.22 +
    1.23 +@interface WinDelegate : NSObject <NSWindowDelegate>
    1.24 +{
    1.25 +	struct window *win;
    1.26 +}
    1.27 +-(id) init;
    1.28 +-(void) dealloc;
    1.29 +
    1.30 +-(void) windowDidExpose: (NSNotification*) notification;
    1.31 +-(void) windowDidResize: (NSNotification*) notification;
    1.32  -(BOOL) windowShouldClose: (id) win;
    1.33  -(void) windowWillClose: (NSNotification*) notification;
    1.34  @end
    1.35 @@ -176,16 +185,6 @@
    1.36  	APPLE_SUCKS();
    1.37  }
    1.38  
    1.39 --(void) windowDidExpose: (NSNotification*) notification
    1.40 -{
    1.41 -	APPLE_SUCKS();
    1.42 -}
    1.43 -
    1.44 --(void) windowDidResize: (NSNotification*) notification
    1.45 -{
    1.46 -	APPLE_SUCKS();
    1.47 -}
    1.48 -
    1.49  -(BOOL) applicationShouldTerminate: (NSApplication*) app
    1.50  {
    1.51  	APPLE_SUCKS();
    1.52 @@ -201,11 +200,40 @@
    1.53  -(void) applicationWillTerminate: (NSNotification*) notification
    1.54  {
    1.55  	APPLE_SUCKS();
    1.56 +	/*[NSApp setDelegate: nil];
    1.57 +	[global_pool drain];*/
    1.58 +}
    1.59 +@end
    1.60 +
    1.61 +@implementation WinDelegate
    1.62 +-(id) init
    1.63 +{
    1.64 +	APPLE_SUCKS();
    1.65 +	self = [super init];
    1.66 +	return self;
    1.67 +}
    1.68 +
    1.69 +-(void) dealloc
    1.70 +{
    1.71 +	APPLE_SUCKS();
    1.72 +	[super dealloc];
    1.73 +}
    1.74 +
    1.75 +-(void) windowDidExpose: (NSNotification*) notification
    1.76 +{
    1.77 +	APPLE_SUCKS();
    1.78 +}
    1.79 +
    1.80 +-(void) windowDidResize: (NSNotification*) notification
    1.81 +{
    1.82 +	APPLE_SUCKS();
    1.83  }
    1.84  
    1.85  -(BOOL) windowShouldClose: (id) win
    1.86  {
    1.87  	APPLE_SUCKS();
    1.88 +	assert(self->win);
    1.89 +	close_window(self->win->wid);
    1.90  	return YES;
    1.91  }
    1.92  
    1.93 @@ -238,8 +266,7 @@
    1.94  	}
    1.95  
    1.96  	quit_main_loop = 1;
    1.97 -	[NSApp setDelegate: nil];
    1.98 -	[global_pool drain];
    1.99 +	[NSApp terminate: nil];
   1.100  }
   1.101  
   1.102  
   1.103 @@ -260,6 +287,7 @@
   1.104  {
   1.105  	APPLE_SUCKS();
   1.106  	NSAutoreleasePool *pool;
   1.107 +	WinDelegate *delegate;
   1.108  	NSWindow *nswin;
   1.109  	NSRect rect;
   1.110  	OpenGLView *view;
   1.111 @@ -291,6 +319,9 @@
   1.112  	nswin = [[NSWindow alloc] initWithContentRect: rect styleMask: style
   1.113  		backing: NSBackingStoreBuffered defer: YES];
   1.114  
   1.115 +	delegate = [[WinDelegate alloc] init];
   1.116 +
   1.117 +	[nswin setDelegate: delegate];
   1.118  	[nswin setTitle: @"OpenGL/Cocoa"];
   1.119  	[nswin setReleasedWhenClosed: YES];
   1.120  	[nswin setContentView: view];
   1.121 @@ -306,6 +337,8 @@
   1.122  	win->next = winlist;
   1.123  	winlist = win;
   1.124  
   1.125 +	delegate->win = win;
   1.126 +
   1.127  	if(!active_win) {
   1.128  		activate_window(win);
   1.129  	}
   1.130 @@ -325,7 +358,7 @@
   1.131  
   1.132  	while(win) {
   1.133  		if(win->wid == wid) {
   1.134 -			if(!(close_func = sgl_get_callback(SGL_CLOSE))) {
   1.135 +			if((close_func = sgl_get_callback(SGL_CLOSE))) {
   1.136  				close_func(wid);
   1.137  			}
   1.138  			[win->win close];
   1.139 @@ -346,7 +379,8 @@
   1.140  		win = win->next;
   1.141  	}
   1.142  
   1.143 -	if(!winlist) {
   1.144 +	if(!dummy.next) {
   1.145 +		winlist = 0;
   1.146  		shutdown();
   1.147  	}
   1.148  }