# HG changeset patch # User John Tsiombikas # Date 1305620469 -10800 # Node ID a16b34ac3f2ab91828f3d93225205d4f6c4159df # Parent 5b8fb89fe63faaa2f55dc5016356366351eb7985 bah diff -r 5b8fb89fe63f -r a16b34ac3f2a configure --- a/configure Mon May 16 23:09:53 2011 +0300 +++ b/configure Tue May 17 11:21:09 2011 +0300 @@ -74,7 +74,7 @@ fi fi - name=`echo $m | sort | sed 's/src\/wsys_//' | sed 's/\.c\|\.m//'` + name=`echo $m | sort | sed 's/src\/wsys_//' | sed 's/\.c//' | sed 's/\.m//'` `which echo` -n "-> trying module $name (needs: $dep) ... " if try_link "$dep"; then diff -r 5b8fb89fe63f -r a16b34ac3f2a src/wsys_cocoa.m --- a/src/wsys_cocoa.m Mon May 16 23:09:53 2011 +0300 +++ b/src/wsys_cocoa.m Tue May 17 11:21:09 2011 +0300 @@ -6,12 +6,14 @@ #import #include "sgl.h" +#include "wsys.h" @interface OpenGLView : NSOpenGLView { + int foo; } -//-(id) initWithFrame: (NSRect) frameRect; +/*-(id) initWithFrame: (NSRect) frameRect;*/ -(void) drawRect: (NSRect) rect; -(void) reshape; @@ -32,8 +34,11 @@ struct window { int wid; + int width, height; NSWindow *win; OpenGLView *view; + NSOpenGLContext *ctx; + int needs_redisplay; struct window *next; }; @@ -89,7 +94,7 @@ void sgl_register_cocoa(void) { - sgl_register_cocoa(&ws); + sgl_register_module(&ws); } @@ -105,9 +110,16 @@ -(void) reshape { - sgl_reshape_callback_t func = sgl_get_callback(SGL_RESHAPE); - if(func) { - func(x, y); + NSSize sz; + sgl_reshape_callback_t func; + + sz = [self bounds].size; + + if((func = sgl_get_callback(SGL_RESHAPE)) && (sz.width != active_win->width || + sz.height != active_win->height)) { + active_win->width = sz.width; + active_win->height = sz.height; + func(sz.width, sz.height); } } @@ -120,6 +132,7 @@ static int init(void) { app = [NSApplication sharedApplication]; + return 0; } static void shutdown(void) @@ -151,7 +164,7 @@ { NSWindow *nswin; NSRect rect; - NSView *view; + OpenGLView *view; unsigned int style; struct window *win; static int next_id = 1; @@ -176,10 +189,15 @@ win->win = nswin; win->view = view; + win->ctx = [view openGLContext]; win->wid = next_id++; + win->needs_redisplay = 1; win->next = winlist; winlist = win; + if(!active_win) { + activate_window(win); + } return win->wid; } @@ -215,6 +233,8 @@ /* window management */ static int set_active(int wid) { + struct window *win = find_window(wid); + return activate_window(win); } static struct window *find_window(int wid) @@ -222,7 +242,7 @@ struct window *win = winlist; while(win) { - if(win->win == id) { + if(win->wid == wid) { return win; } win = win->next; @@ -247,16 +267,17 @@ nsstr = [[NSString alloc] initWithCString: str encoding: NSASCIIStringEncoding]; [active_win->win setTitle: nsstr]; [nsstr release]; + return 0; } static void redisplay(void) { - [active_win->view setNeedsRedisplay: YES]; + active_win->needs_redisplay = 1; } static void swap_buffers(void) { - [active_win->flushBuffer]; + [active_win->ctx flushBuffer]; } @@ -274,11 +295,26 @@ static int process_events(void) { NSAutoreleasePool *pool; - int state; sgl_idle_callback_t idle; + sgl_display_callback_t disp; + struct window *win; + int res = 0; pool = [[NSAutoreleasePool alloc] init]; + idle = sgl_get_callback(SGL_IDLE); + disp = sgl_get_callback(SGL_DISPLAY); + + win = winlist; + while(win) { + if(win->needs_redisplay && disp) { + activate_window(win); + disp(); + win->needs_redisplay = 0; + } + win = win->next; + } + for(;;) { NSEvent *ev = [app nextEventMatchingMask: NSAnyEventMask untilDate: [NSDate distantPast] inMode: NSDefaultRunLoopMode dequeue: YES]; @@ -286,8 +322,15 @@ break; } - handle_event(ev); + res = handle_event(ev); } + + if(idle) { + idle(); + } + + [pool drain]; + return 0; } static int handle_event(NSEvent *ev) @@ -295,7 +338,13 @@ switch([ev type]) { case NSKeyDown: case NSKeyUp: + printf("key pressed\n"); + break; + default: + break; + } + return 0; } #endif /* USE_WSYS_MODULE_COCOA */