*** empty log message ***
authorSam Lantinga <slouken@libsdl.org>
Sat, 01 Jun 2002 19:51:08 +0000
changeset 3884e9044b378fd
parent 387 469d5c0da01d
child 389 ca655a7a9d80
*** empty log message ***
src/main/macosx/SDLMain.m
src/video/quartz/SDL_QuartzEvents.m
     1.1 --- a/src/main/macosx/SDLMain.m	Sat Jun 01 18:48:13 2002 +0000
     1.2 +++ b/src/main/macosx/SDLMain.m	Sat Jun 01 19:51:08 2002 +0000
     1.3 @@ -51,22 +51,22 @@
     1.4  /* Set the working directory to the .app's parent directory */
     1.5  - (void) setupWorkingDirectory:(BOOL)shouldChdir
     1.6  {
     1.7 -    char parentdir[MAXPATHLEN];
     1.8 -    char *c;
     1.9 -    
    1.10 -    strncpy ( parentdir, gArgv[0], sizeof(parentdir) );
    1.11 -    c = (char*) parentdir;
    1.12 -
    1.13 -    while (*c != '\0')     /* go to end */
    1.14 -        c++;
    1.15 -    
    1.16 -    while (*c != '/')      /* back up to parent */
    1.17 -        c--;
    1.18 -    
    1.19 -    *c++ = '\0';             /* cut off last part (binary name) */
    1.20 -  
    1.21      if (shouldChdir)
    1.22      {
    1.23 +	  char parentdir[MAXPATHLEN];
    1.24 +	  char *c;
    1.25 +	  
    1.26 +	  strncpy ( parentdir, gArgv[0], sizeof(parentdir) );
    1.27 +	  c = (char*) parentdir;
    1.28 +  
    1.29 +	  while (*c != '\0')     /* go to end */
    1.30 +		  c++;
    1.31 +	  
    1.32 +	  while (*c != '/')      /* back up to parent */
    1.33 +		  c--;
    1.34 +	  
    1.35 +	  *c++ = '\0';             /* cut off last part (binary name) */
    1.36 +	
    1.37        assert ( chdir (parentdir) == 0 );   /* chdir to the binary app's parent */
    1.38        assert ( chdir ("../../../") == 0 ); /* chdir to the .app's parent */
    1.39      }
     2.1 --- a/src/video/quartz/SDL_QuartzEvents.m	Sat Jun 01 18:48:13 2002 +0000
     2.2 +++ b/src/video/quartz/SDL_QuartzEvents.m	Sat Jun 01 19:51:08 2002 +0000
     2.3 @@ -1,23 +1,23 @@
     2.4  /*
     2.5 -	SDL - Simple DirectMedia Layer
     2.6 -	Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002	Sam Lantinga
     2.7 +    SDL - Simple DirectMedia Layer
     2.8 +    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002    Sam Lantinga
     2.9  
    2.10 -	This library is free software; you can redistribute it and/or
    2.11 -	modify it under the terms of the GNU Library General Public
    2.12 -	License as published by the Free Software Foundation; either
    2.13 -	version 2 of the License, or (at your option) any later version.
    2.14 +    This library is free software; you can redistribute it and/or
    2.15 +    modify it under the terms of the GNU Library General Public
    2.16 +    License as published by the Free Software Foundation; either
    2.17 +    version 2 of the License, or (at your option) any later version.
    2.18  
    2.19 -	This library is distributed in the hope that it will be useful,
    2.20 -	but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.21 -	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    2.22 -	Library General Public License for more details.
    2.23 +    This library is distributed in the hope that it will be useful,
    2.24 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.25 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    2.26 +    Library General Public License for more details.
    2.27  
    2.28 -	You should have received a copy of the GNU Library General Public
    2.29 -	License along with this library; if not, write to the Free
    2.30 -	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    2.31 +    You should have received a copy of the GNU Library General Public
    2.32 +    License along with this library; if not, write to the Free
    2.33 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    2.34  
    2.35 -	Sam Lantinga
    2.36 -	slouken@libsdl.org
    2.37 +    Sam Lantinga
    2.38 +    slouken@libsdl.org
    2.39  */
    2.40  #include <sys/time.h>
    2.41  
    2.42 @@ -27,304 +27,301 @@
    2.43  static unsigned int currentMods = 0; /* Current keyboard modifiers, to track modifier state */
    2.44  static int last_virtual_button = 0; /* Last virtual mouse button pressed */
    2.45  
    2.46 -static void	 QZ_InitOSKeymap (_THIS) {
    2.47 -	const void *KCHRPtr;
    2.48 -	UInt32 state;
    2.49 -	UInt32 value;
    2.50 -	int i;
    2.51 -	int world = SDLK_WORLD_0;
    2.52 -	
    2.53 -	for ( i=0; i<SDL_TABLESIZE(keymap); ++i )
    2.54 -		keymap[i] = SDLK_UNKNOWN;
    2.55 +static void  QZ_InitOSKeymap (_THIS) {
    2.56 +    const void *KCHRPtr;
    2.57 +    UInt32 state;
    2.58 +    UInt32 value;
    2.59 +    int i;
    2.60 +    int world = SDLK_WORLD_0;
    2.61 +    
    2.62 +    for ( i=0; i<SDL_TABLESIZE(keymap); ++i )
    2.63 +        keymap[i] = SDLK_UNKNOWN;
    2.64  
    2.65 -	/* This keymap is almost exactly the same as the OS 9 one */
    2.66 -	keymap[QZ_ESCAPE] = SDLK_ESCAPE;
    2.67 -	keymap[QZ_F1] = SDLK_F1;
    2.68 -	keymap[QZ_F2] = SDLK_F2;
    2.69 -	keymap[QZ_F3] = SDLK_F3;
    2.70 -	keymap[QZ_F4] = SDLK_F4;
    2.71 -	keymap[QZ_F5] = SDLK_F5;
    2.72 -	keymap[QZ_F6] = SDLK_F6;
    2.73 -	keymap[QZ_F7] = SDLK_F7;
    2.74 -	keymap[QZ_F8] = SDLK_F8;
    2.75 -	keymap[QZ_F9] = SDLK_F9;
    2.76 -	keymap[QZ_F10] = SDLK_F10;
    2.77 -	keymap[QZ_F11] = SDLK_F11;
    2.78 -	keymap[QZ_F12] = SDLK_F12;
    2.79 -	keymap[QZ_PRINT] = SDLK_PRINT;
    2.80 -	keymap[QZ_SCROLLOCK] = SDLK_SCROLLOCK;
    2.81 -	keymap[QZ_PAUSE] = SDLK_PAUSE;
    2.82 -	keymap[QZ_POWER] = SDLK_POWER;
    2.83 -	keymap[QZ_BACKQUOTE] = SDLK_BACKQUOTE;
    2.84 -	keymap[QZ_1] = SDLK_1;
    2.85 -	keymap[QZ_2] = SDLK_2;
    2.86 -	keymap[QZ_3] = SDLK_3;
    2.87 -	keymap[QZ_4] = SDLK_4;
    2.88 -	keymap[QZ_5] = SDLK_5;
    2.89 -	keymap[QZ_6] = SDLK_6;
    2.90 -	keymap[QZ_7] = SDLK_7;
    2.91 -	keymap[QZ_8] = SDLK_8;
    2.92 -	keymap[QZ_9] = SDLK_9;
    2.93 -	keymap[QZ_0] = SDLK_0;
    2.94 -	keymap[QZ_MINUS] = SDLK_MINUS;
    2.95 -	keymap[QZ_EQUALS] = SDLK_EQUALS;
    2.96 -	keymap[QZ_BACKSPACE] = SDLK_BACKSPACE;
    2.97 -	keymap[QZ_INSERT] = SDLK_INSERT;
    2.98 -	keymap[QZ_HOME] = SDLK_HOME;
    2.99 -	keymap[QZ_PAGEUP] = SDLK_PAGEUP;
   2.100 -	keymap[QZ_NUMLOCK] = SDLK_NUMLOCK;
   2.101 -	keymap[QZ_KP_EQUALS] = SDLK_KP_EQUALS;
   2.102 -	keymap[QZ_KP_DIVIDE] = SDLK_KP_DIVIDE;
   2.103 -	keymap[QZ_KP_MULTIPLY] = SDLK_KP_MULTIPLY;
   2.104 -	keymap[QZ_TAB] = SDLK_TAB;
   2.105 -	keymap[QZ_q] = SDLK_q;
   2.106 -	keymap[QZ_w] = SDLK_w;
   2.107 -	keymap[QZ_e] = SDLK_e;
   2.108 -	keymap[QZ_r] = SDLK_r;
   2.109 -	keymap[QZ_t] = SDLK_t;
   2.110 -	keymap[QZ_y] = SDLK_y;
   2.111 -	keymap[QZ_u] = SDLK_u;
   2.112 -	keymap[QZ_i] = SDLK_i;
   2.113 -	keymap[QZ_o] = SDLK_o;
   2.114 -	keymap[QZ_p] = SDLK_p;
   2.115 -	keymap[QZ_LEFTBRACKET] = SDLK_LEFTBRACKET;
   2.116 -	keymap[QZ_RIGHTBRACKET] = SDLK_RIGHTBRACKET;
   2.117 -	keymap[QZ_BACKSLASH] = SDLK_BACKSLASH;
   2.118 -	keymap[QZ_DELETE] = SDLK_DELETE;
   2.119 -	keymap[QZ_END] = SDLK_END;
   2.120 -	keymap[QZ_PAGEDOWN] = SDLK_PAGEDOWN;
   2.121 -	keymap[QZ_KP7] = SDLK_KP7;
   2.122 -	keymap[QZ_KP8] = SDLK_KP8;
   2.123 -	keymap[QZ_KP9] = SDLK_KP9;
   2.124 -	keymap[QZ_KP_MINUS] = SDLK_KP_MINUS;
   2.125 -	keymap[QZ_CAPSLOCK] = SDLK_CAPSLOCK;
   2.126 -	keymap[QZ_a] = SDLK_a;
   2.127 -	keymap[QZ_s] = SDLK_s;
   2.128 -	keymap[QZ_d] = SDLK_d;
   2.129 -	keymap[QZ_f] = SDLK_f;
   2.130 -	keymap[QZ_g] = SDLK_g;
   2.131 -	keymap[QZ_h] = SDLK_h;
   2.132 -	keymap[QZ_j] = SDLK_j;
   2.133 -	keymap[QZ_k] = SDLK_k;
   2.134 -	keymap[QZ_l] = SDLK_l;
   2.135 -	keymap[QZ_SEMICOLON] = SDLK_SEMICOLON;
   2.136 -	keymap[QZ_QUOTE] = SDLK_QUOTE;
   2.137 -	keymap[QZ_RETURN] = SDLK_RETURN;
   2.138 -	keymap[QZ_KP4] = SDLK_KP4;
   2.139 -	keymap[QZ_KP5] = SDLK_KP5;
   2.140 -	keymap[QZ_KP6] = SDLK_KP6;
   2.141 -	keymap[QZ_KP_PLUS] = SDLK_KP_PLUS;
   2.142 -	keymap[QZ_LSHIFT] = SDLK_LSHIFT;
   2.143 -	keymap[QZ_z] = SDLK_z;
   2.144 -	keymap[QZ_x] = SDLK_x;
   2.145 -	keymap[QZ_c] = SDLK_c;
   2.146 -	keymap[QZ_v] = SDLK_v;
   2.147 -	keymap[QZ_b] = SDLK_b;
   2.148 -	keymap[QZ_n] = SDLK_n;
   2.149 -	keymap[QZ_m] = SDLK_m;
   2.150 -	keymap[QZ_COMMA] = SDLK_COMMA;
   2.151 -	keymap[QZ_PERIOD] = SDLK_PERIOD;
   2.152 -	keymap[QZ_SLASH] = SDLK_SLASH;
   2.153 -	keymap[QZ_UP] = SDLK_UP;
   2.154 -	keymap[QZ_KP1] = SDLK_KP1;
   2.155 -	keymap[QZ_KP2] = SDLK_KP2;
   2.156 -	keymap[QZ_KP3] = SDLK_KP3;
   2.157 -	keymap[QZ_KP_ENTER] = SDLK_KP_ENTER;
   2.158 -	keymap[QZ_LCTRL] = SDLK_LCTRL;
   2.159 -	keymap[QZ_LALT] = SDLK_LALT;
   2.160 -	keymap[QZ_LMETA] = SDLK_LMETA;
   2.161 -	keymap[QZ_SPACE] = SDLK_SPACE;
   2.162 -	keymap[QZ_LEFT] = SDLK_LEFT;
   2.163 -	keymap[QZ_DOWN] = SDLK_DOWN;
   2.164 -	keymap[QZ_RIGHT] = SDLK_RIGHT;
   2.165 -	keymap[QZ_KP0] = SDLK_KP0;
   2.166 -	keymap[QZ_KP_PERIOD] = SDLK_KP_PERIOD;
   2.167 -	keymap[QZ_IBOOK_ENTER] = SDLK_KP_ENTER;
   2.168 -	keymap[QZ_IBOOK_RIGHT] = SDLK_RIGHT;
   2.169 -	keymap[QZ_IBOOK_DOWN] = SDLK_DOWN;
   2.170 -	keymap[QZ_IBOOK_UP]	  = SDLK_UP;
   2.171 -	keymap[QZ_IBOOK_LEFT] = SDLK_LEFT;
   2.172 -	
   2.173 -	/* Up there we setup a static scancode->keysym map. However, it will not
   2.174 -	 * work very well on international keyboard. Hence we now query MacOS
   2.175 -	 * for its own keymap to adjust our own mapping table. However, this is
   2.176 -	 * bascially only useful for ascii char keys. This is also the reason
   2.177 -	 * why we keep the static table, too.
   2.178 -	 */
   2.179 -	
   2.180 -	/* Get a pointer to the systems cached KCHR */
   2.181 -	KCHRPtr = (void *)GetScriptManagerVariable(smKCHRCache);
   2.182 -	if (KCHRPtr)
   2.183 -	{
   2.184 -		/* Loop over all 127 possible scan codes */
   2.185 -		for (i = 0; i < 0x7F; i++)
   2.186 -		{
   2.187 -			/* We pretend a clean start to begin with (i.e. no dead keys active */
   2.188 -			state = 0;
   2.189 -			
   2.190 -			/* Now translate the key code to a key value */
   2.191 -			value = KeyTranslate(KCHRPtr, i, &state) & 0xff;
   2.192 -			
   2.193 -			/* If the state become 0, it was a dead key. We need to translate again,
   2.194 -			passing in the new state, to get the actual key value */
   2.195 -			if (state != 0)
   2.196 -				value = KeyTranslate(KCHRPtr, i, &state) & 0xff;
   2.197 -			
   2.198 -			/* Now we should have an ascii value, or 0. Try to figure out to which SDL symbol it maps */
   2.199 -			if (value >= 128)	 /* Some non-ASCII char, map it to SDLK_WORLD_* */
   2.200 -				keymap[i] = world++;
   2.201 -			else if (value >= 32)	 /* non-control ASCII char */
   2.202 -				keymap[i] = value;
   2.203 -		}
   2.204 -	}
   2.205 -	
   2.206 -	/* The keypad codes are re-setup here, because the loop above cannot
   2.207 -	 * distinguish between a key on the keypad and a regular key. We maybe
   2.208 -	 * could get around this problem in another fashion: NSEvent's flags
   2.209 -	 * include a "NSNumericPadKeyMask" bit; we could check that and modify
   2.210 -	 * the symbol we return on the fly. However, this flag seems to exhibit
   2.211 -	 * some weird behaviour related to the num lock key
   2.212 -	 */
   2.213 -	keymap[QZ_KP0] = SDLK_KP0;
   2.214 -	keymap[QZ_KP1] = SDLK_KP1;
   2.215 -	keymap[QZ_KP2] = SDLK_KP2;
   2.216 -	keymap[QZ_KP3] = SDLK_KP3;
   2.217 -	keymap[QZ_KP4] = SDLK_KP4;
   2.218 -	keymap[QZ_KP5] = SDLK_KP5;
   2.219 -	keymap[QZ_KP6] = SDLK_KP6;
   2.220 -	keymap[QZ_KP7] = SDLK_KP7;
   2.221 -	keymap[QZ_KP8] = SDLK_KP8;
   2.222 -	keymap[QZ_KP9] = SDLK_KP9;
   2.223 -	keymap[QZ_KP_MINUS] = SDLK_KP_MINUS;
   2.224 -	keymap[QZ_KP_PLUS] = SDLK_KP_PLUS;
   2.225 -	keymap[QZ_KP_PERIOD] = SDLK_KP_PERIOD;
   2.226 -	keymap[QZ_KP_EQUALS] = SDLK_KP_EQUALS;
   2.227 -	keymap[QZ_KP_DIVIDE] = SDLK_KP_DIVIDE;
   2.228 -	keymap[QZ_KP_MULTIPLY] = SDLK_KP_MULTIPLY;
   2.229 -	keymap[QZ_KP_ENTER] = SDLK_KP_ENTER;
   2.230 +    /* This keymap is almost exactly the same as the OS 9 one */
   2.231 +    keymap[QZ_ESCAPE] = SDLK_ESCAPE;
   2.232 +    keymap[QZ_F1] = SDLK_F1;
   2.233 +    keymap[QZ_F2] = SDLK_F2;
   2.234 +    keymap[QZ_F3] = SDLK_F3;
   2.235 +    keymap[QZ_F4] = SDLK_F4;
   2.236 +    keymap[QZ_F5] = SDLK_F5;
   2.237 +    keymap[QZ_F6] = SDLK_F6;
   2.238 +    keymap[QZ_F7] = SDLK_F7;
   2.239 +    keymap[QZ_F8] = SDLK_F8;
   2.240 +    keymap[QZ_F9] = SDLK_F9;
   2.241 +    keymap[QZ_F10] = SDLK_F10;
   2.242 +    keymap[QZ_F11] = SDLK_F11;
   2.243 +    keymap[QZ_F12] = SDLK_F12;
   2.244 +    keymap[QZ_PRINT] = SDLK_PRINT;
   2.245 +    keymap[QZ_SCROLLOCK] = SDLK_SCROLLOCK;
   2.246 +    keymap[QZ_PAUSE] = SDLK_PAUSE;
   2.247 +    keymap[QZ_POWER] = SDLK_POWER;
   2.248 +    keymap[QZ_BACKQUOTE] = SDLK_BACKQUOTE;
   2.249 +    keymap[QZ_1] = SDLK_1;
   2.250 +    keymap[QZ_2] = SDLK_2;
   2.251 +    keymap[QZ_3] = SDLK_3;
   2.252 +    keymap[QZ_4] = SDLK_4;
   2.253 +    keymap[QZ_5] = SDLK_5;
   2.254 +    keymap[QZ_6] = SDLK_6;
   2.255 +    keymap[QZ_7] = SDLK_7;
   2.256 +    keymap[QZ_8] = SDLK_8;
   2.257 +    keymap[QZ_9] = SDLK_9;
   2.258 +    keymap[QZ_0] = SDLK_0;
   2.259 +    keymap[QZ_MINUS] = SDLK_MINUS;
   2.260 +    keymap[QZ_EQUALS] = SDLK_EQUALS;
   2.261 +    keymap[QZ_BACKSPACE] = SDLK_BACKSPACE;
   2.262 +    keymap[QZ_INSERT] = SDLK_INSERT;
   2.263 +    keymap[QZ_HOME] = SDLK_HOME;
   2.264 +    keymap[QZ_PAGEUP] = SDLK_PAGEUP;
   2.265 +    keymap[QZ_NUMLOCK] = SDLK_NUMLOCK;
   2.266 +    keymap[QZ_KP_EQUALS] = SDLK_KP_EQUALS;
   2.267 +    keymap[QZ_KP_DIVIDE] = SDLK_KP_DIVIDE;
   2.268 +    keymap[QZ_KP_MULTIPLY] = SDLK_KP_MULTIPLY;
   2.269 +    keymap[QZ_TAB] = SDLK_TAB;
   2.270 +    keymap[QZ_q] = SDLK_q;
   2.271 +    keymap[QZ_w] = SDLK_w;
   2.272 +    keymap[QZ_e] = SDLK_e;
   2.273 +    keymap[QZ_r] = SDLK_r;
   2.274 +    keymap[QZ_t] = SDLK_t;
   2.275 +    keymap[QZ_y] = SDLK_y;
   2.276 +    keymap[QZ_u] = SDLK_u;
   2.277 +    keymap[QZ_i] = SDLK_i;
   2.278 +    keymap[QZ_o] = SDLK_o;
   2.279 +    keymap[QZ_p] = SDLK_p;
   2.280 +    keymap[QZ_LEFTBRACKET] = SDLK_LEFTBRACKET;
   2.281 +    keymap[QZ_RIGHTBRACKET] = SDLK_RIGHTBRACKET;
   2.282 +    keymap[QZ_BACKSLASH] = SDLK_BACKSLASH;
   2.283 +    keymap[QZ_DELETE] = SDLK_DELETE;
   2.284 +    keymap[QZ_END] = SDLK_END;
   2.285 +    keymap[QZ_PAGEDOWN] = SDLK_PAGEDOWN;
   2.286 +    keymap[QZ_KP7] = SDLK_KP7;
   2.287 +    keymap[QZ_KP8] = SDLK_KP8;
   2.288 +    keymap[QZ_KP9] = SDLK_KP9;
   2.289 +    keymap[QZ_KP_MINUS] = SDLK_KP_MINUS;
   2.290 +    keymap[QZ_CAPSLOCK] = SDLK_CAPSLOCK;
   2.291 +    keymap[QZ_a] = SDLK_a;
   2.292 +    keymap[QZ_s] = SDLK_s;
   2.293 +    keymap[QZ_d] = SDLK_d;
   2.294 +    keymap[QZ_f] = SDLK_f;
   2.295 +    keymap[QZ_g] = SDLK_g;
   2.296 +    keymap[QZ_h] = SDLK_h;
   2.297 +    keymap[QZ_j] = SDLK_j;
   2.298 +    keymap[QZ_k] = SDLK_k;
   2.299 +    keymap[QZ_l] = SDLK_l;
   2.300 +    keymap[QZ_SEMICOLON] = SDLK_SEMICOLON;
   2.301 +    keymap[QZ_QUOTE] = SDLK_QUOTE;
   2.302 +    keymap[QZ_RETURN] = SDLK_RETURN;
   2.303 +    keymap[QZ_KP4] = SDLK_KP4;
   2.304 +    keymap[QZ_KP5] = SDLK_KP5;
   2.305 +    keymap[QZ_KP6] = SDLK_KP6;
   2.306 +    keymap[QZ_KP_PLUS] = SDLK_KP_PLUS;
   2.307 +    keymap[QZ_LSHIFT] = SDLK_LSHIFT;
   2.308 +    keymap[QZ_z] = SDLK_z;
   2.309 +    keymap[QZ_x] = SDLK_x;
   2.310 +    keymap[QZ_c] = SDLK_c;
   2.311 +    keymap[QZ_v] = SDLK_v;
   2.312 +    keymap[QZ_b] = SDLK_b;
   2.313 +    keymap[QZ_n] = SDLK_n;
   2.314 +    keymap[QZ_m] = SDLK_m;
   2.315 +    keymap[QZ_COMMA] = SDLK_COMMA;
   2.316 +    keymap[QZ_PERIOD] = SDLK_PERIOD;
   2.317 +    keymap[QZ_SLASH] = SDLK_SLASH;
   2.318 +    keymap[QZ_UP] = SDLK_UP;
   2.319 +    keymap[QZ_KP1] = SDLK_KP1;
   2.320 +    keymap[QZ_KP2] = SDLK_KP2;
   2.321 +    keymap[QZ_KP3] = SDLK_KP3;
   2.322 +    keymap[QZ_KP_ENTER] = SDLK_KP_ENTER;
   2.323 +    keymap[QZ_LCTRL] = SDLK_LCTRL;
   2.324 +    keymap[QZ_LALT] = SDLK_LALT;
   2.325 +    keymap[QZ_LMETA] = SDLK_LMETA;
   2.326 +    keymap[QZ_SPACE] = SDLK_SPACE;
   2.327 +    keymap[QZ_LEFT] = SDLK_LEFT;
   2.328 +    keymap[QZ_DOWN] = SDLK_DOWN;
   2.329 +    keymap[QZ_RIGHT] = SDLK_RIGHT;
   2.330 +    keymap[QZ_KP0] = SDLK_KP0;
   2.331 +    keymap[QZ_KP_PERIOD] = SDLK_KP_PERIOD;
   2.332 +    keymap[QZ_IBOOK_ENTER] = SDLK_KP_ENTER;
   2.333 +    keymap[QZ_IBOOK_RIGHT] = SDLK_RIGHT;
   2.334 +    keymap[QZ_IBOOK_DOWN] = SDLK_DOWN;
   2.335 +    keymap[QZ_IBOOK_UP]   = SDLK_UP;
   2.336 +    keymap[QZ_IBOOK_LEFT] = SDLK_LEFT;
   2.337 +    
   2.338 +    /* Up there we setup a static scancode->keysym map. However, it will not
   2.339 +     * work very well on international keyboard. Hence we now query MacOS
   2.340 +     * for its own keymap to adjust our own mapping table. However, this is
   2.341 +     * bascially only useful for ascii char keys. This is also the reason
   2.342 +     * why we keep the static table, too.
   2.343 +     */
   2.344 +    
   2.345 +    /* Get a pointer to the systems cached KCHR */
   2.346 +    KCHRPtr = (void *)GetScriptManagerVariable(smKCHRCache);
   2.347 +    if (KCHRPtr)
   2.348 +    {
   2.349 +        /* Loop over all 127 possible scan codes */
   2.350 +        for (i = 0; i < 0x7F; i++)
   2.351 +        {
   2.352 +            /* We pretend a clean start to begin with (i.e. no dead keys active */
   2.353 +            state = 0;
   2.354 +            
   2.355 +            /* Now translate the key code to a key value */
   2.356 +            value = KeyTranslate(KCHRPtr, i, &state) & 0xff;
   2.357 +            
   2.358 +            /* If the state become 0, it was a dead key. We need to translate again,
   2.359 +            passing in the new state, to get the actual key value */
   2.360 +            if (state != 0)
   2.361 +                value = KeyTranslate(KCHRPtr, i, &state) & 0xff;
   2.362 +            
   2.363 +            /* Now we should have an ascii value, or 0. Try to figure out to which SDL symbol it maps */
   2.364 +            if (value >= 128)    /* Some non-ASCII char, map it to SDLK_WORLD_* */
   2.365 +                keymap[i] = world++;
   2.366 +            else if (value >= 32)    /* non-control ASCII char */
   2.367 +                keymap[i] = value;
   2.368 +        }
   2.369 +    }
   2.370 +    
   2.371 +    /* The keypad codes are re-setup here, because the loop above cannot
   2.372 +     * distinguish between a key on the keypad and a regular key. We maybe
   2.373 +     * could get around this problem in another fashion: NSEvent's flags
   2.374 +     * include a "NSNumericPadKeyMask" bit; we could check that and modify
   2.375 +     * the symbol we return on the fly. However, this flag seems to exhibit
   2.376 +     * some weird behaviour related to the num lock key
   2.377 +     */
   2.378 +    keymap[QZ_KP0] = SDLK_KP0;
   2.379 +    keymap[QZ_KP1] = SDLK_KP1;
   2.380 +    keymap[QZ_KP2] = SDLK_KP2;
   2.381 +    keymap[QZ_KP3] = SDLK_KP3;
   2.382 +    keymap[QZ_KP4] = SDLK_KP4;
   2.383 +    keymap[QZ_KP5] = SDLK_KP5;
   2.384 +    keymap[QZ_KP6] = SDLK_KP6;
   2.385 +    keymap[QZ_KP7] = SDLK_KP7;
   2.386 +    keymap[QZ_KP8] = SDLK_KP8;
   2.387 +    keymap[QZ_KP9] = SDLK_KP9;
   2.388 +    keymap[QZ_KP_MINUS] = SDLK_KP_MINUS;
   2.389 +    keymap[QZ_KP_PLUS] = SDLK_KP_PLUS;
   2.390 +    keymap[QZ_KP_PERIOD] = SDLK_KP_PERIOD;
   2.391 +    keymap[QZ_KP_EQUALS] = SDLK_KP_EQUALS;
   2.392 +    keymap[QZ_KP_DIVIDE] = SDLK_KP_DIVIDE;
   2.393 +    keymap[QZ_KP_MULTIPLY] = SDLK_KP_MULTIPLY;
   2.394 +    keymap[QZ_KP_ENTER] = SDLK_KP_ENTER;
   2.395  }
   2.396  
   2.397  static void QZ_DoKey (int state, NSEvent *event) {
   2.398  
   2.399 -	NSString *chars;
   2.400 -	int i;
   2.401 -	SDL_keysym key;
   2.402 -	
   2.403 -	/* An event can contain multiple characters */
   2.404 -	/* I'll ignore this fact for now, since there is only one virtual key code per event */
   2.405 -	chars = [ event characters ];
   2.406 -	for (i =0; i < 1 /*[ chars length ] */; i++) {
   2.407 -				
   2.408 -		key.scancode = [ event keyCode ];
   2.409 -		key.sym		 = keymap [ key.scancode ];
   2.410 -		key.unicode	 = [ chars characterAtIndex:i];
   2.411 -		key.mod		 = KMOD_NONE;
   2.412 -					
   2.413 -		SDL_PrivateKeyboard (state, &key);
   2.414 -	}
   2.415 +    NSString *chars;
   2.416 +    int i;
   2.417 +    SDL_keysym key;
   2.418 +    
   2.419 +    /* An event can contain multiple characters */
   2.420 +    /* I'll ignore this fact for now, since there is only one virtual key code per event */
   2.421 +    chars = [ event characters ];
   2.422 +    for (i =0; i < 1 /*[ chars length ] */; i++) {
   2.423 +                
   2.424 +        key.scancode = [ event keyCode ];
   2.425 +        key.sym      = keymap [ key.scancode ];
   2.426 +        key.unicode  = [ chars characterAtIndex:i];
   2.427 +        key.mod      = KMOD_NONE;
   2.428 +                    
   2.429 +        SDL_PrivateKeyboard (state, &key);
   2.430 +    }
   2.431  }
   2.432  
   2.433  static void QZ_DoModifiers (unsigned int newMods) {
   2.434  
   2.435 -	const int mapping[] = { SDLK_CAPSLOCK, SDLK_LSHIFT, SDLK_LCTRL, SDLK_LALT, SDLK_LMETA } ;
   2.436 +    const int mapping[] = { SDLK_CAPSLOCK, SDLK_LSHIFT, SDLK_LCTRL, SDLK_LALT, SDLK_LMETA } ;
   2.437  
   2.438 -	int i;
   2.439 -	int bit;
   2.440 -	SDL_keysym key;
   2.441 +    int i;
   2.442 +    int bit;
   2.443 +    SDL_keysym key;
   2.444  
   2.445 -	key.scancode = 0;
   2.446 -	key.sym		 = SDLK_UNKNOWN;
   2.447 -	key.unicode	 = 0;
   2.448 -	key.mod		 = KMOD_NONE;
   2.449 -	
   2.450 -	/* Iterate through the bits, testing each against the current modifiers */
   2.451 -	for (i = 0, bit = NSAlphaShiftKeyMask; bit <= NSCommandKeyMask; bit <<= 1, ++i) {
   2.452 -	
   2.453 -		unsigned int currentMask, newMask;
   2.454 -		
   2.455 -		currentMask = currentMods & bit;
   2.456 -		newMask		= newMods & bit;
   2.457 -		
   2.458 -		if ( currentMask &&
   2.459 -			 currentMask != newMask ) {	 /* modifier up event */
   2.460 +    key.scancode = 0;
   2.461 +    key.sym      = SDLK_UNKNOWN;
   2.462 +    key.unicode  = 0;
   2.463 +    key.mod      = KMOD_NONE;
   2.464 +    
   2.465 +    /* Iterate through the bits, testing each against the current modifiers */
   2.466 +    for (i = 0, bit = NSAlphaShiftKeyMask; bit <= NSCommandKeyMask; bit <<= 1, ++i) {
   2.467 +    
   2.468 +        unsigned int currentMask, newMask;
   2.469 +        
   2.470 +        currentMask = currentMods & bit;
   2.471 +        newMask     = newMods & bit;
   2.472 +        
   2.473 +        if ( currentMask &&
   2.474 +             currentMask != newMask ) {  /* modifier up event */
   2.475  
   2.476 -			key.sym = mapping[i];
   2.477 -			/* If this was Caps Lock, we need some additional voodoo to make SDL happy */
   2.478 -			if (bit == NSAlphaShiftKeyMask)
   2.479 -				SDL_PrivateKeyboard (SDL_PRESSED, &key);
   2.480 -			SDL_PrivateKeyboard (SDL_RELEASED, &key);
   2.481 -		}
   2.482 -		else
   2.483 -		if ( newMask &&
   2.484 -			 currentMask != newMask ) {	 /* modifier down event */
   2.485 -		
   2.486 -			key.sym = mapping[i];
   2.487 -			SDL_PrivateKeyboard (SDL_PRESSED, &key);
   2.488 -			/* If this was Caps Lock, we need some additional voodoo to make SDL happy */
   2.489 -			if (bit == NSAlphaShiftKeyMask)
   2.490 -				SDL_PrivateKeyboard (SDL_RELEASED, &key);
   2.491 -		}
   2.492 -	}
   2.493 -	
   2.494 -	currentMods = newMods;
   2.495 +            key.sym = mapping[i];
   2.496 +            /* If this was Caps Lock, we need some additional voodoo to make SDL happy */
   2.497 +            if (bit == NSAlphaShiftKeyMask)
   2.498 +                SDL_PrivateKeyboard (SDL_PRESSED, &key);
   2.499 +            SDL_PrivateKeyboard (SDL_RELEASED, &key);
   2.500 +        }
   2.501 +        else
   2.502 +        if ( newMask &&
   2.503 +             currentMask != newMask ) {  /* modifier down event */
   2.504 +        
   2.505 +            key.sym = mapping[i];
   2.506 +            SDL_PrivateKeyboard (SDL_PRESSED, &key);
   2.507 +            /* If this was Caps Lock, we need some additional voodoo to make SDL happy */
   2.508 +            if (bit == NSAlphaShiftKeyMask)
   2.509 +                SDL_PrivateKeyboard (SDL_RELEASED, &key);
   2.510 +        }
   2.511 +    }
   2.512 +    
   2.513 +    currentMods = newMods;
   2.514  }
   2.515  
   2.516  static void QZ_DoActivate (_THIS)
   2.517  {
   2.518 -	inForeground = YES;
   2.519 +    inForeground = YES;
   2.520  
   2.521 -	/* Regrab the mouse */
   2.522 -	if (currentGrabMode == SDL_GRAB_ON) {
   2.523 -		QZ_WarpWMCursor (this, SDL_VideoSurface->w / 2, SDL_VideoSurface->h / 2);
   2.524 -		CGAssociateMouseAndMouseCursorPosition (0);
   2.525 -	}
   2.526 +    /* Regrab the mouse */
   2.527 +    if (currentGrabMode == SDL_GRAB_ON) {
   2.528 +        QZ_WarpWMCursor (this, SDL_VideoSurface->w / 2, SDL_VideoSurface->h / 2);
   2.529 +        CGAssociateMouseAndMouseCursorPosition (0);
   2.530 +    }
   2.531  
   2.532 -	/* Hide the mouse cursor if inside the app window */
   2.533 -	if (!QZ_cursor_visible) {
   2.534 -		HideCursor ();
   2.535 -	}
   2.536 -	
   2.537 -	SDL_PrivateAppActive (1, SDL_APPINPUTFOCUS);
   2.538 +    /* Hide the mouse cursor if inside the app window */
   2.539 +    if (!QZ_cursor_visible) {
   2.540 +        HideCursor ();
   2.541 +    }
   2.542 +    
   2.543 +    SDL_PrivateAppActive (1, SDL_APPINPUTFOCUS);
   2.544  }
   2.545  
   2.546  static void QZ_DoDeactivate (_THIS) {
   2.547 -	
   2.548 -	inForeground = NO;
   2.549 +    
   2.550 +    inForeground = NO;
   2.551  
   2.552 -	/* Ungrab mouse if it is grabbed */
   2.553 -	if (currentGrabMode == SDL_GRAB_ON) {
   2.554 -		CGAssociateMouseAndMouseCursorPosition (1);
   2.555 -	}
   2.556 +    /* Ungrab mouse if it is grabbed */
   2.557 +    if (currentGrabMode == SDL_GRAB_ON) {
   2.558 +        CGAssociateMouseAndMouseCursorPosition (1);
   2.559 +    }
   2.560  
   2.561 -	/* Show the mouse cursor */
   2.562 -	if (!QZ_cursor_visible) {
   2.563 -		ShowCursor ();
   2.564 -	}
   2.565 -	
   2.566 -	SDL_PrivateAppActive (0, SDL_APPINPUTFOCUS);
   2.567 +    /* Show the mouse cursor */
   2.568 +    if (!QZ_cursor_visible) {
   2.569 +        ShowCursor ();
   2.570 +    }
   2.571 +    
   2.572 +    SDL_PrivateAppActive (0, SDL_APPINPUTFOCUS);
   2.573  }
   2.574  
   2.575  static void QZ_PumpEvents (_THIS)
   2.576  {
   2.577 -	
   2.578 -        static NSPoint lastMouse;
   2.579 -        NSPoint mouse, saveMouse;
   2.580 -        Point qdMouse;
   2.581 -        CGMouseDelta dx, dy;
   2.582 -        
   2.583 -        NSDate *distantPast;
   2.584 -	NSEvent *event;
   2.585 -	NSRect winRect;
   2.586 -	NSRect titleBarRect;
   2.587 -	NSAutoreleasePool *pool;
   2.588 -	
   2.589 -	pool = [ [ NSAutoreleasePool alloc ] init ];
   2.590 -	distantPast = [ NSDate distantPast ];
   2.591 -	
   2.592 -	winRect = NSMakeRect (0, 0, SDL_VideoSurface->w, SDL_VideoSurface->h);
   2.593 -	titleBarRect = NSMakeRect ( 0, SDL_VideoSurface->h, SDL_VideoSurface->w,
   2.594 -		SDL_VideoSurface->h + 22 );
   2.595 -	
   2.596 +    static NSPoint lastMouse;
   2.597 +    NSPoint mouse, saveMouse;
   2.598 +    Point qdMouse;
   2.599 +    CGMouseDelta dx, dy;
   2.600 +    
   2.601 +    NSDate *distantPast;
   2.602 +    NSEvent *event;
   2.603 +    NSRect titleBarRect;
   2.604 +    NSAutoreleasePool *pool;
   2.605 +    
   2.606 +    pool = [ [ NSAutoreleasePool alloc ] init ];
   2.607 +    distantPast = [ NSDate distantPast ];
   2.608 +    
   2.609 +    titleBarRect = NSMakeRect ( 0, SDL_VideoSurface->h, SDL_VideoSurface->w,
   2.610 +        SDL_VideoSurface->h + 22 );
   2.611 +    
   2.612          if (currentGrabMode != SDL_GRAB_ON) { /* if grabbed, the cursor can't move! (see fallback below) */
   2.613          
   2.614              /* 1/2 second after a warp, the mouse cannot move (don't ask me why) */
   2.615 @@ -338,7 +335,7 @@
   2.616                  if (mouse.x != lastMouse.x || mouse.y != lastMouse.y) {
   2.617                  
   2.618                      QZ_PrivateCGToSDL (this, &mouse);
   2.619 -                    if (inForeground && NSPointInRect (mouse, winRect)) {
   2.620 +                    if (inForeground) {
   2.621                          //printf ("Mouse Loc: (%f, %f)\n", mouse.x, mouse.y);
   2.622                          SDL_PrivateMouseMotion (0, 0, mouse.x, mouse.y);
   2.623                      }
   2.624 @@ -351,155 +348,149 @@
   2.625          dx = 0;
   2.626          dy = 0;
   2.627          
   2.628 -	do {
   2.629 -	
   2.630 -		/* Poll for an event. This will not block */
   2.631 -		event = [ NSApp nextEventMatchingMask:NSAnyEventMask
   2.632 -					untilDate:distantPast
   2.633 -					inMode: NSDefaultRunLoopMode dequeue:YES ];
   2.634 -	
   2.635 -		if (event != nil) {
   2.636 -			unsigned int type;
   2.637 -			BOOL isForGameWin;
   2.638 +    do {
   2.639 +    
   2.640 +        /* Poll for an event. This will not block */
   2.641 +        event = [ NSApp nextEventMatchingMask:NSAnyEventMask
   2.642 +                    untilDate:distantPast
   2.643 +                    inMode: NSDefaultRunLoopMode dequeue:YES ];
   2.644 +    
   2.645 +        if (event != nil) {
   2.646 +            unsigned int type;
   2.647 +            BOOL isForGameWin;
   2.648  
   2.649 -			#define DO_MOUSE_DOWN(button, sendToWindow) do {				 \
   2.650 -				if ( inForeground ) {			                                 \
   2.651 -					if ( (SDL_VideoSurface->flags & SDL_FULLSCREEN) ||		 \
   2.652 -						 NSPointInRect([event locationInWindow], winRect) )	 \
   2.653 -						SDL_PrivateMouseButton (SDL_PRESSED, button, 0, 0);	 \
   2.654 -				}                                                                        \
   2.655 -				else {									 \
   2.656 -					QZ_DoActivate (this);                                            \
   2.657 -				}									 \
   2.658 -				[ NSApp sendEvent:event ];			                         \
   2.659 -				} while(0)
   2.660 -				
   2.661 -			#define DO_MOUSE_UP(button, sendToWindow) do {					 \
   2.662 -				if ( (SDL_VideoSurface->flags & SDL_FULLSCREEN) ||			 \
   2.663 -					 !NSPointInRect([event locationInWindow], titleBarRect) )        \
   2.664 -					SDL_PrivateMouseButton (SDL_RELEASED, button, 0, 0);	         \
   2.665 -				[ NSApp sendEvent:event ];						 \
   2.666 -				} while(0)
   2.667 +            #define DO_MOUSE_DOWN(button, sendToWindow) do {                  \
   2.668 +                if ( inForeground ) {                                         \
   2.669 +                    SDL_PrivateMouseButton (SDL_PRESSED, button, 0, 0);       \
   2.670 +                }                                                             \
   2.671 +                else {                                                        \
   2.672 +                    QZ_DoActivate (this);                                     \
   2.673 +                }                                                             \
   2.674 +                [ NSApp sendEvent:event ];                                    \
   2.675 +                } while(0)
   2.676 +                
   2.677 +            #define DO_MOUSE_UP(button, sendToWindow) do {                    \
   2.678 +                if ( (SDL_VideoSurface->flags & SDL_FULLSCREEN) ||            \
   2.679 +                     !NSPointInRect([event locationInWindow], titleBarRect) ) \
   2.680 +                    SDL_PrivateMouseButton (SDL_RELEASED, button, 0, 0);      \
   2.681 +                [ NSApp sendEvent:event ];                                    \
   2.682 +                } while(0)
   2.683  
   2.684 -			type = [ event type ];
   2.685 -			isForGameWin = (qz_window == [ event window ]);
   2.686 -			switch (type) {
   2.687 -			
   2.688 -			case NSLeftMouseDown:
   2.689 -				if ( NSCommandKeyMask & currentMods ) {
   2.690 -					last_virtual_button = 3;
   2.691 -					DO_MOUSE_DOWN (3, 0);
   2.692 -				}
   2.693 -				else if ( NSAlternateKeyMask & currentMods ) {
   2.694 -					last_virtual_button = 2;
   2.695 -					DO_MOUSE_DOWN (2, 0);
   2.696 -				}
   2.697 -				else {
   2.698 -					DO_MOUSE_DOWN (1, 1);
   2.699 -				}
   2.700 -				break;
   2.701 -			case NSOtherMouseDown: DO_MOUSE_DOWN (2, 0); break;
   2.702 -			case NSRightMouseDown: DO_MOUSE_DOWN (3, 0); break;	
   2.703 -			case NSLeftMouseUp:
   2.704 -			
   2.705 -				if ( last_virtual_button != 0 ) {
   2.706 -					DO_MOUSE_UP (last_virtual_button, 0);
   2.707 -					last_virtual_button = 0;
   2.708 -				}
   2.709 -				else {
   2.710 -					DO_MOUSE_UP (1, 1);
   2.711 -				}
   2.712 -				break;
   2.713 -			case NSOtherMouseUp:   DO_MOUSE_UP (2, 0);	 break;
   2.714 -			case NSRightMouseUp:   DO_MOUSE_UP (3, 0);	 break;
   2.715 -			case NSSystemDefined:
   2.716 -				//if ([event subtype] == 7) {
   2.717 -				//	  unsigned int buttons;	  // up to 32 mouse button states!
   2.718 -				//	  buttons = [ event data2 ];
   2.719 -				//}
   2.720 -				break;
   2.721 -			case NSLeftMouseDragged:
   2.722 -			case NSRightMouseDragged:
   2.723 -			case 27:
   2.724 -			case NSMouseMoved:
   2.725 -                            
   2.726 -                                if (currentGrabMode == SDL_GRAB_ON) { 
   2.727 -                                    
   2.728 -                                    /** 
   2.729 -                                     *  If input is grabbed, we'll wing it and try to send some mouse
   2.730 -                                     *  moved events with CGGetLastMouseDelta(). Not optimal, but better
   2.731 -                                     *  than nothing.
   2.732 -                                     **/ 
   2.733 -                                     CGMouseDelta dx1, dy1;
   2.734 -                                     CGGetLastMouseDelta (&dx1, &dy1);
   2.735 -                                     dx += dx1;
   2.736 -                                     dy += dy1;
   2.737 -                                }
   2.738 -                                else if (warp_flag) {
   2.739 -                                
   2.740 -                                    Uint32 ticks;
   2.741 +            type = [ event type ];
   2.742 +            isForGameWin = (qz_window == [ event window ]);
   2.743 +            switch (type) {
   2.744 +            
   2.745 +            case NSLeftMouseDown:
   2.746 +                if ( NSCommandKeyMask & currentMods ) {
   2.747 +                    last_virtual_button = 3;
   2.748 +                    DO_MOUSE_DOWN (3, 0);
   2.749 +                }
   2.750 +                else if ( NSAlternateKeyMask & currentMods ) {
   2.751 +                    last_virtual_button = 2;
   2.752 +                    DO_MOUSE_DOWN (2, 0);
   2.753 +                }
   2.754 +                else {
   2.755 +                    DO_MOUSE_DOWN (1, 1);
   2.756 +                }
   2.757 +                break;
   2.758 +            case NSOtherMouseDown: DO_MOUSE_DOWN (2, 0); break;
   2.759 +            case NSRightMouseDown: DO_MOUSE_DOWN (3, 0); break; 
   2.760 +            case NSLeftMouseUp:
   2.761 +            
   2.762 +                if ( last_virtual_button != 0 ) {
   2.763 +                    DO_MOUSE_UP (last_virtual_button, 0);
   2.764 +                    last_virtual_button = 0;
   2.765 +                }
   2.766 +                else {
   2.767 +                    DO_MOUSE_UP (1, 1);
   2.768 +                }
   2.769 +                break;
   2.770 +            case NSOtherMouseUp:   DO_MOUSE_UP (2, 0);   break;
   2.771 +            case NSRightMouseUp:   DO_MOUSE_UP (3, 0);   break;
   2.772 +            case NSSystemDefined:
   2.773 +                //if ([event subtype] == 7) {
   2.774 +                //    unsigned int buttons;   // up to 32 mouse button states!
   2.775 +                //    buttons = [ event data2 ];
   2.776 +                //}
   2.777 +                break;
   2.778 +            case NSLeftMouseDragged:
   2.779 +            case NSRightMouseDragged:
   2.780 +            case 27:
   2.781 +            case NSMouseMoved:
   2.782 +                if (currentGrabMode == SDL_GRAB_ON) { 
   2.783 +                    
   2.784 +                    /** 
   2.785 +                     *  If input is grabbed, we'll wing it and try to send some mouse
   2.786 +                     *  moved events with CGGetLastMouseDelta(). Not optimal, but better
   2.787 +                     *  than nothing.
   2.788 +                     **/ 
   2.789 +                     CGMouseDelta dx1, dy1;
   2.790 +                     CGGetLastMouseDelta (&dx1, &dy1);
   2.791 +                     dx += dx1;
   2.792 +                     dy += dy1;
   2.793 +                }
   2.794 +                else if (warp_flag) {
   2.795                  
   2.796 -                                    ticks = SDL_GetTicks();
   2.797 -                                    if (ticks - warp_ticks < 150) {
   2.798 -                                    
   2.799 -                                        CGMouseDelta dx1, dy1;
   2.800 -                                        CGGetLastMouseDelta (&dx1, &dy1);
   2.801 -                                        dx += dx1;
   2.802 -                                        dy += dy1;
   2.803 -                                    }
   2.804 -                                    else {
   2.805 -                                        
   2.806 -                                        warp_flag = 0;
   2.807 -                                    }
   2.808 -                                }
   2.809 -                                
   2.810 -				break;
   2.811 -			case NSScrollWheel:
   2.812 -				{
   2.813 -					if (NSPointInRect([ event locationInWindow ], winRect)) {
   2.814 -						float dy;
   2.815 -						dy = [ event deltaY ];
   2.816 -						if ( dy > 0.0 ) /* Scroll up */
   2.817 -							SDL_PrivateMouseButton (SDL_PRESSED, 4, 0, 0);
   2.818 -						else /* Scroll down */
   2.819 -							SDL_PrivateMouseButton (SDL_PRESSED, 5, 0, 0);
   2.820 -					}
   2.821 -				}
   2.822 -				break;
   2.823 -			case NSKeyUp:
   2.824 -				QZ_DoKey (SDL_RELEASED, event);
   2.825 -				break;
   2.826 -			case NSKeyDown:
   2.827 -				QZ_DoKey (SDL_PRESSED, event);
   2.828 -				break;
   2.829 -			case NSFlagsChanged:
   2.830 -				QZ_DoModifiers( [ event modifierFlags ] );
   2.831 -				break;
   2.832 -			case NSAppKitDefined:
   2.833 -				switch ( [ event subtype ] ) {
   2.834 -				case NSApplicationActivatedEventType:
   2.835 -					QZ_DoActivate (this);
   2.836 -					break;
   2.837 -				case NSApplicationDeactivatedEventType:
   2.838 -					QZ_DoDeactivate (this);
   2.839 -					break;
   2.840 -				}
   2.841 -				[ NSApp sendEvent:event ];
   2.842 -				break;
   2.843 -			/* case NSApplicationDefined: break; */
   2.844 -			/* case NSPeriodic: break; */
   2.845 -			/* case NSCursorUpdate: break; */
   2.846 +                    Uint32 ticks;
   2.847 +
   2.848 +                    ticks = SDL_GetTicks();
   2.849 +                    if (ticks - warp_ticks < 150) {
   2.850 +                    
   2.851 +                        CGMouseDelta dx1, dy1;
   2.852 +                        CGGetLastMouseDelta (&dx1, &dy1);
   2.853 +                        dx += dx1;
   2.854 +                        dy += dy1;
   2.855 +                    }
   2.856 +                    else {
   2.857 +                        
   2.858 +                        warp_flag = 0;
   2.859 +                    }
   2.860 +                }
   2.861 +                break;
   2.862 +            case NSScrollWheel:
   2.863 +                {
   2.864 +                    float dy;
   2.865 +                    dy = [ event deltaY ];
   2.866 +                    if ( dy > 0.0 ) /* Scroll up */
   2.867 +                        SDL_PrivateMouseButton (SDL_PRESSED, 4, 0, 0);
   2.868 +                    else /* Scroll down */
   2.869 +                        SDL_PrivateMouseButton (SDL_PRESSED, 5, 0, 0);
   2.870 +                }
   2.871 +                break;
   2.872 +            case NSKeyUp:
   2.873 +                QZ_DoKey (SDL_RELEASED, event);
   2.874 +                break;
   2.875 +            case NSKeyDown:
   2.876 +                QZ_DoKey (SDL_PRESSED, event);
   2.877 +                break;
   2.878 +            case NSFlagsChanged:
   2.879 +                QZ_DoModifiers( [ event modifierFlags ] );
   2.880 +                break;
   2.881 +            case NSAppKitDefined:
   2.882 +                switch ( [ event subtype ] ) {
   2.883 +                case NSApplicationActivatedEventType:
   2.884 +                    QZ_DoActivate (this);
   2.885 +                    break;
   2.886 +                case NSApplicationDeactivatedEventType:
   2.887 +                    QZ_DoDeactivate (this);
   2.888 +                    break;
   2.889 +                }
   2.890 +                [ NSApp sendEvent:event ];
   2.891 +                break;
   2.892 +            /* case NSApplicationDefined: break; */
   2.893 +            /* case NSPeriodic: break; */
   2.894 +            /* case NSCursorUpdate: break; */
   2.895                          
   2.896                          default:
   2.897 -				[ NSApp sendEvent:event ];
   2.898 -			}
   2.899 -		}
   2.900 -	  } while (event != nil);
   2.901 -	
   2.902 +                [ NSApp sendEvent:event ];
   2.903 +            }
   2.904 +        }
   2.905 +      } while (event != nil);
   2.906 +    
   2.907            /* check for accumulated mouse events */
   2.908            if (dx != 0 || dy != 0)
   2.909              SDL_PrivateMouseMotion (0, 1, dx, dy);
   2.910          
   2.911 -	  [ pool release ];
   2.912 +      [ pool release ];
   2.913  }
   2.914