Index: makefile.lst
===================================================================
--- makefile.lst	(revision 7856)
+++ makefile.lst	(working copy)
@@ -382,12 +382,11 @@
 	src/macosx/hidman.m \
 	src/macosx/keybd.m \
 	src/macosx/pcpu.m \
-	src/macosx/qtmidi.m \
 	src/macosx/quartz.m \
 	src/macosx/qzfull.m \
 	src/macosx/qzmouse.m \
 	src/macosx/qzwindow.m \
-	src/macosx/soundman.m \
+	src/macosx/osxgl.m \
 	src/macosx/system.m \
 	src/unix/ufile.c \
 	src/unix/usystem.c \
Index: makefile.osx
===================================================================
--- makefile.osx	(revision 7856)
+++ makefile.osx	(working copy)
@@ -158,7 +158,7 @@
 
 OBJECT_LIST = $(COMMON_OBJECTS) $(C_OBJECTS) $(basename $(notdir $(ALLEGRO_SRC_MACOSX_FILES)))
 
-STATIC_LIBRARIES = -framework Cocoa -framework Carbon -framework IOKit -framework System -framework CoreAudio -framework AudioUnit -framework AudioToolbox -framework QuickTime
+STATIC_LIBRARIES = -framework Cocoa -framework Carbon -framework IOKit -framework System -framework CoreAudio -framework AudioUnit -framework AudioToolbox -framework OpenGL
 ifdef STATICLINK
 LIBRARIES = $(STATIC_LIBRARIES)
 else
Index: src/compat/comouse.c
===================================================================
--- src/compat/comouse.c	(revision 7856)
+++ src/compat/comouse.c	(working copy)
@@ -163,7 +163,8 @@
 static void draw_mouse_doublebuffer(int newx, int newy)
 {
    int x1, y1, w, h;
-
+   if (_mouse_screen == NULL) return;
+   
    /* grab bit of screen containing where we are and where we'll be */
    x1 = MIN(mx, newx) - mouse_x_focus;
    y1 = MIN(my, newy) - mouse_y_focus;
Index: src/macosx/main.m
===================================================================
--- src/macosx/main.m	(revision 7856)
+++ src/macosx/main.m	(working copy)
@@ -63,12 +63,10 @@
 
 
 /* applicationDidFinishLaunching:
- *  Called when the app is ready to run. This runs the system events pump and
- *  updates the app window if it exists.
+ *  Called when the app is ready to run. 
  */
 - (void)applicationDidFinishLaunching: (NSNotification *)aNotification
 {
-   NSAutoreleasePool *pool = NULL;
    CFDictionaryRef mode;
    NSString* exename, *resdir;
    NSFileManager* fm;
@@ -77,7 +75,6 @@
    /* create mutex */
    _al_mutex_init(&osx_event_mutex);
    
-   pool = [[NSAutoreleasePool alloc] init];
    if (in_bundle() == YES)   
    {
       /* In a bundle, so chdir to the containing directory,
@@ -124,23 +121,6 @@
       toTarget: [AllegroAppDelegate class]
       withObject: nil];
    return;
-   while (1) {
-      if (osx_gfx_mode == OSX_GFX_WINDOW)
-         osx_update_dirty_lines();
-      _al_mutex_lock(&osx_event_mutex);
-      if (osx_gfx_mode == OSX_GFX_FULL) {
-         if ((osx_palette) && (osx_palette_dirty)) {
-            CGDisplaySetPalette(kCGDirectMainDisplay, osx_palette);
-	    osx_palette_dirty = FALSE;
-	 }
-      }
-      osx_event_handler();
-      _al_mutex_unlock(&osx_event_mutex);
-      usleep(1000000 / refresh_rate);
-   }
-   
-   [pool release];
-   _al_mutex_destroy(&osx_event_mutex);
 }
 
 
Index: src/macosx/system.m
===================================================================
--- src/macosx/system.m	(revision 7856)
+++ src/macosx/system.m	(working copy)
@@ -143,209 +143,6 @@
 }
 
 
-
-/* osx_event_handler:
- *  Event handling function; gets repeatedly called inside a dedicated thread.
- */
- /*
-void osx_event_handler()
-{
-   NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-   NSEvent *event;
-   NSDate *distant_past = [NSDate distantPast];
-   NSPoint point;
-   NSRect frame;
-   CGMouseDelta fdx, fdy;
-   int dx = 0, dy = 0, dz = 0;
-   int mx=_mouse_x;
-   int my=_mouse_y;
-   static int buttons = 0;
-   int old_buttons = buttons;
-   int event_type;
-   BOOL gotmouseevent = NO;
-   
-   while ((event = [NSApp nextEventMatchingMask: NSAnyEventMask
-         untilDate: distant_past
-         inMode: NSDefaultRunLoopMode
-         dequeue: YES]) != nil)
-     {
-      if ((skip_events_processing) || (osx_gfx_mode == OSX_GFX_NONE)) {
-         [NSApp sendEvent: event];
-	 continue;
-      }
-      
-      point = [event locationInWindow];
-      if (osx_window) 
-      {
-	 frame = [[osx_window contentView] frame];
-      }
-      else
-      {
-	 frame = [[NSScreen mainScreen] frame];
-      }
-      event_type = [event type];
-      switch (event_type) {
-	 
-//         case NSKeyDown:
-//	    if (_keyboard_installed)
-//	       osx_keyboard_handler(TRUE, event);
-//	    if ([event modifierFlags] & NSCommandKeyMask) 
-//	       [NSApp sendEvent: event];
-//	    break;
-	
-//         case NSKeyUp:
-//	    if (_keyboard_installed)
-//	       osx_keyboard_handler(FALSE, event);
-//	    if ([event modifierFlags] & NSCommandKeyMask) 
-//	       [NSApp sendEvent: event];
-//	    break;
-
-//          case NSFlagsChanged:
-// 	    break;
-	 
-         case NSLeftMouseDown:
-         case NSOtherMouseDown:
-         case NSRightMouseDown:
-	    if (![NSApp isActive]) {
-	       // App is regaining focus 
-	       if (_mouse_installed) {
-	          if ((osx_window) && (NSPointInRect(point, NSMakeRect(0, 0, gfx_driver->w, gfx_driver->h)))) {
-                     mx = point.x;
-	             my = frame.size.height - point.y;
-		     buttons = 0;
-                     _mouse_on = TRUE;
-	          }
-	       }
-	       if (osx_window)
-                  [osx_window invalidateCursorRectsForView: [osx_window contentView]];
-	       if (_keyboard_installed)
-	          osx_keyboard_focused(TRUE, 0);
-	       _switch_in();
-	       gotmouseevent = YES;
-	       [NSApp sendEvent: event];
-	       break;
-	    }
-	    // fallthrough 
-         case NSLeftMouseUp:
-         case NSOtherMouseUp:
-         case NSRightMouseUp:
-	    if (osx_emulate_mouse_buttons) {
-	       if (event_type == NSLeftMouseDown) {
-                  if ((!osx_window) || (NSPointInRect(point, NSMakeRect(0, 0, gfx_driver->w, gfx_driver->h)))) {
-		     buttons = 0x1;
-		     if (key[KEY_ALT])
-		        buttons = 0x4;
-		     if (key[KEY_LCONTROL])
-		        buttons = 0x2;
-		  }
-	       }
-	       else if (event_type == NSLeftMouseUp)
-	          buttons &= ~0x7;
-	    }
-	    else {
-	       if ((!osx_window) || (NSPointInRect(point, NSMakeRect(0, 0, gfx_driver->w, gfx_driver->h)))) {
-	          // Deliver mouse downs only if cursor is on the window 
-	          buttons |= ((event_type == NSLeftMouseDown) ? 0x1 : 0);
-	          buttons |= ((event_type == NSRightMouseDown) ? 0x2 : 0);
-	          buttons |= ((event_type == NSOtherMouseDown) ? 0x4 : 0);
-	       }
-	       buttons &= ~((event_type == NSLeftMouseUp) ? 0x1 : 0);
-	       buttons &= ~((event_type == NSRightMouseUp) ? 0x2 : 0);
-	       buttons &= ~((event_type == NSOtherMouseUp) ? 0x4 : 0);
-	    }
-	    gotmouseevent = YES;
-	    [NSApp sendEvent: event];
-	    break;
-	    
-         case NSLeftMouseDragged:
-         case NSRightMouseDragged:
-         case NSOtherMouseDragged:
-         case NSMouseMoved:
-	    dx += [event deltaX];
-	    dy += [event deltaY];
-
-	    mx=point.x;
-	    my=frame.size.height-point.y;
-
-	    [NSApp sendEvent: event];
-	    gotmouseevent = YES;
-	    break;
-            
-         case NSScrollWheel:
-	    dz += [event deltaY];
-	    gotmouseevent = YES;
-            break;
-	    
-	 case NSMouseEntered:
-	    if (([event trackingNumber] == osx_mouse_tracking_rect) && ([NSApp isActive])) {
-	       if (_mouse_installed) {
-		  mx = point.x;
-	          my = frame.size.height - point.y;
-		  buttons = 0;
-                  _mouse_on = TRUE;
-		  gotmouseevent = YES;
-	       }
-	    }
-	    [NSApp sendEvent: event];
-	    break;
-            
-	 case NSMouseExited:
-	    if ([event trackingNumber] == osx_mouse_tracking_rect) {
-	       if (_mouse_installed) {
-	          _mouse_on = FALSE;
-		  gotmouseevent = YES;
-	       }
-	    }
-            [NSApp sendEvent: event];
-	    break;
-            
-	 case NSAppKitDefined:
-            switch ([event subtype]) {
-               case NSApplicationActivatedEventType:
-	          if (osx_window) {
-		     [osx_window invalidateCursorRectsForView: [osx_window contentView]];
-                     if (_keyboard_installed)
-	                osx_keyboard_focused(TRUE, 0);
-		  }
-		  _switch_in();
-                  break;
-		  
-               case NSApplicationDeactivatedEventType:
-		  if (osx_window && _keyboard_installed)
-		     osx_keyboard_focused(FALSE, 0);
-		  _switch_out();
-                  break;
-	       
-	       case NSWindowMovedEventType:
-                  // This is needed to ensure the shadow gets drawn when the window is
-		   // created. It's weird, but when the window is created on another
-		   // thread, sometimes its shadow doesn't get drawn. The same applies
-		   // to the cursor rectangle, which doesn't seem to be set at window
-		   // creation (it works once you move the mouse though).
-		   
-	          if ((osx_window) && (osx_window_first_expose)) {
-		     osx_window_first_expose = FALSE;
-                     [osx_window setHasShadow: NO];
-                     [osx_window setHasShadow: YES];
-		     [osx_window invalidateCursorRectsForView: [osx_window contentView]];
-		  }
-		  break;
-	    }
-            [NSApp sendEvent: event];
-            break;
-	 
-	 default:
-	    [NSApp sendEvent: event];
-	    break;
-      }
-   }
-   if (gotmouseevent == YES)
-      osx_mouse_handler(mx, my, dx, dy, dz, buttons);
-   [pool release];
-}
-*/
-
-
 /* osx_tell_dock:
  *  Tell the dock about us; the origins of this hack are unknown, but it's
  *  currently the only way to make a Cocoa app to work when started from a
Index: src/macosx/keybd.m
===================================================================
--- src/macosx/keybd.m	(revision 7856)
+++ src/macosx/keybd.m	(working copy)
@@ -39,9 +39,6 @@
    int type;
    _al_event_source_lock(&keyboard.es);
    {
-      /* Update the key_down array.  */
-      //      _AL_KBDSTATE_SET_KEY_DOWN(the_keyboard.state, mycode);
-
       /* Generate the press event if necessary. */
       type = is_repeat ? AL_EVENT_KEY_REPEAT : AL_EVENT_KEY_DOWN;
       if ((_al_event_source_needs_to_generate_event(&keyboard.es, type)) \
@@ -60,8 +57,25 @@
    _al_event_source_unlock(&keyboard.es);
 
 }
-static void _handle_key_release(int x) {
-
+static void _handle_key_release(int scancode) {
+   AL_EVENT* event;
+   _al_event_source_lock(&keyboard.es);
+   {
+      /* Generate the release event if necessary. */
+      if ((_al_event_source_needs_to_generate_event(&keyboard.es, AL_EVENT_KEY_UP)) \
+&&
+          (event = _al_event_source_get_unused_event(&keyboard.es)))
+         {
+            event->keyboard.type = AL_EVENT_KEY_UP;
+            event->keyboard.timestamp = al_current_time();
+            event->keyboard.__display__dont_use_yet__ = NULL; /* TODO */
+            event->keyboard.keycode   = scancode;
+            event->keyboard.unichar   = 0;
+            event->keyboard.modifiers = 0;
+            _al_event_source_emit_event(&keyboard.es, event);
+         }
+   }
+   _al_event_source_unlock(&keyboard.es);
 }
 /* Mac keycode to Allegro scancode conversion table */
 static const int mac_to_scancode[128] = {
@@ -124,9 +138,9 @@
 /* osx_keyboard_handler:
  *  Keyboard "interrupt" handler.
  */
-void osx_keyboard_handler(int pressed, NSEvent *event)
+void osx_keyboard_handler(int pressed, NSEvent *event, AL_DISPLAY* dpy)
 {
-   const char character = [[event charactersIgnoringModifiers] lossyCString][0];
+   const char character = [[event charactersIgnoringModifiers] characterAtIndex: 0];
    int scancode = mac_to_scancode[[event keyCode]];
    int modifiers = [event modifierFlags];
    
@@ -153,7 +167,7 @@
 /* osx_keyboard_modifier:
  *  Handles keyboard modifiers changes.
  */
-void osx_keyboard_modifiers(unsigned int mods)
+void osx_keyboard_modifiers(unsigned int mods, AL_DISPLAY* dpy)
 {
    unsigned const int mod_info[5][3] = { { NSAlphaShiftKeyMask, KB_CAPSLOCK_FLAG, KEY_CAPSLOCK },
                                          { NSShiftKeyMask,      KB_SHIFT_FLAG,    KEY_LSHIFT   },
Index: src/macosx/qzmouse.m
===================================================================
--- src/macosx/qzmouse.m	(revision 7856)
+++ src/macosx/qzmouse.m	(working copy)
@@ -41,9 +41,7 @@
 static bool osx_set_mouse_axis(int axis, int value);
 static AL_MOUSE* osx_get_mouse(void);
 static void osx_get_state(AL_MSESTATE *ret_state);
-void osx_mouse_generate_event(NSEvent* evt);
 
-
 AL_MOUSE_DRIVER mouse_macosx = {
    MOUSE_MACOSX,
    empty_string,
@@ -66,12 +64,6 @@
 int osx_skip_mouse_move = FALSE;
 NSTrackingRectTag osx_mouse_tracking_rect = -1;
 
-
-/*
-  static NSCursor *cursor = NULL, *current_cursor = NULL;
-  static NSCursor *requested_cursor = NULL;
-*/
-
 /* Mouse info - includes extra info for OS X */
 static struct {
    AL_MOUSE parent;
@@ -97,7 +89,7 @@
  * and push it into a queue.
  * First check that the event is wanted.
  */
-void osx_mouse_generate_event(NSEvent* evt)
+void osx_mouse_generate_event(NSEvent* evt, AL_DISPLAY* dpy)
 {
    NSPoint pos;
    int type, b_change = 0, dx = 0, dy = 0, dz = 0, dw = 0, b = 0;
Index: src/macosx/qzfull.m
===================================================================
--- src/macosx/qzfull.m	(revision 7856)
+++ src/macosx/qzfull.m	(working copy)
@@ -251,12 +251,13 @@
 
 static BITMAP *osx_qz_full_init(int w, int h, int v_w, int v_h, int color_depth)
 {
-   BITMAP *bmp;
-   _al_mutex_lock(&osx_event_mutex);
-   bmp = private_osx_qz_full_init(w, h, v_w, v_h, color_depth);
-   _al_mutex_unlock(&osx_event_mutex);
-   if (!bmp)
-      osx_qz_full_exit(bmp);
+   BITMAP *bmp = NULL;
+   /* Unfortunately fullscreen mode is broken in 4.3 */
+//   _al_mutex_lock(&osx_event_mutex);
+//   bmp = private_osx_qz_full_init(w, h, v_w, v_h, color_depth);
+//   _al_mutex_unlock(&osx_event_mutex);
+//   if (!bmp)
+//      osx_qz_full_exit(bmp);
    return bmp;
 }
 
Index: src/macosx/drivers.m
===================================================================
--- src/macosx/drivers.m	(revision 7856)
+++ src/macosx/drivers.m	(working copy)
@@ -36,6 +36,7 @@
 
 
 BEGIN_GFX_DRIVER_LIST
+{   GFX_OPENGL_WINDOW,        &gfx_opengl_window,       TRUE  },
 {   GFX_QUARTZ_FULLSCREEN,    &gfx_quartz_full,         TRUE  },
 {   GFX_QUARTZ_WINDOW,        &gfx_quartz_window,       TRUE  },
 END_GFX_DRIVER_LIST
@@ -43,13 +44,15 @@
 
 BEGIN_DIGI_DRIVER_LIST
 {   DIGI_CORE_AUDIO,          &digi_core_audio,         TRUE  },
-{   DIGI_SOUND_MANAGER,       &digi_sound_manager,      TRUE  },
+/* Obsolete in 10.2 and above */
+//{   DIGI_SOUND_MANAGER,       &digi_sound_manager,      TRUE  },
 END_DIGI_DRIVER_LIST
 
 
 BEGIN_MIDI_DRIVER_LIST
 {   MIDI_CORE_AUDIO,          &midi_core_audio,         TRUE  },
-{   MIDI_QUICKTIME,           &midi_quicktime,          TRUE  },
+/* Obsolete in 10.2 and above */
+//{   MIDI_QUICKTIME,           &midi_quicktime,          TRUE  },
 END_MIDI_DRIVER_LIST
 
 
Index: src/macosx/qzwindow.m
===================================================================
--- src/macosx/qzwindow.m	(revision 7856)
+++ src/macosx/qzwindow.m	(working copy)
@@ -257,17 +257,18 @@
 -(void) keyDown:(NSEvent*) event
 {
    if (_keyboard_installed)
-      osx_keyboard_handler(TRUE, event);
+      osx_keyboard_handler(TRUE, event, 0);
 }
 -(void) keyUp:(NSEvent*) event 
 {
    if (_keyboard_installed)
-      osx_keyboard_handler(FALSE, event);
+      osx_keyboard_handler(FALSE, event, 0);
 }
 -(void) flagsChanged:(NSEvent*) event
 {
-   if (_keyboard_installed)
-      osx_keyboard_modifiers([event modifierFlags]);
+   if (_keyboard_installed) {
+      osx_keyboard_modifiers([event modifierFlags], 0);
+   }
 }
 -(void) drawRect:(NSRect) aRect
 {
@@ -279,7 +280,7 @@
    char *qd_view_addr;
 
    [super drawRect: aRect];
-   _al_mutex_lock(&osx_window_mutex);
+   //_al_mutex_lock(&osx_window_mutex);
 
    if ([self lockFocusIfCanDraw] == YES) {
       while (!QDDone([self qdPort]));
@@ -326,7 +327,7 @@
       UnlockPortBits(qd_view_port);
       [self unlockFocus];
    }
-   _al_mutex_unlock(&osx_window_mutex);
+   //_al_mutex_unlock(&osx_window_mutex);
 
    osx_signal_vsync();
 
@@ -335,47 +336,47 @@
 /* Mouse handling */
 -(void) mouseDown: (NSEvent*) evt
 {
-   osx_mouse_generate_event(evt);
+   osx_mouse_generate_event(evt, 0);
 }
 -(void) mouseUp: (NSEvent*) evt
 {
-   osx_mouse_generate_event(evt);
+   osx_mouse_generate_event(evt, 0);
 }
 -(void) mouseDragged: (NSEvent*) evt
 {
-   osx_mouse_generate_event(evt);
+   osx_mouse_generate_event(evt, 0);
 }
 -(void) rightMouseDown: (NSEvent*) evt
 {
-   osx_mouse_generate_event(evt);
+   osx_mouse_generate_event(evt, 0);
 }
 -(void) rightMouseUp: (NSEvent*) evt
 {
-   osx_mouse_generate_event(evt);
+   osx_mouse_generate_event(evt, 0);
 }
 -(void) rightMouseDragged: (NSEvent*) evt
 {
-   osx_mouse_generate_event(evt);
+   osx_mouse_generate_event(evt, 0);
 }
 -(void) otherMouseDown: (NSEvent*) evt
 {
-   osx_mouse_generate_event(evt);
+   osx_mouse_generate_event(evt, 0);
 }
 -(void) otherMouseUp: (NSEvent*) evt
 {
-   osx_mouse_generate_event(evt);
+   osx_mouse_generate_event(evt, 0);
 }
 -(void) otherMouseDragged: (NSEvent*) evt
 {
-   osx_mouse_generate_event(evt);
+   osx_mouse_generate_event(evt, 0);
 }
 -(void) mouseMoved: (NSEvent*) evt
 {
-   osx_mouse_generate_event(evt);
+   osx_mouse_generate_event(evt, 0);
 }
 -(void) scrollWheel: (NSEvent*) evt
 {
-   osx_mouse_generate_event(evt);
+   osx_mouse_generate_event(evt, 0);
 }
 -(void) mouseEntered: (NSEvent*) evt
 {
@@ -388,11 +389,11 @@
    {
       [NSCursor hide];
    }
-   osx_mouse_generate_event(evt);
+   osx_mouse_generate_event(evt, 0);
 }
 -(void) mouseExited: (NSEvent*) evt
 {
-   osx_mouse_generate_event(evt);
+   osx_mouse_generate_event(evt, 0);
    [[NSCursor arrowCursor] set];
    [NSCursor unhide];
 }
@@ -408,7 +409,7 @@
 {
 	/* to prevent the drawing threads and the rendering proc
 	from concurrently accessing the dirty lines array */
-	_al_mutex_lock(&osx_window_mutex);
+	//_al_mutex_lock(&osx_window_mutex);
 	if (lock_nesting++ == 0) {
 		bmp->id |= BMP_ID_LOCKED;
 	}
@@ -424,7 +425,7 @@
 		bmp->id &= ~BMP_ID_LOCKED;
 	}
 	
-	_al_mutex_unlock(&osx_window_mutex);
+	//_al_mutex_unlock(&osx_window_mutex);
 }
 
 
@@ -443,6 +444,8 @@
       bmp->id |= BMP_ID_AUTOLOCK;
    }
    dirty_lines[line + bmp->y_ofs] = 1;
+   
+   [qd_view setNeedsDisplayInRect: NSMakeRect(0, line + bmp->y_ofs, bmp->w, line + bmp->y_ofs)];
 
    return (unsigned long)(bmp->line[line]);
 }
@@ -462,94 +465,6 @@
    }
 }
 
-
-
-/* update_dirty_lines:
- *  Dirty lines updater routine. This is always called from the main app
- *  thread only.
- */
-void osx_update_dirty_lines(void)
-{
-   struct GRAPHICS_RECT src_gfx_rect, dest_gfx_rect;
-   Rect rect;
-   CGrafPtr qd_view_port;
-   int qd_view_pitch;
-   char *qd_view_addr;
-
-   if (![osx_window isVisible])
-      return;
-
-   /* Skip everything if there are no dirty lines */
-   _al_mutex_lock(&osx_window_mutex);
-   for (rect.top = 0; (rect.top < gfx_quartz_window.h) && (!dirty_lines[rect.top]); rect.top++)
-      ;
-   if (rect.top >= gfx_quartz_window.h) {
-      _al_mutex_unlock(&osx_window_mutex);
-      osx_signal_vsync();
-      return;
-   }
-
-   /* Dirty lines need to be updated */
-   if ([qd_view lockFocusIfCanDraw] == YES) {
-      while (!QDDone([qd_view qdPort]));
-      LockPortBits([qd_view qdPort]);
-
-      qd_view_port = [qd_view qdPort];
-      if (qd_view_port) {
-         qd_view_pitch = GetPixRowBytes(GetPortPixMap(qd_view_port));
-         qd_view_addr = GetPixBaseAddr(GetPortPixMap(qd_view_port)) +
-            ((int)([osx_window frame].size.height) - gfx_quartz_window.h) * qd_view_pitch;
-
-         if (colorconv_blitter || (osx_setup_colorconv_blitter() == 0)) {
-            SetEmptyRgn(update_region);
-
-            rect.left = 0;
-            rect.right = gfx_quartz_window.w;
-
-            while (rect.top < gfx_quartz_window.h) {
-               while ((!dirty_lines[rect.top]) && (rect.top < gfx_quartz_window.h))
-                  rect.top++;
-               if (rect.top >= gfx_quartz_window.h)
-                  break;
-               rect.bottom = rect.top;
-               while ((dirty_lines[rect.bottom]) && (rect.bottom < gfx_quartz_window.h)) {
-                  dirty_lines[rect.bottom] = 0;
-                  rect.bottom++;
-               }
-               /* fill in source graphics rectangle description */
-               src_gfx_rect.width  = rect.right - rect.left;
-               src_gfx_rect.height = rect.bottom - rect.top;
-               src_gfx_rect.pitch  = pseudo_screen_pitch;
-               src_gfx_rect.data   = pseudo_screen->line[0] +
-                  (rect.top * pseudo_screen_pitch) +
-                  (rect.left * BYTES_PER_PIXEL(pseudo_screen_depth));
-
-               /* fill in destination graphics rectangle description */
-               dest_gfx_rect.pitch = qd_view_pitch;
-               dest_gfx_rect.data  = qd_view_addr +
-                  (rect.top * qd_view_pitch) + 
-                  (rect.left * BYTES_PER_PIXEL(desktop_depth));
-
-               /* function doing the hard work */
-               colorconv_blitter(&src_gfx_rect, &dest_gfx_rect);
-
-               RectRgn(temp_region, &rect);
-               UnionRgn(temp_region, update_region, update_region);
-               rect.top = rect.bottom;
-            }
-         }   
-         QDFlushPortBuffer(qd_view_port, update_region);
-      }
-      UnlockPortBits([qd_view qdPort]);
-      [qd_view unlockFocus];
-   }
-   _al_mutex_unlock(&osx_window_mutex);
-
-   osx_signal_vsync();
-}
-
-
-
 /* osx_setup_colorconv_blitter:
  *  Sets up the window color conversion blitter function depending on the
  *  Allegro requested color depth and the current desktop color depth.
@@ -814,7 +729,7 @@
 
    /* invalidate the whole screen */
    memset(dirty_lines, 1, gfx_quartz_window.h);
-
+   [qd_view setNeedsDisplay: YES];
    _al_mutex_unlock(&osx_window_mutex);
 }
 
Index: include/allegro/platform/aintosx.h
===================================================================
--- include/allegro/platform/aintosx.h	(revision 7856)
+++ include/allegro/platform/aintosx.h	(working copy)
@@ -29,6 +29,7 @@
 #include <unistd.h>
 #include <signal.h>
 #include <pthread.h>
+#import <OpenGL/OpenGL.h>
 
 
 #ifndef NSAppKitVersionNumber10_1
@@ -101,7 +102,28 @@
 - (void) viewDidMoveToWindow;
 @end
 
-AllegroView* osx_view_from_display(AL_DISPLAY*);
+/* The OS-specific part of a display */
+/* This might draw to a windowed, fullscreen, */
+/* or offscreen context */
+@interface ALDisplay : NSObject
+{
+	@public
+	BITMAP* scn;
+	unsigned char* linedata;
+	int gl_fmt, gl_datasize;
+	NSOpenGLContext* ctx;
+	NSRecursiveLock* lock;
+	int lock_nesting;
+	int* status;
+}
++ (ALDisplay*) activeDisplay;
+- (id) initWithWidth: (int) w Height: (int) w Depth: (int) d;
+- (void) dealloc;
+- (void) becomeCurrent;
+- (void) resignCurrent;
+- (BITMAP*) screen;
+- (AL_DISPLAY*) display;
+@end
 
 typedef void RETSIGTYPE;
 
@@ -163,11 +185,11 @@
 void osx_qz_acquire(BITMAP *bmp);
 void osx_qz_release(BITMAP *bmp);
 
-void osx_keyboard_handler(int pressed, NSEvent *event);
-void osx_keyboard_modifiers(unsigned int new_mods);
+void osx_keyboard_handler(int pressed, NSEvent *event, AL_DISPLAY*);
+void osx_keyboard_modifiers(unsigned int new_mods, AL_DISPLAY*);
 void osx_keyboard_focused(int focused, int state);
 
-void osx_mouse_generate_event(NSEvent*);
+void osx_mouse_generate_event(NSEvent*, AL_DISPLAY*);
 void osx_mouse_handler(NSEvent*);
 int osx_mouse_set_sprite(BITMAP *sprite, int x, int y);
 int osx_mouse_show(BITMAP *bmp, int x, int y);
Index: include/allegro/platform/alosx.h
===================================================================
--- include/allegro/platform/alosx.h	(revision 7856)
+++ include/allegro/platform/alosx.h	(working copy)
@@ -92,8 +92,10 @@
 /* Gfx drivers */
 #define GFX_QUARTZ_WINDOW       AL_ID('Q','Z','W','N')
 #define GFX_QUARTZ_FULLSCREEN   AL_ID('Q','Z','F','L')
+#define GFX_OPENGL_WINDOW       AL_ID('G','L','W','N')
 AL_VAR(GFX_DRIVER, gfx_quartz_window);
 AL_VAR(GFX_DRIVER, gfx_quartz_full);
+AL_VAR(GFX_DRIVER, gfx_opengl_window);
 
 /* Digital sound drivers */
 #define DIGI_CORE_AUDIO         AL_ID('D','C','A',' ')
