Date: Sat, 1 Jun 2002 17:56:45 -0500
authorSam Lantinga <slouken@libsdl.org>
Sat, 01 Jun 2002 23:05:05 +0000
changeset 39019e73568a75c
parent 389 ca655a7a9d80
child 391 52f577c8e0b7
Date: Sat, 1 Jun 2002 17:56:45 -0500
From: Darrell Walisser <dwaliss1@purdue.edu>
Subject: mac patch

In this patch:

- yuv code
- links to QuickTime
- tabs -> 4 spaces
- mouse events fix
- SDLMain path parsing fix
- BUGS updates
- some miscellaneous docs/comments/code cleanup
BUGS
src/main/macosx/SDLMain.m
src/video/quartz/SDL_QuartzEvents.m
src/video/quartz/SDL_QuartzKeys.h
src/video/quartz/SDL_QuartzVideo.h
src/video/quartz/SDL_QuartzVideo.m
src/video/quartz/SDL_QuartzWM.m
     1.1 --- a/BUGS	Sat Jun 01 19:54:15 2002 +0000
     1.2 +++ b/BUGS	Sat Jun 01 23:05:05 2002 +0000
     1.3 @@ -72,26 +72,20 @@
     1.4  
     1.5  	Joystick code is not extensively tested yet.
     1.6  
     1.7 -	Window may not close when unsetting video mode and resetting.
     1.8 -
     1.9  	Resizeable windows aren't implemented yet.
    1.10  
    1.11  	Depth switching for windowed mode isn't implemented yet.
    1.12  	
    1.13  	Palette handling isn't implemented in windowed mode yet.
    1.14  	
    1.15 -	Command-line arguments Dialog is not implemented yet.
    1.16 +	Command-line arguments dialog is not implemented yet.
    1.17  
    1.18  	Fullscreen drawing has some artifacts.
    1.19  	
    1.20 -	Fullscreen window covers *all* other windows - even force quit.
    1.21 -	
    1.22  	Fullscreen OpenGL for the software renderer is broken.
    1.23  
    1.24  	Some OpenGL parameters are not accounted for, for example color bits customization.
    1.25  	
    1.26 -	Getting OpenGL context parameters is not implemented.
    1.27 -	
    1.28  	Continuous mouse motion perhaps is not as smooth as it should be.
    1.29  
    1.30  	SDL_WM_GrabInput() is implemented, but it "freezes" the hardware
     2.1 --- a/src/main/macosx/SDLMain.m	Sat Jun 01 19:54:15 2002 +0000
     2.2 +++ b/src/main/macosx/SDLMain.m	Sat Jun 01 23:05:05 2002 +0000
     2.3 @@ -51,24 +51,25 @@
     2.4  /* Set the working directory to the .app's parent directory */
     2.5  - (void) setupWorkingDirectory:(BOOL)shouldChdir
     2.6  {
     2.7 -    char parentdir[MAXPATHLEN];
     2.8 -    char *c;
     2.9 -    
    2.10 -    strncpy ( parentdir, gArgv[0], sizeof(parentdir) );
    2.11 -    c = (char*) parentdir;
    2.12  
    2.13 -    while (*c != '\0')     /* go to end */
    2.14 -        c++;
    2.15 -    
    2.16 -    while (*c != '/')      /* back up to parent */
    2.17 -        c--;
    2.18 -    
    2.19 -    *c++ = '\0';             /* cut off last part (binary name) */
    2.20 -  
    2.21      if (shouldChdir)
    2.22      {
    2.23 -      assert ( chdir (parentdir) == 0 );   /* chdir to the binary app's parent */
    2.24 -      assert ( chdir ("../../../") == 0 ); /* chdir to the .app's parent */
    2.25 +        char parentdir[MAXPATHLEN];
    2.26 +        char *c;
    2.27 +
    2.28 +        strncpy ( parentdir, gArgv[0], sizeof(parentdir) );
    2.29 +        c = (char*) parentdir;
    2.30 +
    2.31 +        while (*c != '\0')     /* go to end */
    2.32 +               c++;
    2.33 +
    2.34 +        while (*c != '/')      /* back up to parent */
    2.35 +               c--;
    2.36 +
    2.37 +        *c++ = '\0';           /* cut off last part (binary name) */
    2.38 +
    2.39 +        assert ( chdir (parentdir) == 0 );   /* chdir to the binary app's parent */
    2.40 +        assert ( chdir ("../../../") == 0 ); /* chdir to the .app's parent */
    2.41      }
    2.42  }
    2.43  
     3.1 --- a/src/video/quartz/SDL_QuartzEvents.m	Sat Jun 01 19:54:15 2002 +0000
     3.2 +++ b/src/video/quartz/SDL_QuartzEvents.m	Sat Jun 01 23:05:05 2002 +0000
     3.3 @@ -1,23 +1,23 @@
     3.4  /*
     3.5 -	SDL - Simple DirectMedia Layer
     3.6 -	Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002	Sam Lantinga
     3.7 +    SDL - Simple DirectMedia Layer
     3.8 +    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002    Sam Lantinga
     3.9  
    3.10 -	This library is free software; you can redistribute it and/or
    3.11 -	modify it under the terms of the GNU Library General Public
    3.12 -	License as published by the Free Software Foundation; either
    3.13 -	version 2 of the License, or (at your option) any later version.
    3.14 +    This library is free software; you can redistribute it and/or
    3.15 +    modify it under the terms of the GNU Library General Public
    3.16 +    License as published by the Free Software Foundation; either
    3.17 +    version 2 of the License, or (at your option) any later version.
    3.18  
    3.19 -	This library is distributed in the hope that it will be useful,
    3.20 -	but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.21 -	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    3.22 -	Library General Public License for more details.
    3.23 +    This library is distributed in the hope that it will be useful,
    3.24 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.25 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    3.26 +    Library General Public License for more details.
    3.27  
    3.28 -	You should have received a copy of the GNU Library General Public
    3.29 -	License along with this library; if not, write to the Free
    3.30 -	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    3.31 +    You should have received a copy of the GNU Library General Public
    3.32 +    License along with this library; if not, write to the Free
    3.33 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    3.34  
    3.35 -	Sam Lantinga
    3.36 -	slouken@libsdl.org
    3.37 +    Sam Lantinga
    3.38 +    slouken@libsdl.org
    3.39  */
    3.40  #include <sys/time.h>
    3.41  
    3.42 @@ -27,479 +27,473 @@
    3.43  static unsigned int currentMods = 0; /* Current keyboard modifiers, to track modifier state */
    3.44  static int last_virtual_button = 0; /* Last virtual mouse button pressed */
    3.45  
    3.46 -static void	 QZ_InitOSKeymap (_THIS) {
    3.47 -	const void *KCHRPtr;
    3.48 -	UInt32 state;
    3.49 -	UInt32 value;
    3.50 -	int i;
    3.51 -	int world = SDLK_WORLD_0;
    3.52 -	
    3.53 -	for ( i=0; i<SDL_TABLESIZE(keymap); ++i )
    3.54 -		keymap[i] = SDLK_UNKNOWN;
    3.55 +static void     QZ_InitOSKeymap (_THIS) {
    3.56 +    const void *KCHRPtr;
    3.57 +    UInt32 state;
    3.58 +    UInt32 value;
    3.59 +    int i;
    3.60 +    int world = SDLK_WORLD_0;
    3.61  
    3.62 -	/* This keymap is almost exactly the same as the OS 9 one */
    3.63 -	keymap[QZ_ESCAPE] = SDLK_ESCAPE;
    3.64 -	keymap[QZ_F1] = SDLK_F1;
    3.65 -	keymap[QZ_F2] = SDLK_F2;
    3.66 -	keymap[QZ_F3] = SDLK_F3;
    3.67 -	keymap[QZ_F4] = SDLK_F4;
    3.68 -	keymap[QZ_F5] = SDLK_F5;
    3.69 -	keymap[QZ_F6] = SDLK_F6;
    3.70 -	keymap[QZ_F7] = SDLK_F7;
    3.71 -	keymap[QZ_F8] = SDLK_F8;
    3.72 -	keymap[QZ_F9] = SDLK_F9;
    3.73 -	keymap[QZ_F10] = SDLK_F10;
    3.74 -	keymap[QZ_F11] = SDLK_F11;
    3.75 -	keymap[QZ_F12] = SDLK_F12;
    3.76 -	keymap[QZ_PRINT] = SDLK_PRINT;
    3.77 -	keymap[QZ_SCROLLOCK] = SDLK_SCROLLOCK;
    3.78 -	keymap[QZ_PAUSE] = SDLK_PAUSE;
    3.79 -	keymap[QZ_POWER] = SDLK_POWER;
    3.80 -	keymap[QZ_BACKQUOTE] = SDLK_BACKQUOTE;
    3.81 -	keymap[QZ_1] = SDLK_1;
    3.82 -	keymap[QZ_2] = SDLK_2;
    3.83 -	keymap[QZ_3] = SDLK_3;
    3.84 -	keymap[QZ_4] = SDLK_4;
    3.85 -	keymap[QZ_5] = SDLK_5;
    3.86 -	keymap[QZ_6] = SDLK_6;
    3.87 -	keymap[QZ_7] = SDLK_7;
    3.88 -	keymap[QZ_8] = SDLK_8;
    3.89 -	keymap[QZ_9] = SDLK_9;
    3.90 -	keymap[QZ_0] = SDLK_0;
    3.91 -	keymap[QZ_MINUS] = SDLK_MINUS;
    3.92 -	keymap[QZ_EQUALS] = SDLK_EQUALS;
    3.93 -	keymap[QZ_BACKSPACE] = SDLK_BACKSPACE;
    3.94 -	keymap[QZ_INSERT] = SDLK_INSERT;
    3.95 -	keymap[QZ_HOME] = SDLK_HOME;
    3.96 -	keymap[QZ_PAGEUP] = SDLK_PAGEUP;
    3.97 -	keymap[QZ_NUMLOCK] = SDLK_NUMLOCK;
    3.98 -	keymap[QZ_KP_EQUALS] = SDLK_KP_EQUALS;
    3.99 -	keymap[QZ_KP_DIVIDE] = SDLK_KP_DIVIDE;
   3.100 -	keymap[QZ_KP_MULTIPLY] = SDLK_KP_MULTIPLY;
   3.101 -	keymap[QZ_TAB] = SDLK_TAB;
   3.102 -	keymap[QZ_q] = SDLK_q;
   3.103 -	keymap[QZ_w] = SDLK_w;
   3.104 -	keymap[QZ_e] = SDLK_e;
   3.105 -	keymap[QZ_r] = SDLK_r;
   3.106 -	keymap[QZ_t] = SDLK_t;
   3.107 -	keymap[QZ_y] = SDLK_y;
   3.108 -	keymap[QZ_u] = SDLK_u;
   3.109 -	keymap[QZ_i] = SDLK_i;
   3.110 -	keymap[QZ_o] = SDLK_o;
   3.111 -	keymap[QZ_p] = SDLK_p;
   3.112 -	keymap[QZ_LEFTBRACKET] = SDLK_LEFTBRACKET;
   3.113 -	keymap[QZ_RIGHTBRACKET] = SDLK_RIGHTBRACKET;
   3.114 -	keymap[QZ_BACKSLASH] = SDLK_BACKSLASH;
   3.115 -	keymap[QZ_DELETE] = SDLK_DELETE;
   3.116 -	keymap[QZ_END] = SDLK_END;
   3.117 -	keymap[QZ_PAGEDOWN] = SDLK_PAGEDOWN;
   3.118 -	keymap[QZ_KP7] = SDLK_KP7;
   3.119 -	keymap[QZ_KP8] = SDLK_KP8;
   3.120 -	keymap[QZ_KP9] = SDLK_KP9;
   3.121 -	keymap[QZ_KP_MINUS] = SDLK_KP_MINUS;
   3.122 -	keymap[QZ_CAPSLOCK] = SDLK_CAPSLOCK;
   3.123 -	keymap[QZ_a] = SDLK_a;
   3.124 -	keymap[QZ_s] = SDLK_s;
   3.125 -	keymap[QZ_d] = SDLK_d;
   3.126 -	keymap[QZ_f] = SDLK_f;
   3.127 -	keymap[QZ_g] = SDLK_g;
   3.128 -	keymap[QZ_h] = SDLK_h;
   3.129 -	keymap[QZ_j] = SDLK_j;
   3.130 -	keymap[QZ_k] = SDLK_k;
   3.131 -	keymap[QZ_l] = SDLK_l;
   3.132 -	keymap[QZ_SEMICOLON] = SDLK_SEMICOLON;
   3.133 -	keymap[QZ_QUOTE] = SDLK_QUOTE;
   3.134 -	keymap[QZ_RETURN] = SDLK_RETURN;
   3.135 -	keymap[QZ_KP4] = SDLK_KP4;
   3.136 -	keymap[QZ_KP5] = SDLK_KP5;
   3.137 -	keymap[QZ_KP6] = SDLK_KP6;
   3.138 -	keymap[QZ_KP_PLUS] = SDLK_KP_PLUS;
   3.139 -	keymap[QZ_LSHIFT] = SDLK_LSHIFT;
   3.140 -	keymap[QZ_z] = SDLK_z;
   3.141 -	keymap[QZ_x] = SDLK_x;
   3.142 -	keymap[QZ_c] = SDLK_c;
   3.143 -	keymap[QZ_v] = SDLK_v;
   3.144 -	keymap[QZ_b] = SDLK_b;
   3.145 -	keymap[QZ_n] = SDLK_n;
   3.146 -	keymap[QZ_m] = SDLK_m;
   3.147 -	keymap[QZ_COMMA] = SDLK_COMMA;
   3.148 -	keymap[QZ_PERIOD] = SDLK_PERIOD;
   3.149 -	keymap[QZ_SLASH] = SDLK_SLASH;
   3.150 -	keymap[QZ_UP] = SDLK_UP;
   3.151 -	keymap[QZ_KP1] = SDLK_KP1;
   3.152 -	keymap[QZ_KP2] = SDLK_KP2;
   3.153 -	keymap[QZ_KP3] = SDLK_KP3;
   3.154 -	keymap[QZ_KP_ENTER] = SDLK_KP_ENTER;
   3.155 -	keymap[QZ_LCTRL] = SDLK_LCTRL;
   3.156 -	keymap[QZ_LALT] = SDLK_LALT;
   3.157 -	keymap[QZ_LMETA] = SDLK_LMETA;
   3.158 -	keymap[QZ_SPACE] = SDLK_SPACE;
   3.159 -	keymap[QZ_LEFT] = SDLK_LEFT;
   3.160 -	keymap[QZ_DOWN] = SDLK_DOWN;
   3.161 -	keymap[QZ_RIGHT] = SDLK_RIGHT;
   3.162 -	keymap[QZ_KP0] = SDLK_KP0;
   3.163 -	keymap[QZ_KP_PERIOD] = SDLK_KP_PERIOD;
   3.164 -	keymap[QZ_IBOOK_ENTER] = SDLK_KP_ENTER;
   3.165 -	keymap[QZ_IBOOK_RIGHT] = SDLK_RIGHT;
   3.166 -	keymap[QZ_IBOOK_DOWN] = SDLK_DOWN;
   3.167 -	keymap[QZ_IBOOK_UP]	  = SDLK_UP;
   3.168 -	keymap[QZ_IBOOK_LEFT] = SDLK_LEFT;
   3.169 -	
   3.170 -	/* Up there we setup a static scancode->keysym map. However, it will not
   3.171 -	 * work very well on international keyboard. Hence we now query MacOS
   3.172 -	 * for its own keymap to adjust our own mapping table. However, this is
   3.173 -	 * bascially only useful for ascii char keys. This is also the reason
   3.174 -	 * why we keep the static table, too.
   3.175 -	 */
   3.176 -	
   3.177 -	/* Get a pointer to the systems cached KCHR */
   3.178 -	KCHRPtr = (void *)GetScriptManagerVariable(smKCHRCache);
   3.179 -	if (KCHRPtr)
   3.180 -	{
   3.181 -		/* Loop over all 127 possible scan codes */
   3.182 -		for (i = 0; i < 0x7F; i++)
   3.183 -		{
   3.184 -			/* We pretend a clean start to begin with (i.e. no dead keys active */
   3.185 -			state = 0;
   3.186 -			
   3.187 -			/* Now translate the key code to a key value */
   3.188 -			value = KeyTranslate(KCHRPtr, i, &state) & 0xff;
   3.189 -			
   3.190 -			/* If the state become 0, it was a dead key. We need to translate again,
   3.191 -			passing in the new state, to get the actual key value */
   3.192 -			if (state != 0)
   3.193 -				value = KeyTranslate(KCHRPtr, i, &state) & 0xff;
   3.194 -			
   3.195 -			/* Now we should have an ascii value, or 0. Try to figure out to which SDL symbol it maps */
   3.196 -			if (value >= 128)	 /* Some non-ASCII char, map it to SDLK_WORLD_* */
   3.197 -				keymap[i] = world++;
   3.198 -			else if (value >= 32)	 /* non-control ASCII char */
   3.199 -				keymap[i] = value;
   3.200 -		}
   3.201 -	}
   3.202 -	
   3.203 -	/* The keypad codes are re-setup here, because the loop above cannot
   3.204 -	 * distinguish between a key on the keypad and a regular key. We maybe
   3.205 -	 * could get around this problem in another fashion: NSEvent's flags
   3.206 -	 * include a "NSNumericPadKeyMask" bit; we could check that and modify
   3.207 -	 * the symbol we return on the fly. However, this flag seems to exhibit
   3.208 -	 * some weird behaviour related to the num lock key
   3.209 -	 */
   3.210 -	keymap[QZ_KP0] = SDLK_KP0;
   3.211 -	keymap[QZ_KP1] = SDLK_KP1;
   3.212 -	keymap[QZ_KP2] = SDLK_KP2;
   3.213 -	keymap[QZ_KP3] = SDLK_KP3;
   3.214 -	keymap[QZ_KP4] = SDLK_KP4;
   3.215 -	keymap[QZ_KP5] = SDLK_KP5;
   3.216 -	keymap[QZ_KP6] = SDLK_KP6;
   3.217 -	keymap[QZ_KP7] = SDLK_KP7;
   3.218 -	keymap[QZ_KP8] = SDLK_KP8;
   3.219 -	keymap[QZ_KP9] = SDLK_KP9;
   3.220 -	keymap[QZ_KP_MINUS] = SDLK_KP_MINUS;
   3.221 -	keymap[QZ_KP_PLUS] = SDLK_KP_PLUS;
   3.222 -	keymap[QZ_KP_PERIOD] = SDLK_KP_PERIOD;
   3.223 -	keymap[QZ_KP_EQUALS] = SDLK_KP_EQUALS;
   3.224 -	keymap[QZ_KP_DIVIDE] = SDLK_KP_DIVIDE;
   3.225 -	keymap[QZ_KP_MULTIPLY] = SDLK_KP_MULTIPLY;
   3.226 -	keymap[QZ_KP_ENTER] = SDLK_KP_ENTER;
   3.227 +    for ( i=0; i<SDL_TABLESIZE(keymap); ++i )
   3.228 +        keymap[i] = SDLK_UNKNOWN;
   3.229 +
   3.230 +    /* This keymap is almost exactly the same as the OS 9 one */
   3.231 +    keymap[QZ_ESCAPE] = SDLK_ESCAPE;
   3.232 +    keymap[QZ_F1] = SDLK_F1;
   3.233 +    keymap[QZ_F2] = SDLK_F2;
   3.234 +    keymap[QZ_F3] = SDLK_F3;
   3.235 +    keymap[QZ_F4] = SDLK_F4;
   3.236 +    keymap[QZ_F5] = SDLK_F5;
   3.237 +    keymap[QZ_F6] = SDLK_F6;
   3.238 +    keymap[QZ_F7] = SDLK_F7;
   3.239 +    keymap[QZ_F8] = SDLK_F8;
   3.240 +    keymap[QZ_F9] = SDLK_F9;
   3.241 +    keymap[QZ_F10] = SDLK_F10;
   3.242 +    keymap[QZ_F11] = SDLK_F11;
   3.243 +    keymap[QZ_F12] = SDLK_F12;
   3.244 +    keymap[QZ_PRINT] = SDLK_PRINT;
   3.245 +    keymap[QZ_SCROLLOCK] = SDLK_SCROLLOCK;
   3.246 +    keymap[QZ_PAUSE] = SDLK_PAUSE;
   3.247 +    keymap[QZ_POWER] = SDLK_POWER;
   3.248 +    keymap[QZ_BACKQUOTE] = SDLK_BACKQUOTE;
   3.249 +    keymap[QZ_1] = SDLK_1;
   3.250 +    keymap[QZ_2] = SDLK_2;
   3.251 +    keymap[QZ_3] = SDLK_3;
   3.252 +    keymap[QZ_4] = SDLK_4;
   3.253 +    keymap[QZ_5] = SDLK_5;
   3.254 +    keymap[QZ_6] = SDLK_6;
   3.255 +    keymap[QZ_7] = SDLK_7;
   3.256 +    keymap[QZ_8] = SDLK_8;
   3.257 +    keymap[QZ_9] = SDLK_9;
   3.258 +    keymap[QZ_0] = SDLK_0;
   3.259 +    keymap[QZ_MINUS] = SDLK_MINUS;
   3.260 +    keymap[QZ_EQUALS] = SDLK_EQUALS;
   3.261 +    keymap[QZ_BACKSPACE] = SDLK_BACKSPACE;
   3.262 +    keymap[QZ_INSERT] = SDLK_INSERT;
   3.263 +    keymap[QZ_HOME] = SDLK_HOME;
   3.264 +    keymap[QZ_PAGEUP] = SDLK_PAGEUP;
   3.265 +    keymap[QZ_NUMLOCK] = SDLK_NUMLOCK;
   3.266 +    keymap[QZ_KP_EQUALS] = SDLK_KP_EQUALS;
   3.267 +    keymap[QZ_KP_DIVIDE] = SDLK_KP_DIVIDE;
   3.268 +    keymap[QZ_KP_MULTIPLY] = SDLK_KP_MULTIPLY;
   3.269 +    keymap[QZ_TAB] = SDLK_TAB;
   3.270 +    keymap[QZ_q] = SDLK_q;
   3.271 +    keymap[QZ_w] = SDLK_w;
   3.272 +    keymap[QZ_e] = SDLK_e;
   3.273 +    keymap[QZ_r] = SDLK_r;
   3.274 +    keymap[QZ_t] = SDLK_t;
   3.275 +    keymap[QZ_y] = SDLK_y;
   3.276 +    keymap[QZ_u] = SDLK_u;
   3.277 +    keymap[QZ_i] = SDLK_i;
   3.278 +    keymap[QZ_o] = SDLK_o;
   3.279 +    keymap[QZ_p] = SDLK_p;
   3.280 +    keymap[QZ_LEFTBRACKET] = SDLK_LEFTBRACKET;
   3.281 +    keymap[QZ_RIGHTBRACKET] = SDLK_RIGHTBRACKET;
   3.282 +    keymap[QZ_BACKSLASH] = SDLK_BACKSLASH;
   3.283 +    keymap[QZ_DELETE] = SDLK_DELETE;
   3.284 +    keymap[QZ_END] = SDLK_END;
   3.285 +    keymap[QZ_PAGEDOWN] = SDLK_PAGEDOWN;
   3.286 +    keymap[QZ_KP7] = SDLK_KP7;
   3.287 +    keymap[QZ_KP8] = SDLK_KP8;
   3.288 +    keymap[QZ_KP9] = SDLK_KP9;
   3.289 +    keymap[QZ_KP_MINUS] = SDLK_KP_MINUS;
   3.290 +    keymap[QZ_CAPSLOCK] = SDLK_CAPSLOCK;
   3.291 +    keymap[QZ_a] = SDLK_a;
   3.292 +    keymap[QZ_s] = SDLK_s;
   3.293 +    keymap[QZ_d] = SDLK_d;
   3.294 +    keymap[QZ_f] = SDLK_f;
   3.295 +    keymap[QZ_g] = SDLK_g;
   3.296 +    keymap[QZ_h] = SDLK_h;
   3.297 +    keymap[QZ_j] = SDLK_j;
   3.298 +    keymap[QZ_k] = SDLK_k;
   3.299 +    keymap[QZ_l] = SDLK_l;
   3.300 +    keymap[QZ_SEMICOLON] = SDLK_SEMICOLON;
   3.301 +    keymap[QZ_QUOTE] = SDLK_QUOTE;
   3.302 +    keymap[QZ_RETURN] = SDLK_RETURN;
   3.303 +    keymap[QZ_KP4] = SDLK_KP4;
   3.304 +    keymap[QZ_KP5] = SDLK_KP5;
   3.305 +    keymap[QZ_KP6] = SDLK_KP6;
   3.306 +    keymap[QZ_KP_PLUS] = SDLK_KP_PLUS;
   3.307 +    keymap[QZ_LSHIFT] = SDLK_LSHIFT;
   3.308 +    keymap[QZ_z] = SDLK_z;
   3.309 +    keymap[QZ_x] = SDLK_x;
   3.310 +    keymap[QZ_c] = SDLK_c;
   3.311 +    keymap[QZ_v] = SDLK_v;
   3.312 +    keymap[QZ_b] = SDLK_b;
   3.313 +    keymap[QZ_n] = SDLK_n;
   3.314 +    keymap[QZ_m] = SDLK_m;
   3.315 +    keymap[QZ_COMMA] = SDLK_COMMA;
   3.316 +    keymap[QZ_PERIOD] = SDLK_PERIOD;
   3.317 +    keymap[QZ_SLASH] = SDLK_SLASH;
   3.318 +    keymap[QZ_UP] = SDLK_UP;
   3.319 +    keymap[QZ_KP1] = SDLK_KP1;
   3.320 +    keymap[QZ_KP2] = SDLK_KP2;
   3.321 +    keymap[QZ_KP3] = SDLK_KP3;
   3.322 +    keymap[QZ_KP_ENTER] = SDLK_KP_ENTER;
   3.323 +    keymap[QZ_LCTRL] = SDLK_LCTRL;
   3.324 +    keymap[QZ_LALT] = SDLK_LALT;
   3.325 +    keymap[QZ_LMETA] = SDLK_LMETA;
   3.326 +    keymap[QZ_SPACE] = SDLK_SPACE;
   3.327 +    keymap[QZ_LEFT] = SDLK_LEFT;
   3.328 +    keymap[QZ_DOWN] = SDLK_DOWN;
   3.329 +    keymap[QZ_RIGHT] = SDLK_RIGHT;
   3.330 +    keymap[QZ_KP0] = SDLK_KP0;
   3.331 +    keymap[QZ_KP_PERIOD] = SDLK_KP_PERIOD;
   3.332 +    keymap[QZ_IBOOK_ENTER] = SDLK_KP_ENTER;
   3.333 +    keymap[QZ_IBOOK_RIGHT] = SDLK_RIGHT;
   3.334 +    keymap[QZ_IBOOK_DOWN] = SDLK_DOWN;
   3.335 +    keymap[QZ_IBOOK_UP]      = SDLK_UP;
   3.336 +    keymap[QZ_IBOOK_LEFT] = SDLK_LEFT;
   3.337 +
   3.338 +    /* Up there we setup a static scancode->keysym map. However, it will not
   3.339 +     * work very well on international keyboard. Hence we now query MacOS
   3.340 +     * for its own keymap to adjust our own mapping table. However, this is
   3.341 +     * bascially only useful for ascii char keys. This is also the reason
   3.342 +     * why we keep the static table, too.
   3.343 +     */
   3.344 +
   3.345 +    /* Get a pointer to the systems cached KCHR */
   3.346 +    KCHRPtr = (void *)GetScriptManagerVariable(smKCHRCache);
   3.347 +    if (KCHRPtr)
   3.348 +    {
   3.349 +        /* Loop over all 127 possible scan codes */
   3.350 +        for (i = 0; i < 0x7F; i++)
   3.351 +        {
   3.352 +            /* We pretend a clean start to begin with (i.e. no dead keys active */
   3.353 +            state = 0;
   3.354 +
   3.355 +            /* Now translate the key code to a key value */
   3.356 +            value = KeyTranslate(KCHRPtr, i, &state) & 0xff;
   3.357 +
   3.358 +            /* If the state become 0, it was a dead key. We need to translate again,
   3.359 +                passing in the new state, to get the actual key value */
   3.360 +            if (state != 0)
   3.361 +                value = KeyTranslate(KCHRPtr, i, &state) & 0xff;
   3.362 +
   3.363 +            /* Now we should have an ascii value, or 0. Try to figure out to which SDL symbol it maps */
   3.364 +            if (value >= 128)     /* Some non-ASCII char, map it to SDLK_WORLD_* */
   3.365 +                keymap[i] = world++;
   3.366 +            else if (value >= 32)     /* non-control ASCII char */
   3.367 +                keymap[i] = value;
   3.368 +        }
   3.369 +    }
   3.370 +
   3.371 +    /* The keypad codes are re-setup here, because the loop above cannot
   3.372 +     * distinguish between a key on the keypad and a regular key. We maybe
   3.373 +     * could get around this problem in another fashion: NSEvent's flags
   3.374 +     * include a "NSNumericPadKeyMask" bit; we could check that and modify
   3.375 +     * the symbol we return on the fly. However, this flag seems to exhibit
   3.376 +     * some weird behaviour related to the num lock key
   3.377 +     */
   3.378 +    keymap[QZ_KP0] = SDLK_KP0;
   3.379 +    keymap[QZ_KP1] = SDLK_KP1;
   3.380 +    keymap[QZ_KP2] = SDLK_KP2;
   3.381 +    keymap[QZ_KP3] = SDLK_KP3;
   3.382 +    keymap[QZ_KP4] = SDLK_KP4;
   3.383 +    keymap[QZ_KP5] = SDLK_KP5;
   3.384 +    keymap[QZ_KP6] = SDLK_KP6;
   3.385 +    keymap[QZ_KP7] = SDLK_KP7;
   3.386 +    keymap[QZ_KP8] = SDLK_KP8;
   3.387 +    keymap[QZ_KP9] = SDLK_KP9;
   3.388 +    keymap[QZ_KP_MINUS] = SDLK_KP_MINUS;
   3.389 +    keymap[QZ_KP_PLUS] = SDLK_KP_PLUS;
   3.390 +    keymap[QZ_KP_PERIOD] = SDLK_KP_PERIOD;
   3.391 +    keymap[QZ_KP_EQUALS] = SDLK_KP_EQUALS;
   3.392 +    keymap[QZ_KP_DIVIDE] = SDLK_KP_DIVIDE;
   3.393 +    keymap[QZ_KP_MULTIPLY] = SDLK_KP_MULTIPLY;
   3.394 +    keymap[QZ_KP_ENTER] = SDLK_KP_ENTER;
   3.395  }
   3.396  
   3.397  static void QZ_DoKey (int state, NSEvent *event) {
   3.398  
   3.399 -	NSString *chars;
   3.400 -	int i;
   3.401 -	SDL_keysym key;
   3.402 -	
   3.403 -	/* An event can contain multiple characters */
   3.404 -	/* I'll ignore this fact for now, since there is only one virtual key code per event */
   3.405 -	chars = [ event characters ];
   3.406 -	for (i =0; i < 1 /*[ chars length ] */; i++) {
   3.407 -				
   3.408 -		key.scancode = [ event keyCode ];
   3.409 -		key.sym		 = keymap [ key.scancode ];
   3.410 -		key.unicode	 = [ chars characterAtIndex:i];
   3.411 -		key.mod		 = KMOD_NONE;
   3.412 -					
   3.413 -		SDL_PrivateKeyboard (state, &key);
   3.414 -	}
   3.415 +    NSString *chars;
   3.416 +    int i;
   3.417 +    SDL_keysym key;
   3.418 +
   3.419 +    /* An event can contain multiple characters */
   3.420 +    /* I'll ignore this fact for now, since there is only one virtual key code per event */
   3.421 +    chars = [ event characters ];
   3.422 +    for (i =0; i < 1 /*[ chars length ] */; i++) {
   3.423 +
   3.424 +        key.scancode = [ event keyCode ];
   3.425 +        key.sym         = keymap [ key.scancode ];
   3.426 +        key.unicode     = [ chars characterAtIndex:i];
   3.427 +        key.mod         = KMOD_NONE;
   3.428 +
   3.429 +        SDL_PrivateKeyboard (state, &key);
   3.430 +    }
   3.431  }
   3.432  
   3.433  static void QZ_DoModifiers (unsigned int newMods) {
   3.434  
   3.435 -	const int mapping[] = { SDLK_CAPSLOCK, SDLK_LSHIFT, SDLK_LCTRL, SDLK_LALT, SDLK_LMETA } ;
   3.436 +    const int mapping[] = { SDLK_CAPSLOCK, SDLK_LSHIFT, SDLK_LCTRL, SDLK_LALT, SDLK_LMETA } ;
   3.437  
   3.438 -	int i;
   3.439 -	int bit;
   3.440 -	SDL_keysym key;
   3.441 +    int i;
   3.442 +    int bit;
   3.443 +    SDL_keysym key;
   3.444  
   3.445 -	key.scancode = 0;
   3.446 -	key.sym		 = SDLK_UNKNOWN;
   3.447 -	key.unicode	 = 0;
   3.448 -	key.mod		 = KMOD_NONE;
   3.449 -	
   3.450 -	/* Iterate through the bits, testing each against the current modifiers */
   3.451 -	for (i = 0, bit = NSAlphaShiftKeyMask; bit <= NSCommandKeyMask; bit <<= 1, ++i) {
   3.452 -	
   3.453 -		unsigned int currentMask, newMask;
   3.454 -		
   3.455 -		currentMask = currentMods & bit;
   3.456 -		newMask		= newMods & bit;
   3.457 -		
   3.458 -		if ( currentMask &&
   3.459 -			 currentMask != newMask ) {	 /* modifier up event */
   3.460 +    key.scancode = 0;
   3.461 +    key.sym         = SDLK_UNKNOWN;
   3.462 +    key.unicode     = 0;
   3.463 +    key.mod         = KMOD_NONE;
   3.464  
   3.465 -			key.sym = mapping[i];
   3.466 -			/* If this was Caps Lock, we need some additional voodoo to make SDL happy */
   3.467 -			if (bit == NSAlphaShiftKeyMask)
   3.468 -				SDL_PrivateKeyboard (SDL_PRESSED, &key);
   3.469 -			SDL_PrivateKeyboard (SDL_RELEASED, &key);
   3.470 -		}
   3.471 -		else
   3.472 -		if ( newMask &&
   3.473 -			 currentMask != newMask ) {	 /* modifier down event */
   3.474 -		
   3.475 -			key.sym = mapping[i];
   3.476 -			SDL_PrivateKeyboard (SDL_PRESSED, &key);
   3.477 -			/* If this was Caps Lock, we need some additional voodoo to make SDL happy */
   3.478 -			if (bit == NSAlphaShiftKeyMask)
   3.479 -				SDL_PrivateKeyboard (SDL_RELEASED, &key);
   3.480 -		}
   3.481 -	}
   3.482 -	
   3.483 -	currentMods = newMods;
   3.484 +    /* Iterate through the bits, testing each against the current modifiers */
   3.485 +    for (i = 0, bit = NSAlphaShiftKeyMask; bit <= NSCommandKeyMask; bit <<= 1, ++i) {
   3.486 +
   3.487 +        unsigned int currentMask, newMask;
   3.488 +
   3.489 +        currentMask = currentMods & bit;
   3.490 +        newMask        = newMods & bit;
   3.491 +
   3.492 +        if ( currentMask &&
   3.493 +             currentMask != newMask ) {     /* modifier up event */
   3.494 +
   3.495 +             key.sym = mapping[i];
   3.496 +             /* If this was Caps Lock, we need some additional voodoo to make SDL happy */
   3.497 +             if (bit == NSAlphaShiftKeyMask)
   3.498 +             SDL_PrivateKeyboard (SDL_PRESSED, &key);
   3.499 +             SDL_PrivateKeyboard (SDL_RELEASED, &key);
   3.500 +        }
   3.501 +        else if ( newMask &&
   3.502 +                  currentMask != newMask ) {     /* modifier down event */
   3.503 +        
   3.504 +             key.sym = mapping[i];
   3.505 +             SDL_PrivateKeyboard (SDL_PRESSED, &key);
   3.506 +             /* If this was Caps Lock, we need some additional voodoo to make SDL happy */
   3.507 +             if (bit == NSAlphaShiftKeyMask)
   3.508 +                  SDL_PrivateKeyboard (SDL_RELEASED, &key);
   3.509 +        }
   3.510 +    }
   3.511 +
   3.512 +    currentMods = newMods;
   3.513  }
   3.514  
   3.515  static void QZ_DoActivate (_THIS)
   3.516  {
   3.517 -	inForeground = YES;
   3.518 +    inForeground = YES;
   3.519  
   3.520 -	/* Regrab the mouse */
   3.521 -	if (currentGrabMode == SDL_GRAB_ON) {
   3.522 -		QZ_WarpWMCursor (this, SDL_VideoSurface->w / 2, SDL_VideoSurface->h / 2);
   3.523 -		CGAssociateMouseAndMouseCursorPosition (0);
   3.524 -	}
   3.525 +    /* Regrab the mouse */
   3.526 +    if (currentGrabMode == SDL_GRAB_ON) {
   3.527 +        QZ_WarpWMCursor (this, SDL_VideoSurface->w / 2, SDL_VideoSurface->h / 2);
   3.528 +        CGAssociateMouseAndMouseCursorPosition (0);
   3.529 +    }
   3.530  
   3.531 -	/* Hide the mouse cursor if inside the app window */
   3.532 -	if (!QZ_cursor_visible) {
   3.533 -		HideCursor ();
   3.534 -	}
   3.535 -	
   3.536 -	SDL_PrivateAppActive (1, SDL_APPINPUTFOCUS);
   3.537 +    /* Hide the mouse cursor if inside the app window */
   3.538 +    if (!QZ_cursor_visible) {
   3.539 +        HideCursor ();
   3.540 +    }
   3.541 +
   3.542 +    SDL_PrivateAppActive (1, SDL_APPINPUTFOCUS);
   3.543  }
   3.544  
   3.545  static void QZ_DoDeactivate (_THIS) {
   3.546 -	
   3.547 -	inForeground = NO;
   3.548  
   3.549 -	/* Ungrab mouse if it is grabbed */
   3.550 -	if (currentGrabMode == SDL_GRAB_ON) {
   3.551 -		CGAssociateMouseAndMouseCursorPosition (1);
   3.552 -	}
   3.553 +    inForeground = NO;
   3.554  
   3.555 -	/* Show the mouse cursor */
   3.556 -	if (!QZ_cursor_visible) {
   3.557 -		ShowCursor ();
   3.558 -	}
   3.559 -	
   3.560 -	SDL_PrivateAppActive (0, SDL_APPINPUTFOCUS);
   3.561 +    /* Ungrab mouse if it is grabbed */
   3.562 +    if (currentGrabMode == SDL_GRAB_ON) {
   3.563 +        CGAssociateMouseAndMouseCursorPosition (1);
   3.564 +    }
   3.565 +
   3.566 +    /* Show the mouse cursor */
   3.567 +    if (!QZ_cursor_visible) {
   3.568 +        ShowCursor ();
   3.569 +    }
   3.570 +
   3.571 +    SDL_PrivateAppActive (0, SDL_APPINPUTFOCUS);
   3.572  }
   3.573  
   3.574  static void QZ_PumpEvents (_THIS)
   3.575  {
   3.576 -	
   3.577 -        static NSPoint lastMouse;
   3.578 -        NSPoint mouse, saveMouse;
   3.579 -        Point qdMouse;
   3.580 -        CGMouseDelta dx, dy;
   3.581 -        
   3.582 -        NSDate *distantPast;
   3.583 -	NSEvent *event;
   3.584 -	NSRect winRect;
   3.585 -	NSRect titleBarRect;
   3.586 -	NSAutoreleasePool *pool;
   3.587 -	
   3.588 -	pool = [ [ NSAutoreleasePool alloc ] init ];
   3.589 -	distantPast = [ NSDate distantPast ];
   3.590 -	
   3.591 -	winRect = NSMakeRect (0, 0, SDL_VideoSurface->w, SDL_VideoSurface->h);
   3.592 -	titleBarRect = NSMakeRect ( 0, SDL_VideoSurface->h, SDL_VideoSurface->w,
   3.593 -		SDL_VideoSurface->h + 22 );
   3.594 -	
   3.595 -        if (currentGrabMode != SDL_GRAB_ON) { /* if grabbed, the cursor can't move! (see fallback below) */
   3.596 -        
   3.597 -            /* 1/2 second after a warp, the mouse cannot move (don't ask me why) */
   3.598 -            /* So, approximate motion with CGGetLastMouseDelta, which still works, somehow */
   3.599 -            if (! warp_flag) {
   3.600 +    static NSPoint lastMouse;
   3.601 +    NSPoint mouse, saveMouse;
   3.602 +    Point qdMouse;
   3.603 +    CGMouseDelta dx, dy;
   3.604 +
   3.605 +    NSDate *distantPast;
   3.606 +    NSEvent *event;
   3.607 +    NSRect winRect;
   3.608 +    NSRect titleBarRect;
   3.609 +    NSAutoreleasePool *pool;
   3.610 +
   3.611 +    pool = [ [ NSAutoreleasePool alloc ] init ];
   3.612 +    distantPast = [ NSDate distantPast ];
   3.613 +
   3.614 +    winRect = NSMakeRect (0, 0, SDL_VideoSurface->w, SDL_VideoSurface->h);
   3.615 +    titleBarRect = NSMakeRect ( 0, SDL_VideoSurface->h, SDL_VideoSurface->w,
   3.616 +                                SDL_VideoSurface->h + 22 );
   3.617 +
   3.618 +    if (currentGrabMode != SDL_GRAB_ON) { /* if grabbed, the cursor can't move! (see fallback below) */
   3.619 +
   3.620 +        /* 1/2 second after a warp, the mouse cannot move (don't ask me why) */
   3.621 +        /* So, approximate motion with CGGetLastMouseDelta, which still works, somehow */
   3.622 +        if (! warp_flag) {
   3.623 +
   3.624 +            GetGlobalMouse (&qdMouse);  /* use Carbon since [ NSEvent mouseLocation ] is broken */
   3.625 +            mouse = NSMakePoint (qdMouse.h, qdMouse.v);
   3.626 +            saveMouse = mouse;
   3.627 +
   3.628 +            if (mouse.x != lastMouse.x || mouse.y != lastMouse.y) {
   3.629 +
   3.630 +                QZ_PrivateCGToSDL (this, &mouse);
   3.631 +                /* -note- we now generate mouse motion events if the mouse isn't over the window */
   3.632 +                if (inForeground /* && NSPointInRect (mouse, winRect)*/) {
   3.633 +                    //printf ("Mouse Loc: (%f, %f)\n", mouse.x, mouse.y);
   3.634 +                    SDL_PrivateMouseMotion (0, 0, mouse.x, mouse.y);
   3.635 +                }
   3.636 +            }
   3.637 +            lastMouse = saveMouse;
   3.638 +        }
   3.639 +    }
   3.640 +
   3.641 +    /* accumulate any mouse events into one SDL mouse event */
   3.642 +    dx = 0;
   3.643 +    dy = 0;
   3.644 +    
   3.645 +    do {
   3.646 +    
   3.647 +        /* Poll for an event. This will not block */
   3.648 +        event = [ NSApp nextEventMatchingMask:NSAnyEventMask
   3.649 +                                    untilDate:distantPast
   3.650 +                                    inMode: NSDefaultRunLoopMode dequeue:YES ];
   3.651 +    
   3.652 +        if (event != nil) {
   3.653 +
   3.654 +            unsigned int type;
   3.655 +            BOOL isForGameWin;
   3.656 +    
   3.657 +            #define DO_MOUSE_DOWN(button, sendToWindow) do {                                 \
   3.658 +                            if ( inForeground ) {                                            \
   3.659 +                                if ( (SDL_VideoSurface->flags & SDL_FULLSCREEN) ||           \
   3.660 +                                    NSPointInRect([event locationInWindow], winRect) )       \
   3.661 +                                        SDL_PrivateMouseButton (SDL_PRESSED, button, 0, 0);  \
   3.662 +                            }                                                                \
   3.663 +                            else {                                                           \
   3.664 +                                QZ_DoActivate (this);                                        \
   3.665 +                            }                                                                \
   3.666 +                            [ NSApp sendEvent:event ];                                       \
   3.667 +            } while(0)
   3.668              
   3.669 -                GetGlobalMouse (&qdMouse);  /* use Carbon since [ NSEvent mouseLocation ] is broken */
   3.670 -                mouse = NSMakePoint (qdMouse.h, qdMouse.v);
   3.671 -                saveMouse = mouse;
   3.672 +            #define DO_MOUSE_UP(button, sendToWindow) do {                      \
   3.673 +                            if ( (SDL_VideoSurface->flags & SDL_FULLSCREEN) ||  \
   3.674 +                    !NSPointInRect([event locationInWindow], titleBarRect) )    \
   3.675 +                        SDL_PrivateMouseButton (SDL_RELEASED, button, 0, 0);    \
   3.676 +                            [ NSApp sendEvent:event ];                          \
   3.677 +            } while(0)
   3.678 +            
   3.679 +            type = [ event type ];
   3.680 +            isForGameWin = (qz_window == [ event window ]);
   3.681 +            switch (type) {
   3.682 +            
   3.683 +                case NSLeftMouseDown:
   3.684 +                    if ( NSCommandKeyMask & currentMods ) {
   3.685 +                        last_virtual_button = 3;
   3.686 +                        DO_MOUSE_DOWN (3, 0);
   3.687 +                    }
   3.688 +                    else if ( NSAlternateKeyMask & currentMods ) {
   3.689 +                        last_virtual_button = 2;
   3.690 +                        DO_MOUSE_DOWN (2, 0);
   3.691 +                    }
   3.692 +                    else {
   3.693 +                        DO_MOUSE_DOWN (1, 1);
   3.694 +                    }
   3.695 +                    break;
   3.696 +                case NSOtherMouseDown: DO_MOUSE_DOWN (2, 0); break;
   3.697 +                case NSRightMouseDown: DO_MOUSE_DOWN (3, 0); break;
   3.698 +                case NSLeftMouseUp:
   3.699 +                    if ( last_virtual_button != 0 ) {
   3.700 +                        DO_MOUSE_UP (last_virtual_button, 0);
   3.701 +                        last_virtual_button = 0;
   3.702 +                    }
   3.703 +                    else {
   3.704 +                        DO_MOUSE_UP (1, 1);
   3.705 +                    }
   3.706 +                    break;
   3.707 +                case NSOtherMouseUp:   DO_MOUSE_UP (2, 0);     break;
   3.708 +                case NSRightMouseUp:   DO_MOUSE_UP (3, 0);     break;
   3.709 +                case NSSystemDefined:
   3.710 +                    //if ([event subtype] == 7) {
   3.711 +                    //      unsigned int buttons;      // up to 32 mouse button states!
   3.712 +                    //      buttons = [ event data2 ];
   3.713 +                    //}
   3.714 +                    break;
   3.715 +                case NSLeftMouseDragged:
   3.716 +                case NSRightMouseDragged:
   3.717 +                case 27:
   3.718 +                case NSMouseMoved:
   3.719 +                    if (currentGrabMode == SDL_GRAB_ON) {
   3.720                  
   3.721 -                if (mouse.x != lastMouse.x || mouse.y != lastMouse.y) {
   3.722 +                        /**
   3.723 +                         *  If input is grabbed, we'll wing it and try to send some mouse
   3.724 +                         *  moved events with CGGetLastMouseDelta(). Not optimal, but better
   3.725 +                         *  than nothing.
   3.726 +                         **/
   3.727 +                        CGMouseDelta dx1, dy1;
   3.728 +                        CGGetLastMouseDelta (&dx1, &dy1);
   3.729 +                        dx += dx1;
   3.730 +                        dy += dy1;
   3.731 +                    }
   3.732 +                    else if (warp_flag) {
   3.733                  
   3.734 -                    QZ_PrivateCGToSDL (this, &mouse);
   3.735 -                    if (inForeground && NSPointInRect (mouse, winRect)) {
   3.736 -                        //printf ("Mouse Loc: (%f, %f)\n", mouse.x, mouse.y);
   3.737 -                        SDL_PrivateMouseMotion (0, 0, mouse.x, mouse.y);
   3.738 +                        Uint32 ticks;
   3.739 +                
   3.740 +                        ticks = SDL_GetTicks();
   3.741 +                        if (ticks - warp_ticks < 150) {
   3.742 +                
   3.743 +                            CGMouseDelta dx1, dy1;
   3.744 +                            CGGetLastMouseDelta (&dx1, &dy1);
   3.745 +                            dx += dx1;
   3.746 +                            dy += dy1;
   3.747 +                        }
   3.748 +                        else {
   3.749 +                
   3.750 +                            warp_flag = 0;
   3.751 +                        }
   3.752                      }
   3.753 -                }
   3.754 -                lastMouse = saveMouse;
   3.755 +                    break;
   3.756 +                case NSScrollWheel:
   3.757 +                    if (NSPointInRect([ event locationInWindow ], winRect)) {
   3.758 +                        float dy;
   3.759 +                        dy = [ event deltaY ];
   3.760 +                        if ( dy > 0.0 ) /* Scroll up */
   3.761 +                            SDL_PrivateMouseButton (SDL_PRESSED, 4, 0, 0);
   3.762 +                        else /* Scroll down */
   3.763 +                            SDL_PrivateMouseButton (SDL_PRESSED, 5, 0, 0);
   3.764 +                    }
   3.765 +                    break;
   3.766 +                case NSKeyUp:
   3.767 +                    QZ_DoKey (SDL_RELEASED, event);
   3.768 +                    break;
   3.769 +                case NSKeyDown:
   3.770 +                    QZ_DoKey (SDL_PRESSED, event);
   3.771 +                    break;
   3.772 +                case NSFlagsChanged:
   3.773 +                    QZ_DoModifiers( [ event modifierFlags ] );
   3.774 +                    break;
   3.775 +                case NSAppKitDefined:
   3.776 +                    switch ( [ event subtype ] ) {
   3.777 +                        case NSApplicationActivatedEventType:
   3.778 +                            QZ_DoActivate (this);
   3.779 +                            break;
   3.780 +                        case NSApplicationDeactivatedEventType:
   3.781 +                            QZ_DoDeactivate (this);
   3.782 +                            break;
   3.783 +                    }
   3.784 +                    [ NSApp sendEvent:event ];
   3.785 +                    break;
   3.786 +                    /* case NSApplicationDefined: break; */
   3.787 +                    /* case NSPeriodic: break; */
   3.788 +                    /* case NSCursorUpdate: break; */
   3.789 +                default:
   3.790 +                    [ NSApp sendEvent:event ];
   3.791              }
   3.792          }
   3.793 -        
   3.794 -        /* accumulate any mouse events into one SDL mouse event */
   3.795 -        dx = 0;
   3.796 -        dy = 0;
   3.797 -        
   3.798 -	do {
   3.799 -	
   3.800 -		/* Poll for an event. This will not block */
   3.801 -		event = [ NSApp nextEventMatchingMask:NSAnyEventMask
   3.802 -					untilDate:distantPast
   3.803 -					inMode: NSDefaultRunLoopMode dequeue:YES ];
   3.804 -	
   3.805 -		if (event != nil) {
   3.806 -			unsigned int type;
   3.807 -			BOOL isForGameWin;
   3.808 -
   3.809 -			#define DO_MOUSE_DOWN(button, sendToWindow) do {				 \
   3.810 -				if ( inForeground ) {			                                 \
   3.811 -					if ( (SDL_VideoSurface->flags & SDL_FULLSCREEN) ||		 \
   3.812 -						 NSPointInRect([event locationInWindow], winRect) )	 \
   3.813 -						SDL_PrivateMouseButton (SDL_PRESSED, button, 0, 0);	 \
   3.814 -				}                                                                        \
   3.815 -				else {									 \
   3.816 -					QZ_DoActivate (this);                                            \
   3.817 -				}									 \
   3.818 -				[ NSApp sendEvent:event ];			                         \
   3.819 -				} while(0)
   3.820 -				
   3.821 -			#define DO_MOUSE_UP(button, sendToWindow) do {					 \
   3.822 -				if ( (SDL_VideoSurface->flags & SDL_FULLSCREEN) ||			 \
   3.823 -					 !NSPointInRect([event locationInWindow], titleBarRect) )        \
   3.824 -					SDL_PrivateMouseButton (SDL_RELEASED, button, 0, 0);	         \
   3.825 -				[ NSApp sendEvent:event ];						 \
   3.826 -				} while(0)
   3.827 -
   3.828 -			type = [ event type ];
   3.829 -			isForGameWin = (qz_window == [ event window ]);
   3.830 -			switch (type) {
   3.831 -			
   3.832 -			case NSLeftMouseDown:
   3.833 -				if ( NSCommandKeyMask & currentMods ) {
   3.834 -					last_virtual_button = 3;
   3.835 -					DO_MOUSE_DOWN (3, 0);
   3.836 -				}
   3.837 -				else if ( NSAlternateKeyMask & currentMods ) {
   3.838 -					last_virtual_button = 2;
   3.839 -					DO_MOUSE_DOWN (2, 0);
   3.840 -				}
   3.841 -				else {
   3.842 -					DO_MOUSE_DOWN (1, 1);
   3.843 -				}
   3.844 -				break;
   3.845 -			case NSOtherMouseDown: DO_MOUSE_DOWN (2, 0); break;
   3.846 -			case NSRightMouseDown: DO_MOUSE_DOWN (3, 0); break;	
   3.847 -			case NSLeftMouseUp:
   3.848 -			
   3.849 -				if ( last_virtual_button != 0 ) {
   3.850 -					DO_MOUSE_UP (last_virtual_button, 0);
   3.851 -					last_virtual_button = 0;
   3.852 -				}
   3.853 -				else {
   3.854 -					DO_MOUSE_UP (1, 1);
   3.855 -				}
   3.856 -				break;
   3.857 -			case NSOtherMouseUp:   DO_MOUSE_UP (2, 0);	 break;
   3.858 -			case NSRightMouseUp:   DO_MOUSE_UP (3, 0);	 break;
   3.859 -			case NSSystemDefined:
   3.860 -				//if ([event subtype] == 7) {
   3.861 -				//	  unsigned int buttons;	  // up to 32 mouse button states!
   3.862 -				//	  buttons = [ event data2 ];
   3.863 -				//}
   3.864 -				break;
   3.865 -			case NSLeftMouseDragged:
   3.866 -			case NSRightMouseDragged:
   3.867 -			case 27:
   3.868 -			case NSMouseMoved:
   3.869 -                            
   3.870 -                                if (currentGrabMode == SDL_GRAB_ON) { 
   3.871 -                                    
   3.872 -                                    /** 
   3.873 -                                     *  If input is grabbed, we'll wing it and try to send some mouse
   3.874 -                                     *  moved events with CGGetLastMouseDelta(). Not optimal, but better
   3.875 -                                     *  than nothing.
   3.876 -                                     **/ 
   3.877 -                                     CGMouseDelta dx1, dy1;
   3.878 -                                     CGGetLastMouseDelta (&dx1, &dy1);
   3.879 -                                     dx += dx1;
   3.880 -                                     dy += dy1;
   3.881 -                                }
   3.882 -                                else if (warp_flag) {
   3.883 -                                
   3.884 -                                    Uint32 ticks;
   3.885 -                
   3.886 -                                    ticks = SDL_GetTicks();
   3.887 -                                    if (ticks - warp_ticks < 150) {
   3.888 -                                    
   3.889 -                                        CGMouseDelta dx1, dy1;
   3.890 -                                        CGGetLastMouseDelta (&dx1, &dy1);
   3.891 -                                        dx += dx1;
   3.892 -                                        dy += dy1;
   3.893 -                                    }
   3.894 -                                    else {
   3.895 -                                        
   3.896 -                                        warp_flag = 0;
   3.897 -                                    }
   3.898 -                                }
   3.899 -                                
   3.900 -				break;
   3.901 -			case NSScrollWheel:
   3.902 -				{
   3.903 -					if (NSPointInRect([ event locationInWindow ], winRect)) {
   3.904 -						float dy;
   3.905 -						dy = [ event deltaY ];
   3.906 -						if ( dy > 0.0 ) /* Scroll up */
   3.907 -							SDL_PrivateMouseButton (SDL_PRESSED, 4, 0, 0);
   3.908 -						else /* Scroll down */
   3.909 -							SDL_PrivateMouseButton (SDL_PRESSED, 5, 0, 0);
   3.910 -					}
   3.911 -				}
   3.912 -				break;
   3.913 -			case NSKeyUp:
   3.914 -				QZ_DoKey (SDL_RELEASED, event);
   3.915 -				break;
   3.916 -			case NSKeyDown:
   3.917 -				QZ_DoKey (SDL_PRESSED, event);
   3.918 -				break;
   3.919 -			case NSFlagsChanged:
   3.920 -				QZ_DoModifiers( [ event modifierFlags ] );
   3.921 -				break;
   3.922 -			case NSAppKitDefined:
   3.923 -				switch ( [ event subtype ] ) {
   3.924 -				case NSApplicationActivatedEventType:
   3.925 -					QZ_DoActivate (this);
   3.926 -					break;
   3.927 -				case NSApplicationDeactivatedEventType:
   3.928 -					QZ_DoDeactivate (this);
   3.929 -					break;
   3.930 -				}
   3.931 -				[ NSApp sendEvent:event ];
   3.932 -				break;
   3.933 -			/* case NSApplicationDefined: break; */
   3.934 -			/* case NSPeriodic: break; */
   3.935 -			/* case NSCursorUpdate: break; */
   3.936 -                        
   3.937 -                        default:
   3.938 -				[ NSApp sendEvent:event ];
   3.939 -			}
   3.940 -		}
   3.941 -	  } while (event != nil);
   3.942 -	
   3.943 -          /* check for accumulated mouse events */
   3.944 -          if (dx != 0 || dy != 0)
   3.945 -            SDL_PrivateMouseMotion (0, 1, dx, dy);
   3.946 -        
   3.947 -	  [ pool release ];
   3.948 +    } while (event != nil);
   3.949 +    
   3.950 +    /* check for accumulated mouse events */
   3.951 +    if (dx != 0 || dy != 0)
   3.952 +    SDL_PrivateMouseMotion (0, 1, dx, dy);
   3.953 +    
   3.954 +    [ pool release ];
   3.955  }
   3.956  
     4.1 --- a/src/video/quartz/SDL_QuartzKeys.h	Sat Jun 01 19:54:15 2002 +0000
     4.2 +++ b/src/video/quartz/SDL_QuartzKeys.h	Sat Jun 01 23:05:05 2002 +0000
     4.3 @@ -1,24 +1,24 @@
     4.4  /*
     4.5      SDL - Simple DirectMedia Layer
     4.6      Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
     4.7 -
     4.8 +    
     4.9      This library is free software; you can redistribute it and/or
    4.10      modify it under the terms of the GNU Library General Public
    4.11      License as published by the Free Software Foundation; either
    4.12      version 2 of the License, or (at your option) any later version.
    4.13 -
    4.14 +    
    4.15      This library is distributed in the hope that it will be useful,
    4.16      but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.17      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    4.18      Library General Public License for more details.
    4.19 -
    4.20 +    
    4.21      You should have received a copy of the GNU Library General Public
    4.22      License along with this library; if not, write to the Free
    4.23      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    4.24 -
    4.25 +    
    4.26      Sam Lantinga
    4.27      slouken@libsdl.org
    4.28 -*/
    4.29 + */
    4.30  
    4.31  /* These are the Macintosh key scancode constants -- from Inside Macintosh */
    4.32  
    4.33 @@ -36,10 +36,10 @@
    4.34  #define QZ_F11			0x67
    4.35  #define QZ_F12			0x6F
    4.36  #define QZ_PRINT		0x69
    4.37 -#define QZ_SCROLLOCK		0x6B
    4.38 +#define QZ_SCROLLOCK    0x6B
    4.39  #define QZ_PAUSE		0x71
    4.40  #define QZ_POWER		0x7F
    4.41 -#define QZ_BACKQUOTE		0x32
    4.42 +#define QZ_BACKQUOTE	0x32
    4.43  #define QZ_1			0x12
    4.44  #define QZ_2			0x13
    4.45  #define QZ_3			0x14
    4.46 @@ -52,14 +52,14 @@
    4.47  #define QZ_0			0x1D
    4.48  #define QZ_MINUS		0x1B
    4.49  #define QZ_EQUALS		0x18
    4.50 -#define QZ_BACKSPACE		0x33
    4.51 +#define QZ_BACKSPACE	0x33
    4.52  #define QZ_INSERT		0x72
    4.53  #define QZ_HOME			0x73
    4.54  #define QZ_PAGEUP		0x74
    4.55  #define QZ_NUMLOCK		0x47
    4.56 -#define QZ_KP_EQUALS		0x51
    4.57 -#define QZ_KP_DIVIDE		0x4B
    4.58 -#define QZ_KP_MULTIPLY		0x43
    4.59 +#define QZ_KP_EQUALS	0x51
    4.60 +#define QZ_KP_DIVIDE	0x4B
    4.61 +#define QZ_KP_MULTIPLY	0x43
    4.62  #define QZ_TAB			0x30
    4.63  #define QZ_q			0x0C
    4.64  #define QZ_w			0x0D
    4.65 @@ -71,9 +71,9 @@
    4.66  #define QZ_i			0x22
    4.67  #define QZ_o			0x1F
    4.68  #define QZ_p			0x23
    4.69 -#define QZ_LEFTBRACKET		0x21
    4.70 -#define QZ_RIGHTBRACKET		0x1E
    4.71 -#define QZ_BACKSLASH		0x2A
    4.72 +#define QZ_LEFTBRACKET	0x21
    4.73 +#define QZ_RIGHTBRACKET	0x1E
    4.74 +#define QZ_BACKSLASH	0x2A
    4.75  #define QZ_DELETE		0x75
    4.76  #define QZ_END			0x77
    4.77  #define QZ_PAGEDOWN		0x79
    4.78 @@ -91,7 +91,7 @@
    4.79  #define QZ_j			0x26
    4.80  #define QZ_k			0x28
    4.81  #define QZ_l			0x25
    4.82 -#define QZ_SEMICOLON		0x29
    4.83 +#define QZ_SEMICOLON	0x29
    4.84  #define QZ_QUOTE		0x27
    4.85  #define QZ_RETURN		0x24
    4.86  #define QZ_KP4			0x56
    4.87 @@ -130,11 +130,11 @@
    4.88  #define QZ_DOWN			0x7D
    4.89  #define QZ_RIGHT		0x7C
    4.90  #define QZ_KP0			0x52
    4.91 -#define QZ_KP_PERIOD		0x41
    4.92 +#define QZ_KP_PERIOD	0x41
    4.93  
    4.94  /* Wierd, these keys are on my iBook under MacOS X */
    4.95  #define QZ_IBOOK_ENTER		0x34
    4.96  #define QZ_IBOOK_LEFT		0x3B
    4.97  #define QZ_IBOOK_RIGHT		0x3C
    4.98  #define QZ_IBOOK_DOWN		0x3D
    4.99 -#define QZ_IBOOK_UP		0x3E
   4.100 +#define QZ_IBOOK_UP			0x3E
     5.1 --- a/src/video/quartz/SDL_QuartzVideo.h	Sat Jun 01 19:54:15 2002 +0000
     5.2 +++ b/src/video/quartz/SDL_QuartzVideo.h	Sat Jun 01 23:05:05 2002 +0000
     5.3 @@ -20,7 +20,7 @@
     5.4      slouken@libsdl.org
     5.5  */
     5.6  
     5.7 -/*	
     5.8 +/*    
     5.9      @file   SDL_QuartzVideo.h
    5.10      @author Darrell Walisser
    5.11      
    5.12 @@ -33,16 +33,15 @@
    5.13          - Keyboard repeat/mouse speed adjust (if needed)
    5.14          - Multiple monitor support (currently only main display)
    5.15          - Accelerated blitting support
    5.16 -        - Set the window icon (dock icon when API is available)
    5.17 -        - Fix white OpenGL window on minimize
    5.18 +        - Fix white OpenGL window on minimize (fixed)
    5.19          - Find out what events should be sent/ignored if window is mimimized
    5.20 -        - Find a better way to deal with resolution/depth switch while app is running
    5.21 +        - Find a way to deal with external resolution/depth switch while app is running
    5.22          - Resizeable windows
    5.23          - Check accuracy of QZ_SetGamma()
    5.24      Problems:
    5.25          - OGL not working in full screen with software renderer
    5.26          - SetColors sets palette correctly but clears framebuffer
    5.27 -        - Crash in CG after several mode switches
    5.28 +        - Crash in CG after several mode switches (I think this has been fixed)
    5.29          - Retained windows don't draw their title bar quite right (OS Bug) (not using retained windows)
    5.30          - Cursor in 8 bit modes is screwy (might just be Radeon PCI bug)
    5.31          - Warping cursor delays mouse events for a fraction of a second,
    5.32 @@ -52,6 +51,7 @@
    5.33  #include <Cocoa/Cocoa.h>
    5.34  #include <OpenGL/OpenGL.h>
    5.35  #include <Carbon/Carbon.h>
    5.36 +#include <QuickTime/QuickTime.h>
    5.37  
    5.38  #include "SDL_video.h"
    5.39  #include "SDL_error.h"
    5.40 @@ -102,10 +102,17 @@
    5.41      Uint32             warp_ticks;         /* timestamp when the warp occured */
    5.42      NSWindow           *window;            /* Cocoa window to implement the SDL window */
    5.43      NSQuickDrawView    *view;              /* the window's view; draw 2D into this view */
    5.44 -    
    5.45 +    ImageDescriptionHandle yuv_idh;
    5.46 +    MatrixRecordPtr        yuv_matrix;
    5.47 +    DecompressorComponent  yuv_codec;
    5.48 +    ImageSequence          yuv_seq;
    5.49 +    PlanarPixmapInfoYUV420 *yuv_pixmap;
    5.50 +    Sint16                  yuv_width, yuv_height;
    5.51 +    CGrafPtr                yuv_port;
    5.52 +
    5.53  } SDL_PrivateVideoData ;
    5.54  
    5.55 -#define _THIS	SDL_VideoDevice *this
    5.56 +#define _THIS    SDL_VideoDevice *this
    5.57  #define display_id (this->hidden->display)
    5.58  #define mode (this->hidden->mode)
    5.59  #define save_mode (this->hidden->save_mode)
    5.60 @@ -121,6 +128,15 @@
    5.61  #define video_set (this->hidden->video_set)
    5.62  #define warp_ticks (this->hidden->warp_ticks)
    5.63  #define warp_flag (this->hidden->warp_flag)
    5.64 +#define yuv_idh (this->hidden->yuv_idh)
    5.65 +#define yuv_matrix (this->hidden->yuv_matrix)
    5.66 +#define yuv_codec (this->hidden->yuv_codec)
    5.67 +#define yuv_seq (this->hidden->yuv_seq)
    5.68 +#define yuv_pixmap (this->hidden->yuv_pixmap)
    5.69 +#define yuv_data (this->hidden->yuv_data)
    5.70 +#define yuv_width (this->hidden->yuv_width)
    5.71 +#define yuv_height (this->hidden->yuv_height)
    5.72 +#define yuv_port (this->hidden->yuv_port)
    5.73  
    5.74  /* Obscuring code: maximum number of windows above ours (inclusive) */
    5.75  #define kMaxWindows 256
    5.76 @@ -144,16 +160,16 @@
    5.77  */
    5.78  
    5.79  typedef CGError       CGSError;
    5.80 -typedef long	      CGSWindowCount;
    5.81 -typedef void *	      CGSConnectionID;
    5.82 -typedef int	      CGSWindowID;
    5.83 +typedef long          CGSWindowCount;
    5.84 +typedef void *        CGSConnectionID;
    5.85 +typedef int           CGSWindowID;
    5.86  typedef CGSWindowID*  CGSWindowIDList;
    5.87  typedef CGWindowLevel CGSWindowLevel;
    5.88  typedef NSRect        CGSRect;
    5.89  
    5.90  extern CGSConnectionID _CGSDefaultConnection ();
    5.91  
    5.92 -extern CGSError CGSGetOnScreenWindowList (CGSConnectionID cid, 
    5.93 +extern CGSError CGSGetOnScreenWindowList (CGSConnectionID cid,
    5.94                                            CGSConnectionID owner,
    5.95                                            CGSWindowCount listCapacity,
    5.96                                            CGSWindowIDList list,
    5.97 @@ -166,9 +182,9 @@
    5.98  extern CGWindowLevel CGSGetWindowLevel (CGSConnectionID cid,
    5.99                                          CGSWindowID wid,
   5.100                                          CGSWindowLevel *level);
   5.101 -                                        
   5.102 -extern CGSError CGSDisplayHWFill (CGDirectDisplayID id, unsigned int x, unsigned int y, 
   5.103 -                      unsigned int w, unsigned int h, unsigned int color);
   5.104 +
   5.105 +extern CGSError CGSDisplayHWFill (CGDirectDisplayID id, unsigned int x, unsigned int y,
   5.106 +                                  unsigned int w, unsigned int h, unsigned int color);
   5.107  
   5.108  extern CGSError CGSDisplayCanHWFill (CGDirectDisplayID id);
   5.109  
   5.110 @@ -182,16 +198,16 @@
   5.111  /* Initialization, Query, Setup, and Redrawing functions */
   5.112  static int          QZ_VideoInit        (_THIS, SDL_PixelFormat *video_format);
   5.113  
   5.114 -static SDL_Rect**   QZ_ListModes        (_THIS, SDL_PixelFormat *format, 
   5.115 -					 Uint32 flags);
   5.116 +static SDL_Rect**   QZ_ListModes        (_THIS, SDL_PixelFormat *format,
   5.117 +                                         Uint32 flags);
   5.118  static void         QZ_UnsetVideoMode   (_THIS);
   5.119  
   5.120 -static SDL_Surface* QZ_SetVideoMode     (_THIS, SDL_Surface *current, 
   5.121 -					 int width, int height, int bpp, 
   5.122 -					 Uint32 flags);
   5.123 +static SDL_Surface* QZ_SetVideoMode     (_THIS, SDL_Surface *current,
   5.124 +                                         int width, int height, int bpp,
   5.125 +                                         Uint32 flags);
   5.126  static int          QZ_ToggleFullScreen (_THIS, int on);
   5.127 -static int          QZ_SetColors        (_THIS, int first_color, 
   5.128 -					 int num_colors, SDL_Color *colors);
   5.129 +static int          QZ_SetColors        (_THIS, int first_color,
   5.130 +                                         int num_colors, SDL_Color *colors);
   5.131  static void         QZ_DirectUpdate     (_THIS, int num_rects, SDL_Rect *rects);
   5.132  static void         QZ_UpdateRects      (_THIS, int num_rects, SDL_Rect *rects);
   5.133  static void         QZ_VideoQuit        (_THIS);
   5.134 @@ -223,8 +239,8 @@
   5.135  
   5.136  /* Cursor and Mouse functions */
   5.137  static void         QZ_FreeWMCursor     (_THIS, WMcursor *cursor);
   5.138 -static WMcursor*    QZ_CreateWMCursor   (_THIS, Uint8 *data, Uint8 *mask, 
   5.139 -                                          int w, int h, int hot_x, int hot_y);
   5.140 +static WMcursor*    QZ_CreateWMCursor   (_THIS, Uint8 *data, Uint8 *mask,
   5.141 +                                         int w, int h, int hot_x, int hot_y);
   5.142  static int          QZ_ShowWMCursor     (_THIS, WMcursor *cursor);
   5.143  static void         QZ_WarpWMCursor     (_THIS, Uint16 x, Uint16 y);
   5.144  static void         QZ_MoveWMCursor     (_THIS, int x, int y);
   5.145 @@ -241,3 +257,7 @@
   5.146  static SDL_GrabMode QZ_GrabInput (_THIS, SDL_GrabMode grab_mode);
   5.147  /*static int  QZ_GetWMInfo     (_THIS, SDL_SysWMinfo *info);*/
   5.148  
   5.149 +/* YUV functions */
   5.150 +static SDL_Overlay* QZ_CreateYUVOverlay (_THIS, int width, int height,
   5.151 +                                         Uint32 format, SDL_Surface *display);
   5.152 +
     6.1 --- a/src/video/quartz/SDL_QuartzVideo.m	Sat Jun 01 19:54:15 2002 +0000
     6.2 +++ b/src/video/quartz/SDL_QuartzVideo.m	Sat Jun 01 23:05:05 2002 +0000
     6.3 @@ -32,7 +32,6 @@
     6.4  #include "SDL_QuartzEvents.m"
     6.5  #include "SDL_QuartzWindow.m"
     6.6  
     6.7 -
     6.8  /* Bootstrap binding, enables entry point into the driver */
     6.9  VideoBootStrap QZ_bootstrap = {
    6.10      "Quartz", "Mac OS X CoreGraphics", QZ_Available, QZ_CreateDevice
    6.11 @@ -100,7 +99,9 @@
    6.12      /*device->GetWMInfo     = QZ_GetWMInfo;*/
    6.13      device->GrabInput     = QZ_GrabInput;
    6.14  
    6.15 -    device->free = QZ_DeleteDevice;
    6.16 +    device->CreateYUVOverlay =  QZ_CreateYUVOverlay;
    6.17 +
    6.18 +    device->free             = QZ_DeleteDevice;
    6.19  
    6.20      return device;
    6.21  }
    6.22 @@ -135,106 +136,106 @@
    6.23  }
    6.24  
    6.25  static SDL_Rect** QZ_ListModes (_THIS, SDL_PixelFormat *format, Uint32 flags) {
    6.26 -    
    6.27 +
    6.28      CFIndex num_modes;
    6.29      CFIndex i;
    6.30  
    6.31      static SDL_Rect **list = NULL;
    6.32      int list_size = 0;
    6.33 -    
    6.34 +
    6.35      /* Any windowed mode is acceptable */
    6.36      if ( (flags & SDL_FULLSCREEN) == 0 )
    6.37          return (SDL_Rect**)-1;
    6.38 -        
    6.39 +
    6.40      /* Free memory from previous call, if any */
    6.41      if ( list != NULL ) {
    6.42  
    6.43 -      int i;
    6.44 +        int i;
    6.45  
    6.46 -      for (i = 0; list[i] != NULL; i++)
    6.47 -	free (list[i]);
    6.48 +        for (i = 0; list[i] != NULL; i++)
    6.49 +            free (list[i]);
    6.50  
    6.51 -      free (list);
    6.52 -      list = NULL;
    6.53 +        free (list);
    6.54 +        list = NULL;
    6.55      }
    6.56 -    
    6.57 +
    6.58      num_modes = CFArrayGetCount (mode_list);
    6.59  
    6.60      /* Build list of modes with the requested bpp */
    6.61      for (i = 0; i < num_modes; i++) {
    6.62 -   
    6.63 +
    6.64          CFDictionaryRef onemode;
    6.65          CFNumberRef     number;
    6.66 -	int bpp;
    6.67 -	
    6.68 -        onemode = CFArrayGetValueAtIndex (mode_list, i); 
    6.69 -	number = CFDictionaryGetValue (onemode, kCGDisplayBitsPerPixel);
    6.70 -	CFNumberGetValue (number, kCFNumberSInt32Type, &bpp);
    6.71 +        int bpp;
    6.72  
    6.73 -	if (bpp == format->BitsPerPixel) {
    6.74 -	  
    6.75 -	  int intvalue;
    6.76 -          int hasMode;
    6.77 -          int width, height;
    6.78 -          
    6.79 -	  number = CFDictionaryGetValue (onemode, kCGDisplayWidth);
    6.80 -	  CFNumberGetValue (number, kCFNumberSInt32Type, &intvalue);
    6.81 -	  width = (Uint16) intvalue;
    6.82 -	  
    6.83 -	  number = CFDictionaryGetValue (onemode, kCGDisplayHeight);
    6.84 -	  CFNumberGetValue (number, kCFNumberSInt32Type, &intvalue);
    6.85 -	  height = (Uint16) intvalue;
    6.86 -          
    6.87 -          /* Check if mode is already in the list */
    6.88 -          {
    6.89 -            int i;
    6.90 -            hasMode = SDL_FALSE;
    6.91 -            for (i = 0; i < list_size; i++) {
    6.92 -                if (list[i]->w == width && list[i]->h == height) {
    6.93 -                    hasMode = SDL_TRUE;
    6.94 -                    break;
    6.95 +        onemode = CFArrayGetValueAtIndex (mode_list, i);
    6.96 +        number = CFDictionaryGetValue (onemode, kCGDisplayBitsPerPixel);
    6.97 +        CFNumberGetValue (number, kCFNumberSInt32Type, &bpp);
    6.98 +
    6.99 +        if (bpp == format->BitsPerPixel) {
   6.100 +
   6.101 +            int intvalue;
   6.102 +            int hasMode;
   6.103 +            int width, height;
   6.104 +
   6.105 +            number = CFDictionaryGetValue (onemode, kCGDisplayWidth);
   6.106 +            CFNumberGetValue (number, kCFNumberSInt32Type, &intvalue);
   6.107 +            width = (Uint16) intvalue;
   6.108 +
   6.109 +            number = CFDictionaryGetValue (onemode, kCGDisplayHeight);
   6.110 +            CFNumberGetValue (number, kCFNumberSInt32Type, &intvalue);
   6.111 +            height = (Uint16) intvalue;
   6.112 +
   6.113 +            /* Check if mode is already in the list */
   6.114 +            {
   6.115 +                int i;
   6.116 +                hasMode = SDL_FALSE;
   6.117 +                for (i = 0; i < list_size; i++) {
   6.118 +                    if (list[i]->w == width && list[i]->h == height) {
   6.119 +                        hasMode = SDL_TRUE;
   6.120 +                        break;
   6.121 +                    }
   6.122                  }
   6.123              }
   6.124 -          }
   6.125 -          
   6.126 -          /* Grow the list and add mode to the list */
   6.127 -          if ( ! hasMode ) {
   6.128 -	  
   6.129 -            SDL_Rect *rect;
   6.130 -            
   6.131 -            list_size++;
   6.132  
   6.133 -            if (list == NULL)
   6.134 -                list = (SDL_Rect**) malloc (sizeof(*list) * (list_size+1) );
   6.135 -            else
   6.136 -                list = (SDL_Rect**) realloc (list, sizeof(*list) * (list_size+1));
   6.137 -            
   6.138 -            rect = (SDL_Rect*) malloc (sizeof(**list));
   6.139 -            
   6.140 -            if (list == NULL || rect == NULL) {
   6.141 -                SDL_OutOfMemory ();
   6.142 -                return NULL;
   6.143 +            /* Grow the list and add mode to the list */
   6.144 +            if ( ! hasMode ) {
   6.145 +
   6.146 +                SDL_Rect *rect;
   6.147 +
   6.148 +                list_size++;
   6.149 +
   6.150 +                if (list == NULL)
   6.151 +                    list = (SDL_Rect**) malloc (sizeof(*list) * (list_size+1) );
   6.152 +                else
   6.153 +                    list = (SDL_Rect**) realloc (list, sizeof(*list) * (list_size+1));
   6.154 +
   6.155 +                rect = (SDL_Rect*) malloc (sizeof(**list));
   6.156 +
   6.157 +                if (list == NULL || rect == NULL) {
   6.158 +                    SDL_OutOfMemory ();
   6.159 +                    return NULL;
   6.160 +                }
   6.161 +
   6.162 +                rect->w = width;
   6.163 +                rect->h = height;
   6.164 +
   6.165 +                list[list_size-1] = rect;
   6.166 +                list[list_size]   = NULL;
   6.167              }
   6.168 -            
   6.169 -            rect->w = width;
   6.170 -            rect->h = height;
   6.171 -    
   6.172 -            list[list_size-1] = rect;
   6.173 -            list[list_size]   = NULL;
   6.174          }
   6.175 -      }
   6.176      }
   6.177 -    
   6.178 +
   6.179      /* Sort list largest to smallest (by area) */
   6.180      {
   6.181          int i, j;
   6.182          for (i = 0; i < list_size; i++) {
   6.183              for (j = 0; j < list_size-1; j++) {
   6.184 -            
   6.185 +
   6.186                  int area1, area2;
   6.187                  area1 = list[j]->w * list[j]->h;
   6.188                  area2 = list[j+1]->w * list[j+1]->h;
   6.189 -                
   6.190 +
   6.191                  if (area1 < area2) {
   6.192                      SDL_Rect *tmp = list[j];
   6.193                      list[j] = list[j+1];
   6.194 @@ -299,8 +300,8 @@
   6.195  static UInt32 QZ_FadeGammaIn (_THIS, SDL_QuartzGammaTable *table) {
   6.196  
   6.197      CGGammaValue redTable[QZ_GAMMA_TABLE_SIZE],
   6.198 -        greenTable[QZ_GAMMA_TABLE_SIZE],
   6.199 -        blueTable[QZ_GAMMA_TABLE_SIZE];
   6.200 +    greenTable[QZ_GAMMA_TABLE_SIZE],
   6.201 +    blueTable[QZ_GAMMA_TABLE_SIZE];
   6.202  
   6.203      float percent;
   6.204      int j;
   6.205 @@ -308,7 +309,7 @@
   6.206      memset (redTable, 0, sizeof(redTable));
   6.207      memset (greenTable, 0, sizeof(greenTable));
   6.208      memset (blueTable, 0, sizeof(greenTable));
   6.209 -    
   6.210 +
   6.211      for (percent = 0.0; percent <= 1.0; percent += 0.01) {
   6.212  
   6.213          for (j = 0; j < QZ_GAMMA_TABLE_SIZE; j++) {
   6.214 @@ -338,7 +339,7 @@
   6.215      this->info.blit_fill = 0;
   6.216      this->FillHWRect     = NULL;
   6.217      this->UpdateRects    = NULL;
   6.218 -   
   6.219 +
   6.220      /* Release fullscreen resources */
   6.221      if ( mode_flags & SDL_FULLSCREEN ) {
   6.222  
   6.223 @@ -351,7 +352,7 @@
   6.224          /* Do this first to avoid trash on the display before fade */
   6.225          if ( mode_flags & SDL_OPENGL )
   6.226              QZ_TearDownOpenGL (this);
   6.227 -        
   6.228 +
   6.229          if (mode_flags & SDL_OPENGL)
   6.230              CGLSetFullScreen(NULL);
   6.231  
   6.232 @@ -359,12 +360,12 @@
   6.233          CGDisplaySwitchToMode (display_id, save_mode);
   6.234          CGDisplayRelease (display_id);
   6.235          ShowMenuBar ();
   6.236 -        
   6.237 +
   6.238          if (! gamma_error)
   6.239              QZ_FadeGammaIn (this, &gamma_table);
   6.240      }
   6.241      /* Release window mode resources */
   6.242 -    else { 
   6.243 +    else {
   6.244          if ( (mode_flags & SDL_OPENGL) == 0 ) {
   6.245              UnlockPortBits ( [ window_view qdPort ] );
   6.246              [ window_view release  ];
   6.247 @@ -373,7 +374,7 @@
   6.248          [ qz_window setDelegate:nil ];
   6.249          [ qz_window close ];
   6.250          [ qz_window release ];
   6.251 -	qz_window = nil;
   6.252 +        qz_window = nil;
   6.253  
   6.254          /* Release the OpenGL context */
   6.255          if ( mode_flags & SDL_OPENGL )
   6.256 @@ -382,15 +383,15 @@
   6.257  
   6.258      /* Restore gamma settings */
   6.259      CGDisplayRestoreColorSyncSettings ();
   6.260 -    
   6.261 +
   6.262      /* Set pixels to null (so other code doesn't try to free it) */
   6.263      if (this->screen != NULL)
   6.264          this->screen->pixels = NULL;
   6.265 -        
   6.266 +
   6.267      /* Ensure the cursor will be visible and working when we quit */
   6.268      CGDisplayShowCursor (display_id);
   6.269      CGAssociateMouseAndMouseCursorPosition (1);
   6.270 -    
   6.271 +
   6.272      /* Signal successful teardown */
   6.273      video_set = SDL_FALSE;
   6.274  }
   6.275 @@ -400,11 +401,11 @@
   6.276      int exact_match;
   6.277      int gamma_error;
   6.278      SDL_QuartzGammaTable gamma_table;
   6.279 -    
   6.280 +
   6.281      /* See if requested mode exists */
   6.282 -    mode = CGDisplayBestModeForParameters (display_id, bpp, width, 
   6.283 -					   height, &exact_match);
   6.284 -    
   6.285 +    mode = CGDisplayBestModeForParameters (display_id, bpp, width,
   6.286 +                                           height, &exact_match);
   6.287 +
   6.288      /* Require an exact match to the requested mode */
   6.289      if ( ! exact_match ) {
   6.290          sprintf (QZ_Error, "Failed to find display resolution: %dx%dx%d", width, height, bpp);
   6.291 @@ -421,7 +422,7 @@
   6.292          goto ERR_NO_CAPTURE;
   6.293      }
   6.294  
   6.295 -    
   6.296 +
   6.297      /* Do the physical switch */
   6.298      if ( CGDisplayNoErr != CGDisplaySwitchToMode (display_id, mode) ) {
   6.299          SDL_SetError ("Failed switching display resolution");
   6.300 @@ -434,45 +435,45 @@
   6.301      current->flags = 0;
   6.302      current->w = width;
   6.303      current->h = height;
   6.304 -    current->flags |= SDL_FULLSCREEN;  
   6.305 +    current->flags |= SDL_FULLSCREEN;
   6.306      current->flags |= SDL_HWSURFACE;
   6.307 -   
   6.308 +
   6.309      this->UpdateRects = QZ_DirectUpdate;
   6.310 -    
   6.311 +
   6.312      /* Setup some mode-dependant info */
   6.313      if ( CGSDisplayCanHWFill (display_id) ) {
   6.314 -         this->info.blit_fill = 1;
   6.315 -         this->FillHWRect = QZ_FillHWRect;
   6.316 +        this->info.blit_fill = 1;
   6.317 +        this->FillHWRect = QZ_FillHWRect;
   6.318      }
   6.319 -        
   6.320 +
   6.321      if ( CGDisplayCanSetPalette (display_id) )
   6.322          current->flags |= SDL_HWPALETTE;
   6.323 -    
   6.324 +
   6.325      /* Setup OpenGL for a fullscreen context */
   6.326      if (flags & SDL_OPENGL) {
   6.327  
   6.328          CGLError err;
   6.329          CGLContextObj ctx;
   6.330 -        
   6.331 +
   6.332          if ( ! QZ_SetupOpenGL (this, bpp, flags) ) {
   6.333              goto ERR_NO_GL;
   6.334          }
   6.335 -       
   6.336 +
   6.337          ctx = [ gl_context cglContext ];
   6.338          err = CGLSetFullScreen (ctx);
   6.339 -        
   6.340 +
   6.341          if (err) {
   6.342              sprintf (QZ_Error, "Error setting OpenGL fullscreen: %s", CGLErrorString(err));
   6.343              SDL_SetError (QZ_Error);
   6.344              goto ERR_NO_GL;
   6.345          }
   6.346 -         
   6.347 +
   6.348          [ gl_context makeCurrentContext];
   6.349  
   6.350          glClear (GL_COLOR_BUFFER_BIT);
   6.351  
   6.352          [ gl_context flushBuffer ];
   6.353 -        
   6.354 +
   6.355          current->flags |= SDL_OPENGL;
   6.356      }
   6.357  
   6.358 @@ -482,23 +483,23 @@
   6.359      /* Fade the display to original gamma */
   6.360      if (! gamma_error )
   6.361          QZ_FadeGammaIn (this, &gamma_table);
   6.362 -    
   6.363 +
   6.364      /* Save the flags to ensure correct tear-down */
   6.365      mode_flags = current->flags;
   6.366 -    
   6.367 +
   6.368      return current;
   6.369  
   6.370 - /* Since the blanking window covers *all* windows (even force quit) correct recovery is crucial */
   6.371 - ERR_NO_GL:      CGDisplaySwitchToMode (display_id, save_mode);
   6.372 - ERR_NO_SWITCH:  CGDisplayRelease (display_id);
   6.373 - ERR_NO_CAPTURE: if (!gamma_error) { QZ_FadeGammaIn (this, &gamma_table); }
   6.374 - ERR_NO_MATCH:	return NULL;
   6.375 +    /* Since the blanking window covers *all* windows (even force quit) correct recovery is crucial */
   6.376 +ERR_NO_GL:      CGDisplaySwitchToMode (display_id, save_mode);
   6.377 +ERR_NO_SWITCH:  CGDisplayRelease (display_id);
   6.378 +ERR_NO_CAPTURE: if (!gamma_error) { QZ_FadeGammaIn (this, &gamma_table); }
   6.379 +ERR_NO_MATCH:    return NULL;
   6.380  }
   6.381  
   6.382  static SDL_Surface* QZ_SetVideoWindowed (_THIS, SDL_Surface *current, int width,
   6.383 -                                           int height, int bpp, Uint32 flags) {    
   6.384 +                                         int height, int bpp, Uint32 flags) {
   6.385      unsigned int style;
   6.386 -    NSRect rect;    
   6.387 +    NSRect rect;
   6.388      rect = NSMakeRect (0, 0, width, height);
   6.389  
   6.390  #if 1 // FIXME - the resize button doesn't show?  Also need resize events...
   6.391 @@ -515,17 +516,17 @@
   6.392      }
   6.393  
   6.394      /* Manually create a window, avoids having a nib file resource */
   6.395 -    qz_window = [ [ SDL_QuartzWindow alloc ] initWithContentRect:rect 
   6.396 -        styleMask:style backing:NSBackingStoreBuffered defer:NO ];
   6.397 +    qz_window = [ [ SDL_QuartzWindow alloc ] initWithContentRect:rect
   6.398 +                                                       styleMask:style backing:NSBackingStoreBuffered defer:NO ];
   6.399      if (qz_window == nil) {
   6.400          SDL_SetError ("Could not create the Cocoa window");
   6.401          return NULL;
   6.402      }
   6.403 -    
   6.404 +
   6.405      current->flags = 0;
   6.406      current->w = width;
   6.407      current->h = height;
   6.408 -    
   6.409 +
   6.410      [ qz_window setReleasedWhenClosed:YES ];
   6.411      QZ_SetCaption(this, this->wm_title, this->wm_icon);
   6.412      [ qz_window setAcceptsMouseMovedEvents:YES ];
   6.413 @@ -533,14 +534,14 @@
   6.414      [ qz_window center ];
   6.415      [ qz_window setDelegate:
   6.416          [ [ [ SDL_QuartzWindowDelegate alloc ] init ] autorelease ] ];
   6.417 -    
   6.418 +
   6.419      /* For OpenGL, we set the content view to a NSOpenGLView */
   6.420      if ( flags & SDL_OPENGL ) {
   6.421 -    
   6.422 +
   6.423          if ( ! QZ_SetupOpenGL (this, bpp, flags) ) {
   6.424              return NULL;
   6.425          }
   6.426 -        
   6.427 +
   6.428          [ gl_context setView: [ qz_window contentView ] ];
   6.429          [ gl_context makeCurrentContext];
   6.430          [ qz_window makeKeyAndOrderFront:nil ];
   6.431 @@ -548,45 +549,45 @@
   6.432      }
   6.433      /* For 2D, we set the content view to a NSQuickDrawView */
   6.434      else {
   6.435 -    
   6.436 +
   6.437          window_view = [ [ SDL_QuartzWindowView alloc ] init ];
   6.438          [ qz_window setContentView:window_view ];
   6.439 -        [ qz_window makeKeyAndOrderFront:nil ];    
   6.440 -        
   6.441 +        [ qz_window makeKeyAndOrderFront:nil ];
   6.442 +
   6.443          LockPortBits ( [ window_view qdPort ] );
   6.444          current->pixels = GetPixBaseAddr ( GetPortPixMap ( [ window_view qdPort ] ) );
   6.445          current->pitch  = GetPixRowBytes ( GetPortPixMap ( [ window_view qdPort ] ) );
   6.446 -        
   6.447 +
   6.448          current->flags |= SDL_SWSURFACE;
   6.449          current->flags |= SDL_PREALLOC;
   6.450 -        
   6.451 -	if ( flags & SDL_NOFRAME )
   6.452 -        	current->flags |= SDL_NOFRAME;
   6.453 -	if ( flags & SDL_RESIZABLE )
   6.454 -        	current->flags |= SDL_RESIZABLE;
   6.455 +
   6.456 +        if ( flags & SDL_NOFRAME )
   6.457 +            current->flags |= SDL_NOFRAME;
   6.458 +        if ( flags & SDL_RESIZABLE )
   6.459 +            current->flags |= SDL_RESIZABLE;
   6.460  
   6.461          /* Offset 22 pixels down to fill the full content region */
   6.462 -	if ( ! (current->flags & SDL_NOFRAME) ) {
   6.463 -        	current->pixels += 22 * current->pitch;
   6.464 -	}
   6.465 +        if ( ! (current->flags & SDL_NOFRAME) ) {
   6.466 +            current->pixels += 22 * current->pitch;
   6.467 +        }
   6.468  
   6.469          this->UpdateRects = QZ_UpdateRects;
   6.470      }
   6.471 -    
   6.472 +
   6.473      /* Save flags to ensure correct teardown */
   6.474      mode_flags = current->flags;
   6.475 -      
   6.476 +
   6.477      return current;
   6.478  }
   6.479  
   6.480 -static SDL_Surface* QZ_SetVideoMode (_THIS, SDL_Surface *current, int width, 
   6.481 -				     int height, int bpp, Uint32 flags) {
   6.482 +static SDL_Surface* QZ_SetVideoMode (_THIS, SDL_Surface *current, int width,
   6.483 +                                     int height, int bpp, Uint32 flags) {
   6.484  
   6.485      if (video_set == SDL_TRUE)
   6.486          QZ_UnsetVideoMode (this);
   6.487 -       
   6.488 +
   6.489      current->flags = 0;
   6.490 -    
   6.491 +
   6.492      /* Setup full screen video */
   6.493      if ( flags & SDL_FULLSCREEN ) {
   6.494          current = QZ_SetVideoFullScreen (this, current, width, height, bpp, flags );
   6.495 @@ -601,17 +602,17 @@
   6.496          if (current == NULL)
   6.497              return NULL;
   6.498      }
   6.499 -    
   6.500 +
   6.501      /* Setup the new pixel format */
   6.502      {
   6.503 -        int amask = 0, 
   6.504 -            rmask = 0, 
   6.505 -            gmask = 0,
   6.506 -            bmask = 0;
   6.507 -            
   6.508 +        int amask = 0,
   6.509 +        rmask = 0,
   6.510 +        gmask = 0,
   6.511 +        bmask = 0;
   6.512 +
   6.513          switch (bpp) {
   6.514              case 16:   /* (1)-5-5-5 RGB */
   6.515 -                amask = 0; 
   6.516 +                amask = 0;
   6.517                  rmask = 0x7C00;
   6.518                  gmask = 0x03E0;
   6.519                  bmask = 0x001F;
   6.520 @@ -626,212 +627,212 @@
   6.521                  bmask = 0x000000FF;
   6.522                  break;
   6.523          }
   6.524 -        
   6.525 +
   6.526          if ( ! SDL_ReallocFormat (current, bpp,
   6.527                                    rmask, gmask, bmask, amask ) ) {
   6.528 -       	   SDL_SetError ("Couldn't reallocate pixel format");
   6.529 -           return NULL;
   6.530 -       	}
   6.531 +            SDL_SetError ("Couldn't reallocate pixel format");
   6.532 +            return NULL;
   6.533 +           }
   6.534      }
   6.535 -    
   6.536 +
   6.537      /* Signal successful completion (used internally) */
   6.538      video_set = SDL_TRUE;
   6.539 -    
   6.540 +
   6.541      return current;
   6.542  }
   6.543  
   6.544 -static int QZ_ToggleFullScreen (_THIS, int on) { 
   6.545 +static int QZ_ToggleFullScreen (_THIS, int on) {
   6.546      return -1;
   6.547  }
   6.548  
   6.549 -static int QZ_SetColors (_THIS, int first_color, int num_colors, 
   6.550 -			 SDL_Color *colors) {
   6.551 +static int QZ_SetColors (_THIS, int first_color, int num_colors,
   6.552 +                         SDL_Color *colors) {
   6.553  
   6.554      CGTableCount  index;
   6.555      CGDeviceColor color;
   6.556 -    
   6.557 +
   6.558      for (index = first_color; index < first_color+num_colors; index++) {
   6.559 -    
   6.560 +
   6.561          /* Clamp colors between 0.0 and 1.0 */
   6.562          color.red   = colors->r / 255.0;
   6.563          color.blue  = colors->b / 255.0;
   6.564          color.green = colors->g / 255.0;
   6.565 -        
   6.566 +
   6.567          colors++;
   6.568 -        
   6.569 +
   6.570          CGPaletteSetColorAtIndex (palette, color, index);
   6.571      }
   6.572 -     
   6.573 +
   6.574      if ( CGDisplayNoErr != CGDisplaySetPalette (display_id, palette) )
   6.575          return 0;
   6.576 -        
   6.577 +
   6.578      return 1;
   6.579  }
   6.580  
   6.581  static void QZ_DirectUpdate (_THIS, int num_rects, SDL_Rect *rects) {
   6.582 -    #pragma unused(this,num_rects,rects)
   6.583 +#pragma unused(this,num_rects,rects)
   6.584  }
   6.585  
   6.586 -/** 
   6.587 +/**
   6.588   *  The obscured code is based on work by Matt Slot fprefect@ambrosiasw.com,
   6.589   *  who supplied sample code for Carbon.
   6.590   **/
   6.591  static int QZ_IsWindowObscured (NSWindow *window) {
   6.592  
   6.593 -//#define TEST_OBSCURED 1
   6.594 +    //#define TEST_OBSCURED 1
   6.595  
   6.596  #if TEST_OBSCURED
   6.597 +
   6.598 +    /*  In order to determine if a direct copy to the screen is possible,
   6.599 +        we must figure out if there are any windows covering ours (including shadows).
   6.600 +        This can be done by querying the window server about the on screen
   6.601 +        windows for their screen rectangle and window level.
   6.602 +        The procedure used below is puts accuracy before speed; however, it aims to call
   6.603 +        the window server the fewest number of times possible to keep things reasonable.
   6.604 +        In my testing on a 300mhz G3, this routine typically takes < 2 ms. -DW
   6.605      
   6.606 -    /*  In order to determine if a direct copy to the screen is possible,
   6.607 -       we must figure out if there are any windows covering ours (including shadows).
   6.608 -       This can be done by querying the window server about the on screen            
   6.609 -       windows for their screen rectangle and window level.                          
   6.610 -       The procedure used below is puts accuracy before speed; however, it aims to call 
   6.611 -       the window server the fewest number of times possible to keep things reasonable.
   6.612 -       In my testing on a 300mhz G3, this routine typically takes < 2 ms. -DW
   6.613 +    Notes:
   6.614 +        -Calls into the Window Server involve IPC which is slow.
   6.615 +        -Getting a rectangle seems slower than getting the window level
   6.616 +        -The window list we get back is in sorted order, top to bottom
   6.617 +        -On average, I suspect, most windows above ours are dock icon windows (hence optimization)
   6.618 +        -Some windows above ours are always there, and cannot move or obscure us (menu bar)
   6.619      
   6.620 -        Notes:
   6.621 -            -Calls into the Window Server involve IPC which is slow.
   6.622 -            -Getting a rectangle seems slower than getting the window level
   6.623 -            -The window list we get back is in sorted order, top to bottom
   6.624 -            -On average, I suspect, most windows above ours are dock icon windows (hence optimization)
   6.625 -            -Some windows above ours are always there, and cannot move or obscure us (menu bar)
   6.626 -            
   6.627 -        Bugs:
   6.628 -            -no way (yet) to deactivate direct drawing when a window is dragged, 
   6.629 -               or suddenly obscured, so drawing continues and can produce garbage
   6.630 -               We need some kind of locking mechanism on window movement to prevent this
   6.631 -               
   6.632 -            -deactivated normal windows use activated normal 
   6.633 -               window shadows (slight inaccuraccy)
   6.634 +    Bugs:
   6.635 +        -no way (yet) to deactivate direct drawing when a window is dragged,
   6.636 +        or suddenly obscured, so drawing continues and can produce garbage
   6.637 +        We need some kind of locking mechanism on window movement to prevent this
   6.638 +    
   6.639 +        -deactivated normal windows use activated normal
   6.640 +        window shadows (slight inaccuraccy)
   6.641      */
   6.642 -    
   6.643 +
   6.644      /* Cache the connection to the window server */
   6.645 -    static CGSConnectionID	cgsConnection = (CGSConnectionID) -1;
   6.646 -    
   6.647 +    static CGSConnectionID    cgsConnection = (CGSConnectionID) -1;
   6.648 +
   6.649      /* Cache the dock icon windows */
   6.650      static CGSWindowID          dockIcons[kMaxWindows];
   6.651      static int                  numCachedDockIcons = 0;
   6.652 -    
   6.653 -    CGSWindowID		        windows[kMaxWindows];
   6.654 -    CGSWindowCount	        i, count;
   6.655 -    CGSWindowLevel	        winLevel;
   6.656 -    CGSRect			winRect;
   6.657 +
   6.658 +    CGSWindowID                windows[kMaxWindows];
   6.659 +    CGSWindowCount             i, count;
   6.660 +    CGSWindowLevel             winLevel;
   6.661 +    CGSRect                    winRect;
   6.662  
   6.663      CGSRect contentRect;
   6.664      int     windowNumber;
   6.665      //int     isMainWindow;
   6.666 -    int     firstDockIcon;    
   6.667 +    int     firstDockIcon;
   6.668      int     dockIconCacheMiss;
   6.669      int     windowContentOffset;
   6.670 -    
   6.671 +
   6.672      int     obscured = SDL_TRUE;
   6.673 -        
   6.674 +
   6.675      if ( [ window isVisible ] ) {
   6.676 -        
   6.677 -        /*  walk the window list looking for windows over top of 
   6.678 -                (or casting a shadow on) ours */
   6.679 -       
   6.680 +
   6.681 +        /*  walk the window list looking for windows over top of
   6.682 +        (or casting a shadow on) ours */
   6.683 +
   6.684          /* Get a connection to the window server */
   6.685          /* Should probably be moved out into SetVideoMode() or InitVideo() */
   6.686          if (cgsConnection == (CGSConnectionID) -1) {
   6.687              cgsConnection = (CGSConnectionID) 0;
   6.688              cgsConnection = _CGSDefaultConnection ();
   6.689          }
   6.690 -        
   6.691 -        if (cgsConnection) { 
   6.692 -        
   6.693 +
   6.694 +        if (cgsConnection) {
   6.695 +
   6.696              if ( ! [ window styleMask ] & NSBorderlessWindowMask )
   6.697                  windowContentOffset = 22;
   6.698              else
   6.699                  windowContentOffset = 0;
   6.700 -                
   6.701 +
   6.702              windowNumber = [ window windowNumber ];
   6.703              //isMainWindow = [ window isMainWindow ];
   6.704 -            
   6.705 +
   6.706              /* The window list is sorted according to order on the screen */
   6.707              count = 0;
   6.708              CGSGetOnScreenWindowList (cgsConnection, 0, kMaxWindows, windows, &count);
   6.709              CGSGetScreenRectForWindow (cgsConnection, windowNumber, &contentRect);
   6.710 -    
   6.711 +
   6.712              /* adjust rect for window title bar (if present) */
   6.713              contentRect.origin.y    += windowContentOffset;
   6.714              contentRect.size.height -= windowContentOffset;
   6.715 -            
   6.716 +
   6.717              firstDockIcon = -1;
   6.718              dockIconCacheMiss = SDL_FALSE;
   6.719 -            
   6.720 -            /* The first window is always an empty window with level kCGSWindowLevelTop 
   6.721 -               so start at index 1 */
   6.722 +
   6.723 +            /* The first window is always an empty window with level kCGSWindowLevelTop
   6.724 +                so start at index 1 */
   6.725              for (i = 1; i < count; i++) {
   6.726 -                
   6.727 +
   6.728                  /* If we reach our window in the list, it cannot be obscured */
   6.729                  if (windows[i] == windowNumber) {
   6.730 -                    
   6.731 +
   6.732                      obscured = SDL_FALSE;
   6.733                      break;
   6.734                  }
   6.735                  else {
   6.736 -                    
   6.737 +
   6.738                      float shadowSide;
   6.739                      float shadowTop;
   6.740                      float shadowBottom;
   6.741  
   6.742                      CGSGetWindowLevel (cgsConnection, windows[i], &winLevel);
   6.743 -                    
   6.744 +
   6.745                      if (winLevel == kCGSWindowLevelDockIcon) {
   6.746 -                    
   6.747 +
   6.748                          int j;
   6.749 -                        
   6.750 +
   6.751                          if (firstDockIcon < 0) {
   6.752 -                            
   6.753 +
   6.754                              firstDockIcon = i;
   6.755 -                        
   6.756 +
   6.757                              if (numCachedDockIcons > 0) {
   6.758 -                            
   6.759 +
   6.760                                  for (j = 0; j < numCachedDockIcons; j++) {
   6.761 -                            
   6.762 +
   6.763                                      if (windows[i] == dockIcons[j])
   6.764                                          i++;
   6.765                                      else
   6.766                                          break;
   6.767                                  }
   6.768 -                            
   6.769 +
   6.770                                  if (j != 0) {
   6.771 -                                 
   6.772 +
   6.773                                      i--;
   6.774 -                                                                    
   6.775 +
   6.776                                      if (j < numCachedDockIcons) {
   6.777 -                                        
   6.778 +
   6.779                                          dockIconCacheMiss = SDL_TRUE;
   6.780                                      }
   6.781                                  }
   6.782  
   6.783                              }
   6.784                          }
   6.785 -                                               
   6.786 +
   6.787                          continue;
   6.788                      }
   6.789                      else if (winLevel == kCGSWindowLevelMenuIgnore
   6.790                               /* winLevel == kCGSWindowLevelTop */) {
   6.791 -                     
   6.792 +
   6.793                          continue; /* cannot obscure window */
   6.794                      }
   6.795                      else if (winLevel == kCGSWindowLevelDockMenu ||
   6.796                               winLevel == kCGSWindowLevelMenu) {
   6.797 -                     
   6.798 +
   6.799                          shadowSide = 18;
   6.800                          shadowTop = 4;
   6.801 -                        shadowBottom = 22;   
   6.802 +                        shadowBottom = 22;
   6.803                      }
   6.804                      else if (winLevel == kCGSWindowLevelUtility) {
   6.805 -                    
   6.806 +
   6.807                          shadowSide = 8;
   6.808                          shadowTop = 4;
   6.809                          shadowBottom = 12;
   6.810                      }
   6.811                      else if (winLevel == kCGSWindowLevelNormal) {
   6.812 -                    
   6.813 +
   6.814                          /* These numbers are for foreground windows,
   6.815                             they are too big (but will work) for background windows */
   6.816                          shadowSide = 20;
   6.817 @@ -839,52 +840,52 @@
   6.818                          shadowBottom = 24;
   6.819                      }
   6.820                      else if (winLevel == kCGSWindowLevelDock) {
   6.821 -                    
   6.822 +
   6.823                          /* Create dock icon cache */
   6.824                          if (numCachedDockIcons != (i-firstDockIcon) ||
   6.825                              dockIconCacheMiss) {
   6.826 -                        
   6.827 +
   6.828                              numCachedDockIcons = i - firstDockIcon;
   6.829 -                            memcpy (dockIcons, &(windows[firstDockIcon]), 
   6.830 +                            memcpy (dockIcons, &(windows[firstDockIcon]),
   6.831                                      numCachedDockIcons * sizeof(*windows));
   6.832                          }
   6.833 -                        
   6.834 +
   6.835                          /* no shadow */
   6.836                          shadowSide = 0;
   6.837                          shadowTop = 0;
   6.838                          shadowBottom = 0;
   6.839                      }
   6.840                      else {
   6.841 -                    
   6.842 +
   6.843                          /*   kCGSWindowLevelDockLabel,
   6.844 -                             kCGSWindowLevelDock,
   6.845 -                             kOther??? */
   6.846 -                        
   6.847 +                        kCGSWindowLevelDock,
   6.848 +                        kOther??? */
   6.849 +
   6.850                          /* no shadow */
   6.851                          shadowSide = 0;
   6.852                          shadowTop = 0;
   6.853                          shadowBottom = 0;
   6.854                      }
   6.855 -                    
   6.856 +
   6.857                      CGSGetScreenRectForWindow (cgsConnection, windows[i], &winRect);
   6.858 -                    
   6.859 +
   6.860                      winRect.origin.x -= shadowSide;
   6.861                      winRect.origin.y -= shadowTop;
   6.862                      winRect.size.width += shadowSide;
   6.863                      winRect.size.height += shadowBottom;
   6.864 -                    
   6.865 +
   6.866                      if (NSIntersectsRect (contentRect, winRect)) {
   6.867 -                    
   6.868 +
   6.869                          obscured = SDL_TRUE;
   6.870                          break;
   6.871                      }
   6.872 -               
   6.873 -               } /* window was not our window */
   6.874 -            
   6.875 +
   6.876 +                } /* window was not our window */
   6.877 +
   6.878              } /* iterate over windows */
   6.879 -            
   6.880 +
   6.881          } /* get cgsConnection */
   6.882 -    
   6.883 +
   6.884      } /* window is visible */
   6.885      
   6.886      return obscured;
   6.887 @@ -893,86 +894,86 @@
   6.888  #endif
   6.889  }
   6.890  
   6.891 -static void QZ_UpdateRects (_THIS, int numRects, SDL_Rect *rects) { 
   6.892 +static void QZ_UpdateRects (_THIS, int numRects, SDL_Rect *rects) {
   6.893  
   6.894      if (SDL_VideoSurface->flags & SDL_OPENGLBLIT) {
   6.895          QZ_GL_SwapBuffers (this);
   6.896      }
   6.897 -    else if ( [ qz_window isMiniaturized ] && 
   6.898 +    else if ( [ qz_window isMiniaturized ] &&
   6.899                ! (SDL_VideoSurface->flags & SDL_OPENGL)) {
   6.900 -    
   6.901 -        /** 
   6.902 +
   6.903 +        /**
   6.904           * Set port alpha opaque so deminiaturize looks right
   6.905 -         * This isn't so nice, but there is no 
   6.906 +         * This isn't so nice, but there is no
   6.907           * initial deminatureize notification (before demini starts)
   6.908           **/
   6.909          QZ_SetPortAlphaOpaque ([ [ qz_window contentView ] qdPort],
   6.910 -                                [ qz_window styleMask ] & NSBorderlessWindowMask);
   6.911 +                               [ qz_window styleMask ] & NSBorderlessWindowMask);
   6.912      }
   6.913      else if ( ! QZ_IsWindowObscured (qz_window) ) {
   6.914 -        
   6.915 +
   6.916          /* Use direct copy to flush contents to the display */
   6.917          CGrafPtr savePort;
   6.918          CGrafPtr dstPort, srcPort;
   6.919          const BitMap  *dstBits, *srcBits;
   6.920 -        Rect     dstRect, srcRect;      
   6.921 +        Rect     dstRect, srcRect;
   6.922          Point    offset;
   6.923          int i;
   6.924 -        
   6.925 +
   6.926          GetPort (&savePort);
   6.927 -        
   6.928 +
   6.929          dstPort = CreateNewPortForCGDisplayID ((UInt32)display_id);
   6.930          srcPort = [ window_view qdPort ];
   6.931 -        
   6.932 +
   6.933          offset.h = 0;
   6.934          offset.v = 0;
   6.935          SetPort (srcPort);
   6.936          LocalToGlobal (&offset);
   6.937 -        
   6.938 +
   6.939          SetPort (dstPort);
   6.940 -        
   6.941 +
   6.942          LockPortBits (dstPort);
   6.943          LockPortBits (srcPort);
   6.944 -        
   6.945 +
   6.946          dstBits = GetPortBitMapForCopyBits (dstPort);
   6.947          srcBits = GetPortBitMapForCopyBits (srcPort);
   6.948 -        
   6.949 +
   6.950          for (i = 0; i < numRects; i++) {
   6.951 -            
   6.952 +
   6.953              SetRect (&srcRect, rects[i].x, rects[i].y,
   6.954                       rects[i].x + rects[i].w,
   6.955                       rects[i].y + rects[i].h);
   6.956 -            
   6.957 +
   6.958              SetRect (&dstRect,
   6.959 -                     rects[i].x + offset.h, 
   6.960 +                     rects[i].x + offset.h,
   6.961                       rects[i].y + offset.v,
   6.962                       rects[i].x + rects[i].w + offset.h,
   6.963                       rects[i].y + rects[i].h + offset.v);
   6.964 -                        
   6.965 +
   6.966              CopyBits (srcBits, dstBits,
   6.967                        &srcRect, &dstRect, srcCopy, NULL);
   6.968 -                        
   6.969 +
   6.970          }
   6.971 -        
   6.972 +
   6.973          SetPort (savePort);
   6.974      }
   6.975      else {
   6.976 -    
   6.977 +
   6.978          /* Use QDFlushPortBuffer() to flush content to display */
   6.979          int i;
   6.980          RgnHandle dirty = NewRgn ();
   6.981          RgnHandle temp  = NewRgn ();
   6.982 -        
   6.983 +
   6.984          SetEmptyRgn (dirty);
   6.985 -        
   6.986 +
   6.987          /* Build the region of dirty rectangles */
   6.988          for (i = 0; i < numRects; i++) {
   6.989 -        
   6.990 -            MacSetRectRgn (temp, rects[i].x, rects[i].y, 
   6.991 -                rects[i].x + rects[i].w, rects[i].y + rects[i].h);
   6.992 +
   6.993 +            MacSetRectRgn (temp, rects[i].x, rects[i].y,
   6.994 +                           rects[i].x + rects[i].w, rects[i].y + rects[i].h);
   6.995              MacUnionRgn (dirty, temp, dirty);
   6.996          }
   6.997 -        
   6.998 +
   6.999          /* Flush the dirty region */
  6.1000          QDFlushPortBuffer ( [ window_view qdPort ], dirty );
  6.1001          DisposeRgn (dirty);
  6.1002 @@ -993,7 +994,7 @@
  6.1003      return 0;
  6.1004  }
  6.1005  
  6.1006 -static int  QZ_LockHWSurface(_THIS, SDL_Surface *surface) { 
  6.1007 +static int  QZ_LockHWSurface(_THIS, SDL_Surface *surface) {
  6.1008  
  6.1009      return 1;
  6.1010  }
  6.1011 @@ -1006,10 +1007,10 @@
  6.1012  }
  6.1013  
  6.1014  /*
  6.1015 -int QZ_FlipHWSurface (_THIS, SDL_Surface *surface) {
  6.1016 -    return 0;
  6.1017 -}
  6.1018 -*/
  6.1019 + int QZ_FlipHWSurface (_THIS, SDL_Surface *surface) {
  6.1020 +     return 0;
  6.1021 + }
  6.1022 + */
  6.1023  
  6.1024  /* Gamma functions */
  6.1025  static int QZ_SetGamma (_THIS, float red, float green, float blue) {
  6.1026 @@ -1030,14 +1031,14 @@
  6.1027          blue = FLT_MAX;
  6.1028      else
  6.1029          blue  = 1.0 / blue;
  6.1030 -    
  6.1031 -    if ( CGDisplayNoErr == CGSetDisplayTransferByFormula 
  6.1032 -        (display_id, min, max, red, min, max, green, min, max, blue) ) {
  6.1033 -            
  6.1034 +
  6.1035 +    if ( CGDisplayNoErr == CGSetDisplayTransferByFormula
  6.1036 +         (display_id, min, max, red, min, max, green, min, max, blue) ) {
  6.1037 +
  6.1038          return 0;
  6.1039      }
  6.1040      else {
  6.1041 -    
  6.1042 +
  6.1043          return -1;
  6.1044      }
  6.1045  }
  6.1046 @@ -1046,66 +1047,66 @@
  6.1047  
  6.1048      CGGammaValue dummy;
  6.1049      if ( CGDisplayNoErr == CGGetDisplayTransferByFormula
  6.1050 -        (display_id, &dummy, &dummy, red, 
  6.1051 -	 &dummy, &dummy, green, &dummy, &dummy, blue) )
  6.1052 -        
  6.1053 +         (display_id, &dummy, &dummy, red,
  6.1054 +          &dummy, &dummy, green, &dummy, &dummy, blue) )
  6.1055 +
  6.1056          return 0;
  6.1057      else
  6.1058          return -1;
  6.1059  }
  6.1060  
  6.1061  static int QZ_SetGammaRamp (_THIS, Uint16 *ramp) {
  6.1062 - 
  6.1063 -   const CGTableCount tableSize = 255;
  6.1064 -   CGGammaValue redTable[tableSize];
  6.1065 -   CGGammaValue greenTable[tableSize];
  6.1066 -   CGGammaValue blueTable[tableSize];
  6.1067 -   
  6.1068 -   int i;
  6.1069 -   
  6.1070 -   /* Extract gamma values into separate tables, convert to floats between 0.0 and 1.0 */
  6.1071 -   for (i = 0; i < 256; i++)
  6.1072 -    redTable[i % 256] = ramp[i] / 65535.0;
  6.1073 -   
  6.1074 -   for (i=256; i < 512; i++)
  6.1075 -    greenTable[i % 256] = ramp[i] / 65535.0;
  6.1076 -   
  6.1077 -   for (i=512; i < 768; i++)
  6.1078 -     blueTable[i % 256] = ramp[i] / 65535.0;
  6.1079 -     
  6.1080 -    if ( CGDisplayNoErr == CGSetDisplayTransferByTable 
  6.1081 -            (display_id, tableSize, redTable, greenTable, blueTable) )        
  6.1082 +
  6.1083 +    const CGTableCount tableSize = 255;
  6.1084 +    CGGammaValue redTable[tableSize];
  6.1085 +    CGGammaValue greenTable[tableSize];
  6.1086 +    CGGammaValue blueTable[tableSize];
  6.1087 +
  6.1088 +    int i;
  6.1089 +
  6.1090 +    /* Extract gamma values into separate tables, convert to floats between 0.0 and 1.0 */
  6.1091 +    for (i = 0; i < 256; i++)
  6.1092 +        redTable[i % 256] = ramp[i] / 65535.0;
  6.1093 +
  6.1094 +    for (i=256; i < 512; i++)
  6.1095 +        greenTable[i % 256] = ramp[i] / 65535.0;
  6.1096 +
  6.1097 +    for (i=512; i < 768; i++)
  6.1098 +        blueTable[i % 256] = ramp[i] / 65535.0;
  6.1099 +
  6.1100 +    if ( CGDisplayNoErr == CGSetDisplayTransferByTable
  6.1101 +         (display_id, tableSize, redTable, greenTable, blueTable) )
  6.1102          return 0;
  6.1103      else
  6.1104          return -1;
  6.1105  }
  6.1106  
  6.1107  static int QZ_GetGammaRamp (_THIS, Uint16 *ramp) {
  6.1108 -    
  6.1109 +
  6.1110      const CGTableCount tableSize = 255;
  6.1111      CGGammaValue redTable[tableSize];
  6.1112      CGGammaValue greenTable[tableSize];
  6.1113      CGGammaValue blueTable[tableSize];
  6.1114      CGTableCount actual;
  6.1115      int i;
  6.1116 -    
  6.1117 -    if ( CGDisplayNoErr != CGGetDisplayTransferByTable 
  6.1118 -            (display_id, tableSize, redTable, greenTable, blueTable, &actual) ||
  6.1119 -          actual != tableSize)
  6.1120 -        
  6.1121 +
  6.1122 +    if ( CGDisplayNoErr != CGGetDisplayTransferByTable
  6.1123 +         (display_id, tableSize, redTable, greenTable, blueTable, &actual) ||
  6.1124 +         actual != tableSize)
  6.1125 +
  6.1126          return -1;
  6.1127 -    
  6.1128 +
  6.1129      /* Pack tables into one array, with values from 0 to 65535 */
  6.1130      for (i = 0; i < 256; i++)
  6.1131          ramp[i] = redTable[i % 256] * 65535.0;
  6.1132 -   
  6.1133 +
  6.1134      for (i=256; i < 512; i++)
  6.1135          ramp[i] = greenTable[i % 256] * 65535.0;
  6.1136 -   
  6.1137 +
  6.1138      for (i=512; i < 768; i++)
  6.1139          ramp[i] = blueTable[i % 256] * 65535.0;
  6.1140 -      
  6.1141 -    return 0;    
  6.1142 +
  6.1143 +    return 0;
  6.1144  }
  6.1145  
  6.1146  /* OpenGL helper functions (used internally) */
  6.1147 @@ -1118,53 +1119,53 @@
  6.1148      int colorBits = bpp;
  6.1149  
  6.1150      if ( flags & SDL_FULLSCREEN ) {
  6.1151 -    
  6.1152 +
  6.1153          attr[i++] = NSOpenGLPFAFullScreen;
  6.1154      }
  6.1155      /* In windowed mode, the OpenGL pixel depth must match device pixel depth */
  6.1156 -    else if ( colorBits != device_bpp ) { 
  6.1157 +    else if ( colorBits != device_bpp ) {
  6.1158  
  6.1159          colorBits = device_bpp;
  6.1160      }
  6.1161 -    
  6.1162 +
  6.1163      attr[i++] = NSOpenGLPFAColorSize;
  6.1164      attr[i++] = colorBits;
  6.1165 -    
  6.1166 +
  6.1167      attr[i++] = NSOpenGLPFADepthSize;
  6.1168      attr[i++] = this->gl_config.depth_size;
  6.1169  
  6.1170      if ( this->gl_config.double_buffer ) {
  6.1171          attr[i++] = NSOpenGLPFADoubleBuffer;
  6.1172      }
  6.1173 -    
  6.1174 +
  6.1175      if ( this->gl_config.stencil_size != 0 ) {
  6.1176          attr[i++] = NSOpenGLPFAStencilSize;
  6.1177          attr[i++] = this->gl_config.stencil_size;
  6.1178      }
  6.1179 -    
  6.1180 +
  6.1181      attr[i++] = NSOpenGLPFAScreenMask;
  6.1182      attr[i++] = CGDisplayIDToOpenGLDisplayMask (display_id);
  6.1183      attr[i] = 0;
  6.1184 -    
  6.1185 +
  6.1186      fmt = [ [ NSOpenGLPixelFormat alloc ] initWithAttributes:attr ];
  6.1187      if (fmt == nil) {
  6.1188          SDL_SetError ("Failed creating OpenGL pixel format");
  6.1189          return 0;
  6.1190      }
  6.1191 -    
  6.1192 -    gl_context = [ [ NSOpenGLContext alloc ] initWithFormat:fmt 
  6.1193 -        shareContext:nil];
  6.1194 -    
  6.1195 +
  6.1196 +    gl_context = [ [ NSOpenGLContext alloc ] initWithFormat:fmt
  6.1197 +                                               shareContext:nil];
  6.1198 +
  6.1199      if (gl_context == nil) {
  6.1200          SDL_SetError ("Failed creating OpenGL context");
  6.1201          return 0;
  6.1202 -    }	
  6.1203 -    
  6.1204 +    }
  6.1205 +
  6.1206      /* Convince SDL that the GL "driver" is loaded */
  6.1207      this->gl_config.driver_loaded = 1;
  6.1208 -    
  6.1209 +
  6.1210      [ fmt release ];
  6.1211 -    
  6.1212 +
  6.1213      return 1;
  6.1214  }
  6.1215  
  6.1216 @@ -1187,23 +1188,23 @@
  6.1217  
  6.1218      /* We may want to cache the bundleRef at some point */
  6.1219      CFBundleRef bundle;
  6.1220 -    CFURLRef bundleURL = CFURLCreateWithFileSystemPath (kCFAllocatorDefault, 
  6.1221 -        CFSTR("/System/Library/Frameworks/OpenGL.framework"), kCFURLPOSIXPathStyle, true);
  6.1222 -    
  6.1223 -    CFStringRef functionName = CFStringCreateWithCString 
  6.1224 +    CFURLRef bundleURL = CFURLCreateWithFileSystemPath (kCFAllocatorDefault,
  6.1225 +                                                        CFSTR("/System/Library/Frameworks/OpenGL.framework"), kCFURLPOSIXPathStyle, true);
  6.1226 +
  6.1227 +    CFStringRef functionName = CFStringCreateWithCString
  6.1228          (kCFAllocatorDefault, proc, kCFStringEncodingASCII);
  6.1229 -    
  6.1230 +
  6.1231      void *function;
  6.1232 -    
  6.1233 +
  6.1234      bundle = CFBundleCreate (kCFAllocatorDefault, bundleURL);
  6.1235      assert (bundle != NULL);
  6.1236 -    
  6.1237 +
  6.1238      function = CFBundleGetFunctionPointerForName (bundle, functionName);
  6.1239  
  6.1240      CFRelease ( bundleURL );
  6.1241      CFRelease ( functionName );
  6.1242      CFRelease ( bundle );
  6.1243 -    
  6.1244 +
  6.1245      return function;
  6.1246  }
  6.1247  
  6.1248 @@ -1214,18 +1215,18 @@
  6.1249      QZ_GL_MakeCurrent (this);
  6.1250  
  6.1251      switch (attrib) {
  6.1252 -    case SDL_GL_RED_SIZE: attr = GL_RED_BITS;   break;
  6.1253 -    case SDL_GL_BLUE_SIZE: attr = GL_BLUE_BITS;  break;
  6.1254 -    case SDL_GL_GREEN_SIZE: attr = GL_GREEN_BITS; break;
  6.1255 -    case SDL_GL_ALPHA_SIZE: attr = GL_ALPHA_BITS; break;
  6.1256 -    case SDL_GL_DOUBLEBUFFER: attr = GL_DOUBLEBUFFER; break;
  6.1257 -    case SDL_GL_DEPTH_SIZE: attr = GL_DEPTH_BITS;  break;
  6.1258 -    case SDL_GL_STENCIL_SIZE: attr = GL_STENCIL_BITS; break;
  6.1259 -    case SDL_GL_ACCUM_RED_SIZE: attr = GL_ACCUM_RED_BITS; break;
  6.1260 -    case SDL_GL_ACCUM_GREEN_SIZE: attr = GL_ACCUM_GREEN_BITS; break;
  6.1261 -    case SDL_GL_ACCUM_BLUE_SIZE: attr = GL_ACCUM_BLUE_BITS; break;
  6.1262 -    case SDL_GL_ACCUM_ALPHA_SIZE: attr = GL_ACCUM_ALPHA_BITS; break;
  6.1263 -    case SDL_GL_BUFFER_SIZE:
  6.1264 +        case SDL_GL_RED_SIZE: attr = GL_RED_BITS;   break;
  6.1265 +        case SDL_GL_BLUE_SIZE: attr = GL_BLUE_BITS;  break;
  6.1266 +        case SDL_GL_GREEN_SIZE: attr = GL_GREEN_BITS; break;
  6.1267 +        case SDL_GL_ALPHA_SIZE: attr = GL_ALPHA_BITS; break;
  6.1268 +        case SDL_GL_DOUBLEBUFFER: attr = GL_DOUBLEBUFFER; break;
  6.1269 +        case SDL_GL_DEPTH_SIZE: attr = GL_DEPTH_BITS;  break;
  6.1270 +        case SDL_GL_STENCIL_SIZE: attr = GL_STENCIL_BITS; break;
  6.1271 +        case SDL_GL_ACCUM_RED_SIZE: attr = GL_ACCUM_RED_BITS; break;
  6.1272 +        case SDL_GL_ACCUM_GREEN_SIZE: attr = GL_ACCUM_GREEN_BITS; break;
  6.1273 +        case SDL_GL_ACCUM_BLUE_SIZE: attr = GL_ACCUM_BLUE_BITS; break;
  6.1274 +        case SDL_GL_ACCUM_ALPHA_SIZE: attr = GL_ACCUM_ALPHA_BITS; break;
  6.1275 +        case SDL_GL_BUFFER_SIZE:
  6.1276          {
  6.1277              GLint bits = 0;
  6.1278              GLint component;
  6.1279 @@ -1254,4 +1255,298 @@
  6.1280      [ gl_context flushBuffer ];
  6.1281  }
  6.1282  
  6.1283 +static int QZ_LockYUV (_THIS, SDL_Overlay *overlay) {
  6.1284  
  6.1285 +    return 0;
  6.1286 +}
  6.1287 +
  6.1288 +static void QZ_UnlockYUV (_THIS, SDL_Overlay *overlay) {
  6.1289 +
  6.1290 +    ;
  6.1291 +}
  6.1292 +
  6.1293 +static int QZ_DisplayYUV (_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect) {
  6.1294 +
  6.1295 +    OSErr err;
  6.1296 +    CodecFlags flags;
  6.1297 +
  6.1298 +    if (dstrect->x != 0 || dstrect->y != 0) {
  6.1299 +
  6.1300 +        SDL_SetError ("Need a dstrect at (0,0)");
  6.1301 +        return -1;
  6.1302 +    }
  6.1303 +
  6.1304 +    if (dstrect->w != yuv_width || dstrect->h != yuv_height) {
  6.1305 +
  6.1306 +        Fixed scale_x, scale_y;
  6.1307 +
  6.1308 +        scale_x = FixDiv ( Long2Fix (dstrect->w), Long2Fix (overlay->w) );
  6.1309 +        scale_y = FixDiv ( Long2Fix (dstrect->h), Long2Fix (overlay->h) );
  6.1310 +
  6.1311 +        SetIdentityMatrix (yuv_matrix);
  6.1312 +        ScaleMatrix (yuv_matrix, scale_x, scale_y, Long2Fix (0), Long2Fix (0));
  6.1313 +
  6.1314 +        SetDSequenceMatrix (yuv_seq, yuv_matrix);
  6.1315 +
  6.1316 +        yuv_width = dstrect->w;
  6.1317 +        yuv_height = dstrect->h;
  6.1318 +    }
  6.1319 +
  6.1320 +    if( ( err = DecompressSequenceFrameS(
  6.1321 +                                         yuv_seq,
  6.1322 +                                         (void*)yuv_pixmap,
  6.1323 +                                         sizeof (PlanarPixmapInfoYUV420),
  6.1324 +                                         codecFlagUseImageBuffer, &flags, nil ) != noErr ) )
  6.1325 +    {
  6.1326 +        SDL_SetError ("DecompressSequenceFrameS failed");
  6.1327 +    }
  6.1328 +
  6.1329 +    return err == noErr;
  6.1330 +}
  6.1331 +
  6.1332 +static void QZ_FreeHWYUV (_THIS, SDL_Overlay *overlay) {
  6.1333 +
  6.1334 +    CDSequenceEnd (yuv_seq);
  6.1335 +    ExitMovies();
  6.1336 +
  6.1337 +    free (overlay->hwfuncs);
  6.1338 +    free (overlay->pitches);
  6.1339 +    free (overlay->pixels);
  6.1340 +
  6.1341 +    if (SDL_VideoSurface->flags & SDL_FULLSCREEN) {
  6.1342 +        [ qz_window close ];
  6.1343 +        qz_window = nil;
  6.1344 +    }
  6.1345 +
  6.1346 +    free (yuv_matrix);
  6.1347 +    DisposeHandle ((Handle)yuv_idh);
  6.1348 +}
  6.1349 +
  6.1350 +#include "SDL_yuvfuncs.h"
  6.1351 +
  6.1352 +/**
  6.1353 + * check for 16 byte alignment, bail otherwise
  6.1354 + **/
  6.1355 +#define CHECK_ALIGN(x) do { if ((Uint32)x & 15) { SDL_SetError("Alignment error"); return NULL; } } while(0)
  6.1356 +
  6.1357 +/**
  6.1358 + * align a byte offset, return how much to add to make it
  6.1359 + * a multiple of 16
  6.1360 + **/
  6.1361 +#define ALIGN(x) ((16 - (x & 15)) & 15)
  6.1362 +
  6.1363 +static SDL_Overlay* QZ_CreateYUVOverlay (_THIS, int width, int height,
  6.1364 +                                         Uint32 format, SDL_Surface *display) {
  6.1365 +
  6.1366 +    Uint32 codec;
  6.1367 +    OSStatus err;
  6.1368 +    CGrafPtr port;
  6.1369 +    SDL_Overlay *overlay;
  6.1370 +
  6.1371 +    if (format == SDL_YV12_OVERLAY ||
  6.1372 +        format == SDL_IYUV_OVERLAY) {
  6.1373 +
  6.1374 +        codec = kYUV420CodecType;
  6.1375 +    }
  6.1376 +    else {
  6.1377 +        SDL_SetError ("Hardware: unsupported video format");
  6.1378 +        return NULL;
  6.1379 +    }
  6.1380 +
  6.1381 +    yuv_idh = (ImageDescriptionHandle) NewHandleClear (sizeof(ImageDescription));
  6.1382 +    if (yuv_idh == NULL) {
  6.1383 +        SDL_OutOfMemory();
  6.1384 +        return NULL;
  6.1385 +    }
  6.1386 +
  6.1387 +    yuv_matrix = (MatrixRecordPtr) malloc (sizeof(MatrixRecord));
  6.1388 +    if (yuv_matrix == NULL) {
  6.1389 +        SDL_OutOfMemory();
  6.1390 +        return NULL;
  6.1391 +    }
  6.1392 +
  6.1393 +    if ( EnterMovies() != noErr ) {
  6.1394 +        SDL_SetError ("Could not init QuickTime for YUV playback");
  6.1395 +        return NULL;
  6.1396 +    }
  6.1397 +
  6.1398 +    err = FindCodec (codec, bestSpeedCodec, nil, &yuv_codec);
  6.1399 +    if (err != noErr) {
  6.1400 +        SDL_SetError ("Could not find QuickTime codec for format");
  6.1401 +        return NULL;
  6.1402 +    }
  6.1403 +
  6.1404 +    if (SDL_VideoSurface->flags & SDL_FULLSCREEN) {
  6.1405 +
  6.1406 +        /**
  6.1407 +         * Good acceleration requires a window to be present.
  6.1408 +         * A CGrafPtr that points to the screen isn't good enough
  6.1409 +         **/
  6.1410 +        NSRect content = NSMakeRect (0, 0, SDL_VideoSurface->w, SDL_VideoSurface->h);
  6.1411 +
  6.1412 +        qz_window = [ [ SDL_QuartzWindow alloc ]
  6.1413 +                            initWithContentRect:content
  6.1414 +                            styleMask:NSBorderlessWindowMask
  6.1415 +                            backing:NSBackingStoreBuffered defer:NO ];
  6.1416 +
  6.1417 +        if (qz_window == nil) {
  6.1418 +            SDL_SetError ("Could not create the Cocoa window");
  6.1419 +            return NULL;
  6.1420 +        }
  6.1421 +
  6.1422 +        [ qz_window setContentView:[ [ SDL_QuartzWindowView alloc ] init ] ];
  6.1423 +        [ qz_window setReleasedWhenClosed:YES ];
  6.1424 +        [ qz_window center ];
  6.1425 +        [ qz_window setAcceptsMouseMovedEvents:YES ];
  6.1426 +        [ qz_window setLevel:CGShieldingWindowLevel() ];
  6.1427 +        [ qz_window makeKeyAndOrderFront:nil ];
  6.1428 +
  6.1429 +        port = [ [ qz_window contentView ] qdPort ];
  6.1430 +        SetPort (port);
  6.1431 +        // BUG: would like to remove white flash when window kicks in
  6.1432 +        //{
  6.1433 +        //    Rect r;
  6.1434 +        //    SetRect (&r, 0, 0, SDL_VideoSurface->w, SDL_VideoSurface->h);
  6.1435 +        //    PaintRect (&r);
  6.1436 +        //    QDFlushPortBuffer (port, nil);
  6.1437 +        //}
  6.1438 +
  6.1439 +    }
  6.1440 +    else {
  6.1441 +        port = [ [ qz_window contentView ] qdPort ];
  6.1442 +        SetPort (port);
  6.1443 +    }
  6.1444 +    
  6.1445 +    SetIdentityMatrix (yuv_matrix);
  6.1446 +    
  6.1447 +    HLock ((Handle)yuv_idh);
  6.1448 +    
  6.1449 +    (**yuv_idh).idSize = sizeof(ImageDescription);
  6.1450 +    (**yuv_idh).cType  = codec;
  6.1451 +    (**yuv_idh).version = 1;
  6.1452 +    (**yuv_idh).revisionLevel = 0;
  6.1453 +    (**yuv_idh).width = width;
  6.1454 +    (**yuv_idh).height = height;
  6.1455 +    (**yuv_idh).hRes = Long2Fix(72);
  6.1456 +    (**yuv_idh).vRes = Long2Fix(72);
  6.1457 +    (**yuv_idh).spatialQuality = codecLosslessQuality;
  6.1458 +    (**yuv_idh).frameCount = 1;
  6.1459 +    (**yuv_idh).clutID = -1;
  6.1460 +    (**yuv_idh).dataSize = 0;
  6.1461 +    (**yuv_idh).depth = 12;
  6.1462 +    
  6.1463 +    HUnlock ((Handle)yuv_idh);
  6.1464 +    
  6.1465 +    err = DecompressSequenceBeginS (
  6.1466 +                                    &yuv_seq,
  6.1467 +                                    yuv_idh,
  6.1468 +                                    NULL,
  6.1469 +                                    0,
  6.1470 +                                    port,
  6.1471 +                                    NULL,
  6.1472 +                                    NULL,
  6.1473 +                                    yuv_matrix,
  6.1474 +                                    0,
  6.1475 +                                    NULL,
  6.1476 +                                    codecFlagUseImageBuffer,
  6.1477 +                                    codecLosslessQuality,
  6.1478 +                                    yuv_codec);
  6.1479 +    
  6.1480 +    if (err != noErr) {
  6.1481 +        SDL_SetError ("Error trying to start YUV codec.");
  6.1482 +        return NULL;
  6.1483 +    }
  6.1484 +    
  6.1485 +    overlay = (SDL_Overlay*) malloc (sizeof(*overlay));
  6.1486 +    if (overlay == NULL) {
  6.1487 +        SDL_OutOfMemory();
  6.1488 +        return NULL;
  6.1489 +    }
  6.1490 +    
  6.1491 +    overlay->format      = format;
  6.1492 +    overlay->w           = width;
  6.1493 +    overlay->h           = height;
  6.1494 +    overlay->planes      = 3;
  6.1495 +    overlay->hw_overlay  = 1;
  6.1496 +    {
  6.1497 +        int      offset;
  6.1498 +        Uint8  **pixels;
  6.1499 +        Uint16  *pitches;
  6.1500 +        int      plane2, plane3;
  6.1501 +
  6.1502 +        if (format == SDL_IYUV_OVERLAY) {
  6.1503 +
  6.1504 +            plane2 = 1; /* Native codec format */
  6.1505 +            plane3 = 2;
  6.1506 +        }
  6.1507 +        else if (format == SDL_YV12_OVERLAY) {
  6.1508 +
  6.1509 +            /* switch the U and V planes */
  6.1510 +            plane2 = 2; /* U plane maps to plane 3 */
  6.1511 +            plane3 = 1; /* V plane maps to plane 2 */
  6.1512 +        }
  6.1513 +        else {
  6.1514 +            SDL_SetError("Unsupported YUV format");
  6.1515 +            return NULL;
  6.1516 +        }
  6.1517 +
  6.1518 +        pixels = (Uint8**) malloc (sizeof(*pixels) * 3);
  6.1519 +        pitches = (Uint16*) malloc (sizeof(*pitches) * 3);
  6.1520 +        if (pixels == NULL || pitches == NULL) {
  6.1521 +            SDL_OutOfMemory();
  6.1522 +            return NULL;
  6.1523 +        }
  6.1524 +
  6.1525 +        yuv_pixmap = (PlanarPixmapInfoYUV420*)
  6.1526 +            malloc (sizeof(PlanarPixmapInfoYUV420) +
  6.1527 +                    (width * height * 2));
  6.1528 +        if (yuv_pixmap == NULL) {
  6.1529 +            SDL_OutOfMemory ();
  6.1530 +            return NULL;
  6.1531 +        }
  6.1532 +
  6.1533 +        //CHECK_ALIGN(yuv_pixmap);
  6.1534 +        offset  = sizeof(PlanarPixmapInfoYUV420);
  6.1535 +        //offset += ALIGN(offset);
  6.1536 +        //CHECK_ALIGN(offset);
  6.1537 +
  6.1538 +        pixels[0] = (Uint8*)yuv_pixmap + offset;
  6.1539 +        //CHECK_ALIGN(pixels[0]);
  6.1540 +
  6.1541 +        pitches[0] = width;
  6.1542 +        yuv_pixmap->componentInfoY.offset = offset;
  6.1543 +        yuv_pixmap->componentInfoY.rowBytes = width;
  6.1544 +
  6.1545 +        offset += width * height;
  6.1546 +        pixels[plane2] = (Uint8*)yuv_pixmap + offset;
  6.1547 +        pitches[plane2] = width / 2;
  6.1548 +        yuv_pixmap->componentInfoCb.offset = offset;
  6.1549 +        yuv_pixmap->componentInfoCb.rowBytes = width / 2;
  6.1550 +
  6.1551 +        offset += (width * height / 4);
  6.1552 +        pixels[plane3] = (Uint8*)yuv_pixmap + offset;
  6.1553 +        pitches[plane3] = width / 2;
  6.1554 +        yuv_pixmap->componentInfoCr.offset = offset;
  6.1555 +        yuv_pixmap->componentInfoCr.rowBytes = width / 2;
  6.1556 +
  6.1557 +        overlay->pixels = pixels;
  6.1558 +        overlay->pitches = pitches;
  6.1559 +    }
  6.1560 +
  6.1561 +    overlay->hwfuncs = malloc (sizeof(*overlay->hwfuncs));
  6.1562 +    if (overlay->hwfuncs == NULL) {
  6.1563 +        SDL_OutOfMemory();
  6.1564 +        return NULL;
  6.1565 +    }
  6.1566 +    
  6.1567 +    overlay->hwfuncs->Lock    = QZ_LockYUV;
  6.1568 +    overlay->hwfuncs->Unlock  = QZ_UnlockYUV;
  6.1569 +    overlay->hwfuncs->Display = QZ_DisplayYUV;
  6.1570 +    overlay->hwfuncs->FreeHW  = QZ_FreeHWYUV;
  6.1571 +
  6.1572 +    yuv_width = overlay->w;
  6.1573 +    yuv_height = overlay->h;
  6.1574 +    
  6.1575 +    return overlay;
  6.1576 +}
  6.1577 +
     7.1 --- a/src/video/quartz/SDL_QuartzWM.m	Sat Jun 01 19:54:15 2002 +0000
     7.2 +++ b/src/video/quartz/SDL_QuartzWM.m	Sat Jun 01 23:05:05 2002 +0000
     7.3 @@ -32,17 +32,17 @@
     7.4  
     7.5  /* Use the Carbon cursor routines for now */
     7.6  static WMcursor*    QZ_CreateWMCursor   (_THIS, Uint8 *data, Uint8 *mask, 
     7.7 -                                          int w, int h, int hot_x, int hot_y) { 
     7.8 -	WMcursor *cursor;
     7.9 -	int row, bytes;
    7.10 -		
    7.11 -	/* Allocate the cursor memory */
    7.12 -	cursor = (WMcursor *)malloc(sizeof(WMcursor));
    7.13 -	if ( cursor == NULL ) {
    7.14 -		SDL_OutOfMemory();
    7.15 -		return(NULL);
    7.16 -	}
    7.17 -	memset(cursor, 0, sizeof(*cursor));
    7.18 +                                         int w, int h, int hot_x, int hot_y) { 
    7.19 +    WMcursor *cursor;
    7.20 +    int row, bytes;
    7.21 +        
    7.22 +    /* Allocate the cursor memory */
    7.23 +    cursor = (WMcursor *)malloc(sizeof(WMcursor));
    7.24 +    if ( cursor == NULL ) {
    7.25 +        SDL_OutOfMemory();
    7.26 +        return(NULL);
    7.27 +    }
    7.28 +    memset(cursor, 0, sizeof(*cursor));
    7.29      
    7.30      if (w > 16)
    7.31          w = 16;
    7.32 @@ -50,19 +50,19 @@
    7.33      if (h > 16)
    7.34          h = 16;
    7.35      
    7.36 -	bytes = (w+7)/8;
    7.37 +    bytes = (w+7)/8;
    7.38  
    7.39 -	for ( row=0; row<h; ++row ) {
    7.40 -		memcpy(&cursor->curs.data[row], data, bytes);
    7.41 -		data += bytes;
    7.42 -	}
    7.43 -	for ( row=0; row<h; ++row ) {
    7.44 -		memcpy(&cursor->curs.mask[row], mask, bytes);
    7.45 -		mask += bytes;
    7.46 -	}
    7.47 -	cursor->curs.hotSpot.h = hot_x;
    7.48 -	cursor->curs.hotSpot.v = hot_y;
    7.49 -	
    7.50 +    for ( row=0; row<h; ++row ) {
    7.51 +        memcpy(&cursor->curs.data[row], data, bytes);
    7.52 +        data += bytes;
    7.53 +    }
    7.54 +    for ( row=0; row<h; ++row ) {
    7.55 +        memcpy(&cursor->curs.mask[row], mask, bytes);
    7.56 +        mask += bytes;
    7.57 +    }
    7.58 +    cursor->curs.hotSpot.h = hot_x;
    7.59 +    cursor->curs.hotSpot.v = hot_y;
    7.60 +    
    7.61      return(cursor);
    7.62  }
    7.63  
    7.64 @@ -246,18 +246,18 @@
    7.65       #define ALPHASHIFT 3
    7.66       for (i=0;i<masksize;i+=8)
    7.67           for (j=0;j<8;j++) 
    7.68 -surfPtr[ALPHASHIFT+((i+j)<<2)]=(mask[i>>3]&(1<<(7-j)))?0xFF:0x00;
    7.69 +             surfPtr[ALPHASHIFT+((i+j)<<2)]=(mask[i>>3]&(1<<(7-j)))?0xFF:0x00;
    7.70       }
    7.71 -     imgrep = [[NSBitmapImageRep alloc] 
    7.72 -initWithBitmapDataPlanes:(unsigned char **)&mergedSurface->pixels 
    7.73 -pixelsWide:icon->w pixelsHigh:icon->h bitsPerSample:8 samplesPerPixel:4 
    7.74 -hasAlpha:YES isPlanar:NO colorSpaceName:NSDeviceRGBColorSpace 
    7.75 -bytesPerRow:icon->w<<2 bitsPerPixel:32];
    7.76 -     img = [[NSImage alloc] initWithSize:imgSize];
    7.77 -     [img addRepresentation: imgrep];
    7.78 -     [NSApp setApplicationIconImage:img];
    7.79 -     [img release];
    7.80 -     [imgrep release];
    7.81 +     imgrep = [ [ NSBitmapImageRep alloc] 
    7.82 +                     initWithBitmapDataPlanes:(unsigned char **)&mergedSurface->pixels 
    7.83 +                         pixelsWide:icon->w pixelsHigh:icon->h bitsPerSample:8 samplesPerPixel:4 
    7.84 +                         hasAlpha:YES isPlanar:NO colorSpaceName:NSDeviceRGBColorSpace 
    7.85 +                         bytesPerRow:icon->w<<2 bitsPerPixel:32 ];
    7.86 +     img = [ [ NSImage alloc ] initWithSize:imgSize ];
    7.87 +     [ img addRepresentation: imgrep ];
    7.88 +     [ NSApp setApplicationIconImage:img ];
    7.89 +     [ img release ];
    7.90 +     [ imgrep release ];
    7.91       SDL_FreeSurface(mergedSurface);
    7.92  freePool:
    7.93       [pool release];
    7.94 @@ -285,19 +285,18 @@
    7.95  static SDL_GrabMode QZ_GrabInput (_THIS, SDL_GrabMode grab_mode) {
    7.96  
    7.97      switch (grab_mode) {
    7.98 -	case SDL_GRAB_QUERY:
    7.99 +    case SDL_GRAB_QUERY:
   7.100              break;
   7.101 -	case SDL_GRAB_OFF:
   7.102 +    case SDL_GRAB_OFF:
   7.103              CGAssociateMouseAndMouseCursorPosition (1);
   7.104              currentGrabMode = SDL_GRAB_OFF;
   7.105              break;
   7.106 -	case SDL_GRAB_ON:
   7.107 +    case SDL_GRAB_ON:
   7.108              QZ_WarpWMCursor (this, SDL_VideoSurface->w / 2, SDL_VideoSurface->h / 2);
   7.109              CGAssociateMouseAndMouseCursorPosition (0);
   7.110              currentGrabMode = SDL_GRAB_ON;
   7.111              break;
   7.112 -        case SDL_GRAB_FULLSCREEN:
   7.113 -            
   7.114 +    case SDL_GRAB_FULLSCREEN:        
   7.115              break;
   7.116      }
   7.117