sgl

diff src/wsys_cocoa.m @ 31:124195562f7e

FUCKING AUTORELEASE POOL
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 03 Jul 2011 04:33:32 +0300
parents 171aa71b97e7
children fc2dba4c5a5f
line diff
     1.1 --- a/src/wsys_cocoa.m	Tue Jun 28 13:52:02 2011 +0300
     1.2 +++ b/src/wsys_cocoa.m	Sun Jul 03 04:33:32 2011 +0300
     1.3 @@ -8,6 +8,9 @@
     1.4  #import <Cocoa/Cocoa.h>
     1.5  #include "sgl.h"
     1.6  #include "wsys.h"
     1.7 +#include "log.h"
     1.8 +
     1.9 +#define APPLE_SUCKS()	sgl_log("%s called\n", __func__)
    1.10  
    1.11  @interface OpenGLView : NSOpenGLView
    1.12  {
    1.13 @@ -38,8 +41,18 @@
    1.14  {
    1.15  	int foo;
    1.16  }
    1.17 +
    1.18 +-(void) applicationWillFinishLaunching: (NSNotification*) notification;
    1.19 +-(void) applicationDidFinishLaunching: (NSNotification*) notification;
    1.20 +
    1.21 +-(void) windowDidExpose: (NSNotification*) notification;
    1.22 +-(void) windowDidResize: (NSNotification*) notification;
    1.23 +
    1.24  -(BOOL) applicationShouldTerminate: (NSApplication*) app;
    1.25 --(BOOL) applicationShouldTerminateAfterLastWindowClosed: (NSApplication*)app;
    1.26 +-(BOOL) applicationShouldTerminateAfterLastWindowClosed: (NSApplication*) app;
    1.27 +-(void) applicationWillTerminate: (NSNotification*) notification;
    1.28 +-(BOOL) windowShouldClose: (id) win;
    1.29 +-(void) windowWillClose: (NSNotification*) notification;
    1.30  @end
    1.31  
    1.32  
    1.33 @@ -103,6 +116,7 @@
    1.34  static struct window *winlist, *active_win;
    1.35  static int quit_main_loop;
    1.36  
    1.37 +static NSAutoreleasePool *global_pool;
    1.38  
    1.39  void sgl_register_cocoa(void)
    1.40  {
    1.41 @@ -114,12 +128,14 @@
    1.42  
    1.43  -(id) initWithFrame: (NSRect) frame pixelFormat: (NSOpenGLPixelFormat*) pf
    1.44  {
    1.45 +	APPLE_SUCKS();
    1.46  	self = [super initWithFrame: frame pixelFormat: pf];
    1.47  	return self;
    1.48  }
    1.49  
    1.50  -(void) drawRect: (NSRect) rect
    1.51  {
    1.52 +	APPLE_SUCKS();
    1.53  	sgl_display_callback_t func = sgl_get_callback(SGL_DISPLAY);
    1.54  	if(func) {
    1.55  		func();
    1.56 @@ -128,6 +144,7 @@
    1.57  
    1.58  -(void) reshape
    1.59  {
    1.60 +	APPLE_SUCKS();
    1.61  	NSSize sz;
    1.62  	sgl_reshape_callback_t func;
    1.63  
    1.64 @@ -143,41 +160,69 @@
    1.65  
    1.66  -(BOOL) acceptsFirstResponder
    1.67  {
    1.68 +	APPLE_SUCKS();
    1.69  	return YES;
    1.70  }
    1.71  @end
    1.72  
    1.73  @implementation AppDelegate
    1.74 +-(void) applicationWillFinishLaunching: (NSNotification*) notification
    1.75 +{
    1.76 +	APPLE_SUCKS();
    1.77 +}
    1.78 +
    1.79 +-(void) applicationDidFinishLaunching: (NSNotification*) notification
    1.80 +{
    1.81 +	APPLE_SUCKS();
    1.82 +}
    1.83 +
    1.84 +-(void) windowDidExpose: (NSNotification*) notification
    1.85 +{
    1.86 +	APPLE_SUCKS();
    1.87 +}
    1.88 +
    1.89 +-(void) windowDidResize: (NSNotification*) notification
    1.90 +{
    1.91 +	APPLE_SUCKS();
    1.92 +}
    1.93 +
    1.94  -(BOOL) applicationShouldTerminate: (NSApplication*) app
    1.95  {
    1.96 +	APPLE_SUCKS();
    1.97  	return NSTerminateNow;
    1.98  }
    1.99  
   1.100  -(BOOL) applicationShouldTerminateAfterLastWindowClosed: (NSApplication*) app
   1.101  {
   1.102 +	APPLE_SUCKS();
   1.103  	return YES;
   1.104  }
   1.105  
   1.106  -(void) applicationWillTerminate: (NSNotification*) notification
   1.107  {
   1.108 -	printf("applicationWillTerminate\n");
   1.109 +	APPLE_SUCKS();
   1.110  }
   1.111  
   1.112  -(BOOL) windowShouldClose: (id) win
   1.113  {
   1.114 +	APPLE_SUCKS();
   1.115  	return YES;
   1.116  }
   1.117  
   1.118  -(void) windowWillClose: (NSNotification*) notification
   1.119  {
   1.120 -	[NSApp terminate: nil];
   1.121 +	APPLE_SUCKS();
   1.122 +	/*[NSApp terminate: nil];*/
   1.123  }
   1.124  @end
   1.125  
   1.126  static int init(void)
   1.127  {
   1.128 +	APPLE_SUCKS();
   1.129  	AppDelegate *delegate;
   1.130  
   1.131 +	global_pool = [[NSAutoreleasePool alloc] init];
   1.132 +
   1.133  	[NSApplication sharedApplication];
   1.134  
   1.135  	delegate = [[AppDelegate alloc] init];
   1.136 @@ -187,15 +232,14 @@
   1.137  
   1.138  static void shutdown(void)
   1.139  {
   1.140 +	APPLE_SUCKS();
   1.141  	while(winlist) {
   1.142 -		struct window *win = winlist;
   1.143 -		winlist = winlist->next;
   1.144 -
   1.145 -		/* TODO destroy window */
   1.146 -		free(win);
   1.147 +		close_window(winlist->wid);
   1.148  	}
   1.149  
   1.150  	quit_main_loop = 1;
   1.151 +	[NSApp setDelegate: nil];
   1.152 +	[global_pool drain];
   1.153  }
   1.154  
   1.155  
   1.156 @@ -214,6 +258,7 @@
   1.157  /* create/destroy windows */
   1.158  static int create_window(int xsz, int ysz, unsigned int flags)
   1.159  {
   1.160 +	APPLE_SUCKS();
   1.161  	NSAutoreleasePool *pool;
   1.162  	NSWindow *nswin;
   1.163  	NSRect rect;
   1.164 @@ -271,6 +316,7 @@
   1.165  
   1.166  static void close_window(int wid)
   1.167  {
   1.168 +	APPLE_SUCKS();
   1.169  	struct window *win, *prev, dummy;
   1.170  	sgl_close_callback_t close_func;
   1.171  
   1.172 @@ -284,17 +330,25 @@
   1.173  			}
   1.174  			[win->win close];
   1.175  
   1.176 +			prev->next = win->next;
   1.177 +
   1.178 +			if(!dummy.next) {
   1.179 +				winlist = 0;
   1.180 +			}
   1.181 +
   1.182  			if(active_win == win) {
   1.183  				activate_window(winlist);
   1.184  			}
   1.185 -
   1.186 -			prev->next = win->next;
   1.187  			free(win);
   1.188 -			return;
   1.189 +			break;
   1.190  		}
   1.191  		prev = win;
   1.192  		win = win->next;
   1.193  	}
   1.194 +
   1.195 +	if(!winlist) {
   1.196 +		shutdown();
   1.197 +	}
   1.198  }
   1.199  
   1.200  
   1.201 @@ -407,6 +461,8 @@
   1.202  
   1.203  	[runloop release];
   1.204  	[pool drain];
   1.205 +
   1.206 +	/*sgl_log("%s returning: %d\n", __func__, quit_main_loop ? -1 : 0);*/
   1.207  	return quit_main_loop ? -1 : 0;
   1.208  }
   1.209