Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
authorSam Lantinga <slouken@libsdl.org>
Sat, 05 Oct 2002 05:07:57 +0000
changeset 50174262d2647ca
parent 500 c335456c421d
child 502 80a3d09bab29
Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
src/video/quartz/SDL_QuartzEvents.m
src/video/quartz/SDL_QuartzVideo.h
src/video/quartz/SDL_QuartzVideo.m
src/video/quartz/SDL_QuartzWM.m
src/video/quartz/SDL_QuartzWindow.m
     1.1 --- a/src/video/quartz/SDL_QuartzEvents.m	Sat Oct 05 04:56:32 2002 +0000
     1.2 +++ b/src/video/quartz/SDL_QuartzEvents.m	Sat Oct 05 05:07:57 2002 +0000
     1.3 @@ -19,16 +19,8 @@
     1.4      Sam Lantinga
     1.5      slouken@libsdl.org
     1.6  */
     1.7 -#include <sys/time.h>
     1.8 -
     1.9  #include "SDL_QuartzKeys.h"
    1.10  
    1.11 -
    1.12 -
    1.13 -static SDLKey keymap[256];
    1.14 -static unsigned int currentMods = 0; /* Current keyboard modifiers, to track modifier state */
    1.15 -static int last_virtual_button = 0; /* Last virtual mouse button pressed */
    1.16 -
    1.17  static void     QZ_InitOSKeymap (_THIS) {
    1.18      const void *KCHRPtr;
    1.19      UInt32 state;
    1.20 @@ -147,11 +139,12 @@
    1.21      keymap[QZ_IBOOK_UP]      = SDLK_UP;
    1.22      keymap[QZ_IBOOK_LEFT] = SDLK_LEFT;
    1.23  
    1.24 -    /* Up there we setup a static scancode->keysym map. However, it will not
    1.25 -     * work very well on international keyboard. Hence we now query MacOS
    1.26 -     * for its own keymap to adjust our own mapping table. However, this is
    1.27 -     * bascially only useful for ascii char keys. This is also the reason
    1.28 -     * why we keep the static table, too.
    1.29 +    /* 
    1.30 +        Up there we setup a static scancode->keysym map. However, it will not
    1.31 +        work very well on international keyboard. Hence we now query MacOS
    1.32 +        for its own keymap to adjust our own mapping table. However, this is
    1.33 +        basically only useful for ascii char keys. This is also the reason
    1.34 +        why we keep the static table, too.
    1.35       */
    1.36  
    1.37      /* Get a pointer to the systems cached KCHR */
    1.38 @@ -180,13 +173,14 @@
    1.39          }
    1.40      }
    1.41  
    1.42 -    /* The keypad codes are re-setup here, because the loop above cannot
    1.43 -     * distinguish between a key on the keypad and a regular key. We maybe
    1.44 -     * could get around this problem in another fashion: NSEvent's flags
    1.45 -     * include a "NSNumericPadKeyMask" bit; we could check that and modify
    1.46 -     * the symbol we return on the fly. However, this flag seems to exhibit
    1.47 -     * some weird behaviour related to the num lock key
    1.48 -     */
    1.49 +    /* 
    1.50 +        The keypad codes are re-setup here, because the loop above cannot
    1.51 +        distinguish between a key on the keypad and a regular key. We maybe
    1.52 +        could get around this problem in another fashion: NSEvent's flags
    1.53 +        include a "NSNumericPadKeyMask" bit; we could check that and modify
    1.54 +        the symbol we return on the fly. However, this flag seems to exhibit
    1.55 +        some weird behaviour related to the num lock key
    1.56 +    */
    1.57      keymap[QZ_KP0] = SDLK_KP0;
    1.58      keymap[QZ_KP1] = SDLK_KP1;
    1.59      keymap[QZ_KP2] = SDLK_KP2;
    1.60 @@ -206,14 +200,18 @@
    1.61      keymap[QZ_KP_ENTER] = SDLK_KP_ENTER;
    1.62  }
    1.63  
    1.64 -static void QZ_DoKey (int state, NSEvent *event) {
    1.65 +static void QZ_DoKey (_THIS, int state, NSEvent *event) {
    1.66  
    1.67      NSString *chars;
    1.68      int i;
    1.69      SDL_keysym key;
    1.70  
    1.71 -    /* An event can contain multiple characters */
    1.72 -    /* I'll ignore this fact for now, since there is only one virtual key code per event */
    1.73 +    /* 
    1.74 +        An event can contain multiple characters
    1.75 +        I'll ignore this fact for now, since there 
    1.76 +        is only one virtual key code per event, so
    1.77 +        no good way to handle this.
    1.78 +    */
    1.79      chars = [ event characters ];
    1.80      for (i =0; i < 1 /*[ chars length ] */; i++) {
    1.81  
    1.82 @@ -226,7 +224,7 @@
    1.83      }
    1.84  }
    1.85  
    1.86 -static void QZ_DoModifiers (unsigned int newMods) {
    1.87 +static void QZ_DoModifiers (_THIS, unsigned int newMods) {
    1.88  
    1.89      const int mapping[] = { SDLK_CAPSLOCK, SDLK_LSHIFT, SDLK_LCTRL, SDLK_LALT, SDLK_LMETA } ;
    1.90  
    1.91 @@ -244,8 +242,8 @@
    1.92  
    1.93          unsigned int currentMask, newMask;
    1.94  
    1.95 -        currentMask = currentMods & bit;
    1.96 -        newMask        = newMods & bit;
    1.97 +        currentMask = current_mods & bit;
    1.98 +        newMask     = newMods & bit;
    1.99  
   1.100          if ( currentMask &&
   1.101               currentMask != newMask ) {     /* modifier up event */
   1.102 @@ -267,15 +265,15 @@
   1.103          }
   1.104      }
   1.105  
   1.106 -    currentMods = newMods;
   1.107 +    current_mods = newMods;
   1.108  }
   1.109  
   1.110  static void QZ_DoActivate (_THIS)
   1.111  {
   1.112 -    inForeground = YES;
   1.113 +    in_foreground = YES;
   1.114  
   1.115 -    /* Regrab the mouse */
   1.116 -    if (currentGrabMode == SDL_GRAB_ON) {
   1.117 +    /* Regrab the mouse, only if it was previously grabbed */
   1.118 +    if ( current_grab_mode == SDL_GRAB_ON ) {
   1.119          QZ_WarpWMCursor (this, SDL_VideoSurface->w / 2, SDL_VideoSurface->h / 2);
   1.120          CGAssociateMouseAndMouseCursorPosition (0);
   1.121      }
   1.122 @@ -290,10 +288,10 @@
   1.123  
   1.124  static void QZ_DoDeactivate (_THIS) {
   1.125  
   1.126 -    inForeground = NO;
   1.127 +    in_foreground = NO;
   1.128  
   1.129      /* Ungrab mouse if it is grabbed */
   1.130 -    if (currentGrabMode == SDL_GRAB_ON) {
   1.131 +    if ( current_grab_mode == SDL_GRAB_ON ) {
   1.132          CGAssociateMouseAndMouseCursorPosition (1);
   1.133      }
   1.134  
   1.135 @@ -343,7 +341,7 @@
   1.136              BOOL isForGameWin;
   1.137      
   1.138              #define DO_MOUSE_DOWN(button, sendToWindow) do {                                 \
   1.139 -                            if ( inForeground ) {                                            \
   1.140 +                            if ( in_foreground ) {                                           \
   1.141                                  if ( (SDL_VideoSurface->flags & SDL_FULLSCREEN) ||           \
   1.142                                      NSPointInRect([event locationInWindow], winRect) )       \
   1.143                                          SDL_PrivateMouseButton (SDL_PRESSED, button, 0, 0);  \
   1.144 @@ -366,11 +364,11 @@
   1.145              switch (type) {
   1.146              
   1.147                  case NSLeftMouseDown:
   1.148 -                    if ( NSCommandKeyMask & currentMods ) {
   1.149 +                    if ( NSCommandKeyMask & current_mods ) {
   1.150                          last_virtual_button = 3;
   1.151                          DO_MOUSE_DOWN (3, 0);
   1.152                      }
   1.153 -                    else if ( NSAlternateKeyMask & currentMods ) {
   1.154 +                    else if ( NSAlternateKeyMask & current_mods ) {
   1.155                          last_virtual_button = 2;
   1.156                          DO_MOUSE_DOWN (2, 0);
   1.157                      }
   1.158 @@ -392,22 +390,24 @@
   1.159                  case NSOtherMouseUp:   DO_MOUSE_UP (2, 0);     break;
   1.160                  case NSRightMouseUp:   DO_MOUSE_UP (3, 0);     break;
   1.161                  case NSSystemDefined:
   1.162 -                    //if ([event subtype] == 7) {
   1.163 -                    //      unsigned int buttons;      // up to 32 mouse button states!
   1.164 -                    //      buttons = [ event data2 ];
   1.165 -                    //}
   1.166 +                    /*
   1.167 +                        Future: up to 32 "mouse" buttons can be handled.
   1.168 +                        if ([event subtype] == 7) {
   1.169 +                            unsigned int buttons;
   1.170 +                            buttons = [ event data2 ];
   1.171 +                    */
   1.172                      break;
   1.173                  case NSLeftMouseDragged:
   1.174                  case NSRightMouseDragged:
   1.175                  case NSOtherMouseDragged: /* usually middle mouse dragged */
   1.176                  case NSMouseMoved:
   1.177 -                    if (currentGrabMode == SDL_GRAB_ON) {
   1.178 +                    if (current_grab_mode == SDL_GRAB_ON) {
   1.179                  
   1.180 -                        /**
   1.181 -                         *  If input is grabbed, the cursor doesn't move,
   1.182 -                         *  so we have to call the lowlevel window server
   1.183 -                         *  function. This is less accurate but works OK.                         
   1.184 -                         **/
   1.185 +                        /*
   1.186 +                            If input is grabbed, the cursor doesn't move,
   1.187 +                            so we have to call the lowlevel window server
   1.188 +                            function. This is less accurate but works OK.                         
   1.189 +                        */
   1.190                          CGMouseDelta dx1, dy1;
   1.191                          CGGetLastMouseDelta (&dx1, &dy1);
   1.192                          dx += dx1;
   1.193 @@ -415,12 +415,14 @@
   1.194                      }
   1.195                      else if (warp_flag) {
   1.196                  
   1.197 -                        /**
   1.198 -                         * If we just warped the mouse, the cursor is frozen for a while.
   1.199 -                         * So we have to use the lowlevel function until it
   1.200 -                         * unfreezes. This really helps apps that continuously
   1.201 -                         * warp the mouse to keep it in the game window.
   1.202 -                         **/
   1.203 +                        /*
   1.204 +                            If we just warped the mouse, the cursor is frozen for a while.
   1.205 +                            So we have to use the lowlevel function until it
   1.206 +                            unfreezes. This really helps apps that continuously
   1.207 +                            warp the mouse to keep it in the game window. Developers should
   1.208 +                            really use GrabInput, but our GrabInput freezes the HW cursor,
   1.209 +                            which doesn't cut it for some apps.
   1.210 +                        */
   1.211                          Uint32 ticks;
   1.212                  
   1.213                          ticks = SDL_GetTicks();
   1.214 @@ -438,14 +440,14 @@
   1.215                      }
   1.216                      else if (firstMouseEvent) {
   1.217                          
   1.218 -                        /**
   1.219 -                         * Get the first mouse event in a possible
   1.220 -                         * sequence of mouse moved events. Since we
   1.221 -                         * use absolute coordinates, this serves to
   1.222 -                         * compensate any inaccuracy in deltas, and
   1.223 -                         * provides the first known mouse position,
   1.224 -                         * since everything after this uses deltas
   1.225 -                         **/
   1.226 +                        /*
   1.227 +                            Get the first mouse event in a possible
   1.228 +                            sequence of mouse moved events. Since we
   1.229 +                            use absolute coordinates, this serves to
   1.230 +                            compensate any inaccuracy in deltas, and
   1.231 +                            provides the first known mouse position,
   1.232 +                            since everything after this uses deltas
   1.233 +                        */
   1.234                          NSPoint p = [ event locationInWindow ];
   1.235                          QZ_PrivateCocoaToSDL(this, &p);
   1.236                          
   1.237 @@ -455,12 +457,12 @@
   1.238                      }
   1.239                      else {
   1.240                      
   1.241 -                       /**
   1.242 -                        * Get the amount moved since the last drag or move event,
   1.243 -                        * add it on for one big move event at the end.
   1.244 -                        **/
   1.245 -                       dx += [ event deltaX ];
   1.246 -                       dy += [ event deltaY ];
   1.247 +                        /*
   1.248 +                            Get the amount moved since the last drag or move event,
   1.249 +                            add it on for one big move event at the end.
   1.250 +                        */
   1.251 +                        dx += [ event deltaX ];
   1.252 +                        dy += [ event deltaY ];
   1.253                      }
   1.254                      break;
   1.255                  case NSScrollWheel:
   1.256 @@ -474,13 +476,13 @@
   1.257                      }
   1.258                      break;
   1.259                  case NSKeyUp:
   1.260 -                    QZ_DoKey (SDL_RELEASED, event);
   1.261 +                    QZ_DoKey (this, SDL_RELEASED, event);
   1.262                      break;
   1.263                  case NSKeyDown:
   1.264 -                    QZ_DoKey (SDL_PRESSED, event);
   1.265 +                    QZ_DoKey (this, SDL_PRESSED, event);
   1.266                      break;
   1.267                  case NSFlagsChanged:
   1.268 -                    QZ_DoModifiers( [ event modifierFlags ] );
   1.269 +                    QZ_DoModifiers(this, [ event modifierFlags ] );
   1.270                      break;
   1.271                  case NSAppKitDefined:
   1.272                      switch ( [ event subtype ] ) {
   1.273 @@ -507,5 +509,4 @@
   1.274          SDL_PrivateMouseMotion (0, 1, dx, dy);
   1.275      
   1.276      [ pool release ];
   1.277 -}
   1.278 -
   1.279 +}
   1.280 \ No newline at end of file
     2.1 --- a/src/video/quartz/SDL_QuartzVideo.h	Sat Oct 05 04:56:32 2002 +0000
     2.2 +++ b/src/video/quartz/SDL_QuartzVideo.h	Sat Oct 05 05:07:57 2002 +0000
     2.3 @@ -22,9 +22,9 @@
     2.4  
     2.5  /*    
     2.6      @file   SDL_QuartzVideo.h
     2.7 -    @author Darrell Walisser
     2.8 +    @author Darrell Walisser, Max Horn, et al.
     2.9      
    2.10 -    @abstract SDL video driver for MacOS X.
    2.11 +    @abstract SDL video driver for Mac OS X.
    2.12      
    2.13      @discussion
    2.14      
    2.15 @@ -33,17 +33,17 @@
    2.16          - Keyboard repeat/mouse speed adjust (if needed)
    2.17          - Multiple monitor support (currently only main display)
    2.18          - Accelerated blitting support
    2.19 -        - Fix white OpenGL window on minimize (fixed)
    2.20 -        - Find out what events should be sent/ignored if window is mimimized
    2.21 +        - Fix white OpenGL window on minimize (fixed) (update: broken again on 10.2)
    2.22 +        - Find out what events should be sent/ignored if window is minimized
    2.23          - Find a way to deal with external resolution/depth switch while app is running
    2.24 -        - Resizeable windows
    2.25 +        - Resizeable windows (done)
    2.26          - Check accuracy of QZ_SetGamma()
    2.27      Problems:
    2.28          - OGL not working in full screen with software renderer
    2.29          - SetColors sets palette correctly but clears framebuffer
    2.30          - Crash in CG after several mode switches (I think this has been fixed)
    2.31          - Retained windows don't draw their title bar quite right (OS Bug) (not using retained windows)
    2.32 -        - Cursor in 8 bit modes is screwy (might just be Radeon PCI bug)
    2.33 +        - Cursor in 8 bit modes is screwy (might just be Radeon PCI bug) (update: not just Radeon)
    2.34          - Warping cursor delays mouse events for a fraction of a second,
    2.35            there is a hack around this that helps a bit
    2.36  */
    2.37 @@ -62,11 +62,11 @@
    2.38  #include "SDL_events_c.h"
    2.39  
    2.40  /* 
    2.41 -   Add methods to get at private members of NSScreen. 
    2.42 -   Since there is a bug in Apple's screen switching code
    2.43 -   that does not update this variable when switching
    2.44 -   to fullscreen, we'll set it manually (but only for the
    2.45 -   main screen).
    2.46 +    Add methods to get at private members of NSScreen. 
    2.47 +    Since there is a bug in Apple's screen switching code
    2.48 +    that does not update this variable when switching
    2.49 +    to fullscreen, we'll set it manually (but only for the
    2.50 +    main screen).
    2.51  */
    2.52  @interface NSScreen (NSScreenAccess)
    2.53  - (void) setFrame:(NSRect)frame;
    2.54 @@ -79,8 +79,10 @@
    2.55  }
    2.56  @end
    2.57  
    2.58 -/* This is a workaround to directly access NSOpenGLContext's CGL context */
    2.59 -/* We need to do this in order to check for errors */
    2.60 +/* 
    2.61 +    This is a workaround to directly access NSOpenGLContext's CGL context
    2.62 +    We need this to check for errors NSOpenGLContext doesn't support
    2.63 +*/
    2.64  @interface NSOpenGLContext (CGLContextAccess)
    2.65  - (CGLContextObj) cglContext;
    2.66  @end
    2.67 @@ -92,8 +94,10 @@
    2.68  }
    2.69  @end
    2.70  
    2.71 -/* Structure for rez switch gamma fades */
    2.72 -/* We can hide the monitor flicker by setting the gamma tables to 0 */
    2.73 +/* 
    2.74 +    Structure for rez switch gamma fades
    2.75 +    We can hide the monitor flicker by setting the gamma tables to 0
    2.76 +*/
    2.77  #define QZ_GAMMA_TABLE_SIZE 256
    2.78  
    2.79  typedef struct {
    2.80 @@ -112,14 +116,22 @@
    2.81      CFDictionaryRef    save_mode;          /* original mode of the display */
    2.82      CFArrayRef         mode_list;          /* list of available fullscreen modes */
    2.83      CGDirectPaletteRef palette;            /* palette of an 8-bit display */
    2.84 -    NSOpenGLContext    *gl_context;        /* object that represents an OpenGL rendering context */
    2.85 +    NSOpenGLContext    *gl_context;        /* OpenGL rendering context */
    2.86      Uint32             width, height, bpp; /* frequently used data about the display */
    2.87 -    Uint32             flags;              /* flags for mode, for teardown purposes */
    2.88 +    Uint32             flags;              /* flags for current mode, for teardown purposes */
    2.89      Uint32             video_set;          /* boolean; indicates if video was set correctly */
    2.90      Uint32             warp_flag;          /* boolean; notify to event loop that a warp just occured */
    2.91      Uint32             warp_ticks;         /* timestamp when the warp occured */
    2.92      NSWindow           *window;            /* Cocoa window to implement the SDL window */
    2.93 -    NSQuickDrawView    *view;              /* the window's view; draw 2D into this view */
    2.94 +    NSQuickDrawView    *view;              /* the window's view; draw 2D and OpenGL into this view */
    2.95 +    SDL_Surface        *resize_icon;       /* icon for the resize badge, we have to draw it by hand */
    2.96 +    SDL_GrabMode       current_grab_mode;  /* default value is SDL_GRAB_OFF */
    2.97 +    BOOL               in_foreground;      /* boolean; indicate if app is in foreground or not */
    2.98 +    SDL_Rect           **client_mode_list; /* resolution list to pass back to client */
    2.99 +    SDLKey             keymap[256];        /* Mac OS X to SDL key mapping */
   2.100 +    Uint32             current_mods;       /* current keyboard modifiers, to track modifier state */
   2.101 +    Uint32             last_virtual_button;/* last virtual mouse button pressed */
   2.102 +    
   2.103      ImageDescriptionHandle yuv_idh;
   2.104      MatrixRecordPtr        yuv_matrix;
   2.105      DecompressorComponent  yuv_codec;
   2.106 @@ -146,6 +158,14 @@
   2.107  #define video_set (this->hidden->video_set)
   2.108  #define warp_ticks (this->hidden->warp_ticks)
   2.109  #define warp_flag (this->hidden->warp_flag)
   2.110 +#define resize_icon (this->hidden->resize_icon)
   2.111 +#define current_grab_mode (this->hidden->current_grab_mode)
   2.112 +#define in_foreground (this->hidden->in_foreground)
   2.113 +#define client_mode_list (this->hidden->client_mode_list)
   2.114 +#define keymap (this->hidden->keymap)
   2.115 +#define current_mods (this->hidden->current_mods)
   2.116 +#define last_virtual_button (this->hidden->last_virtual_button)
   2.117 +
   2.118  #define yuv_idh (this->hidden->yuv_idh)
   2.119  #define yuv_matrix (this->hidden->yuv_matrix)
   2.120  #define yuv_codec (this->hidden->yuv_codec)
   2.121 @@ -156,7 +176,13 @@
   2.122  #define yuv_height (this->hidden->yuv_height)
   2.123  #define yuv_port (this->hidden->yuv_port)
   2.124  
   2.125 -/* Obscuring code: maximum number of windows above ours (inclusive) */
   2.126 +/* 
   2.127 +    Obscuring code: maximum number of windows above ours (inclusive) 
   2.128 +    
   2.129 +    Note: this doesn't work too well in practice and should be
   2.130 +    phased out when we add OpenGL 2D acceleration. It was never
   2.131 +    enabled in the first place, so this shouldn't be a problem ;-)
   2.132 +*/
   2.133  #define kMaxWindows 256
   2.134  
   2.135  /* Some of the Core Graphics Server API for obscuring code */
   2.136 @@ -171,10 +197,11 @@
   2.137  #define kCGSWindowLevelUtility        3
   2.138  #define kCGSWindowLevelNormal         0
   2.139  
   2.140 -/* For completeness; We never use these window levels, they are always below us
   2.141 -#define kCGSWindowLevelMBarShadow -20
   2.142 -#define kCGSWindowLevelDesktopPicture -2147483647
   2.143 -#define kCGSWindowLevelDesktop        -2147483648
   2.144 +/* 
   2.145 +    For completeness; We never use these window levels, they are always below us
   2.146 +    #define kCGSWindowLevelMBarShadow -20
   2.147 +    #define kCGSWindowLevelDesktopPicture -2147483647
   2.148 +    #define kCGSWindowLevelDesktop        -2147483648
   2.149  */
   2.150  
   2.151  typedef CGError       CGSError;
   2.152 @@ -227,7 +254,7 @@
   2.153  static int          QZ_SetColors        (_THIS, int first_color,
   2.154                                           int num_colors, SDL_Color *colors);
   2.155  static void         QZ_DirectUpdate     (_THIS, int num_rects, SDL_Rect *rects);
   2.156 -static int 	     QZ_LockWindow       (_THIS, SDL_Surface *surface);
   2.157 +static int          QZ_LockWindow       (_THIS, SDL_Surface *surface);
   2.158  static void         QZ_UnlockWindow     (_THIS, SDL_Surface *surface);
   2.159  static void         QZ_UpdateRects      (_THIS, int num_rects, SDL_Rect *rects);
   2.160  static void         QZ_VideoQuit        (_THIS);
   2.161 @@ -246,8 +273,8 @@
   2.162  static int QZ_GetGammaRamp (_THIS, Uint16 *ramp);
   2.163  
   2.164  /* OpenGL functions */
   2.165 -static int    QZ_SetupOpenGL (_THIS, int bpp, Uint32 flags);
   2.166 -static void   QZ_TearDownOpenGL (_THIS);
   2.167 +static int    QZ_SetupOpenGL       (_THIS, int bpp, Uint32 flags);
   2.168 +static void   QZ_TearDownOpenGL    (_THIS);
   2.169  static void*  QZ_GL_GetProcAddress (_THIS, const char *proc);
   2.170  static int    QZ_GL_GetAttribute   (_THIS, SDL_GLattr attrib, int* value);
   2.171  static int    QZ_GL_MakeCurrent    (_THIS);
   2.172 @@ -271,13 +298,12 @@
   2.173  static void         QZ_PumpEvents       (_THIS);
   2.174  
   2.175  /* Window Manager functions */
   2.176 -static void QZ_SetCaption    (_THIS, const char *title, const char *icon);
   2.177 -static void QZ_SetIcon       (_THIS, SDL_Surface *icon, Uint8 *mask);
   2.178 -static int  QZ_IconifyWindow (_THIS);
   2.179 +static void QZ_SetCaption        (_THIS, const char *title, const char *icon);
   2.180 +static void QZ_SetIcon           (_THIS, SDL_Surface *icon, Uint8 *mask);
   2.181 +static int  QZ_IconifyWindow     (_THIS);
   2.182  static SDL_GrabMode QZ_GrabInput (_THIS, SDL_GrabMode grab_mode);
   2.183  /*static int  QZ_GetWMInfo     (_THIS, SDL_SysWMinfo *info);*/
   2.184  
   2.185  /* YUV functions */
   2.186  static SDL_Overlay* QZ_CreateYUVOverlay (_THIS, int width, int height,
   2.187 -                                         Uint32 format, SDL_Surface *display);
   2.188 -
   2.189 +                                         Uint32 format, SDL_Surface *display);
   2.190 \ No newline at end of file
     3.1 --- a/src/video/quartz/SDL_QuartzVideo.m	Sat Oct 05 04:56:32 2002 +0000
     3.2 +++ b/src/video/quartz/SDL_QuartzVideo.m	Sat Oct 05 05:07:57 2002 +0000
     3.3 @@ -22,11 +22,6 @@
     3.4  
     3.5  #include "SDL_QuartzVideo.h"
     3.6  
     3.7 -/* Some variables to share among files, put in device structure eventually */
     3.8 -static SDL_GrabMode currentGrabMode = SDL_GRAB_OFF;
     3.9 -static BOOL   inForeground = YES;
    3.10 -static char QZ_Error[255]; /* Global error buffer to temporarily store more informative error messages */
    3.11 -
    3.12  /* Include files into one compile unit...break apart eventually */
    3.13  #include "SDL_QuartzWM.m"
    3.14  #include "SDL_QuartzEvents.m"
    3.15 @@ -132,6 +127,10 @@
    3.16  
    3.17      video_format->BitsPerPixel = device_bpp;
    3.18  
    3.19 +    /* Set misc globals */
    3.20 +    current_grab_mode = SDL_GRAB_OFF;
    3.21 +    in_foreground     = YES;
    3.22 +    
    3.23      return 0;
    3.24  }
    3.25  
    3.26 @@ -140,7 +139,6 @@
    3.27      CFIndex num_modes;
    3.28      CFIndex i;
    3.29  
    3.30 -    static SDL_Rect **list = NULL;
    3.31      int list_size = 0;
    3.32  
    3.33      /* Any windowed mode is acceptable */
    3.34 @@ -148,15 +146,15 @@
    3.35          return (SDL_Rect**)-1;
    3.36  
    3.37      /* Free memory from previous call, if any */
    3.38 -    if ( list != NULL ) {
    3.39 +    if ( client_mode_list != NULL ) {
    3.40  
    3.41          int i;
    3.42  
    3.43 -        for (i = 0; list[i] != NULL; i++)
    3.44 -            free (list[i]);
    3.45 +        for (i = 0; client_mode_list[i] != NULL; i++)
    3.46 +            free (client_mode_list[i]);
    3.47  
    3.48 -        free (list);
    3.49 -        list = NULL;
    3.50 +        free (client_mode_list);
    3.51 +        client_mode_list = NULL;
    3.52      }
    3.53  
    3.54      num_modes = CFArrayGetCount (mode_list);
    3.55 @@ -191,7 +189,8 @@
    3.56                  int i;
    3.57                  hasMode = SDL_FALSE;
    3.58                  for (i = 0; i < list_size; i++) {
    3.59 -                    if (list[i]->w == width && list[i]->h == height) {
    3.60 +                    if (client_mode_list[i]->w == width && 
    3.61 +                        client_mode_list[i]->h == height) {
    3.62                          hasMode = SDL_TRUE;
    3.63                          break;
    3.64                      }
    3.65 @@ -205,14 +204,16 @@
    3.66  
    3.67                  list_size++;
    3.68  
    3.69 -                if (list == NULL)
    3.70 -                    list = (SDL_Rect**) malloc (sizeof(*list) * (list_size+1) );
    3.71 +                if (client_mode_list == NULL)
    3.72 +                    client_mode_list = (SDL_Rect**) 
    3.73 +                        malloc (sizeof(*client_mode_list) * (list_size+1) );
    3.74                  else
    3.75 -                    list = (SDL_Rect**) realloc (list, sizeof(*list) * (list_size+1));
    3.76 +                    client_mode_list = (SDL_Rect**) 
    3.77 +                        realloc (client_mode_list, sizeof(*client_mode_list) * (list_size+1));
    3.78  
    3.79 -                rect = (SDL_Rect*) malloc (sizeof(**list));
    3.80 +                rect = (SDL_Rect*) malloc (sizeof(**client_mode_list));
    3.81  
    3.82 -                if (list == NULL || rect == NULL) {
    3.83 +                if (client_mode_list == NULL || rect == NULL) {
    3.84                      SDL_OutOfMemory ();
    3.85                      return NULL;
    3.86                  }
    3.87 @@ -220,8 +221,8 @@
    3.88                  rect->w = width;
    3.89                  rect->h = height;
    3.90  
    3.91 -                list[list_size-1] = rect;
    3.92 -                list[list_size]   = NULL;
    3.93 +                client_mode_list[list_size-1] = rect;
    3.94 +                client_mode_list[list_size]   = NULL;
    3.95              }
    3.96          }
    3.97      }
    3.98 @@ -233,23 +234,25 @@
    3.99              for (j = 0; j < list_size-1; j++) {
   3.100  
   3.101                  int area1, area2;
   3.102 -                area1 = list[j]->w * list[j]->h;
   3.103 -                area2 = list[j+1]->w * list[j+1]->h;
   3.104 +                area1 = client_mode_list[j]->w * client_mode_list[j]->h;
   3.105 +                area2 = client_mode_list[j+1]->w * client_mode_list[j+1]->h;
   3.106  
   3.107                  if (area1 < area2) {
   3.108 -                    SDL_Rect *tmp = list[j];
   3.109 -                    list[j] = list[j+1];
   3.110 -                    list[j+1] = tmp;
   3.111 +                    SDL_Rect *tmp = client_mode_list[j];
   3.112 +                    client_mode_list[j] = client_mode_list[j+1];
   3.113 +                    client_mode_list[j+1] = tmp;
   3.114                  }
   3.115              }
   3.116          }
   3.117      }
   3.118 -    return list;
   3.119 +    return client_mode_list;
   3.120  }
   3.121  
   3.122 -/* Gamma functions to try to hide the flash from a rez switch */
   3.123 -/* Fade the display from normal to black */
   3.124 -/* Save gamma tables for fade back to normal */
   3.125 +/* 
   3.126 +    Gamma functions to try to hide the flash from a rez switch
   3.127 +    Fade the display from normal to black
   3.128 +    Save gamma tables for fade back to normal
   3.129 +*/
   3.130  static UInt32 QZ_FadeGammaOut (_THIS, SDL_QuartzGammaTable *table) {
   3.131  
   3.132      CGGammaValue redTable[QZ_GAMMA_TABLE_SIZE],
   3.133 @@ -295,8 +298,10 @@
   3.134      return 0;
   3.135  }
   3.136  
   3.137 -/* Fade the display from black to normal */
   3.138 -/* Restore previously saved gamma values */
   3.139 +/* 
   3.140 +    Fade the display from black to normal
   3.141 +    Restore previously saved gamma values
   3.142 +*/
   3.143  static UInt32 QZ_FadeGammaIn (_THIS, SDL_QuartzGammaTable *table) {
   3.144  
   3.145      CGGammaValue redTable[QZ_GAMMA_TABLE_SIZE],
   3.146 @@ -336,10 +341,12 @@
   3.147  static void QZ_UnsetVideoMode (_THIS) {
   3.148  
   3.149      /* Reset values that may change between switches */
   3.150 -    this->info.blit_fill = 0;
   3.151 -    this->FillHWRect     = NULL;
   3.152 -    this->UpdateRects    = NULL;
   3.153 -
   3.154 +    this->info.blit_fill  = 0;
   3.155 +    this->FillHWRect      = NULL;
   3.156 +    this->UpdateRects     = NULL;
   3.157 +    this->LockHWSurface   = NULL;
   3.158 +    this->UnlockHWSurface = NULL;
   3.159 +    
   3.160      /* Release fullscreen resources */
   3.161      if ( mode_flags & SDL_FULLSCREEN ) {
   3.162  
   3.163 @@ -349,22 +356,24 @@
   3.164          
   3.165          gamma_error = QZ_FadeGammaOut (this, &gamma_table);
   3.166  
   3.167 -        /* Release the OpenGL context */
   3.168 -        /* Do this first to avoid trash on the display before fade */
   3.169 -        if ( mode_flags & SDL_OPENGL )
   3.170 +        /* 
   3.171 +            Release the OpenGL context
   3.172 +            Do this first to avoid trash on the display before fade
   3.173 +        */
   3.174 +        if ( mode_flags & SDL_OPENGL ) {
   3.175 +        
   3.176              QZ_TearDownOpenGL (this);
   3.177 -
   3.178 -        if (mode_flags & SDL_OPENGL)
   3.179 -            CGLSetFullScreen(NULL);
   3.180 -
   3.181 +            CGLSetFullScreen (NULL);
   3.182 +        }
   3.183 +        
   3.184          /* Restore original screen resolution/bpp */
   3.185          CGDisplaySwitchToMode (display_id, save_mode);
   3.186          CGDisplayRelease (display_id);
   3.187          ShowMenuBar ();
   3.188  
   3.189          /* 
   3.190 -           reset the main screen's rectangle, see comment
   3.191 -           in QZ_SetVideoFullscreen
   3.192 +            Reset the main screen's rectangle
   3.193 +            See comment in QZ_SetVideoFullscreen for why we do this
   3.194          */
   3.195          screen_rect = NSMakeRect(0,0,device_width,device_height);
   3.196          [ [ NSScreen mainScreen ] setFrame:screen_rect ];
   3.197 @@ -374,16 +383,12 @@
   3.198      }
   3.199      /* Release window mode resources */
   3.200      else {
   3.201 -        if ( (mode_flags & SDL_OPENGL) == 0 ) {
   3.202 -            UnlockPortBits ( [ window_view qdPort ] );
   3.203 -            [ window_view release  ];
   3.204 -        }
   3.205 -        [ qz_window setContentView:nil ];
   3.206 -        [ qz_window setDelegate:nil ];
   3.207 +        
   3.208          [ qz_window close ];
   3.209          [ qz_window release ];
   3.210          qz_window = nil;
   3.211 -
   3.212 +        window_view = nil;
   3.213 +        
   3.214          /* Release the OpenGL context */
   3.215          if ( mode_flags & SDL_OPENGL )
   3.216              QZ_TearDownOpenGL (this);
   3.217 @@ -392,10 +397,6 @@
   3.218      /* Restore gamma settings */
   3.219      CGDisplayRestoreColorSyncSettings ();
   3.220  
   3.221 -    /* Set pixels to null (so other code doesn't try to free it) */
   3.222 -    if (this->screen != NULL)
   3.223 -        this->screen->pixels = NULL;
   3.224 -
   3.225      /* Ensure the cursor will be visible and working when we quit */
   3.226      CGDisplayShowCursor (display_id);
   3.227      CGAssociateMouseAndMouseCursorPosition (1);
   3.228 @@ -411,14 +412,17 @@
   3.229      SDL_QuartzGammaTable gamma_table;
   3.230      NSRect screen_rect;
   3.231      
   3.232 +    /* Destroy any previous mode */
   3.233 +    if (video_set == SDL_TRUE)
   3.234 +        QZ_UnsetVideoMode (this);
   3.235 +
   3.236      /* See if requested mode exists */
   3.237      mode = CGDisplayBestModeForParameters (display_id, bpp, width,
   3.238                                             height, &exact_match);
   3.239  
   3.240      /* Require an exact match to the requested mode */
   3.241      if ( ! exact_match ) {
   3.242 -        sprintf (QZ_Error, "Failed to find display resolution: %dx%dx%d", width, height, bpp);
   3.243 -        SDL_SetError (QZ_Error);
   3.244 +        SDL_SetError ("Failed to find display resolution: %dx%dx%d", width, height, bpp);
   3.245          goto ERR_NO_MATCH;
   3.246      }
   3.247  
   3.248 @@ -431,7 +435,6 @@
   3.249          goto ERR_NO_CAPTURE;
   3.250      }
   3.251  
   3.252 -
   3.253      /* Do the physical switch */
   3.254      if ( CGDisplayNoErr != CGDisplaySwitchToMode (display_id, mode) ) {
   3.255          SDL_SetError ("Failed switching display resolution");
   3.256 @@ -446,9 +449,12 @@
   3.257      current->h = height;
   3.258      current->flags |= SDL_FULLSCREEN;
   3.259      current->flags |= SDL_HWSURFACE;
   3.260 -
   3.261 -    this->UpdateRects = QZ_DirectUpdate;
   3.262 -
   3.263 +    current->flags |= SDL_PREALLOC;
   3.264 +    
   3.265 +    this->UpdateRects     = QZ_DirectUpdate;
   3.266 +    this->LockHWSurface   = QZ_LockHWSurface;
   3.267 +    this->UnlockHWSurface = QZ_UnlockHWSurface;
   3.268 +    
   3.269      /* Setup some mode-dependant info */
   3.270      if ( CGSDisplayCanHWFill (display_id) ) {
   3.271          this->info.blit_fill = 1;
   3.272 @@ -472,8 +478,7 @@
   3.273          err = CGLSetFullScreen (ctx);
   3.274  
   3.275          if (err) {
   3.276 -            sprintf (QZ_Error, "Error setting OpenGL fullscreen: %s", CGLErrorString(err));
   3.277 -            SDL_SetError (QZ_Error);
   3.278 +            SDL_SetError ("Error setting OpenGL fullscreen: %s", CGLErrorString(err));
   3.279              goto ERR_NO_GL;
   3.280          }
   3.281  
   3.282 @@ -494,11 +499,11 @@
   3.283          QZ_FadeGammaIn (this, &gamma_table);
   3.284  
   3.285      /* 
   3.286 -       There is a bug in Cocoa where NSScreen doesn't synchronize
   3.287 -       with CGDirectDisplay, so the main screen's frame is wrong.
   3.288 -       As a result, coordinate translation produces wrong results.
   3.289 -       We can hack around this bug by setting the screen rect
   3.290 -       ourselves. This hack should be removed if/when the bug is fixed.
   3.291 +        There is a bug in Cocoa where NSScreen doesn't synchronize
   3.292 +        with CGDirectDisplay, so the main screen's frame is wrong.
   3.293 +        As a result, coordinate translation produces incorrect results.
   3.294 +        We can hack around this bug by setting the screen rect
   3.295 +        ourselves. This hack should be removed if/when the bug is fixed.
   3.296      */
   3.297      screen_rect = NSMakeRect(0,0,width,height);
   3.298      [ [ NSScreen mainScreen ] setFrame:screen_rect ]; 
   3.299 @@ -518,79 +523,111 @@
   3.300  static SDL_Surface* QZ_SetVideoWindowed (_THIS, SDL_Surface *current, int width,
   3.301                                           int height, int bpp, Uint32 flags) {
   3.302      unsigned int style;
   3.303 -    NSRect rect;
   3.304 -    rect = NSMakeRect (0, 0, width, height);
   3.305 -
   3.306 -#if 1 // FIXME - the resize button doesn't show?  Also need resize events...
   3.307 -    flags &= ~SDL_RESIZABLE;
   3.308 -#endif
   3.309 -    /* Set the window style based on input flags */
   3.310 -    if ( flags & SDL_NOFRAME ) {
   3.311 -        style = NSBorderlessWindowMask;
   3.312 -    } else {
   3.313 -        style = NSTitledWindowMask;
   3.314 -        style |= (NSMiniaturizableWindowMask | NSClosableWindowMask);
   3.315 -        if ( flags & SDL_RESIZABLE )
   3.316 -            style |= NSResizableWindowMask;
   3.317 -    }
   3.318 -
   3.319 -    /* Manually create a window, avoids having a nib file resource */
   3.320 -    qz_window = [ [ SDL_QuartzWindow alloc ] initWithContentRect:rect
   3.321 -                                                       styleMask:style backing:NSBackingStoreBuffered defer:NO ];
   3.322 -    if (qz_window == nil) {
   3.323 -        SDL_SetError ("Could not create the Cocoa window");
   3.324 -        return NULL;
   3.325 -    }
   3.326 +    NSRect contentRect;
   3.327  
   3.328      current->flags = 0;
   3.329      current->w = width;
   3.330      current->h = height;
   3.331 +    
   3.332 +    contentRect = NSMakeRect (0, 0, width, height);
   3.333 +    
   3.334 +    /*
   3.335 +        Check if we should completely destroy the previous mode 
   3.336 +        - If it is fullscreen
   3.337 +        - If it has different noframe or resizable attribute
   3.338 +        - If it is OpenGL (since gl attributes could be different)
   3.339 +        - If new mode is OpenGL, but previous mode wasn't
   3.340 +    */
   3.341 +    if (video_set == SDL_TRUE)
   3.342 +        if ( (mode_flags & SDL_FULLSCREEN) ||
   3.343 +             ((mode_flags ^ flags) & (SDL_NOFRAME|SDL_RESIZABLE)) ||
   3.344 +             (mode_flags & SDL_OPENGL) || 
   3.345 +             (flags & SDL_OPENGL) )
   3.346 +            QZ_UnsetVideoMode (this);
   3.347 +        
   3.348 +    /* Check if we should recreate the window */
   3.349 +    if (qz_window == nil) {
   3.350 +    
   3.351 +        /* Set the window style based on input flags */
   3.352 +        if ( flags & SDL_NOFRAME ) {
   3.353 +            style = NSBorderlessWindowMask;
   3.354 +            current->flags |= SDL_NOFRAME;
   3.355 +        } else {
   3.356 +            style = NSTitledWindowMask;
   3.357 +            style |= (NSMiniaturizableWindowMask | NSClosableWindowMask);
   3.358 +            if ( flags & SDL_RESIZABLE ) {
   3.359 +                style |= NSResizableWindowMask;
   3.360 +                current->flags |= SDL_RESIZABLE;
   3.361 +            }
   3.362 +        }
   3.363 +                
   3.364 +        /* Manually create a window, avoids having a nib file resource */
   3.365 +        qz_window = [ [ SDL_QuartzWindow alloc ] 
   3.366 +            initWithContentRect:contentRect
   3.367 +                styleMask:style 
   3.368 +                    backing:NSBackingStoreBuffered
   3.369 +                        defer:NO ];
   3.370 +                          
   3.371 +        if (qz_window == nil) {
   3.372 +            SDL_SetError ("Could not create the Cocoa window");
   3.373 +            return NULL;
   3.374 +        }
   3.375 +    
   3.376 +        [ qz_window setReleasedWhenClosed:YES ];
   3.377 +        QZ_SetCaption(this, this->wm_title, this->wm_icon);
   3.378 +        [ qz_window setAcceptsMouseMovedEvents:YES ];
   3.379 +        [ qz_window setViewsNeedDisplay:NO ];
   3.380 +        [ qz_window center ];
   3.381 +        [ qz_window setDelegate:
   3.382 +            [ [ [ SDL_QuartzWindowDelegate alloc ] init ] autorelease ] ];
   3.383 +    }
   3.384 +    /* We already have a window, just change its size */
   3.385 +    else {
   3.386 +    
   3.387 +        [ qz_window setContentSize:contentRect.size ];
   3.388 +        current->flags |= (SDL_NOFRAME|SDL_RESIZABLE) & mode_flags;
   3.389 +    }
   3.390  
   3.391 -    [ qz_window setReleasedWhenClosed:YES ];
   3.392 -    QZ_SetCaption(this, this->wm_title, this->wm_icon);
   3.393 -    [ qz_window setAcceptsMouseMovedEvents:YES ];
   3.394 -    [ qz_window setViewsNeedDisplay:NO ];
   3.395 -    [ qz_window center ];
   3.396 -    [ qz_window setDelegate:
   3.397 -        [ [ [ SDL_QuartzWindowDelegate alloc ] init ] autorelease ] ];
   3.398 -
   3.399 -    /* For OpenGL, we set the content view to a NSOpenGLView */
   3.400 +    /* For OpenGL, we bind the context to a subview */
   3.401      if ( flags & SDL_OPENGL ) {
   3.402  
   3.403          if ( ! QZ_SetupOpenGL (this, bpp, flags) ) {
   3.404              return NULL;
   3.405          }
   3.406  
   3.407 -        [ gl_context setView: [ qz_window contentView ] ];
   3.408 +        window_view = [ [ NSView alloc ] initWithFrame:contentRect ];
   3.409 +        [ window_view setAutoresizingMask: NSViewMinYMargin ];
   3.410 +        [ [ qz_window contentView ] addSubview:window_view ];
   3.411 +        [ gl_context setView: window_view ];
   3.412 +        [ window_view release ];
   3.413          [ gl_context makeCurrentContext];
   3.414          [ qz_window makeKeyAndOrderFront:nil ];
   3.415          current->flags |= SDL_OPENGL;
   3.416      }
   3.417 -    /* For 2D, we set the content view to a NSQuickDrawView */
   3.418 +    /* For 2D, we set the subview to an NSQuickDrawView */
   3.419      else {
   3.420  
   3.421 -        window_view = [ [ SDL_QuartzWindowView alloc ] init ];
   3.422 -        [ qz_window setContentView:window_view ];
   3.423 -        [ qz_window makeKeyAndOrderFront:nil ];
   3.424 -
   3.425 +        /* Only recreate the view if it doesn't already exist */
   3.426 +        if (window_view == nil) {
   3.427 +        
   3.428 +            window_view = [ [ SDL_QuartzWindowView alloc ] initWithFrame:contentRect ];
   3.429 +            [ window_view setAutoresizingMask: NSViewMinYMargin ];
   3.430 +            [ [ qz_window contentView ] addSubview:window_view ];
   3.431 +            [ window_view release ];
   3.432 +            [ qz_window makeKeyAndOrderFront:nil ];
   3.433 +        }
   3.434 +        
   3.435          LockPortBits ( [ window_view qdPort ] );
   3.436          current->pixels = GetPixBaseAddr ( GetPortPixMap ( [ window_view qdPort ] ) );
   3.437          current->pitch  = GetPixRowBytes ( GetPortPixMap ( [ window_view qdPort ] ) );
   3.438          UnlockPortBits ( [ window_view qdPort ] );
   3.439 -        
   3.440 +
   3.441          current->flags |= SDL_SWSURFACE;
   3.442          current->flags |= SDL_PREALLOC;
   3.443          current->flags |= SDL_ASYNCBLIT;
   3.444          
   3.445 -        if ( flags & SDL_NOFRAME )
   3.446 -            current->flags |= SDL_NOFRAME;
   3.447 -        if ( flags & SDL_RESIZABLE )
   3.448 -            current->flags |= SDL_RESIZABLE;
   3.449 -
   3.450 -        /* Offset 22 pixels down to fill the full content region */
   3.451 -        if ( ! (current->flags & SDL_NOFRAME) ) {
   3.452 -            current->pixels += 22 * current->pitch;
   3.453 -        }
   3.454 +        /* Offset below the title bar to fill the full content region */
   3.455 +        current->pixels += ((int)([ qz_window frame ].size.height) - height) * current->pitch;
   3.456  
   3.457          this->UpdateRects     = QZ_UpdateRects;
   3.458          this->LockHWSurface   = QZ_LockWindow;
   3.459 @@ -606,9 +643,6 @@
   3.460  static SDL_Surface* QZ_SetVideoMode (_THIS, SDL_Surface *current, int width,
   3.461                                       int height, int bpp, Uint32 flags) {
   3.462  
   3.463 -    if (video_set == SDL_TRUE)
   3.464 -        QZ_UnsetVideoMode (this);
   3.465 -
   3.466      current->flags = 0;
   3.467  
   3.468      /* Setup full screen video */
   3.469 @@ -696,17 +730,18 @@
   3.470  #pragma unused(this,num_rects,rects)
   3.471  }
   3.472  
   3.473 -/**
   3.474 - *  The obscured code is based on work by Matt Slot fprefect@ambrosiasw.com,
   3.475 - *  who supplied sample code for Carbon.
   3.476 - **/
   3.477 +/*
   3.478 +    The obscured code is based on work by Matt Slot fprefect@ambrosiasw.com,
   3.479 +    who supplied sample code for Carbon.
   3.480 +*/
   3.481  static int QZ_IsWindowObscured (NSWindow *window) {
   3.482  
   3.483      //#define TEST_OBSCURED 1
   3.484  
   3.485  #if TEST_OBSCURED
   3.486  
   3.487 -    /*  In order to determine if a direct copy to the screen is possible,
   3.488 +    /*  
   3.489 +        In order to determine if a direct copy to the screen is possible,
   3.490          we must figure out if there are any windows covering ours (including shadows).
   3.491          This can be done by querying the window server about the on screen
   3.492          windows for their screen rectangle and window level.
   3.493 @@ -753,11 +788,15 @@
   3.494  
   3.495      if ( [ window isVisible ] ) {
   3.496  
   3.497 -        /*  walk the window list looking for windows over top of
   3.498 -        (or casting a shadow on) ours */
   3.499 +        /*  
   3.500 +            walk the window list looking for windows over top of
   3.501 +            (or casting a shadow on) ours 
   3.502 +        */
   3.503  
   3.504 -        /* Get a connection to the window server */
   3.505 -        /* Should probably be moved out into SetVideoMode() or InitVideo() */
   3.506 +        /* 
   3.507 +           Get a connection to the window server
   3.508 +           Should probably be moved out into SetVideoMode() or InitVideo()
   3.509 +        */
   3.510          if (cgsConnection == (CGSConnectionID) -1) {
   3.511              cgsConnection = (CGSConnectionID) 0;
   3.512              cgsConnection = _CGSDefaultConnection ();
   3.513 @@ -785,8 +824,10 @@
   3.514              firstDockIcon = -1;
   3.515              dockIconCacheMiss = SDL_FALSE;
   3.516  
   3.517 -            /* The first window is always an empty window with level kCGSWindowLevelTop
   3.518 -                so start at index 1 */
   3.519 +            /* 
   3.520 +                The first window is always an empty window with level kCGSWindowLevelTop
   3.521 +                so start at index 1
   3.522 +            */
   3.523              for (i = 1; i < count; i++) {
   3.524  
   3.525                  /* If we reach our window in the list, it cannot be obscured */
   3.526 @@ -856,8 +897,10 @@
   3.527                      }
   3.528                      else if (winLevel == kCGSWindowLevelNormal) {
   3.529  
   3.530 -                        /* These numbers are for foreground windows,
   3.531 -                           they are too big (but will work) for background windows */
   3.532 +                        /* 
   3.533 +                            These numbers are for foreground windows,
   3.534 +                            they are too big (but will work) for background windows 
   3.535 +                        */
   3.536                          shadowSide = 20;
   3.537                          shadowTop = 10;
   3.538                          shadowBottom = 24;
   3.539 @@ -880,9 +923,11 @@
   3.540                      }
   3.541                      else {
   3.542  
   3.543 -                        /*   kCGSWindowLevelDockLabel,
   3.544 -                        kCGSWindowLevelDock,
   3.545 -                        kOther??? */
   3.546 +                        /*
   3.547 +                            kCGSWindowLevelDockLabel,
   3.548 +                            kCGSWindowLevelDock,
   3.549 +                            kOther???
   3.550 +                        */
   3.551  
   3.552                          /* no shadow */
   3.553                          shadowSide = 0;
   3.554 @@ -917,6 +962,7 @@
   3.555  #endif
   3.556  }
   3.557  
   3.558 +
   3.559  /* Locking functions for the software window buffer */
   3.560  static int QZ_LockWindow (_THIS, SDL_Surface *surface) {
   3.561      
   3.562 @@ -933,17 +979,11 @@
   3.563      if (SDL_VideoSurface->flags & SDL_OPENGLBLIT) {
   3.564          QZ_GL_SwapBuffers (this);
   3.565      }
   3.566 -    else if ( [ qz_window isMiniaturized ] &&
   3.567 -              ! (SDL_VideoSurface->flags & SDL_OPENGL)) {
   3.568 -
   3.569 -        /**
   3.570 -         * Set port alpha opaque so deminiaturize looks right
   3.571 -         * This isn't so nice, but there is no
   3.572 -         * initial deminatureize notification (before demini starts)
   3.573 -         **/
   3.574 -        QZ_SetPortAlphaOpaque ([ [ qz_window contentView ] qdPort],
   3.575 -                               [ qz_window styleMask ] & NSBorderlessWindowMask);
   3.576 +    else if ( [ qz_window isMiniaturized ] ) {
   3.577 +    
   3.578 +        /* Do nothing if miniaturized */
   3.579      }
   3.580 +    
   3.581      else if ( ! QZ_IsWindowObscured (qz_window) ) {
   3.582  
   3.583          /* Use direct copy to flush contents to the display */
   3.584 @@ -992,7 +1032,6 @@
   3.585          SetPort (savePort);
   3.586      }
   3.587      else {
   3.588 -
   3.589          /* Use QDFlushPortBuffer() to flush content to display */
   3.590          int i;
   3.591          RgnHandle dirty = NewRgn ();
   3.592 @@ -1004,10 +1043,12 @@
   3.593          for (i = 0; i < numRects; i++) {
   3.594  
   3.595              MacSetRectRgn (temp, rects[i].x, rects[i].y,
   3.596 -                           rects[i].x + rects[i].w, rects[i].y + rects[i].h);
   3.597 +                        rects[i].x + rects[i].w, rects[i].y + rects[i].h);
   3.598              MacUnionRgn (dirty, temp, dirty);
   3.599          }
   3.600  
   3.601 +        QZ_DrawResizeIcon (this, dirty);
   3.602 +        
   3.603          /* Flush the dirty region */
   3.604          QDFlushPortBuffer ( [ window_view qdPort ], dirty );
   3.605          DisposeRgn (dirty);
   3.606 @@ -1363,15 +1404,10 @@
   3.607  
   3.608  #include "SDL_yuvfuncs.h"
   3.609  
   3.610 -/**
   3.611 - * check for 16 byte alignment, bail otherwise
   3.612 - **/
   3.613 +/* check for 16 byte alignment, bail otherwise */
   3.614  #define CHECK_ALIGN(x) do { if ((Uint32)x & 15) { SDL_SetError("Alignment error"); return NULL; } } while(0)
   3.615  
   3.616 -/**
   3.617 - * align a byte offset, return how much to add to make it
   3.618 - * a multiple of 16
   3.619 - **/
   3.620 +/* align a byte offset, return how much to add to make it a multiple of 16 */
   3.621  #define ALIGN(x) ((16 - (x & 15)) & 15)
   3.622  
   3.623  static SDL_Overlay* QZ_CreateYUVOverlay (_THIS, int width, int height,
   3.624 @@ -1417,10 +1453,10 @@
   3.625  
   3.626      if (SDL_VideoSurface->flags & SDL_FULLSCREEN) {
   3.627  
   3.628 -        /**
   3.629 -         * Good acceleration requires a window to be present.
   3.630 -         * A CGrafPtr that points to the screen isn't good enough
   3.631 -         **/
   3.632 +        /*
   3.633 +          Acceleration requires a window to be present.
   3.634 +          A CGrafPtr that points to the screen isn't good enough
   3.635 +        */
   3.636          NSRect content = NSMakeRect (0, 0, SDL_VideoSurface->w, SDL_VideoSurface->h);
   3.637  
   3.638          qz_window = [ [ SDL_QuartzWindow alloc ]
   3.639 @@ -1442,17 +1478,20 @@
   3.640  
   3.641          port = [ [ qz_window contentView ] qdPort ];
   3.642          SetPort (port);
   3.643 -        // BUG: would like to remove white flash when window kicks in
   3.644 -        //{
   3.645 -        //    Rect r;
   3.646 -        //    SetRect (&r, 0, 0, SDL_VideoSurface->w, SDL_VideoSurface->h);
   3.647 -        //    PaintRect (&r);
   3.648 -        //    QDFlushPortBuffer (port, nil);
   3.649 -        //}
   3.650 +        
   3.651 +        /*
   3.652 +            BUG: would like to remove white flash when window kicks in
   3.653 +            {
   3.654 +                Rect r;
   3.655 +                SetRect (&r, 0, 0, SDL_VideoSurface->w, SDL_VideoSurface->h);
   3.656 +                PaintRect (&r);
   3.657 +                QDFlushPortBuffer (port, nil);
   3.658 +            }
   3.659 +        */
   3.660  
   3.661      }
   3.662      else {
   3.663 -        port = [ [ qz_window contentView ] qdPort ];
   3.664 +        port = [ window_view qdPort ];
   3.665          SetPort (port);
   3.666      }
   3.667      
   3.668 @@ -1544,13 +1583,13 @@
   3.669              return NULL;
   3.670          }
   3.671  
   3.672 -        //CHECK_ALIGN(yuv_pixmap);
   3.673 +        /* CHECK_ALIGN(yuv_pixmap); */
   3.674          offset  = sizeof(PlanarPixmapInfoYUV420);
   3.675 -        //offset += ALIGN(offset);
   3.676 -        //CHECK_ALIGN(offset);
   3.677 +        /* offset += ALIGN(offset); */
   3.678 +        /* CHECK_ALIGN(offset); */
   3.679  
   3.680          pixels[0] = (Uint8*)yuv_pixmap + offset;
   3.681 -        //CHECK_ALIGN(pixels[0]);
   3.682 +        /* CHECK_ALIGN(pixels[0]); */
   3.683  
   3.684          pitches[0] = width;
   3.685          yuv_pixmap->componentInfoY.offset = offset;
   3.686 @@ -1587,5 +1626,4 @@
   3.687      yuv_height = overlay->h;
   3.688      
   3.689      return overlay;
   3.690 -}
   3.691 -
   3.692 +}
   3.693 \ No newline at end of file
     4.1 --- a/src/video/quartz/SDL_QuartzWM.m	Sat Oct 05 04:56:32 2002 +0000
     4.2 +++ b/src/video/quartz/SDL_QuartzWM.m	Sat Oct 05 05:07:57 2002 +0000
     4.3 @@ -87,13 +87,13 @@
     4.4      return 1;
     4.5  }
     4.6  
     4.7 -/**
     4.8 - * Coordinate conversion functions, for convenience
     4.9 - * Cocoa sets the origin at the lower left corner of the window/screen
    4.10 - * SDL, CoreGraphics/WindowServer, and QuickDraw use the origin at the upper left corner
    4.11 - * The routines were written so they could be called before SetVideoMode() has finished;
    4.12 - * this might have limited usefulness at the moment, but the extra cost is trivial.
    4.13 - **/
    4.14 +/*
    4.15 +    Coordinate conversion functions, for convenience
    4.16 +    Cocoa sets the origin at the lower left corner of the window/screen
    4.17 +    SDL, CoreGraphics/WindowServer, and QuickDraw use the origin at the upper left corner
    4.18 +    The routines were written so they could be called before SetVideoMode() has finished;
    4.19 +    this might have limited usefulness at the moment, but the extra cost is trivial.
    4.20 +*/
    4.21  
    4.22  /* Convert Cocoa screen coordinate to Cocoa window coordinate */
    4.23  static void QZ_PrivateGlobalToLocal (_THIS, NSPoint *p) {
    4.24 @@ -190,7 +190,7 @@
    4.25  static void QZ_WarpWMCursor (_THIS, Uint16 x, Uint16 y) {
    4.26  
    4.27      /* Only allow warping when in foreground */
    4.28 -    if ( ! inForeground )
    4.29 +    if ( ! in_foreground )
    4.30          return;
    4.31              
    4.32      /* Do the actual warp */
    4.33 @@ -219,59 +219,66 @@
    4.34  
    4.35  static void QZ_SetIcon       (_THIS, SDL_Surface *icon, Uint8 *mask)
    4.36  {
    4.37 -     NSBitmapImageRep *imgrep;
    4.38 -     NSImage *img;
    4.39 -     SDL_Surface *mergedSurface;
    4.40 -     Uint8 *surfPtr;
    4.41 -     int i,j,masksize;
    4.42 -     NSAutoreleasePool *pool;
    4.43 -     SDL_Rect rrect;
    4.44 -     NSSize imgSize = {icon->w, icon->h};
    4.45 -     pool = [ [ NSAutoreleasePool alloc ] init ];
    4.46 -     SDL_GetClipRect(icon, &rrect);
    4.47 -     /* create a big endian RGBA surface */
    4.48 -     mergedSurface = SDL_CreateRGBSurface(SDL_SWSURFACE|SDL_SRCALPHA, 
    4.49 -                        icon->w, icon->h, 32, 0xff<<24, 0xff<<16, 0xff<<8, 0xff<<0);
    4.50 -     if (mergedSurface==NULL) {
    4.51 +    NSBitmapImageRep *imgrep;
    4.52 +    NSImage *img;
    4.53 +    SDL_Surface *mergedSurface;
    4.54 +    Uint8 *surfPtr;
    4.55 +    int i,j,masksize;
    4.56 +    NSAutoreleasePool *pool;
    4.57 +    SDL_Rect rrect;
    4.58 +    NSSize imgSize = {icon->w, icon->h};
    4.59 +    
    4.60 +    pool = [ [ NSAutoreleasePool alloc ] init ];
    4.61 +    SDL_GetClipRect(icon, &rrect);
    4.62 +    
    4.63 +    /* create a big endian RGBA surface */
    4.64 +    mergedSurface = SDL_CreateRGBSurface(SDL_SWSURFACE|SDL_SRCALPHA, 
    4.65 +                    icon->w, icon->h, 32, 0xff<<24, 0xff<<16, 0xff<<8, 0xff<<0);
    4.66 +    if (mergedSurface==NULL) {
    4.67          NSLog(@"Error creating surface for merge");
    4.68          goto freePool;
    4.69      }
    4.70 -     if (SDL_BlitSurface(icon,&rrect,mergedSurface,&rrect)) {
    4.71 -         NSLog(@"Error blitting to mergedSurface");
    4.72 -         goto freePool;
    4.73 -     }
    4.74 -     if (mask) {
    4.75 -     masksize=icon->w*icon->h;
    4.76 -     surfPtr = (Uint8 *)mergedSurface->pixels;
    4.77 -     #define ALPHASHIFT 3
    4.78 -     for (i=0;i<masksize;i+=8)
    4.79 -         for (j=0;j<8;j++) 
    4.80 -             surfPtr[ALPHASHIFT+((i+j)<<2)]=(mask[i>>3]&(1<<(7-j)))?0xFF:0x00;
    4.81 -     }
    4.82 -     imgrep = [ [ NSBitmapImageRep alloc] 
    4.83 -                     initWithBitmapDataPlanes:(unsigned char **)&mergedSurface->pixels 
    4.84 -                         pixelsWide:icon->w pixelsHigh:icon->h bitsPerSample:8 samplesPerPixel:4 
    4.85 -                         hasAlpha:YES isPlanar:NO colorSpaceName:NSDeviceRGBColorSpace 
    4.86 -                         bytesPerRow:icon->w<<2 bitsPerPixel:32 ];
    4.87 -     img = [ [ NSImage alloc ] initWithSize:imgSize ];
    4.88 -     [ img addRepresentation: imgrep ];
    4.89 -     [ NSApp setApplicationIconImage:img ];
    4.90 -     [ img release ];
    4.91 -     [ imgrep release ];
    4.92 -     SDL_FreeSurface(mergedSurface);
    4.93 +    
    4.94 +    if (SDL_BlitSurface(icon,&rrect,mergedSurface,&rrect)) {
    4.95 +        NSLog(@"Error blitting to mergedSurface");
    4.96 +        goto freePool;
    4.97 +    }
    4.98 +    
    4.99 +    if (mask) {
   4.100 +        masksize=icon->w*icon->h;
   4.101 +        surfPtr = (Uint8 *)mergedSurface->pixels;
   4.102 +        #define ALPHASHIFT 3
   4.103 +        for (i=0;i<masksize;i+=8)
   4.104 +            for (j=0;j<8;j++) 
   4.105 +                surfPtr[ALPHASHIFT+((i+j)<<2)]=(mask[i>>3]&(1<<(7-j)))?0xFF:0x00;
   4.106 +    }
   4.107 +    
   4.108 +    imgrep = [ [ NSBitmapImageRep alloc] 
   4.109 +                    initWithBitmapDataPlanes:(unsigned char **)&mergedSurface->pixels 
   4.110 +                        pixelsWide:icon->w pixelsHigh:icon->h bitsPerSample:8 samplesPerPixel:4 
   4.111 +                        hasAlpha:YES isPlanar:NO colorSpaceName:NSDeviceRGBColorSpace 
   4.112 +                        bytesPerRow:icon->w<<2 bitsPerPixel:32 ];
   4.113 +    
   4.114 +    img = [ [ NSImage alloc ] initWithSize:imgSize ];
   4.115 +    
   4.116 +    [ img addRepresentation: imgrep ];
   4.117 +    [ NSApp setApplicationIconImage:img ];
   4.118 +    
   4.119 +    [ img release ];
   4.120 +    [ imgrep release ];
   4.121 +    SDL_FreeSurface(mergedSurface);
   4.122  freePool:
   4.123 -     [pool release];
   4.124 +    [pool release];
   4.125  }
   4.126  
   4.127  static int  QZ_IconifyWindow (_THIS) { 
   4.128  
   4.129 -    /* Bug! minimize erases the framebuffer */
   4.130      if ( ! [ qz_window isMiniaturized ] ) {
   4.131          [ qz_window miniaturize:nil ];
   4.132          return 1;
   4.133      }
   4.134      else {
   4.135 -        SDL_SetError ("qz_window already iconified");
   4.136 +        SDL_SetError ("window already iconified");
   4.137          return 0;
   4.138      }
   4.139  }
   4.140 @@ -289,16 +296,94 @@
   4.141              break;
   4.142      case SDL_GRAB_OFF:
   4.143              CGAssociateMouseAndMouseCursorPosition (1);
   4.144 -            currentGrabMode = SDL_GRAB_OFF;
   4.145 +            current_grab_mode = SDL_GRAB_OFF;
   4.146              break;
   4.147      case SDL_GRAB_ON:
   4.148              QZ_WarpWMCursor (this, SDL_VideoSurface->w / 2, SDL_VideoSurface->h / 2);
   4.149              CGAssociateMouseAndMouseCursorPosition (0);
   4.150 -            currentGrabMode = SDL_GRAB_ON;
   4.151 +            current_grab_mode = SDL_GRAB_ON;
   4.152              break;
   4.153      case SDL_GRAB_FULLSCREEN:        
   4.154              break;
   4.155      }
   4.156          
   4.157 -    return currentGrabMode;
   4.158 +    return current_grab_mode;
   4.159  }
   4.160 +
   4.161 +/* Resize icon, BMP format */
   4.162 +static unsigned char QZ_ResizeIcon[] = {
   4.163 +    0x42,0x4d,0x31,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x36,0x00,0x00,0x00,0x28,0x00,
   4.164 +    0x00,0x00,0x0d,0x00,0x00,0x00,0x0d,0x00,0x00,0x00,0x01,0x00,0x18,0x00,0x00,0x00,
   4.165 +    0x00,0x00,0xfb,0x01,0x00,0x00,0x13,0x0b,0x00,0x00,0x13,0x0b,0x00,0x00,0x00,0x00,
   4.166 +    0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
   4.167 +    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
   4.168 +    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0b,0xff,0xff,
   4.169 +    0xff,0xda,0xda,0xda,0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xda,0xda,0xda,
   4.170 +    0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xda,0xda,0xda,0x87,0x87,0x87,0xe8,
   4.171 +    0xe8,0xe8,0xff,0xff,0xff,0x0b,0xff,0xff,0xff,0xff,0xff,0xff,0xda,0xda,0xda,0x87,
   4.172 +    0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xda,0xda,0xda,0x87,0x87,0x87,0xe8,0xe8,
   4.173 +    0xe8,0xff,0xff,0xff,0xda,0xda,0xda,0x87,0x87,0x87,0xff,0xff,0xff,0x0b,0xff,0xff,
   4.174 +    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xd5,0xd5,0xd5,0x87,0x87,0x87,0xe8,0xe8,0xe8,
   4.175 +    0xff,0xff,0xff,0xda,0xda,0xda,0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xda,
   4.176 +    0xda,0xda,0xff,0xff,0xff,0x0b,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
   4.177 +    0xff,0xff,0xd7,0xd7,0xd7,0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xda,0xda,
   4.178 +    0xda,0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xff,0xff,0xff,0x0b,0xff,0xff,
   4.179 +    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xd7,0xd7,0xd7,
   4.180 +    0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xda,0xda,0xda,0x87,0x87,0x87,0xe8,
   4.181 +    0xe8,0xe8,0xff,0xff,0xff,0x0b,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
   4.182 +    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xd7,0xd7,0xd7,0x87,0x87,0x87,0xe8,0xe8,
   4.183 +    0xe8,0xff,0xff,0xff,0xdc,0xdc,0xdc,0x87,0x87,0x87,0xff,0xff,0xff,0x0b,0xff,0xff,
   4.184 +    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
   4.185 +    0xff,0xff,0xff,0xd9,0xd9,0xd9,0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xdc,
   4.186 +    0xdc,0xdc,0xff,0xff,0xff,0x0b,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
   4.187 +    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xdb,0xdb,
   4.188 +    0xdb,0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xff,0xff,0xff,0x0b,0xff,0xff,
   4.189 +    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
   4.190 +    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xdb,0xdb,0xdb,0x87,0x87,0x87,0xe8,
   4.191 +    0xe8,0xe8,0xff,0xff,0xff,0x0b,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
   4.192 +    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
   4.193 +    0xff,0xff,0xff,0xff,0xdc,0xdc,0xdc,0x87,0x87,0x87,0xff,0xff,0xff,0x0b,0xff,0xff,
   4.194 +    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
   4.195 +    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xdc,
   4.196 +    0xdc,0xdc,0xff,0xff,0xff,0x0b,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
   4.197 +    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
   4.198 +    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0b
   4.199 +};
   4.200 +
   4.201 +static void QZ_DrawResizeIcon (_THIS, RgnHandle dirtyRegion) {
   4.202 +
   4.203 +    /* Check if we should draw the resize icon */
   4.204 +    if (SDL_VideoSurface->flags & SDL_RESIZABLE) {
   4.205 +    
   4.206 +        Rect	icon;
   4.207 +        SetRect (&icon, SDL_VideoSurface->w - 13, SDL_VideoSurface->h - 13, 
   4.208 +                    SDL_VideoSurface->w, SDL_VideoSurface->h);
   4.209 +                    
   4.210 +        if (RectInRgn (&icon, dirtyRegion)) {
   4.211 +        
   4.212 +            SDL_Rect icon_rect;
   4.213 +            
   4.214 +            /* Create the icon image */
   4.215 +            if (resize_icon == NULL) {
   4.216 +            
   4.217 +                SDL_RWops *rw;
   4.218 +                SDL_Surface *tmp;
   4.219 +                
   4.220 +                rw = SDL_RWFromMem (QZ_ResizeIcon, sizeof(QZ_ResizeIcon));
   4.221 +                tmp = SDL_LoadBMP_RW (rw, SDL_TRUE);
   4.222 +                                                                
   4.223 +                resize_icon = SDL_ConvertSurface (tmp, SDL_VideoSurface->format, SDL_SRCCOLORKEY);								
   4.224 +                SDL_SetColorKey (resize_icon, SDL_SRCCOLORKEY, 0xFFFFFF);
   4.225 +                
   4.226 +                SDL_FreeSurface (tmp);
   4.227 +            }
   4.228 +            
   4.229 +            icon_rect.x = SDL_VideoSurface->w - 13;
   4.230 +            icon_rect.y = SDL_VideoSurface->h - 13;
   4.231 +            icon_rect.w = 13;
   4.232 +            icon_rect.h = 13;
   4.233 +            
   4.234 +            SDL_BlitSurface (resize_icon, NULL, SDL_VideoSurface, &icon_rect);
   4.235 +        }
   4.236 +    }
   4.237 +}
   4.238 \ No newline at end of file
     5.1 --- a/src/video/quartz/SDL_QuartzWindow.m	Sat Oct 05 04:56:32 2002 +0000
     5.2 +++ b/src/video/quartz/SDL_QuartzWindow.m	Sat Oct 05 05:07:57 2002 +0000
     5.3 @@ -1,86 +1,105 @@
     5.4 -/* Subclass of NSWindow to allow customization if we need it */
     5.5  
     5.6 +/*
     5.7 +    This function makes the *SDL region* of the window 100% opaque. 
     5.8 +    The genie effect uses the alpha component. Otherwise,
     5.9 +    it doesn't seem to matter what value it has.
    5.10 +*/
    5.11 +static void QZ_SetPortAlphaOpaque () {
    5.12 +    
    5.13 +    SDL_Surface *surface = current_video->screen;
    5.14 +    int bpp;
    5.15 +    
    5.16 +    bpp = surface->format->BitsPerPixel;
    5.17 +    
    5.18 +    if (bpp == 32) {
    5.19 +    
    5.20 +        Uint32    *pixels = (Uint32*) surface->pixels;
    5.21 +        Uint32    rowPixels = surface->pitch / 4;
    5.22 +        Uint32    i, j;
    5.23 +        
    5.24 +        for (i = 0; i < surface->h; i++)
    5.25 +            for (j = 0; j < surface->w; j++) {
    5.26 +        
    5.27 +                pixels[ (i * rowPixels) + j ] |= 0xFF000000;
    5.28 +            }
    5.29 +    }
    5.30 +}
    5.31 +
    5.32 +/* Subclass of NSWindow to fix genie effect and support resize events  */
    5.33  @interface SDL_QuartzWindow : NSWindow
    5.34  {}
    5.35  - (void)miniaturize:(id)sender;
    5.36 -- (void)deminiaturize:(id)sender;
    5.37  - (void)display;
    5.38 +- (void)setFrame:(NSRect)frameRect display:(BOOL)flag;
    5.39  @end
    5.40  
    5.41 -/**
    5.42 - * Function to set the opacity of window's pixels to 100% 
    5.43 - * The opacity is only used by the window server code that does the minimize effect
    5.44 - **/
    5.45 -static void QZ_SetPortAlphaOpaque (CGrafPtr port, Uint32 noTitleBar) {
    5.46 -    
    5.47 -    Uint32 *pixels;
    5.48 -    Uint32  rowPixels;
    5.49 -    Uint32  width, height;
    5.50 -    Uint32  bpp;
    5.51 -    PixMapHandle pixMap;
    5.52 -    Rect bounds;
    5.53 -    int i, j;
    5.54 -    
    5.55 -    pixMap = GetPortPixMap ( port );
    5.56 -    bpp = GetPixDepth ( pixMap );
    5.57 -    
    5.58 -    if (bpp == 32) {
    5.59 -    
    5.60 -        GetPortBounds ( port, &bounds );
    5.61 -        width = bounds.right - bounds.left;
    5.62 -        height = bounds.bottom - bounds.top;
    5.63 -        
    5.64 -        LockPortBits (port);
    5.65 -        
    5.66 -        pixels = (Uint32*) GetPixBaseAddr ( pixMap );
    5.67 -        rowPixels = GetPixRowBytes ( pixMap ) / 4;
    5.68 -        
    5.69 -        if (! noTitleBar) {
    5.70 -        
    5.71 -            /* offset for title bar */
    5.72 -            pixels += rowPixels * 22;
    5.73 -        }
    5.74 -            
    5.75 -        for (i = 0; i < height; i++)
    5.76 -            for (j = 0; j < width; j++) {
    5.77 -        
    5.78 -                pixels[ (i * rowPixels) + j ] |= 0xFF000000;
    5.79 -            }
    5.80 -            
    5.81 -        UnlockPortBits (port);
    5.82 -    }
    5.83 -}
    5.84 -
    5.85  @implementation SDL_QuartzWindow
    5.86  
    5.87 -/* override these methods to fix the miniaturize animation/dock icon bug */
    5.88 +/* we override these methods to fix the miniaturize animation/dock icon bug */
    5.89  - (void)miniaturize:(id)sender
    5.90  {
    5.91 -    
    5.92      if (SDL_VideoSurface->flags & SDL_OPENGL) {
    5.93      
    5.94 -        /* Grab framebuffer and put into NSImage */
    5.95 -        /* [ qz_window setMiniwindowImage:image ]; */
    5.96 +        /* 
    5.97 +            Future: Grab framebuffer and put into NSImage
    5.98 +            [ qz_window setMiniwindowImage:image ];
    5.99 +        */
   5.100      }
   5.101      else {
   5.102          
   5.103 -        QZ_SetPortAlphaOpaque ([ [ self contentView ] qdPort ], 
   5.104 -                               [ self styleMask ] & NSBorderlessWindowMask);
   5.105 +        /* make the alpha channel opaque so anim won't have holes in it */
   5.106 +        QZ_SetPortAlphaOpaque ();
   5.107      }
   5.108      
   5.109      [ super miniaturize:sender ];
   5.110  }
   5.111  
   5.112 -/* this routine fires *after* deminiaturizing, so it might be useless to us */
   5.113 -- (void)deminiaturize:(id)sender
   5.114 -{
   5.115 -   [ super deminiaturize:sender ];
   5.116 +- (void)display
   5.117 +{    
   5.118 +    /* 
   5.119 +        This method fires just before the window deminaturizes.
   5.120 +        So, it's just the right place to fixup the alpha channel - which
   5.121 +        makes the deminiaturize animation look right.
   5.122 +    */
   5.123 +    if ( (SDL_VideoSurface->flags & SDL_OPENGL) == 0)
   5.124 +        QZ_SetPortAlphaOpaque ();
   5.125  }
   5.126  
   5.127 -- (void)display
   5.128 +- (void)setFrame:(NSRect)frameRect display:(BOOL)flag
   5.129  {
   5.130 -    /* Do nothing to keep pinstripe pattern from drawing */
   5.131 +
   5.132 +    /*
   5.133 +        If the video surface is NULL, this originated from QZ_SetVideoMode,
   5.134 +        so don't send the resize event. 
   5.135 +    */
   5.136 +    if (SDL_VideoSurface == NULL) {
   5.137 +
   5.138 +        [ super setFrame:frameRect display:flag ];
   5.139 +    }
   5.140 +    else {
   5.141 +
   5.142 +        SDL_VideoDevice *this = (SDL_VideoDevice*)current_video;
   5.143 +        
   5.144 +        NSRect sdlRect = [ NSWindow contentRectForFrameRect:frameRect styleMask:[self styleMask] ];
   5.145 +
   5.146 +        [ super setFrame:frameRect display:flag ];
   5.147 +        SDL_PrivateResize (sdlRect.size.width, sdlRect.size.height);
   5.148 +
   5.149 +        /* If not OpenGL, we have to update the pixels and pitch */
   5.150 +        if ( ! this->screen->flags & SDL_OPENGL ) {
   5.151 +            
   5.152 +            LockPortBits ( [ window_view qdPort ] );
   5.153 +            
   5.154 +            SDL_VideoSurface->pixels = GetPixBaseAddr ( GetPortPixMap ( [ window_view qdPort ] ) );
   5.155 +            SDL_VideoSurface->pitch  = GetPixRowBytes ( GetPortPixMap ( [ window_view qdPort ] ) );
   5.156 +            
   5.157 +            SDL_VideoSurface->pixels += ((int)[ self frame ].size.height - (int)sdlRect.size.height) * SDL_VideoSurface->pitch;
   5.158 +    
   5.159 +            UnlockPortBits ( [ window_view qdPort ] );
   5.160 +        }
   5.161 +    }
   5.162  }
   5.163 +
   5.164  @end
   5.165  
   5.166  /* Delegate for our NSWindow to send SDLQuit() on close */
   5.167 @@ -90,19 +109,17 @@
   5.168  @end
   5.169  
   5.170  @implementation SDL_QuartzWindowDelegate
   5.171 -- (BOOL)windowShouldClose:(id)sender {
   5.172 -
   5.173 +- (BOOL)windowShouldClose:(id)sender
   5.174 +{
   5.175      SDL_PrivateQuit();
   5.176      return NO;
   5.177  }
   5.178 -
   5.179  @end
   5.180  
   5.181 -/* empty class; probably could be used to fix bugs in the future */
   5.182 +/* Subclass of NSQuickDrawView for the window's subview */
   5.183  @interface SDL_QuartzWindowView : NSQuickDrawView
   5.184  {}
   5.185  @end
   5.186  
   5.187  @implementation SDL_QuartzWindowView
   5.188 -
   5.189 -@end
   5.190 \ No newline at end of file
   5.191 +@end