src/video/x11/SDL_x11events.c
branchSDL-1.3
changeset 1662 782fd950bd46
parent 1659 14717b52abc0
child 1668 4da1ee79c9af
     1.1 --- a/src/video/x11/SDL_x11events.c	Sun May 21 17:27:13 2006 +0000
     1.2 +++ b/src/video/x11/SDL_x11events.c	Sun May 28 13:04:16 2006 +0000
     1.3 @@ -55,148 +55,151 @@
     1.4  /* The translation tables from an X11 keysym to a SDL keysym */
     1.5  static SDLKey ODD_keymap[256];
     1.6  static SDLKey MISC_keymap[256];
     1.7 -SDLKey X11_TranslateKeycode(Display *display, KeyCode kc);
     1.8 +SDLKey X11_TranslateKeycode (Display * display, KeyCode kc);
     1.9  
    1.10  
    1.11  #ifdef X_HAVE_UTF8_STRING
    1.12 -Uint32 Utf8ToUcs4(const Uint8 *utf8)
    1.13 +Uint32
    1.14 +Utf8ToUcs4 (const Uint8 * utf8)
    1.15  {
    1.16 -	Uint32 c;
    1.17 -	int i = 1;
    1.18 -	int noOctets = 0;
    1.19 -	int firstOctetMask = 0;
    1.20 -	unsigned char firstOctet = utf8[0];
    1.21 -	if (firstOctet < 0x80) {
    1.22 -		/*
    1.23 -		  Characters in the range:
    1.24 -		    00000000 to 01111111 (ASCII Range)
    1.25 -		  are stored in one octet:
    1.26 -		    0xxxxxxx (The same as its ASCII representation)
    1.27 -		  The least 6 significant bits of the first octet is the most 6 significant nonzero bits
    1.28 -		  of the UCS4 representation.
    1.29 -		*/
    1.30 -		noOctets = 1;
    1.31 -		firstOctetMask = 0x7F;  /* 0(1111111) - The most significant bit is ignored */
    1.32 -	} else if ((firstOctet & 0xE0) /* get the most 3 significant bits by AND'ing with 11100000 */
    1.33 -	              == 0xC0 ) {  /* see if those 3 bits are 110. If so, the char is in this range */
    1.34 -		/*
    1.35 -		  Characters in the range:
    1.36 -		    00000000 10000000 to 00000111 11111111
    1.37 -		  are stored in two octets:
    1.38 -		    110xxxxx 10xxxxxx
    1.39 -		  The least 5 significant bits of the first octet is the most 5 significant nonzero bits
    1.40 -		  of the UCS4 representation.
    1.41 -		*/
    1.42 -		noOctets = 2;
    1.43 -		firstOctetMask = 0x1F;  /* 000(11111) - The most 3 significant bits are ignored */
    1.44 -	} else if ((firstOctet & 0xF0) /* get the most 4 significant bits by AND'ing with 11110000 */
    1.45 -	              == 0xE0) {  /* see if those 4 bits are 1110. If so, the char is in this range */
    1.46 -		/*
    1.47 -		  Characters in the range:
    1.48 -		    00001000 00000000 to 11111111 11111111
    1.49 -		  are stored in three octets:
    1.50 -		    1110xxxx 10xxxxxx 10xxxxxx
    1.51 -		  The least 4 significant bits of the first octet is the most 4 significant nonzero bits
    1.52 -		  of the UCS4 representation.
    1.53 -		*/
    1.54 -		noOctets = 3;
    1.55 -		firstOctetMask = 0x0F; /* 0000(1111) - The most 4 significant bits are ignored */
    1.56 -	} else if ((firstOctet & 0xF8) /* get the most 5 significant bits by AND'ing with 11111000 */
    1.57 -	              == 0xF0) {  /* see if those 5 bits are 11110. If so, the char is in this range */
    1.58 -		/*
    1.59 -		  Characters in the range:
    1.60 -		    00000001 00000000 00000000 to 00011111 11111111 11111111
    1.61 -		  are stored in four octets:
    1.62 -		    11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
    1.63 -		  The least 3 significant bits of the first octet is the most 3 significant nonzero bits
    1.64 -		  of the UCS4 representation.
    1.65 -		*/
    1.66 -		noOctets = 4;
    1.67 -		firstOctetMask = 0x07; /* 11110(111) - The most 5 significant bits are ignored */
    1.68 -	} else if ((firstOctet & 0xFC) /* get the most 6 significant bits by AND'ing with 11111100 */
    1.69 -	              == 0xF8) { /* see if those 6 bits are 111110. If so, the char is in this range */
    1.70 -		/*
    1.71 -		  Characters in the range:
    1.72 -		    00000000 00100000 00000000 00000000 to
    1.73 -		    00000011 11111111 11111111 11111111
    1.74 -		  are stored in five octets:
    1.75 -		    111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
    1.76 -		  The least 2 significant bits of the first octet is the most 2 significant nonzero bits
    1.77 -		  of the UCS4 representation.
    1.78 -		*/
    1.79 -		noOctets = 5;
    1.80 -		firstOctetMask = 0x03; /* 111110(11) - The most 6 significant bits are ignored */
    1.81 -	} else if ((firstOctet & 0xFE) /* get the most 7 significant bits by AND'ing with 11111110 */
    1.82 -	              == 0xFC) { /* see if those 7 bits are 1111110. If so, the char is in this range */
    1.83 -		/*
    1.84 -		  Characters in the range:
    1.85 -		    00000100 00000000 00000000 00000000 to
    1.86 -		    01111111 11111111 11111111 11111111
    1.87 -		  are stored in six octets:
    1.88 -		    1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
    1.89 -		  The least significant bit of the first octet is the most significant nonzero bit
    1.90 -		  of the UCS4 representation.
    1.91 -		*/
    1.92 -		noOctets = 6;
    1.93 -		firstOctetMask = 0x01; /* 1111110(1) - The most 7 significant bits are ignored */
    1.94 -	} else
    1.95 -		return 0;  /* The given chunk is not a valid UTF-8 encoded Unicode character */
    1.96 -	
    1.97 -	/*
    1.98 -	  The least noOctets significant bits of the first octet is the most 2 significant nonzero bits
    1.99 -	  of the UCS4 representation.
   1.100 -	  The first 6 bits of the UCS4 representation is the least 8-noOctets-1 significant bits of
   1.101 -	  firstOctet if the character is not ASCII. If so, it's the least 7 significant bits of firstOctet.
   1.102 -	  This done by AND'ing firstOctet with its mask to trim the bits used for identifying the
   1.103 -	  number of continuing octets (if any) and leave only the free bits (the x's)
   1.104 -	  Sample:
   1.105 -	  1-octet:    0xxxxxxx  &  01111111 = 0xxxxxxx
   1.106 -	  2-octets:  110xxxxx  &  00011111 = 000xxxxx
   1.107 -	*/
   1.108 -	c = firstOctet & firstOctetMask;
   1.109 -	
   1.110 -	/* Now, start filling c.ucs4 with the bits from the continuing octets from utf8. */
   1.111 -	for (i = 1; i < noOctets; i++) {
   1.112 -		/* A valid continuing octet is of the form 10xxxxxx */
   1.113 -		if ((utf8[i] & 0xC0) /* get the most 2 significant bits by AND'ing with 11000000 */
   1.114 -		    != 0x80) /* see if those 2 bits are 10. If not, the is a malformed sequence. */
   1.115 -			/*The given chunk is a partial sequence at the end of a string that could
   1.116 -			   begin a valid character */
   1.117 -			return 0;
   1.118 -		
   1.119 -		/* Make room for the next 6-bits */
   1.120 -		c <<= 6;
   1.121 -		
   1.122 -		/*
   1.123 -		  Take only the least 6 significance bits of the current octet (utf8[i]) and fill the created room
   1.124 -		  of c.ucs4 with them.
   1.125 -		  This done by AND'ing utf8[i] with 00111111 and the OR'ing the result with c.ucs4.
   1.126 -		*/
   1.127 -		c |= utf8[i] & 0x3F;
   1.128 -	}
   1.129 -	return c;
   1.130 +    Uint32 c;
   1.131 +    int i = 1;
   1.132 +    int noOctets = 0;
   1.133 +    int firstOctetMask = 0;
   1.134 +    unsigned char firstOctet = utf8[0];
   1.135 +    if (firstOctet < 0x80) {
   1.136 +        /*
   1.137 +           Characters in the range:
   1.138 +           00000000 to 01111111 (ASCII Range)
   1.139 +           are stored in one octet:
   1.140 +           0xxxxxxx (The same as its ASCII representation)
   1.141 +           The least 6 significant bits of the first octet is the most 6 significant nonzero bits
   1.142 +           of the UCS4 representation.
   1.143 +         */
   1.144 +        noOctets = 1;
   1.145 +        firstOctetMask = 0x7F;  /* 0(1111111) - The most significant bit is ignored */
   1.146 +    } else if ((firstOctet & 0xE0)      /* get the most 3 significant bits by AND'ing with 11100000 */
   1.147 +               == 0xC0) {       /* see if those 3 bits are 110. If so, the char is in this range */
   1.148 +        /*
   1.149 +           Characters in the range:
   1.150 +           00000000 10000000 to 00000111 11111111
   1.151 +           are stored in two octets:
   1.152 +           110xxxxx 10xxxxxx
   1.153 +           The least 5 significant bits of the first octet is the most 5 significant nonzero bits
   1.154 +           of the UCS4 representation.
   1.155 +         */
   1.156 +        noOctets = 2;
   1.157 +        firstOctetMask = 0x1F;  /* 000(11111) - The most 3 significant bits are ignored */
   1.158 +    } else if ((firstOctet & 0xF0)      /* get the most 4 significant bits by AND'ing with 11110000 */
   1.159 +               == 0xE0) {       /* see if those 4 bits are 1110. If so, the char is in this range */
   1.160 +        /*
   1.161 +           Characters in the range:
   1.162 +           00001000 00000000 to 11111111 11111111
   1.163 +           are stored in three octets:
   1.164 +           1110xxxx 10xxxxxx 10xxxxxx
   1.165 +           The least 4 significant bits of the first octet is the most 4 significant nonzero bits
   1.166 +           of the UCS4 representation.
   1.167 +         */
   1.168 +        noOctets = 3;
   1.169 +        firstOctetMask = 0x0F;  /* 0000(1111) - The most 4 significant bits are ignored */
   1.170 +    } else if ((firstOctet & 0xF8)      /* get the most 5 significant bits by AND'ing with 11111000 */
   1.171 +               == 0xF0) {       /* see if those 5 bits are 11110. If so, the char is in this range */
   1.172 +        /*
   1.173 +           Characters in the range:
   1.174 +           00000001 00000000 00000000 to 00011111 11111111 11111111
   1.175 +           are stored in four octets:
   1.176 +           11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
   1.177 +           The least 3 significant bits of the first octet is the most 3 significant nonzero bits
   1.178 +           of the UCS4 representation.
   1.179 +         */
   1.180 +        noOctets = 4;
   1.181 +        firstOctetMask = 0x07;  /* 11110(111) - The most 5 significant bits are ignored */
   1.182 +    } else if ((firstOctet & 0xFC)      /* get the most 6 significant bits by AND'ing with 11111100 */
   1.183 +               == 0xF8) {       /* see if those 6 bits are 111110. If so, the char is in this range */
   1.184 +        /*
   1.185 +           Characters in the range:
   1.186 +           00000000 00100000 00000000 00000000 to
   1.187 +           00000011 11111111 11111111 11111111
   1.188 +           are stored in five octets:
   1.189 +           111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
   1.190 +           The least 2 significant bits of the first octet is the most 2 significant nonzero bits
   1.191 +           of the UCS4 representation.
   1.192 +         */
   1.193 +        noOctets = 5;
   1.194 +        firstOctetMask = 0x03;  /* 111110(11) - The most 6 significant bits are ignored */
   1.195 +    } else if ((firstOctet & 0xFE)      /* get the most 7 significant bits by AND'ing with 11111110 */
   1.196 +               == 0xFC) {       /* see if those 7 bits are 1111110. If so, the char is in this range */
   1.197 +        /*
   1.198 +           Characters in the range:
   1.199 +           00000100 00000000 00000000 00000000 to
   1.200 +           01111111 11111111 11111111 11111111
   1.201 +           are stored in six octets:
   1.202 +           1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
   1.203 +           The least significant bit of the first octet is the most significant nonzero bit
   1.204 +           of the UCS4 representation.
   1.205 +         */
   1.206 +        noOctets = 6;
   1.207 +        firstOctetMask = 0x01;  /* 1111110(1) - The most 7 significant bits are ignored */
   1.208 +    } else
   1.209 +        return 0;               /* The given chunk is not a valid UTF-8 encoded Unicode character */
   1.210 +
   1.211 +    /*
   1.212 +       The least noOctets significant bits of the first octet is the most 2 significant nonzero bits
   1.213 +       of the UCS4 representation.
   1.214 +       The first 6 bits of the UCS4 representation is the least 8-noOctets-1 significant bits of
   1.215 +       firstOctet if the character is not ASCII. If so, it's the least 7 significant bits of firstOctet.
   1.216 +       This done by AND'ing firstOctet with its mask to trim the bits used for identifying the
   1.217 +       number of continuing octets (if any) and leave only the free bits (the x's)
   1.218 +       Sample:
   1.219 +       1-octet:    0xxxxxxx  &  01111111 = 0xxxxxxx
   1.220 +       2-octets:  110xxxxx  &  00011111 = 000xxxxx
   1.221 +     */
   1.222 +    c = firstOctet & firstOctetMask;
   1.223 +
   1.224 +    /* Now, start filling c.ucs4 with the bits from the continuing octets from utf8. */
   1.225 +    for (i = 1; i < noOctets; i++) {
   1.226 +        /* A valid continuing octet is of the form 10xxxxxx */
   1.227 +        if ((utf8[i] & 0xC0)    /* get the most 2 significant bits by AND'ing with 11000000 */
   1.228 +            !=0x80)
   1.229 +            /* see if those 2 bits are 10. If not, the is a malformed sequence. */
   1.230 +            /*The given chunk is a partial sequence at the end of a string that could
   1.231 +               begin a valid character */
   1.232 +            return 0;
   1.233 +
   1.234 +        /* Make room for the next 6-bits */
   1.235 +        c <<= 6;
   1.236 +
   1.237 +        /*
   1.238 +           Take only the least 6 significance bits of the current octet (utf8[i]) and fill the created room
   1.239 +           of c.ucs4 with them.
   1.240 +           This done by AND'ing utf8[i] with 00111111 and the OR'ing the result with c.ucs4.
   1.241 +         */
   1.242 +        c |= utf8[i] & 0x3F;
   1.243 +    }
   1.244 +    return c;
   1.245  }
   1.246  #endif
   1.247  
   1.248  /* Check to see if this is a repeated key.
   1.249     (idea shamelessly lifted from GII -- thanks guys! :)
   1.250   */
   1.251 -static int X11_KeyRepeat(Display *display, XEvent *event)
   1.252 +static int
   1.253 +X11_KeyRepeat (Display * display, XEvent * event)
   1.254  {
   1.255 -	XEvent peekevent;
   1.256 -	int repeated;
   1.257 +    XEvent peekevent;
   1.258 +    int repeated;
   1.259  
   1.260 -	repeated = 0;
   1.261 -	if ( XPending(display) ) {
   1.262 -		XPeekEvent(display, &peekevent);
   1.263 -		if ( (peekevent.type == KeyPress) &&
   1.264 -		     (peekevent.xkey.keycode == event->xkey.keycode) &&
   1.265 -		     ((peekevent.xkey.time-event->xkey.time) < 2) ) {
   1.266 -			repeated = 1;
   1.267 -			XNextEvent(display, &peekevent);
   1.268 -		}
   1.269 -	}
   1.270 -	return(repeated);
   1.271 +    repeated = 0;
   1.272 +    if (XPending (display)) {
   1.273 +        XPeekEvent (display, &peekevent);
   1.274 +        if ((peekevent.type == KeyPress) &&
   1.275 +            (peekevent.xkey.keycode == event->xkey.keycode) &&
   1.276 +            ((peekevent.xkey.time - event->xkey.time) < 2)) {
   1.277 +            repeated = 1;
   1.278 +            XNextEvent (display, &peekevent);
   1.279 +        }
   1.280 +    }
   1.281 +    return (repeated);
   1.282  }
   1.283  
   1.284  /* Note:  The X server buffers and accumulates mouse motion events, so
   1.285 @@ -206,738 +209,772 @@
   1.286  */
   1.287  #define MOUSE_FUDGE_FACTOR	8
   1.288  
   1.289 -static __inline__ int X11_WarpedMotion(_THIS, XEvent *xevent)
   1.290 +static __inline__ int
   1.291 +X11_WarpedMotion (_THIS, XEvent * xevent)
   1.292  {
   1.293 -	int w, h, i;
   1.294 -	int deltax, deltay;
   1.295 -	int posted;
   1.296 +    int w, h, i;
   1.297 +    int deltax, deltay;
   1.298 +    int posted;
   1.299  
   1.300 -	w = SDL_VideoSurface->w;
   1.301 -	h = SDL_VideoSurface->h;
   1.302 -	deltax = xevent->xmotion.x - mouse_last.x;
   1.303 -	deltay = xevent->xmotion.y - mouse_last.y;
   1.304 +    w = SDL_VideoSurface->w;
   1.305 +    h = SDL_VideoSurface->h;
   1.306 +    deltax = xevent->xmotion.x - mouse_last.x;
   1.307 +    deltay = xevent->xmotion.y - mouse_last.y;
   1.308  #ifdef DEBUG_MOTION
   1.309 -  printf("Warped mouse motion: %d,%d\n", deltax, deltay);
   1.310 +    printf ("Warped mouse motion: %d,%d\n", deltax, deltay);
   1.311  #endif
   1.312 -	mouse_last.x = xevent->xmotion.x;
   1.313 -	mouse_last.y = xevent->xmotion.y;
   1.314 -	posted = SDL_PrivateMouseMotion(0, 1, deltax, deltay);
   1.315 +    mouse_last.x = xevent->xmotion.x;
   1.316 +    mouse_last.y = xevent->xmotion.y;
   1.317 +    posted = SDL_PrivateMouseMotion (0, 1, deltax, deltay);
   1.318  
   1.319 -	if ( (xevent->xmotion.x < MOUSE_FUDGE_FACTOR) ||
   1.320 -	     (xevent->xmotion.x > (w-MOUSE_FUDGE_FACTOR)) ||
   1.321 -	     (xevent->xmotion.y < MOUSE_FUDGE_FACTOR) ||
   1.322 -	     (xevent->xmotion.y > (h-MOUSE_FUDGE_FACTOR)) ) {
   1.323 -		/* Get the events that have accumulated */
   1.324 -		while ( XCheckTypedEvent(SDL_Display, MotionNotify, xevent) ) {
   1.325 -			deltax = xevent->xmotion.x - mouse_last.x;
   1.326 -			deltay = xevent->xmotion.y - mouse_last.y;
   1.327 +    if ((xevent->xmotion.x < MOUSE_FUDGE_FACTOR) ||
   1.328 +        (xevent->xmotion.x > (w - MOUSE_FUDGE_FACTOR)) ||
   1.329 +        (xevent->xmotion.y < MOUSE_FUDGE_FACTOR) ||
   1.330 +        (xevent->xmotion.y > (h - MOUSE_FUDGE_FACTOR))) {
   1.331 +        /* Get the events that have accumulated */
   1.332 +        while (XCheckTypedEvent (SDL_Display, MotionNotify, xevent)) {
   1.333 +            deltax = xevent->xmotion.x - mouse_last.x;
   1.334 +            deltay = xevent->xmotion.y - mouse_last.y;
   1.335  #ifdef DEBUG_MOTION
   1.336 -  printf("Extra mouse motion: %d,%d\n", deltax, deltay);
   1.337 +            printf ("Extra mouse motion: %d,%d\n", deltax, deltay);
   1.338  #endif
   1.339 -			mouse_last.x = xevent->xmotion.x;
   1.340 -			mouse_last.y = xevent->xmotion.y;
   1.341 -			posted += SDL_PrivateMouseMotion(0, 1, deltax, deltay);
   1.342 -		}
   1.343 -		mouse_last.x = w/2;
   1.344 -		mouse_last.y = h/2;
   1.345 -		XWarpPointer(SDL_Display, None, SDL_Window, 0, 0, 0, 0,
   1.346 -					mouse_last.x, mouse_last.y);
   1.347 -		for ( i=0; i<10; ++i ) {
   1.348 -        		XMaskEvent(SDL_Display, PointerMotionMask, xevent);
   1.349 -			if ( (xevent->xmotion.x >
   1.350 -			          (mouse_last.x-MOUSE_FUDGE_FACTOR)) &&
   1.351 -			     (xevent->xmotion.x <
   1.352 -			          (mouse_last.x+MOUSE_FUDGE_FACTOR)) &&
   1.353 -			     (xevent->xmotion.y >
   1.354 -			          (mouse_last.y-MOUSE_FUDGE_FACTOR)) &&
   1.355 -			     (xevent->xmotion.y <
   1.356 -			          (mouse_last.y+MOUSE_FUDGE_FACTOR)) ) {
   1.357 -				break;
   1.358 -			}
   1.359 +            mouse_last.x = xevent->xmotion.x;
   1.360 +            mouse_last.y = xevent->xmotion.y;
   1.361 +            posted += SDL_PrivateMouseMotion (0, 1, deltax, deltay);
   1.362 +        }
   1.363 +        mouse_last.x = w / 2;
   1.364 +        mouse_last.y = h / 2;
   1.365 +        XWarpPointer (SDL_Display, None, SDL_Window, 0, 0, 0, 0,
   1.366 +                      mouse_last.x, mouse_last.y);
   1.367 +        for (i = 0; i < 10; ++i) {
   1.368 +            XMaskEvent (SDL_Display, PointerMotionMask, xevent);
   1.369 +            if ((xevent->xmotion.x >
   1.370 +                 (mouse_last.x - MOUSE_FUDGE_FACTOR)) &&
   1.371 +                (xevent->xmotion.x <
   1.372 +                 (mouse_last.x + MOUSE_FUDGE_FACTOR)) &&
   1.373 +                (xevent->xmotion.y >
   1.374 +                 (mouse_last.y - MOUSE_FUDGE_FACTOR)) &&
   1.375 +                (xevent->xmotion.y < (mouse_last.y + MOUSE_FUDGE_FACTOR))) {
   1.376 +                break;
   1.377 +            }
   1.378  #ifdef DEBUG_XEVENTS
   1.379 -  printf("Lost mouse motion: %d,%d\n", xevent->xmotion.x, xevent->xmotion.y);
   1.380 +            printf ("Lost mouse motion: %d,%d\n", xevent->xmotion.x,
   1.381 +                    xevent->xmotion.y);
   1.382  #endif
   1.383 -		}
   1.384 +        }
   1.385  #ifdef DEBUG_XEVENTS
   1.386 -		if ( i == 10 ) {
   1.387 -			printf("Warning: didn't detect mouse warp motion\n");
   1.388 -		}
   1.389 +        if (i == 10) {
   1.390 +            printf ("Warning: didn't detect mouse warp motion\n");
   1.391 +        }
   1.392  #endif
   1.393 -	}
   1.394 -	return(posted);
   1.395 +    }
   1.396 +    return (posted);
   1.397  }
   1.398  
   1.399 -static int X11_DispatchEvent(_THIS)
   1.400 +static int
   1.401 +X11_DispatchEvent (_THIS)
   1.402  {
   1.403 -	int posted;
   1.404 -	XEvent xevent;
   1.405 +    int posted;
   1.406 +    XEvent xevent;
   1.407  
   1.408 -	SDL_memset(&xevent, '\0', sizeof (XEvent));  /* valgrind fix. --ryan. */
   1.409 -	XNextEvent(SDL_Display, &xevent);
   1.410 +    SDL_memset (&xevent, '\0', sizeof (XEvent));        /* valgrind fix. --ryan. */
   1.411 +    XNextEvent (SDL_Display, &xevent);
   1.412  
   1.413 -	posted = 0;
   1.414 -	switch (xevent.type) {
   1.415 +    posted = 0;
   1.416 +    switch (xevent.type) {
   1.417  
   1.418 -	    /* Gaining mouse coverage? */
   1.419 -	    case EnterNotify: {
   1.420 +        /* Gaining mouse coverage? */
   1.421 +    case EnterNotify:
   1.422 +        {
   1.423  #ifdef DEBUG_XEVENTS
   1.424 -printf("EnterNotify! (%d,%d)\n", xevent.xcrossing.x, xevent.xcrossing.y);
   1.425 -if ( xevent.xcrossing.mode == NotifyGrab )
   1.426 -printf("Mode: NotifyGrab\n");
   1.427 -if ( xevent.xcrossing.mode == NotifyUngrab )
   1.428 -printf("Mode: NotifyUngrab\n");
   1.429 +            printf ("EnterNotify! (%d,%d)\n", xevent.xcrossing.x,
   1.430 +                    xevent.xcrossing.y);
   1.431 +            if (xevent.xcrossing.mode == NotifyGrab)
   1.432 +                printf ("Mode: NotifyGrab\n");
   1.433 +            if (xevent.xcrossing.mode == NotifyUngrab)
   1.434 +                printf ("Mode: NotifyUngrab\n");
   1.435  #endif
   1.436 -		if ( (xevent.xcrossing.mode != NotifyGrab) &&
   1.437 -		     (xevent.xcrossing.mode != NotifyUngrab) ) {
   1.438 -			if ( this->input_grab == SDL_GRAB_OFF ) {
   1.439 -				posted = SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
   1.440 -			}
   1.441 -			posted = SDL_PrivateMouseMotion(0, 0,
   1.442 -					xevent.xcrossing.x,
   1.443 -					xevent.xcrossing.y);
   1.444 -		}
   1.445 -	    }
   1.446 -	    break;
   1.447 +            if ((xevent.xcrossing.mode != NotifyGrab) &&
   1.448 +                (xevent.xcrossing.mode != NotifyUngrab)) {
   1.449 +                if (SDL_CurrentWindow.input_grab == SDL_GRAB_OFF) {
   1.450 +                    posted = SDL_PrivateAppActive (1, SDL_APPMOUSEFOCUS);
   1.451 +                }
   1.452 +                posted = SDL_PrivateMouseMotion (0, 0,
   1.453 +                                                 xevent.xcrossing.x,
   1.454 +                                                 xevent.xcrossing.y);
   1.455 +            }
   1.456 +        }
   1.457 +        break;
   1.458  
   1.459 -	    /* Losing mouse coverage? */
   1.460 -	    case LeaveNotify: {
   1.461 +        /* Losing mouse coverage? */
   1.462 +    case LeaveNotify:
   1.463 +        {
   1.464  #ifdef DEBUG_XEVENTS
   1.465 -printf("LeaveNotify! (%d,%d)\n", xevent.xcrossing.x, xevent.xcrossing.y);
   1.466 -if ( xevent.xcrossing.mode == NotifyGrab )
   1.467 -printf("Mode: NotifyGrab\n");
   1.468 -if ( xevent.xcrossing.mode == NotifyUngrab )
   1.469 -printf("Mode: NotifyUngrab\n");
   1.470 +            printf ("LeaveNotify! (%d,%d)\n", xevent.xcrossing.x,
   1.471 +                    xevent.xcrossing.y);
   1.472 +            if (xevent.xcrossing.mode == NotifyGrab)
   1.473 +                printf ("Mode: NotifyGrab\n");
   1.474 +            if (xevent.xcrossing.mode == NotifyUngrab)
   1.475 +                printf ("Mode: NotifyUngrab\n");
   1.476  #endif
   1.477 -		if ( (xevent.xcrossing.mode != NotifyGrab) &&
   1.478 -		     (xevent.xcrossing.mode != NotifyUngrab) &&
   1.479 -		     (xevent.xcrossing.detail != NotifyInferior) ) {
   1.480 -			if ( this->input_grab == SDL_GRAB_OFF ) {
   1.481 -				posted = SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
   1.482 -			} else {
   1.483 -				posted = SDL_PrivateMouseMotion(0, 0,
   1.484 -						xevent.xcrossing.x,
   1.485 -						xevent.xcrossing.y);
   1.486 -			}
   1.487 -		}
   1.488 -	    }
   1.489 -	    break;
   1.490 +            if ((xevent.xcrossing.mode != NotifyGrab) &&
   1.491 +                (xevent.xcrossing.mode != NotifyUngrab) &&
   1.492 +                (xevent.xcrossing.detail != NotifyInferior)) {
   1.493 +                if (SDL_CurrentWindow.input_grab == SDL_GRAB_OFF) {
   1.494 +                    posted = SDL_PrivateAppActive (0, SDL_APPMOUSEFOCUS);
   1.495 +                } else {
   1.496 +                    posted = SDL_PrivateMouseMotion (0, 0,
   1.497 +                                                     xevent.xcrossing.x,
   1.498 +                                                     xevent.xcrossing.y);
   1.499 +                }
   1.500 +            }
   1.501 +        }
   1.502 +        break;
   1.503  
   1.504 -	    /* Gaining input focus? */
   1.505 -	    case FocusIn: {
   1.506 +        /* Gaining input focus? */
   1.507 +    case FocusIn:
   1.508 +        {
   1.509  #ifdef DEBUG_XEVENTS
   1.510 -printf("FocusIn!\n");
   1.511 +            printf ("FocusIn!\n");
   1.512  #endif
   1.513 -		posted = SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS);
   1.514 +            posted = SDL_PrivateAppActive (1, SDL_APPINPUTFOCUS);
   1.515  
   1.516  #ifdef X_HAVE_UTF8_STRING
   1.517 -		if ( SDL_IC != NULL ) {
   1.518 -			XSetICFocus(SDL_IC);
   1.519 -		}
   1.520 +            if (SDL_IC != NULL) {
   1.521 +                XSetICFocus (SDL_IC);
   1.522 +            }
   1.523  #endif
   1.524 -		/* Queue entry into fullscreen mode */
   1.525 -		switch_waiting = 0x01 | SDL_FULLSCREEN;
   1.526 -		switch_time = SDL_GetTicks() + 1500;
   1.527 -	    }
   1.528 -	    break;
   1.529 +            /* Queue entry into fullscreen mode */
   1.530 +            switch_waiting = 0x01 | SDL_FULLSCREEN;
   1.531 +            switch_time = SDL_GetTicks () + 1500;
   1.532 +        }
   1.533 +        break;
   1.534  
   1.535 -	    /* Losing input focus? */
   1.536 -	    case FocusOut: {
   1.537 +        /* Losing input focus? */
   1.538 +    case FocusOut:
   1.539 +        {
   1.540  #ifdef DEBUG_XEVENTS
   1.541 -printf("FocusOut!\n");
   1.542 +            printf ("FocusOut!\n");
   1.543  #endif
   1.544 -		posted = SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS);
   1.545 +            posted = SDL_PrivateAppActive (0, SDL_APPINPUTFOCUS);
   1.546  
   1.547  #ifdef X_HAVE_UTF8_STRING
   1.548 -		if ( SDL_IC != NULL ) {
   1.549 -			XUnsetICFocus(SDL_IC);
   1.550 -		}
   1.551 +            if (SDL_IC != NULL) {
   1.552 +                XUnsetICFocus (SDL_IC);
   1.553 +            }
   1.554  #endif
   1.555 -		/* Queue leaving fullscreen mode */
   1.556 -		switch_waiting = 0x01;
   1.557 -		switch_time = SDL_GetTicks() + 200;
   1.558 -	    }
   1.559 -	    break;
   1.560 +            /* Queue leaving fullscreen mode */
   1.561 +            switch_waiting = 0x01;
   1.562 +            switch_time = SDL_GetTicks () + 200;
   1.563 +        }
   1.564 +        break;
   1.565  
   1.566 -	    /* Generated upon EnterWindow and FocusIn */
   1.567 -	    case KeymapNotify: {
   1.568 +        /* Generated upon EnterWindow and FocusIn */
   1.569 +    case KeymapNotify:
   1.570 +        {
   1.571  #ifdef DEBUG_XEVENTS
   1.572 -printf("KeymapNotify!\n");
   1.573 +            printf ("KeymapNotify!\n");
   1.574  #endif
   1.575 -		X11_SetKeyboardState(SDL_Display,  xevent.xkeymap.key_vector);
   1.576 -	    }
   1.577 -	    break;
   1.578 +            X11_SetKeyboardState (SDL_Display, xevent.xkeymap.key_vector);
   1.579 +        }
   1.580 +        break;
   1.581  
   1.582 -	    /* Mouse motion? */
   1.583 -	    case MotionNotify: {
   1.584 -		if ( SDL_VideoSurface ) {
   1.585 -			if ( mouse_relative ) {
   1.586 -				if ( using_dga & DGA_MOUSE ) {
   1.587 +        /* Mouse motion? */
   1.588 +    case MotionNotify:
   1.589 +        {
   1.590 +            if (SDL_VideoSurface) {
   1.591 +                if (mouse_relative) {
   1.592 +                    if (using_dga & DGA_MOUSE) {
   1.593  #ifdef DEBUG_MOTION
   1.594 -  printf("DGA motion: %d,%d\n", xevent.xmotion.x_root, xevent.xmotion.y_root);
   1.595 +                        printf ("DGA motion: %d,%d\n",
   1.596 +                                xevent.xmotion.x_root, xevent.xmotion.y_root);
   1.597  #endif
   1.598 -					posted = SDL_PrivateMouseMotion(0, 1,
   1.599 -							xevent.xmotion.x_root,
   1.600 -							xevent.xmotion.y_root);
   1.601 -				} else {
   1.602 -					posted = X11_WarpedMotion(this,&xevent);
   1.603 -				}
   1.604 -			} else {
   1.605 +                        posted = SDL_PrivateMouseMotion (0, 1,
   1.606 +                                                         xevent.
   1.607 +                                                         xmotion.
   1.608 +                                                         x_root,
   1.609 +                                                         xevent.
   1.610 +                                                         xmotion.y_root);
   1.611 +                    } else {
   1.612 +                        posted = X11_WarpedMotion (_this, &xevent);
   1.613 +                    }
   1.614 +                } else {
   1.615  #ifdef DEBUG_MOTION
   1.616 -  printf("X11 motion: %d,%d\n", xevent.xmotion.x, xevent.xmotion.y);
   1.617 +                    printf ("X11 motion: %d,%d\n", xevent.xmotion.x,
   1.618 +                            xevent.xmotion.y);
   1.619  #endif
   1.620 -				posted = SDL_PrivateMouseMotion(0, 0,
   1.621 -						xevent.xmotion.x,
   1.622 -						xevent.xmotion.y);
   1.623 -			}
   1.624 -		}
   1.625 -	    }
   1.626 -	    break;
   1.627 +                    posted = SDL_PrivateMouseMotion (0, 0,
   1.628 +                                                     xevent.xmotion.x,
   1.629 +                                                     xevent.xmotion.y);
   1.630 +                }
   1.631 +            }
   1.632 +        }
   1.633 +        break;
   1.634  
   1.635 -	    /* Mouse button press? */
   1.636 -	    case ButtonPress: {
   1.637 -		posted = SDL_PrivateMouseButton(SDL_PRESSED, 
   1.638 -					xevent.xbutton.button, 0, 0);
   1.639 -	    }
   1.640 -	    break;
   1.641 +        /* Mouse button press? */
   1.642 +    case ButtonPress:
   1.643 +        {
   1.644 +            posted = SDL_PrivateMouseButton (SDL_PRESSED,
   1.645 +                                             xevent.xbutton.button, 0, 0);
   1.646 +        }
   1.647 +        break;
   1.648  
   1.649 -	    /* Mouse button release? */
   1.650 -	    case ButtonRelease: {
   1.651 -		posted = SDL_PrivateMouseButton(SDL_RELEASED, 
   1.652 -					xevent.xbutton.button, 0, 0);
   1.653 -	    }
   1.654 -	    break;
   1.655 +        /* Mouse button release? */
   1.656 +    case ButtonRelease:
   1.657 +        {
   1.658 +            posted = SDL_PrivateMouseButton (SDL_RELEASED,
   1.659 +                                             xevent.xbutton.button, 0, 0);
   1.660 +        }
   1.661 +        break;
   1.662  
   1.663 -	    /* Key press? */
   1.664 -	    case KeyPress: {
   1.665 -		static SDL_keysym saved_keysym;
   1.666 -		SDL_keysym keysym;
   1.667 -		KeyCode keycode = xevent.xkey.keycode;
   1.668 +        /* Key press? */
   1.669 +    case KeyPress:
   1.670 +        {
   1.671 +            static SDL_keysym saved_keysym;
   1.672 +            SDL_keysym keysym;
   1.673 +            KeyCode keycode = xevent.xkey.keycode;
   1.674  
   1.675  #ifdef DEBUG_XEVENTS
   1.676 -printf("KeyPress (X11 keycode = 0x%X)\n", xevent.xkey.keycode);
   1.677 +            printf ("KeyPress (X11 keycode = 0x%X)\n", xevent.xkey.keycode);
   1.678  #endif
   1.679 -		/* Get the translated SDL virtual keysym */
   1.680 -		if ( keycode ) {
   1.681 -			keysym.scancode = keycode;
   1.682 -			keysym.sym = X11_TranslateKeycode(SDL_Display, keycode);
   1.683 -			keysym.mod = KMOD_NONE;
   1.684 -			keysym.unicode = 0;
   1.685 -		} else {
   1.686 -			keysym = saved_keysym;
   1.687 -		}
   1.688 +            /* Get the translated SDL virtual keysym */
   1.689 +            if (keycode) {
   1.690 +                keysym.scancode = keycode;
   1.691 +                keysym.sym = X11_TranslateKeycode (SDL_Display, keycode);
   1.692 +                keysym.mod = KMOD_NONE;
   1.693 +                keysym.unicode = 0;
   1.694 +            } else {
   1.695 +                keysym = saved_keysym;
   1.696 +            }
   1.697  
   1.698 -		/* If we're not doing translation, we're done! */
   1.699 -		if ( !SDL_TranslateUNICODE ) {
   1.700 -			posted = SDL_PrivateKeyboard(SDL_PRESSED, &keysym);
   1.701 -			break;
   1.702 -		}
   1.703 +            /* If we're not doing translation, we're done! */
   1.704 +            if (!SDL_TranslateUNICODE) {
   1.705 +                posted = SDL_PrivateKeyboard (SDL_PRESSED, &keysym);
   1.706 +                break;
   1.707 +            }
   1.708  
   1.709 -		if ( XFilterEvent(&xevent, None) ) {
   1.710 -			if ( xevent.xkey.keycode ) {
   1.711 -				posted = SDL_PrivateKeyboard(SDL_PRESSED, &keysym);
   1.712 -			} else {
   1.713 -				/* Save event to be associated with IM text
   1.714 -				   In 1.3 we'll have a text event instead.. */
   1.715 -				saved_keysym = keysym;
   1.716 -			}
   1.717 -			break;
   1.718 -		}
   1.719 +            if (XFilterEvent (&xevent, None)) {
   1.720 +                if (xevent.xkey.keycode) {
   1.721 +                    posted = SDL_PrivateKeyboard (SDL_PRESSED, &keysym);
   1.722 +                } else {
   1.723 +                    /* Save event to be associated with IM text
   1.724 +                       In 1.3 we'll have a text event instead.. */
   1.725 +                    saved_keysym = keysym;
   1.726 +                }
   1.727 +                break;
   1.728 +            }
   1.729  
   1.730 -		/* Look up the translated value for the key event */
   1.731 +            /* Look up the translated value for the key event */
   1.732  #ifdef X_HAVE_UTF8_STRING
   1.733 -		if ( SDL_IC != NULL ) {
   1.734 -			static Status state;
   1.735 -			/* A UTF-8 character can be at most 6 bytes */
   1.736 -			char keybuf[6];
   1.737 -			if ( Xutf8LookupString(SDL_IC, &xevent.xkey,
   1.738 -			                        keybuf, sizeof(keybuf),
   1.739 -			                        NULL, &state) ) {
   1.740 -				keysym.unicode = Utf8ToUcs4((Uint8*)keybuf);
   1.741 -			}
   1.742 -		}
   1.743 -		else
   1.744 +            if (SDL_IC != NULL) {
   1.745 +                static Status state;
   1.746 +                /* A UTF-8 character can be at most 6 bytes */
   1.747 +                char keybuf[6];
   1.748 +                if (Xutf8LookupString (SDL_IC, &xevent.xkey,
   1.749 +                                       keybuf, sizeof (keybuf),
   1.750 +                                       NULL, &state)) {
   1.751 +                    keysym.unicode = Utf8ToUcs4 ((Uint8 *) keybuf);
   1.752 +                }
   1.753 +            } else
   1.754  #endif
   1.755 -		{
   1.756 -			static XComposeStatus state;
   1.757 -			char keybuf[32];
   1.758 +            {
   1.759 +                static XComposeStatus state;
   1.760 +                char keybuf[32];
   1.761  
   1.762 -			if ( XLookupString(&xevent.xkey,
   1.763 -			                    keybuf, sizeof(keybuf),
   1.764 -			                    NULL, &state) ) {
   1.765 -				/*
   1.766 -				* FIXME: XLookupString() may yield more than one
   1.767 -				* character, so we need a mechanism to allow for
   1.768 -				* this (perhaps null keypress events with a
   1.769 -				* unicode value)
   1.770 -				*/
   1.771 -				keysym.unicode = (Uint8)keybuf[0];
   1.772 -			}
   1.773 -		}
   1.774 -		posted = SDL_PrivateKeyboard(SDL_PRESSED, &keysym);
   1.775 -	    }
   1.776 -	    break;
   1.777 +                if (XLookupString (&xevent.xkey,
   1.778 +                                   keybuf, sizeof (keybuf), NULL, &state)) {
   1.779 +                    /*
   1.780 +                     * FIXME: XLookupString() may yield more than one
   1.781 +                     * character, so we need a mechanism to allow for
   1.782 +                     * this (perhaps null keypress events with a
   1.783 +                     * unicode value)
   1.784 +                     */
   1.785 +                    keysym.unicode = (Uint8) keybuf[0];
   1.786 +                }
   1.787 +            }
   1.788 +            posted = SDL_PrivateKeyboard (SDL_PRESSED, &keysym);
   1.789 +        }
   1.790 +        break;
   1.791  
   1.792 -	    /* Key release? */
   1.793 -	    case KeyRelease: {
   1.794 -		SDL_keysym keysym;
   1.795 -		KeyCode keycode = xevent.xkey.keycode;
   1.796 +        /* Key release? */
   1.797 +    case KeyRelease:
   1.798 +        {
   1.799 +            SDL_keysym keysym;
   1.800 +            KeyCode keycode = xevent.xkey.keycode;
   1.801  
   1.802  #ifdef DEBUG_XEVENTS
   1.803 -printf("KeyRelease (X11 keycode = 0x%X)\n", xevent.xkey.keycode);
   1.804 +            printf ("KeyRelease (X11 keycode = 0x%X)\n", xevent.xkey.keycode);
   1.805  #endif
   1.806 -		/* Check to see if this is a repeated key */
   1.807 -		if ( X11_KeyRepeat(SDL_Display, &xevent) ) {
   1.808 -			break;
   1.809 -		}
   1.810 +            /* Check to see if this is a repeated key */
   1.811 +            if (X11_KeyRepeat (SDL_Display, &xevent)) {
   1.812 +                break;
   1.813 +            }
   1.814  
   1.815 -		/* Get the translated SDL virtual keysym */
   1.816 -		keysym.scancode = keycode;
   1.817 -		keysym.sym = X11_TranslateKeycode(SDL_Display, keycode);
   1.818 -		keysym.mod = KMOD_NONE;
   1.819 -		keysym.unicode = 0;
   1.820 +            /* Get the translated SDL virtual keysym */
   1.821 +            keysym.scancode = keycode;
   1.822 +            keysym.sym = X11_TranslateKeycode (SDL_Display, keycode);
   1.823 +            keysym.mod = KMOD_NONE;
   1.824 +            keysym.unicode = 0;
   1.825  
   1.826 -		posted = SDL_PrivateKeyboard(SDL_RELEASED, &keysym);
   1.827 -	    }
   1.828 -	    break;
   1.829 +            posted = SDL_PrivateKeyboard (SDL_RELEASED, &keysym);
   1.830 +        }
   1.831 +        break;
   1.832  
   1.833 -	    /* Have we been iconified? */
   1.834 -	    case UnmapNotify: {
   1.835 +        /* Have we been iconified? */
   1.836 +    case UnmapNotify:
   1.837 +        {
   1.838  #ifdef DEBUG_XEVENTS
   1.839 -printf("UnmapNotify!\n");
   1.840 +            printf ("UnmapNotify!\n");
   1.841  #endif
   1.842 -		/* If we're active, make ourselves inactive */
   1.843 -		if ( SDL_GetAppState() & SDL_APPACTIVE ) {
   1.844 -			/* Swap out the gamma before we go inactive */
   1.845 -			X11_SwapVidModeGamma(this);
   1.846 +            /* If we're active, make ourselves inactive */
   1.847 +            if (SDL_GetAppState () & SDL_APPACTIVE) {
   1.848 +                /* Swap out the gamma before we go inactive */
   1.849 +                X11_SwapVidModeGamma (_this);
   1.850  
   1.851 -			/* Send an internal deactivate event */
   1.852 -			posted = SDL_PrivateAppActive(0,
   1.853 -					SDL_APPACTIVE|SDL_APPINPUTFOCUS);
   1.854 -		}
   1.855 -	    }
   1.856 -	    break;
   1.857 +                /* Send an internal deactivate event */
   1.858 +                posted = SDL_PrivateAppActive (0,
   1.859 +                                               SDL_APPACTIVE |
   1.860 +                                               SDL_APPINPUTFOCUS);
   1.861 +            }
   1.862 +        }
   1.863 +        break;
   1.864  
   1.865 -	    /* Have we been restored? */
   1.866 -	    case MapNotify: {
   1.867 +        /* Have we been restored? */
   1.868 +    case MapNotify:
   1.869 +        {
   1.870  #ifdef DEBUG_XEVENTS
   1.871 -printf("MapNotify!\n");
   1.872 +            printf ("MapNotify!\n");
   1.873  #endif
   1.874 -		/* If we're not active, make ourselves active */
   1.875 -		if ( !(SDL_GetAppState() & SDL_APPACTIVE) ) {
   1.876 -			/* Send an internal activate event */
   1.877 -			posted = SDL_PrivateAppActive(1, SDL_APPACTIVE);
   1.878 +            /* If we're not active, make ourselves active */
   1.879 +            if (!(SDL_GetAppState () & SDL_APPACTIVE)) {
   1.880 +                /* Send an internal activate event */
   1.881 +                posted = SDL_PrivateAppActive (1, SDL_APPACTIVE);
   1.882  
   1.883 -			/* Now that we're active, swap the gamma back */
   1.884 -			X11_SwapVidModeGamma(this);
   1.885 -		}
   1.886 +                /* Now that we're active, swap the gamma back */
   1.887 +                X11_SwapVidModeGamma (_this);
   1.888 +            }
   1.889  
   1.890 -		if ( SDL_VideoSurface &&
   1.891 -		     (SDL_VideoSurface->flags & SDL_FULLSCREEN) ) {
   1.892 -			X11_EnterFullScreen(this);
   1.893 -		} else {
   1.894 -			X11_GrabInputNoLock(this, this->input_grab);
   1.895 -		}
   1.896 -		X11_CheckMouseModeNoLock(this);
   1.897 +            if (SDL_VideoSurface &&
   1.898 +                (SDL_VideoSurface->flags & SDL_FULLSCREEN)) {
   1.899 +                X11_EnterFullScreen (_this);
   1.900 +            } else {
   1.901 +                X11_GrabInputNoLock (_this, SDL_CurrentWindow.input_grab);
   1.902 +            }
   1.903 +            X11_CheckMouseModeNoLock (_this);
   1.904  
   1.905 -		if ( SDL_VideoSurface ) {
   1.906 -			X11_RefreshDisplay(this);
   1.907 -		}
   1.908 -	    }
   1.909 -	    break;
   1.910 +            if (SDL_VideoSurface) {
   1.911 +                X11_RefreshDisplay (_this);
   1.912 +            }
   1.913 +        }
   1.914 +        break;
   1.915  
   1.916 -	    /* Have we been resized or moved? */
   1.917 -	    case ConfigureNotify: {
   1.918 +        /* Have we been resized or moved? */
   1.919 +    case ConfigureNotify:
   1.920 +        {
   1.921  #ifdef DEBUG_XEVENTS
   1.922 -printf("ConfigureNotify! (resize: %dx%d)\n", xevent.xconfigure.width, xevent.xconfigure.height);
   1.923 +            printf ("ConfigureNotify! (resize: %dx%d)\n",
   1.924 +                    xevent.xconfigure.width, xevent.xconfigure.height);
   1.925  #endif
   1.926 -		if ( SDL_VideoSurface ) {
   1.927 -		    if ((xevent.xconfigure.width != SDL_VideoSurface->w) ||
   1.928 -		        (xevent.xconfigure.height != SDL_VideoSurface->h)) {
   1.929 -			/* FIXME: Find a better fix for the bug with KDE 1.2 */
   1.930 -			if ( ! ((xevent.xconfigure.width == 32) &&
   1.931 -			        (xevent.xconfigure.height == 32)) ) {
   1.932 -				SDL_PrivateResize(xevent.xconfigure.width,
   1.933 -				                  xevent.xconfigure.height);
   1.934 -			}
   1.935 -		    } else {
   1.936 -			/* OpenGL windows need to know about the change */
   1.937 -			if ( SDL_VideoSurface->flags & SDL_INTERNALOPENGL ) {
   1.938 -				SDL_PrivateExpose();
   1.939 -			}
   1.940 -		    }
   1.941 -		}
   1.942 -	    }
   1.943 -	    break;
   1.944 +            if (SDL_VideoSurface) {
   1.945 +                if ((xevent.xconfigure.width != SDL_VideoSurface->w) ||
   1.946 +                    (xevent.xconfigure.height != SDL_VideoSurface->h)) {
   1.947 +                    /* FIXME: Find a better fix for the bug with KDE 1.2 */
   1.948 +                    if (!((xevent.xconfigure.width == 32) &&
   1.949 +                          (xevent.xconfigure.height == 32))) {
   1.950 +                        SDL_PrivateResize (xevent.xconfigure.width,
   1.951 +                                           xevent.xconfigure.height);
   1.952 +                    }
   1.953 +                } else {
   1.954 +                    /* OpenGL windows need to know about the change */
   1.955 +                    if (SDL_VideoSurface->flags & SDL_INTERNALOPENGL) {
   1.956 +                        SDL_PrivateExpose ();
   1.957 +                    }
   1.958 +                }
   1.959 +            }
   1.960 +        }
   1.961 +        break;
   1.962  
   1.963 -	    /* Have we been requested to quit (or another client message?) */
   1.964 -	    case ClientMessage: {
   1.965 -		if ( (xevent.xclient.format == 32) &&
   1.966 -		     (xevent.xclient.data.l[0] == WM_DELETE_WINDOW) )
   1.967 -		{
   1.968 -			posted = SDL_PrivateQuit();
   1.969 -		} else
   1.970 -		if ( SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE ) {
   1.971 -			SDL_SysWMmsg wmmsg;
   1.972 +        /* Have we been requested to quit (or another client message?) */
   1.973 +    case ClientMessage:
   1.974 +        {
   1.975 +            if ((xevent.xclient.format == 32) &&
   1.976 +                (xevent.xclient.data.l[0] == WM_DELETE_WINDOW)) {
   1.977 +                posted = SDL_PrivateQuit ();
   1.978 +            } else if (SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE) {
   1.979 +                SDL_SysWMmsg wmmsg;
   1.980  
   1.981 -			SDL_VERSION(&wmmsg.version);
   1.982 -			wmmsg.subsystem = SDL_SYSWM_X11;
   1.983 -			wmmsg.event.xevent = xevent;
   1.984 -			posted = SDL_PrivateSysWMEvent(&wmmsg);
   1.985 -		}
   1.986 -	    }
   1.987 -	    break;
   1.988 +                SDL_VERSION (&wmmsg.version);
   1.989 +                wmmsg.subsystem = SDL_SYSWM_X11;
   1.990 +                wmmsg.event.xevent = xevent;
   1.991 +                posted = SDL_PrivateSysWMEvent (&wmmsg);
   1.992 +            }
   1.993 +        }
   1.994 +        break;
   1.995  
   1.996 -	    /* Do we need to refresh ourselves? */
   1.997 -	    case Expose: {
   1.998 +        /* Do we need to refresh ourselves? */
   1.999 +    case Expose:
  1.1000 +        {
  1.1001  #ifdef DEBUG_XEVENTS
  1.1002 -printf("Expose (count = %d)\n", xevent.xexpose.count);
  1.1003 +            printf ("Expose (count = %d)\n", xevent.xexpose.count);
  1.1004  #endif
  1.1005 -		if ( SDL_VideoSurface && (xevent.xexpose.count == 0) ) {
  1.1006 -			X11_RefreshDisplay(this);
  1.1007 -		}
  1.1008 -	    }
  1.1009 -	    break;
  1.1010 +            if (SDL_VideoSurface && (xevent.xexpose.count == 0)) {
  1.1011 +                X11_RefreshDisplay (_this);
  1.1012 +            }
  1.1013 +        }
  1.1014 +        break;
  1.1015  
  1.1016 -	    default: {
  1.1017 +    default:
  1.1018 +        {
  1.1019  #ifdef DEBUG_XEVENTS
  1.1020 -printf("Unhandled event %d\n", xevent.type);
  1.1021 +            printf ("Unhandled event %d\n", xevent.type);
  1.1022  #endif
  1.1023 -		/* Only post the event if we're watching for it */
  1.1024 -		if ( SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE ) {
  1.1025 -			SDL_SysWMmsg wmmsg;
  1.1026 +            /* Only post the event if we're watching for it */
  1.1027 +            if (SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE) {
  1.1028 +                SDL_SysWMmsg wmmsg;
  1.1029  
  1.1030 -			SDL_VERSION(&wmmsg.version);
  1.1031 -			wmmsg.subsystem = SDL_SYSWM_X11;
  1.1032 -			wmmsg.event.xevent = xevent;
  1.1033 -			posted = SDL_PrivateSysWMEvent(&wmmsg);
  1.1034 -		}
  1.1035 -	    }
  1.1036 -	    break;
  1.1037 -	}
  1.1038 -	return(posted);
  1.1039 +                SDL_VERSION (&wmmsg.version);
  1.1040 +                wmmsg.subsystem = SDL_SYSWM_X11;
  1.1041 +                wmmsg.event.xevent = xevent;
  1.1042 +                posted = SDL_PrivateSysWMEvent (&wmmsg);
  1.1043 +            }
  1.1044 +        }
  1.1045 +        break;
  1.1046 +    }
  1.1047 +    return (posted);
  1.1048  }
  1.1049  
  1.1050  /* Ack!  XPending() actually performs a blocking read if no events available */
  1.1051 -int X11_Pending(Display *display)
  1.1052 +int
  1.1053 +X11_Pending (Display * display)
  1.1054  {
  1.1055 -	/* Flush the display connection and look to see if events are queued */
  1.1056 -	XFlush(display);
  1.1057 -	if ( XEventsQueued(display, QueuedAlready) ) {
  1.1058 -		return(1);
  1.1059 -	}
  1.1060 +    /* Flush the display connection and look to see if events are queued */
  1.1061 +    XFlush (display);
  1.1062 +    if (XEventsQueued (display, QueuedAlready)) {
  1.1063 +        return (1);
  1.1064 +    }
  1.1065  
  1.1066 -	/* More drastic measures are required -- see if X is ready to talk */
  1.1067 -	{
  1.1068 -		static struct timeval zero_time;	/* static == 0 */
  1.1069 -		int x11_fd;
  1.1070 -		fd_set fdset;
  1.1071 +    /* More drastic measures are required -- see if X is ready to talk */
  1.1072 +    {
  1.1073 +        static struct timeval zero_time;        /* static == 0 */
  1.1074 +        int x11_fd;
  1.1075 +        fd_set fdset;
  1.1076  
  1.1077 -		x11_fd = ConnectionNumber(display);
  1.1078 -		FD_ZERO(&fdset);
  1.1079 -		FD_SET(x11_fd, &fdset);
  1.1080 -		if ( select(x11_fd+1, &fdset, NULL, NULL, &zero_time) == 1 ) {
  1.1081 -			return(XPending(display));
  1.1082 -		}
  1.1083 -	}
  1.1084 +        x11_fd = ConnectionNumber (display);
  1.1085 +        FD_ZERO (&fdset);
  1.1086 +        FD_SET (x11_fd, &fdset);
  1.1087 +        if (select (x11_fd + 1, &fdset, NULL, NULL, &zero_time) == 1) {
  1.1088 +            return (XPending (display));
  1.1089 +        }
  1.1090 +    }
  1.1091  
  1.1092 -	/* Oh well, nothing is ready .. */
  1.1093 -	return(0);
  1.1094 +    /* Oh well, nothing is ready .. */
  1.1095 +    return (0);
  1.1096  }
  1.1097  
  1.1098 -void X11_PumpEvents(_THIS)
  1.1099 +void
  1.1100 +X11_PumpEvents (_THIS)
  1.1101  {
  1.1102 -	int pending;
  1.1103 +    int pending;
  1.1104  
  1.1105 -	/* Keep processing pending events */
  1.1106 -	pending = 0;
  1.1107 -	while ( X11_Pending(SDL_Display) ) {
  1.1108 -		X11_DispatchEvent(this);
  1.1109 -		++pending;
  1.1110 -	}
  1.1111 -	if ( switch_waiting ) {
  1.1112 -		Uint32 now;
  1.1113 +    /* Keep processing pending events */
  1.1114 +    pending = 0;
  1.1115 +    while (X11_Pending (SDL_Display)) {
  1.1116 +        X11_DispatchEvent (_this);
  1.1117 +        ++pending;
  1.1118 +    }
  1.1119 +    if (switch_waiting) {
  1.1120 +        Uint32 now;
  1.1121  
  1.1122 -		now  = SDL_GetTicks();
  1.1123 -		if ( pending || !SDL_VideoSurface ) {
  1.1124 -			/* Try again later... */
  1.1125 -			if ( switch_waiting & SDL_FULLSCREEN ) {
  1.1126 -				switch_time = now + 1500;
  1.1127 -			} else {
  1.1128 -				switch_time = now + 200;
  1.1129 -			}
  1.1130 -		} else if ( (int)(switch_time-now) <= 0 ) {
  1.1131 -			Uint32 go_fullscreen;
  1.1132 +        now = SDL_GetTicks ();
  1.1133 +        if (pending || !SDL_VideoSurface) {
  1.1134 +            /* Try again later... */
  1.1135 +            if (switch_waiting & SDL_FULLSCREEN) {
  1.1136 +                switch_time = now + 1500;
  1.1137 +            } else {
  1.1138 +                switch_time = now + 200;
  1.1139 +            }
  1.1140 +        } else if ((int) (switch_time - now) <= 0) {
  1.1141 +            Uint32 go_fullscreen;
  1.1142  
  1.1143 -			go_fullscreen = switch_waiting & SDL_FULLSCREEN;
  1.1144 -			switch_waiting = 0;
  1.1145 -			if ( SDL_VideoSurface->flags & SDL_FULLSCREEN ) {
  1.1146 -				if ( go_fullscreen ) {
  1.1147 -					X11_EnterFullScreen(this);
  1.1148 -				} else {
  1.1149 -					X11_LeaveFullScreen(this);
  1.1150 -				}
  1.1151 -			}
  1.1152 -			/* Handle focus in/out when grabbed */
  1.1153 -			if ( go_fullscreen ) {
  1.1154 -				X11_GrabInputNoLock(this, this->input_grab);
  1.1155 -			} else {
  1.1156 -				X11_GrabInputNoLock(this, SDL_GRAB_OFF);
  1.1157 -			}
  1.1158 -			X11_CheckMouseModeNoLock(this);
  1.1159 -		}
  1.1160 -	}
  1.1161 +            go_fullscreen = switch_waiting & SDL_FULLSCREEN;
  1.1162 +            switch_waiting = 0;
  1.1163 +            if (SDL_VideoSurface->flags & SDL_FULLSCREEN) {
  1.1164 +                if (go_fullscreen) {
  1.1165 +                    X11_EnterFullScreen (_this);
  1.1166 +                } else {
  1.1167 +                    X11_LeaveFullScreen (_this);
  1.1168 +                }
  1.1169 +            }
  1.1170 +            /* Handle focus in/out when grabbed */
  1.1171 +            if (go_fullscreen) {
  1.1172 +                X11_GrabInputNoLock (_this, SDL_CurrentWindow.input_grab);
  1.1173 +            } else {
  1.1174 +                X11_GrabInputNoLock (_this, SDL_GRAB_OFF);
  1.1175 +            }
  1.1176 +            X11_CheckMouseModeNoLock (_this);
  1.1177 +        }
  1.1178 +    }
  1.1179  }
  1.1180  
  1.1181 -void X11_InitKeymap(void)
  1.1182 +void
  1.1183 +X11_InitKeymap (void)
  1.1184  {
  1.1185 -	int i;
  1.1186 +    int i;
  1.1187  
  1.1188 -	/* Odd keys used in international keyboards */
  1.1189 -	for ( i=0; i<SDL_arraysize(ODD_keymap); ++i )
  1.1190 -		ODD_keymap[i] = SDLK_UNKNOWN;
  1.1191 +    /* Odd keys used in international keyboards */
  1.1192 +    for (i = 0; i < SDL_arraysize (ODD_keymap); ++i)
  1.1193 +        ODD_keymap[i] = SDLK_UNKNOWN;
  1.1194  
  1.1195 - 	/* Some of these might be mappable to an existing SDLK_ code */
  1.1196 - 	ODD_keymap[XK_dead_grave&0xFF] = SDLK_COMPOSE;
  1.1197 - 	ODD_keymap[XK_dead_acute&0xFF] = SDLK_COMPOSE;
  1.1198 - 	ODD_keymap[XK_dead_tilde&0xFF] = SDLK_COMPOSE;
  1.1199 - 	ODD_keymap[XK_dead_macron&0xFF] = SDLK_COMPOSE;
  1.1200 - 	ODD_keymap[XK_dead_breve&0xFF] = SDLK_COMPOSE;
  1.1201 - 	ODD_keymap[XK_dead_abovedot&0xFF] = SDLK_COMPOSE;
  1.1202 - 	ODD_keymap[XK_dead_diaeresis&0xFF] = SDLK_COMPOSE;
  1.1203 - 	ODD_keymap[XK_dead_abovering&0xFF] = SDLK_COMPOSE;
  1.1204 - 	ODD_keymap[XK_dead_doubleacute&0xFF] = SDLK_COMPOSE;
  1.1205 - 	ODD_keymap[XK_dead_caron&0xFF] = SDLK_COMPOSE;
  1.1206 - 	ODD_keymap[XK_dead_cedilla&0xFF] = SDLK_COMPOSE;
  1.1207 - 	ODD_keymap[XK_dead_ogonek&0xFF] = SDLK_COMPOSE;
  1.1208 - 	ODD_keymap[XK_dead_iota&0xFF] = SDLK_COMPOSE;
  1.1209 - 	ODD_keymap[XK_dead_voiced_sound&0xFF] = SDLK_COMPOSE;
  1.1210 - 	ODD_keymap[XK_dead_semivoiced_sound&0xFF] = SDLK_COMPOSE;
  1.1211 - 	ODD_keymap[XK_dead_belowdot&0xFF] = SDLK_COMPOSE;
  1.1212 +    /* Some of these might be mappable to an existing SDLK_ code */
  1.1213 +    ODD_keymap[XK_dead_grave & 0xFF] = SDLK_COMPOSE;
  1.1214 +    ODD_keymap[XK_dead_acute & 0xFF] = SDLK_COMPOSE;
  1.1215 +    ODD_keymap[XK_dead_tilde & 0xFF] = SDLK_COMPOSE;
  1.1216 +    ODD_keymap[XK_dead_macron & 0xFF] = SDLK_COMPOSE;
  1.1217 +    ODD_keymap[XK_dead_breve & 0xFF] = SDLK_COMPOSE;
  1.1218 +    ODD_keymap[XK_dead_abovedot & 0xFF] = SDLK_COMPOSE;
  1.1219 +    ODD_keymap[XK_dead_diaeresis & 0xFF] = SDLK_COMPOSE;
  1.1220 +    ODD_keymap[XK_dead_abovering & 0xFF] = SDLK_COMPOSE;
  1.1221 +    ODD_keymap[XK_dead_doubleacute & 0xFF] = SDLK_COMPOSE;
  1.1222 +    ODD_keymap[XK_dead_caron & 0xFF] = SDLK_COMPOSE;
  1.1223 +    ODD_keymap[XK_dead_cedilla & 0xFF] = SDLK_COMPOSE;
  1.1224 +    ODD_keymap[XK_dead_ogonek & 0xFF] = SDLK_COMPOSE;
  1.1225 +    ODD_keymap[XK_dead_iota & 0xFF] = SDLK_COMPOSE;
  1.1226 +    ODD_keymap[XK_dead_voiced_sound & 0xFF] = SDLK_COMPOSE;
  1.1227 +    ODD_keymap[XK_dead_semivoiced_sound & 0xFF] = SDLK_COMPOSE;
  1.1228 +    ODD_keymap[XK_dead_belowdot & 0xFF] = SDLK_COMPOSE;
  1.1229  #ifdef XK_dead_hook
  1.1230 - 	ODD_keymap[XK_dead_hook&0xFF] = SDLK_COMPOSE;
  1.1231 +    ODD_keymap[XK_dead_hook & 0xFF] = SDLK_COMPOSE;
  1.1232  #endif
  1.1233  #ifdef XK_dead_horn
  1.1234 - 	ODD_keymap[XK_dead_horn&0xFF] = SDLK_COMPOSE;
  1.1235 +    ODD_keymap[XK_dead_horn & 0xFF] = SDLK_COMPOSE;
  1.1236  #endif
  1.1237  
  1.1238  #ifdef XK_dead_circumflex
  1.1239 -	/* These X keysyms have 0xFE as the high byte */
  1.1240 -	ODD_keymap[XK_dead_circumflex&0xFF] = SDLK_CARET;
  1.1241 +    /* These X keysyms have 0xFE as the high byte */
  1.1242 +    ODD_keymap[XK_dead_circumflex & 0xFF] = SDLK_CARET;
  1.1243  #endif
  1.1244  #ifdef XK_ISO_Level3_Shift
  1.1245 -	ODD_keymap[XK_ISO_Level3_Shift&0xFF] = SDLK_MODE; /* "Alt Gr" key */
  1.1246 +    ODD_keymap[XK_ISO_Level3_Shift & 0xFF] = SDLK_MODE; /* "Alt Gr" key */
  1.1247  #endif
  1.1248  
  1.1249 -	/* Map the miscellaneous keys */
  1.1250 -	for ( i=0; i<SDL_arraysize(MISC_keymap); ++i )
  1.1251 -		MISC_keymap[i] = SDLK_UNKNOWN;
  1.1252 +    /* Map the miscellaneous keys */
  1.1253 +    for (i = 0; i < SDL_arraysize (MISC_keymap); ++i)
  1.1254 +        MISC_keymap[i] = SDLK_UNKNOWN;
  1.1255  
  1.1256 -	/* These X keysyms have 0xFF as the high byte */
  1.1257 -	MISC_keymap[XK_BackSpace&0xFF] = SDLK_BACKSPACE;
  1.1258 -	MISC_keymap[XK_Tab&0xFF] = SDLK_TAB;
  1.1259 -	MISC_keymap[XK_Clear&0xFF] = SDLK_CLEAR;
  1.1260 -	MISC_keymap[XK_Return&0xFF] = SDLK_RETURN;
  1.1261 -	MISC_keymap[XK_Pause&0xFF] = SDLK_PAUSE;
  1.1262 -	MISC_keymap[XK_Escape&0xFF] = SDLK_ESCAPE;
  1.1263 -	MISC_keymap[XK_Delete&0xFF] = SDLK_DELETE;
  1.1264 +    /* These X keysyms have 0xFF as the high byte */
  1.1265 +    MISC_keymap[XK_BackSpace & 0xFF] = SDLK_BACKSPACE;
  1.1266 +    MISC_keymap[XK_Tab & 0xFF] = SDLK_TAB;
  1.1267 +    MISC_keymap[XK_Clear & 0xFF] = SDLK_CLEAR;
  1.1268 +    MISC_keymap[XK_Return & 0xFF] = SDLK_RETURN;
  1.1269 +    MISC_keymap[XK_Pause & 0xFF] = SDLK_PAUSE;
  1.1270 +    MISC_keymap[XK_Escape & 0xFF] = SDLK_ESCAPE;
  1.1271 +    MISC_keymap[XK_Delete & 0xFF] = SDLK_DELETE;
  1.1272  
  1.1273 -	MISC_keymap[XK_KP_0&0xFF] = SDLK_KP0;		/* Keypad 0-9 */
  1.1274 -	MISC_keymap[XK_KP_1&0xFF] = SDLK_KP1;
  1.1275 -	MISC_keymap[XK_KP_2&0xFF] = SDLK_KP2;
  1.1276 -	MISC_keymap[XK_KP_3&0xFF] = SDLK_KP3;
  1.1277 -	MISC_keymap[XK_KP_4&0xFF] = SDLK_KP4;
  1.1278 -	MISC_keymap[XK_KP_5&0xFF] = SDLK_KP5;
  1.1279 -	MISC_keymap[XK_KP_6&0xFF] = SDLK_KP6;
  1.1280 -	MISC_keymap[XK_KP_7&0xFF] = SDLK_KP7;
  1.1281 -	MISC_keymap[XK_KP_8&0xFF] = SDLK_KP8;
  1.1282 -	MISC_keymap[XK_KP_9&0xFF] = SDLK_KP9;
  1.1283 -	MISC_keymap[XK_KP_Insert&0xFF] = SDLK_KP0;
  1.1284 -	MISC_keymap[XK_KP_End&0xFF] = SDLK_KP1;	
  1.1285 -	MISC_keymap[XK_KP_Down&0xFF] = SDLK_KP2;
  1.1286 -	MISC_keymap[XK_KP_Page_Down&0xFF] = SDLK_KP3;
  1.1287 -	MISC_keymap[XK_KP_Left&0xFF] = SDLK_KP4;
  1.1288 -	MISC_keymap[XK_KP_Begin&0xFF] = SDLK_KP5;
  1.1289 -	MISC_keymap[XK_KP_Right&0xFF] = SDLK_KP6;
  1.1290 -	MISC_keymap[XK_KP_Home&0xFF] = SDLK_KP7;
  1.1291 -	MISC_keymap[XK_KP_Up&0xFF] = SDLK_KP8;
  1.1292 -	MISC_keymap[XK_KP_Page_Up&0xFF] = SDLK_KP9;
  1.1293 -	MISC_keymap[XK_KP_Delete&0xFF] = SDLK_KP_PERIOD;
  1.1294 -	MISC_keymap[XK_KP_Decimal&0xFF] = SDLK_KP_PERIOD;
  1.1295 -	MISC_keymap[XK_KP_Divide&0xFF] = SDLK_KP_DIVIDE;
  1.1296 -	MISC_keymap[XK_KP_Multiply&0xFF] = SDLK_KP_MULTIPLY;
  1.1297 -	MISC_keymap[XK_KP_Subtract&0xFF] = SDLK_KP_MINUS;
  1.1298 -	MISC_keymap[XK_KP_Add&0xFF] = SDLK_KP_PLUS;
  1.1299 -	MISC_keymap[XK_KP_Enter&0xFF] = SDLK_KP_ENTER;
  1.1300 -	MISC_keymap[XK_KP_Equal&0xFF] = SDLK_KP_EQUALS;
  1.1301 +    MISC_keymap[XK_KP_0 & 0xFF] = SDLK_KP0;     /* Keypad 0-9 */
  1.1302 +    MISC_keymap[XK_KP_1 & 0xFF] = SDLK_KP1;
  1.1303 +    MISC_keymap[XK_KP_2 & 0xFF] = SDLK_KP2;
  1.1304 +    MISC_keymap[XK_KP_3 & 0xFF] = SDLK_KP3;
  1.1305 +    MISC_keymap[XK_KP_4 & 0xFF] = SDLK_KP4;
  1.1306 +    MISC_keymap[XK_KP_5 & 0xFF] = SDLK_KP5;
  1.1307 +    MISC_keymap[XK_KP_6 & 0xFF] = SDLK_KP6;
  1.1308 +    MISC_keymap[XK_KP_7 & 0xFF] = SDLK_KP7;
  1.1309 +    MISC_keymap[XK_KP_8 & 0xFF] = SDLK_KP8;
  1.1310 +    MISC_keymap[XK_KP_9 & 0xFF] = SDLK_KP9;
  1.1311 +    MISC_keymap[XK_KP_Insert & 0xFF] = SDLK_KP0;
  1.1312 +    MISC_keymap[XK_KP_End & 0xFF] = SDLK_KP1;
  1.1313 +    MISC_keymap[XK_KP_Down & 0xFF] = SDLK_KP2;
  1.1314 +    MISC_keymap[XK_KP_Page_Down & 0xFF] = SDLK_KP3;
  1.1315 +    MISC_keymap[XK_KP_Left & 0xFF] = SDLK_KP4;
  1.1316 +    MISC_keymap[XK_KP_Begin & 0xFF] = SDLK_KP5;
  1.1317 +    MISC_keymap[XK_KP_Right & 0xFF] = SDLK_KP6;
  1.1318 +    MISC_keymap[XK_KP_Home & 0xFF] = SDLK_KP7;
  1.1319 +    MISC_keymap[XK_KP_Up & 0xFF] = SDLK_KP8;
  1.1320 +    MISC_keymap[XK_KP_Page_Up & 0xFF] = SDLK_KP9;
  1.1321 +    MISC_keymap[XK_KP_Delete & 0xFF] = SDLK_KP_PERIOD;
  1.1322 +    MISC_keymap[XK_KP_Decimal & 0xFF] = SDLK_KP_PERIOD;
  1.1323 +    MISC_keymap[XK_KP_Divide & 0xFF] = SDLK_KP_DIVIDE;
  1.1324 +    MISC_keymap[XK_KP_Multiply & 0xFF] = SDLK_KP_MULTIPLY;
  1.1325 +    MISC_keymap[XK_KP_Subtract & 0xFF] = SDLK_KP_MINUS;
  1.1326 +    MISC_keymap[XK_KP_Add & 0xFF] = SDLK_KP_PLUS;
  1.1327 +    MISC_keymap[XK_KP_Enter & 0xFF] = SDLK_KP_ENTER;
  1.1328 +    MISC_keymap[XK_KP_Equal & 0xFF] = SDLK_KP_EQUALS;
  1.1329  
  1.1330 -	MISC_keymap[XK_Up&0xFF] = SDLK_UP;
  1.1331 -	MISC_keymap[XK_Down&0xFF] = SDLK_DOWN;
  1.1332 -	MISC_keymap[XK_Right&0xFF] = SDLK_RIGHT;
  1.1333 -	MISC_keymap[XK_Left&0xFF] = SDLK_LEFT;
  1.1334 -	MISC_keymap[XK_Insert&0xFF] = SDLK_INSERT;
  1.1335 -	MISC_keymap[XK_Home&0xFF] = SDLK_HOME;
  1.1336 -	MISC_keymap[XK_End&0xFF] = SDLK_END;
  1.1337 -	MISC_keymap[XK_Page_Up&0xFF] = SDLK_PAGEUP;
  1.1338 -	MISC_keymap[XK_Page_Down&0xFF] = SDLK_PAGEDOWN;
  1.1339 +    MISC_keymap[XK_Up & 0xFF] = SDLK_UP;
  1.1340 +    MISC_keymap[XK_Down & 0xFF] = SDLK_DOWN;
  1.1341 +    MISC_keymap[XK_Right & 0xFF] = SDLK_RIGHT;
  1.1342 +    MISC_keymap[XK_Left & 0xFF] = SDLK_LEFT;
  1.1343 +    MISC_keymap[XK_Insert & 0xFF] = SDLK_INSERT;
  1.1344 +    MISC_keymap[XK_Home & 0xFF] = SDLK_HOME;
  1.1345 +    MISC_keymap[XK_End & 0xFF] = SDLK_END;
  1.1346 +    MISC_keymap[XK_Page_Up & 0xFF] = SDLK_PAGEUP;
  1.1347 +    MISC_keymap[XK_Page_Down & 0xFF] = SDLK_PAGEDOWN;
  1.1348  
  1.1349 -	MISC_keymap[XK_F1&0xFF] = SDLK_F1;
  1.1350 -	MISC_keymap[XK_F2&0xFF] = SDLK_F2;
  1.1351 -	MISC_keymap[XK_F3&0xFF] = SDLK_F3;
  1.1352 -	MISC_keymap[XK_F4&0xFF] = SDLK_F4;
  1.1353 -	MISC_keymap[XK_F5&0xFF] = SDLK_F5;
  1.1354 -	MISC_keymap[XK_F6&0xFF] = SDLK_F6;
  1.1355 -	MISC_keymap[XK_F7&0xFF] = SDLK_F7;
  1.1356 -	MISC_keymap[XK_F8&0xFF] = SDLK_F8;
  1.1357 -	MISC_keymap[XK_F9&0xFF] = SDLK_F9;
  1.1358 -	MISC_keymap[XK_F10&0xFF] = SDLK_F10;
  1.1359 -	MISC_keymap[XK_F11&0xFF] = SDLK_F11;
  1.1360 -	MISC_keymap[XK_F12&0xFF] = SDLK_F12;
  1.1361 -	MISC_keymap[XK_F13&0xFF] = SDLK_F13;
  1.1362 -	MISC_keymap[XK_F14&0xFF] = SDLK_F14;
  1.1363 -	MISC_keymap[XK_F15&0xFF] = SDLK_F15;
  1.1364 +    MISC_keymap[XK_F1 & 0xFF] = SDLK_F1;
  1.1365 +    MISC_keymap[XK_F2 & 0xFF] = SDLK_F2;
  1.1366 +    MISC_keymap[XK_F3 & 0xFF] = SDLK_F3;
  1.1367 +    MISC_keymap[XK_F4 & 0xFF] = SDLK_F4;
  1.1368 +    MISC_keymap[XK_F5 & 0xFF] = SDLK_F5;
  1.1369 +    MISC_keymap[XK_F6 & 0xFF] = SDLK_F6;
  1.1370 +    MISC_keymap[XK_F7 & 0xFF] = SDLK_F7;
  1.1371 +    MISC_keymap[XK_F8 & 0xFF] = SDLK_F8;
  1.1372 +    MISC_keymap[XK_F9 & 0xFF] = SDLK_F9;
  1.1373 +    MISC_keymap[XK_F10 & 0xFF] = SDLK_F10;
  1.1374 +    MISC_keymap[XK_F11 & 0xFF] = SDLK_F11;
  1.1375 +    MISC_keymap[XK_F12 & 0xFF] = SDLK_F12;
  1.1376 +    MISC_keymap[XK_F13 & 0xFF] = SDLK_F13;
  1.1377 +    MISC_keymap[XK_F14 & 0xFF] = SDLK_F14;
  1.1378 +    MISC_keymap[XK_F15 & 0xFF] = SDLK_F15;
  1.1379  
  1.1380 -	MISC_keymap[XK_Num_Lock&0xFF] = SDLK_NUMLOCK;
  1.1381 -	MISC_keymap[XK_Caps_Lock&0xFF] = SDLK_CAPSLOCK;
  1.1382 -	MISC_keymap[XK_Scroll_Lock&0xFF] = SDLK_SCROLLOCK;
  1.1383 -	MISC_keymap[XK_Shift_R&0xFF] = SDLK_RSHIFT;
  1.1384 -	MISC_keymap[XK_Shift_L&0xFF] = SDLK_LSHIFT;
  1.1385 -	MISC_keymap[XK_Control_R&0xFF] = SDLK_RCTRL;
  1.1386 -	MISC_keymap[XK_Control_L&0xFF] = SDLK_LCTRL;
  1.1387 -	MISC_keymap[XK_Alt_R&0xFF] = SDLK_RALT;
  1.1388 -	MISC_keymap[XK_Alt_L&0xFF] = SDLK_LALT;
  1.1389 -	MISC_keymap[XK_Meta_R&0xFF] = SDLK_RMETA;
  1.1390 -	MISC_keymap[XK_Meta_L&0xFF] = SDLK_LMETA;
  1.1391 -	MISC_keymap[XK_Super_L&0xFF] = SDLK_LSUPER; /* Left "Windows" */
  1.1392 -	MISC_keymap[XK_Super_R&0xFF] = SDLK_RSUPER; /* Right "Windows */
  1.1393 -	MISC_keymap[XK_Mode_switch&0xFF] = SDLK_MODE; /* "Alt Gr" key */
  1.1394 -	MISC_keymap[XK_Multi_key&0xFF] = SDLK_COMPOSE; /* Multi-key compose */
  1.1395 +    MISC_keymap[XK_Num_Lock & 0xFF] = SDLK_NUMLOCK;
  1.1396 +    MISC_keymap[XK_Caps_Lock & 0xFF] = SDLK_CAPSLOCK;
  1.1397 +    MISC_keymap[XK_Scroll_Lock & 0xFF] = SDLK_SCROLLOCK;
  1.1398 +    MISC_keymap[XK_Shift_R & 0xFF] = SDLK_RSHIFT;
  1.1399 +    MISC_keymap[XK_Shift_L & 0xFF] = SDLK_LSHIFT;
  1.1400 +    MISC_keymap[XK_Control_R & 0xFF] = SDLK_RCTRL;
  1.1401 +    MISC_keymap[XK_Control_L & 0xFF] = SDLK_LCTRL;
  1.1402 +    MISC_keymap[XK_Alt_R & 0xFF] = SDLK_RALT;
  1.1403 +    MISC_keymap[XK_Alt_L & 0xFF] = SDLK_LALT;
  1.1404 +    MISC_keymap[XK_Meta_R & 0xFF] = SDLK_RMETA;
  1.1405 +    MISC_keymap[XK_Meta_L & 0xFF] = SDLK_LMETA;
  1.1406 +    MISC_keymap[XK_Super_L & 0xFF] = SDLK_LSUPER;       /* Left "Windows" */
  1.1407 +    MISC_keymap[XK_Super_R & 0xFF] = SDLK_RSUPER;       /* Right "Windows */
  1.1408 +    MISC_keymap[XK_Mode_switch & 0xFF] = SDLK_MODE;     /* "Alt Gr" key */
  1.1409 +    MISC_keymap[XK_Multi_key & 0xFF] = SDLK_COMPOSE;    /* Multi-key compose */
  1.1410  
  1.1411 -	MISC_keymap[XK_Help&0xFF] = SDLK_HELP;
  1.1412 -	MISC_keymap[XK_Print&0xFF] = SDLK_PRINT;
  1.1413 -	MISC_keymap[XK_Sys_Req&0xFF] = SDLK_SYSREQ;
  1.1414 -	MISC_keymap[XK_Break&0xFF] = SDLK_BREAK;
  1.1415 -	MISC_keymap[XK_Menu&0xFF] = SDLK_MENU;
  1.1416 -	MISC_keymap[XK_Hyper_R&0xFF] = SDLK_MENU;   /* Windows "Menu" key */
  1.1417 +    MISC_keymap[XK_Help & 0xFF] = SDLK_HELP;
  1.1418 +    MISC_keymap[XK_Print & 0xFF] = SDLK_PRINT;
  1.1419 +    MISC_keymap[XK_Sys_Req & 0xFF] = SDLK_SYSREQ;
  1.1420 +    MISC_keymap[XK_Break & 0xFF] = SDLK_BREAK;
  1.1421 +    MISC_keymap[XK_Menu & 0xFF] = SDLK_MENU;
  1.1422 +    MISC_keymap[XK_Hyper_R & 0xFF] = SDLK_MENU; /* Windows "Menu" key */
  1.1423  }
  1.1424  
  1.1425  /* Get the translated SDL virtual keysym */
  1.1426 -SDLKey X11_TranslateKeycode(Display *display, KeyCode kc)
  1.1427 +SDLKey
  1.1428 +X11_TranslateKeycode (Display * display, KeyCode kc)
  1.1429  {
  1.1430 -	KeySym xsym;
  1.1431 -	SDLKey key;
  1.1432 +    KeySym xsym;
  1.1433 +    SDLKey key;
  1.1434  
  1.1435 -	xsym = XKeycodeToKeysym(display, kc, 0);
  1.1436 +    xsym = XKeycodeToKeysym (display, kc, 0);
  1.1437  #ifdef DEBUG_KEYS
  1.1438 -	fprintf(stderr, "Translating key code %d -> 0x%.4x\n", kc, xsym);
  1.1439 +    fprintf (stderr, "Translating key code %d -> 0x%.4x\n", kc, xsym);
  1.1440  #endif
  1.1441 -	key = SDLK_UNKNOWN;
  1.1442 -	if ( xsym ) {
  1.1443 -		switch (xsym>>8) {
  1.1444 -		    case 0x1005FF:
  1.1445 +    key = SDLK_UNKNOWN;
  1.1446 +    if (xsym) {
  1.1447 +        switch (xsym >> 8) {
  1.1448 +        case 0x1005FF:
  1.1449  #ifdef SunXK_F36
  1.1450 -			if ( xsym == SunXK_F36 )
  1.1451 -				key = SDLK_F11;
  1.1452 +            if (xsym == SunXK_F36)
  1.1453 +                key = SDLK_F11;
  1.1454  #endif
  1.1455  #ifdef SunXK_F37
  1.1456 -			if ( xsym == SunXK_F37 )
  1.1457 -				key = SDLK_F12;
  1.1458 +            if (xsym == SunXK_F37)
  1.1459 +                key = SDLK_F12;
  1.1460  #endif
  1.1461 -			break;
  1.1462 -		    case 0x00:	/* Latin 1 */
  1.1463 -			key = (SDLKey)(xsym & 0xFF);
  1.1464 -			break;
  1.1465 -		    case 0x01:	/* Latin 2 */
  1.1466 -		    case 0x02:	/* Latin 3 */
  1.1467 -		    case 0x03:	/* Latin 4 */
  1.1468 -		    case 0x04:	/* Katakana */
  1.1469 -		    case 0x05:	/* Arabic */
  1.1470 -		    case 0x06:	/* Cyrillic */
  1.1471 -		    case 0x07:	/* Greek */
  1.1472 -		    case 0x08:	/* Technical */
  1.1473 -		    case 0x0A:	/* Publishing */
  1.1474 -		    case 0x0C:	/* Hebrew */
  1.1475 -		    case 0x0D:	/* Thai */
  1.1476 -			/* These are wrong, but it's better than nothing */
  1.1477 -			key = (SDLKey)(xsym & 0xFF);
  1.1478 -			break;
  1.1479 -		    case 0xFE:
  1.1480 -			key = ODD_keymap[xsym&0xFF];
  1.1481 -			break;
  1.1482 -		    case 0xFF:
  1.1483 -			key = MISC_keymap[xsym&0xFF];
  1.1484 -			break;
  1.1485 -		    default:
  1.1486 -			/*
  1.1487 -			fprintf(stderr, "X11: Unhandled xsym, sym = 0x%04x\n",
  1.1488 -					(unsigned int)xsym);
  1.1489 -			*/
  1.1490 -			break;
  1.1491 -		}
  1.1492 -	} else {
  1.1493 -		/* X11 doesn't know how to translate the key! */
  1.1494 -		switch (kc) {
  1.1495 -		    /* Caution:
  1.1496 -		       These keycodes are from the Microsoft Keyboard
  1.1497 -		     */
  1.1498 -		    case 115:
  1.1499 -			key = SDLK_LSUPER;
  1.1500 -			break;
  1.1501 -		    case 116:
  1.1502 -			key = SDLK_RSUPER;
  1.1503 -			break;
  1.1504 -		    case 117:
  1.1505 -			key = SDLK_MENU;
  1.1506 -			break;
  1.1507 -		    default:
  1.1508 -			/*
  1.1509 -			 * no point in an error message; happens for
  1.1510 -			 * several keys when we get a keymap notify
  1.1511 -			 */
  1.1512 -			break;
  1.1513 -		}
  1.1514 -	}
  1.1515 -	return key;
  1.1516 +            break;
  1.1517 +        case 0x00:             /* Latin 1 */
  1.1518 +            key = (SDLKey) (xsym & 0xFF);
  1.1519 +            break;
  1.1520 +        case 0x01:             /* Latin 2 */
  1.1521 +        case 0x02:             /* Latin 3 */
  1.1522 +        case 0x03:             /* Latin 4 */
  1.1523 +        case 0x04:             /* Katakana */
  1.1524 +        case 0x05:             /* Arabic */
  1.1525 +        case 0x06:             /* Cyrillic */
  1.1526 +        case 0x07:             /* Greek */
  1.1527 +        case 0x08:             /* Technical */
  1.1528 +        case 0x0A:             /* Publishing */
  1.1529 +        case 0x0C:             /* Hebrew */
  1.1530 +        case 0x0D:             /* Thai */
  1.1531 +            /* These are wrong, but it's better than nothing */
  1.1532 +            key = (SDLKey) (xsym & 0xFF);
  1.1533 +            break;
  1.1534 +        case 0xFE:
  1.1535 +            key = ODD_keymap[xsym & 0xFF];
  1.1536 +            break;
  1.1537 +        case 0xFF:
  1.1538 +            key = MISC_keymap[xsym & 0xFF];
  1.1539 +            break;
  1.1540 +        default:
  1.1541 +            /*
  1.1542 +               fprintf(stderr, "X11: Unhandled xsym, sym = 0x%04x\n",
  1.1543 +               (unsigned int)xsym);
  1.1544 +             */
  1.1545 +            break;
  1.1546 +        }
  1.1547 +    } else {
  1.1548 +        /* X11 doesn't know how to translate the key! */
  1.1549 +        switch (kc) {
  1.1550 +            /* Caution:
  1.1551 +               These keycodes are from the Microsoft Keyboard
  1.1552 +             */
  1.1553 +        case 115:
  1.1554 +            key = SDLK_LSUPER;
  1.1555 +            break;
  1.1556 +        case 116:
  1.1557 +            key = SDLK_RSUPER;
  1.1558 +            break;
  1.1559 +        case 117:
  1.1560 +            key = SDLK_MENU;
  1.1561 +            break;
  1.1562 +        default:
  1.1563 +            /*
  1.1564 +             * no point in an error message; happens for
  1.1565 +             * several keys when we get a keymap notify
  1.1566 +             */
  1.1567 +            break;
  1.1568 +        }
  1.1569 +    }
  1.1570 +    return key;
  1.1571  }
  1.1572  
  1.1573  /* X11 modifier masks for various keys */
  1.1574  static unsigned meta_l_mask, meta_r_mask, alt_l_mask, alt_r_mask;
  1.1575  static unsigned num_mask, mode_switch_mask;
  1.1576  
  1.1577 -static void get_modifier_masks(Display *display)
  1.1578 +static void
  1.1579 +get_modifier_masks (Display * display)
  1.1580  {
  1.1581 -	static unsigned got_masks;
  1.1582 -	int i, j;
  1.1583 -	XModifierKeymap *xmods;
  1.1584 -	unsigned n;
  1.1585 +    static unsigned got_masks;
  1.1586 +    int i, j;
  1.1587 +    XModifierKeymap *xmods;
  1.1588 +    unsigned n;
  1.1589  
  1.1590 -	if(got_masks)
  1.1591 -		return;
  1.1592 +    if (got_masks)
  1.1593 +        return;
  1.1594  
  1.1595 -	xmods = XGetModifierMapping(display);
  1.1596 -	n = xmods->max_keypermod;
  1.1597 -	for(i = 3; i < 8; i++) {
  1.1598 -		for(j = 0; j < n; j++) {
  1.1599 -			KeyCode kc = xmods->modifiermap[i * n + j];
  1.1600 -			KeySym ks = XKeycodeToKeysym(display, kc, 0);
  1.1601 -			unsigned mask = 1 << i;
  1.1602 -			switch(ks) {
  1.1603 -			case XK_Num_Lock:
  1.1604 -				num_mask = mask; break;
  1.1605 -			case XK_Alt_L:
  1.1606 -				alt_l_mask = mask; break;
  1.1607 -			case XK_Alt_R:
  1.1608 -				alt_r_mask = mask; break;
  1.1609 -			case XK_Meta_L:
  1.1610 -				meta_l_mask = mask; break;
  1.1611 -			case XK_Meta_R:
  1.1612 -				meta_r_mask = mask; break;
  1.1613 -			case XK_Mode_switch:
  1.1614 -				mode_switch_mask = mask; break;
  1.1615 -			}
  1.1616 -		}
  1.1617 -	}
  1.1618 -	XFreeModifiermap(xmods);
  1.1619 -	got_masks = 1;
  1.1620 +    xmods = XGetModifierMapping (display);
  1.1621 +    n = xmods->max_keypermod;
  1.1622 +    for (i = 3; i < 8; i++) {
  1.1623 +        for (j = 0; j < n; j++) {
  1.1624 +            KeyCode kc = xmods->modifiermap[i * n + j];
  1.1625 +            KeySym ks = XKeycodeToKeysym (display, kc, 0);
  1.1626 +            unsigned mask = 1 << i;
  1.1627 +            switch (ks) {
  1.1628 +            case XK_Num_Lock:
  1.1629 +                num_mask = mask;
  1.1630 +                break;
  1.1631 +            case XK_Alt_L:
  1.1632 +                alt_l_mask = mask;
  1.1633 +                break;
  1.1634 +            case XK_Alt_R:
  1.1635 +                alt_r_mask = mask;
  1.1636 +                break;
  1.1637 +            case XK_Meta_L:
  1.1638 +                meta_l_mask = mask;
  1.1639 +                break;
  1.1640 +            case XK_Meta_R:
  1.1641 +                meta_r_mask = mask;
  1.1642 +                break;
  1.1643 +            case XK_Mode_switch:
  1.1644 +                mode_switch_mask = mask;
  1.1645 +                break;
  1.1646 +            }
  1.1647 +        }
  1.1648 +    }
  1.1649 +    XFreeModifiermap (xmods);
  1.1650 +    got_masks = 1;
  1.1651  }
  1.1652  
  1.1653  
  1.1654 @@ -951,59 +988,60 @@
  1.1655   * sequences (dead accents, compose key sequences) will not work since the
  1.1656   * state has been irrevocably lost.
  1.1657   */
  1.1658 -Uint16 X11_KeyToUnicode(SDLKey keysym, SDLMod modifiers)
  1.1659 +Uint16
  1.1660 +X11_KeyToUnicode (SDLKey keysym, SDLMod modifiers)
  1.1661  {
  1.1662 -	struct SDL_VideoDevice *this = current_video;
  1.1663 -	char keybuf[32];
  1.1664 -	int i;
  1.1665 -	KeySym xsym = 0;
  1.1666 -	XKeyEvent xkey;
  1.1667 -	Uint16 unicode;
  1.1668 +    SDL_VideoDevice *_this = SDL_GetVideoDevice ();
  1.1669 +    char keybuf[32];
  1.1670 +    int i;
  1.1671 +    KeySym xsym = 0;
  1.1672 +    XKeyEvent xkey;
  1.1673 +    Uint16 unicode;
  1.1674  
  1.1675 -	if ( !this || !SDL_Display ) {
  1.1676 -		return 0;
  1.1677 -	}
  1.1678 +    if (!_this || !SDL_Display) {
  1.1679 +        return 0;
  1.1680 +    }
  1.1681  
  1.1682 -	SDL_memset(&xkey, 0, sizeof(xkey));
  1.1683 -	xkey.display = SDL_Display;
  1.1684 +    SDL_memset (&xkey, 0, sizeof (xkey));
  1.1685 +    xkey.display = SDL_Display;
  1.1686  
  1.1687 -	xsym = keysym;		/* last resort if not found */
  1.1688 -	for (i = 0; i < 256; ++i) {
  1.1689 -		if ( MISC_keymap[i] == keysym ) {
  1.1690 -			xsym = 0xFF00 | i;
  1.1691 -			break;
  1.1692 -		} else if ( ODD_keymap[i] == keysym ) {
  1.1693 -			xsym = 0xFE00 | i;
  1.1694 -			break;
  1.1695 -		}
  1.1696 -	}
  1.1697 +    xsym = keysym;              /* last resort if not found */
  1.1698 +    for (i = 0; i < 256; ++i) {
  1.1699 +        if (MISC_keymap[i] == keysym) {
  1.1700 +            xsym = 0xFF00 | i;
  1.1701 +            break;
  1.1702 +        } else if (ODD_keymap[i] == keysym) {
  1.1703 +            xsym = 0xFE00 | i;
  1.1704 +            break;
  1.1705 +        }
  1.1706 +    }
  1.1707  
  1.1708 -	xkey.keycode = XKeysymToKeycode(xkey.display, xsym);
  1.1709 +    xkey.keycode = XKeysymToKeycode (xkey.display, xsym);
  1.1710  
  1.1711 -	get_modifier_masks(SDL_Display);
  1.1712 -	if(modifiers & KMOD_SHIFT)
  1.1713 -		xkey.state |= ShiftMask;
  1.1714 -	if(modifiers & KMOD_CAPS)
  1.1715 -		xkey.state |= LockMask;
  1.1716 -	if(modifiers & KMOD_CTRL)
  1.1717 -		xkey.state |= ControlMask;
  1.1718 -	if(modifiers & KMOD_MODE)
  1.1719 -		xkey.state |= mode_switch_mask;
  1.1720 -	if(modifiers & KMOD_LALT)
  1.1721 -		xkey.state |= alt_l_mask;
  1.1722 -	if(modifiers & KMOD_RALT)
  1.1723 -		xkey.state |= alt_r_mask;
  1.1724 -	if(modifiers & KMOD_LMETA)
  1.1725 -		xkey.state |= meta_l_mask;
  1.1726 -	if(modifiers & KMOD_RMETA)
  1.1727 -		xkey.state |= meta_r_mask;
  1.1728 -	if(modifiers & KMOD_NUM)
  1.1729 -		xkey.state |= num_mask;
  1.1730 +    get_modifier_masks (SDL_Display);
  1.1731 +    if (modifiers & KMOD_SHIFT)
  1.1732 +        xkey.state |= ShiftMask;
  1.1733 +    if (modifiers & KMOD_CAPS)
  1.1734 +        xkey.state |= LockMask;
  1.1735 +    if (modifiers & KMOD_CTRL)
  1.1736 +        xkey.state |= ControlMask;
  1.1737 +    if (modifiers & KMOD_MODE)
  1.1738 +        xkey.state |= mode_switch_mask;
  1.1739 +    if (modifiers & KMOD_LALT)
  1.1740 +        xkey.state |= alt_l_mask;
  1.1741 +    if (modifiers & KMOD_RALT)
  1.1742 +        xkey.state |= alt_r_mask;
  1.1743 +    if (modifiers & KMOD_LMETA)
  1.1744 +        xkey.state |= meta_l_mask;
  1.1745 +    if (modifiers & KMOD_RMETA)
  1.1746 +        xkey.state |= meta_r_mask;
  1.1747 +    if (modifiers & KMOD_NUM)
  1.1748 +        xkey.state |= num_mask;
  1.1749  
  1.1750 -	unicode = 0;
  1.1751 -	if ( XLookupString(&xkey, keybuf, sizeof(keybuf), NULL, NULL) )
  1.1752 -		unicode = (unsigned char)keybuf[0];
  1.1753 -	return(unicode);
  1.1754 +    unicode = 0;
  1.1755 +    if (XLookupString (&xkey, keybuf, sizeof (keybuf), NULL, NULL))
  1.1756 +        unicode = (unsigned char) keybuf[0];
  1.1757 +    return (unicode);
  1.1758  }
  1.1759  
  1.1760  
  1.1761 @@ -1012,162 +1050,169 @@
  1.1762   * synthetic keypress/release events.
  1.1763   * key_vec is a bit vector of keycodes (256 bits)
  1.1764   */
  1.1765 -void X11_SetKeyboardState(Display *display, const char *key_vec)
  1.1766 +void
  1.1767 +X11_SetKeyboardState (Display * display, const char *key_vec)
  1.1768  {
  1.1769 -	char keys_return[32];
  1.1770 -	int i;
  1.1771 -	Uint8 *kstate = SDL_GetKeyState(NULL);
  1.1772 -	SDLMod modstate;
  1.1773 -	Window junk_window;
  1.1774 -	int x, y;
  1.1775 -	unsigned int mask;
  1.1776 +    char keys_return[32];
  1.1777 +    int i;
  1.1778 +    Uint8 *kstate = SDL_GetKeyState (NULL);
  1.1779 +    SDLMod modstate;
  1.1780 +    Window junk_window;
  1.1781 +    int x, y;
  1.1782 +    unsigned int mask;
  1.1783  
  1.1784 -	/* The first time the window is mapped, we initialize key state */
  1.1785 -	if ( ! key_vec ) {
  1.1786 -		XQueryKeymap(display, keys_return);
  1.1787 -		key_vec = keys_return;
  1.1788 -	}
  1.1789 +    /* The first time the window is mapped, we initialize key state */
  1.1790 +    if (!key_vec) {
  1.1791 +        XQueryKeymap (display, keys_return);
  1.1792 +        key_vec = keys_return;
  1.1793 +    }
  1.1794  
  1.1795 -	/* Get the keyboard modifier state */
  1.1796 -	modstate = 0;
  1.1797 -	get_modifier_masks(display);
  1.1798 -	if ( XQueryPointer(display, DefaultRootWindow(display),
  1.1799 -		&junk_window, &junk_window, &x, &y, &x, &y, &mask) ) {
  1.1800 -		if ( mask & LockMask ) {
  1.1801 -			modstate |= KMOD_CAPS;
  1.1802 -		}
  1.1803 -		if ( mask & mode_switch_mask ) {
  1.1804 -			modstate |= KMOD_MODE;
  1.1805 -		}
  1.1806 -		if ( mask & num_mask ) {
  1.1807 -			modstate |= KMOD_NUM;
  1.1808 -		}
  1.1809 -	}
  1.1810 +    /* Get the keyboard modifier state */
  1.1811 +    modstate = 0;
  1.1812 +    get_modifier_masks (display);
  1.1813 +    if (XQueryPointer (display, DefaultRootWindow (display),
  1.1814 +                       &junk_window, &junk_window, &x, &y, &x, &y, &mask)) {
  1.1815 +        if (mask & LockMask) {
  1.1816 +            modstate |= KMOD_CAPS;
  1.1817 +        }
  1.1818 +        if (mask & mode_switch_mask) {
  1.1819 +            modstate |= KMOD_MODE;
  1.1820 +        }
  1.1821 +        if (mask & num_mask) {
  1.1822 +            modstate |= KMOD_NUM;
  1.1823 +        }
  1.1824 +    }
  1.1825  
  1.1826 -	/* Zero the new keyboard state and generate it */
  1.1827 -	SDL_memset(kstate, 0, SDLK_LAST);
  1.1828 -	/*
  1.1829 -	 * An obvious optimisation is to check entire longwords at a time in
  1.1830 -	 * both loops, but we can't be sure the arrays are aligned so it's not
  1.1831 -	 * worth the extra complexity
  1.1832 -	 */
  1.1833 -	for ( i = 0; i < 32; i++ ) {
  1.1834 -		int j;
  1.1835 -		if ( !key_vec[i] )
  1.1836 -			continue;
  1.1837 -		for ( j = 0; j < 8; j++ ) {
  1.1838 -			if ( key_vec[i] & (1 << j) ) {
  1.1839 -				SDLKey key;
  1.1840 -				KeyCode kc = (i << 3 | j);
  1.1841 -				key = X11_TranslateKeycode(display, kc);
  1.1842 -				if ( key == SDLK_UNKNOWN ) {
  1.1843 -					continue;
  1.1844 -				}
  1.1845 -				kstate[key] = SDL_PRESSED;
  1.1846 -				switch (key) {
  1.1847 -				    case SDLK_LSHIFT:
  1.1848 -					modstate |= KMOD_LSHIFT;
  1.1849 -					break;
  1.1850 -				    case SDLK_RSHIFT:
  1.1851 -					modstate |= KMOD_RSHIFT;
  1.1852 -					break;
  1.1853 -				    case SDLK_LCTRL:
  1.1854 -					modstate |= KMOD_LCTRL;
  1.1855 -					break;
  1.1856 -				    case SDLK_RCTRL:
  1.1857 -					modstate |= KMOD_RCTRL;
  1.1858 -					break;
  1.1859 -				    case SDLK_LALT:
  1.1860 -					modstate |= KMOD_LALT;
  1.1861 -					break;
  1.1862 -				    case SDLK_RALT:
  1.1863 -					modstate |= KMOD_RALT;
  1.1864 -					break;
  1.1865 -				    case SDLK_LMETA:
  1.1866 -					modstate |= KMOD_LMETA;
  1.1867 -					break;
  1.1868 -				    case SDLK_RMETA:
  1.1869 -					modstate |= KMOD_RMETA;
  1.1870 -					break;
  1.1871 -				    default:
  1.1872 -					break;
  1.1873 -				}
  1.1874 -			}
  1.1875 -		}
  1.1876 -	}
  1.1877 +    /* Zero the new keyboard state and generate it */
  1.1878 +    SDL_memset (kstate, 0, SDLK_LAST);
  1.1879 +    /*
  1.1880 +     * An obvious optimisation is to check entire longwords at a time in
  1.1881 +     * both loops, but we can't be sure the arrays are aligned so it's not
  1.1882 +     * worth the extra complexity
  1.1883 +     */
  1.1884 +    for (i = 0; i < 32; i++) {
  1.1885 +        int j;
  1.1886 +        if (!key_vec[i])
  1.1887 +            continue;
  1.1888 +        for (j = 0; j < 8; j++) {
  1.1889 +            if (key_vec[i] & (1 << j)) {
  1.1890 +                SDLKey key;
  1.1891 +                KeyCode kc = (i << 3 | j);
  1.1892 +                key = X11_TranslateKeycode (display, kc);
  1.1893 +                if (key == SDLK_UNKNOWN) {
  1.1894 +                    continue;
  1.1895 +                }
  1.1896 +                kstate[key] = SDL_PRESSED;
  1.1897 +                switch (key) {
  1.1898 +                case SDLK_LSHIFT:
  1.1899 +                    modstate |= KMOD_LSHIFT;
  1.1900 +                    break;
  1.1901 +                case SDLK_RSHIFT:
  1.1902 +                    modstate |= KMOD_RSHIFT;
  1.1903 +                    break;
  1.1904 +                case SDLK_LCTRL:
  1.1905 +                    modstate |= KMOD_LCTRL;
  1.1906 +                    break;
  1.1907 +                case SDLK_RCTRL:
  1.1908 +                    modstate |= KMOD_RCTRL;
  1.1909 +                    break;
  1.1910 +                case SDLK_LALT:
  1.1911 +                    modstate |= KMOD_LALT;
  1.1912 +                    break;
  1.1913 +                case SDLK_RALT:
  1.1914 +                    modstate |= KMOD_RALT;
  1.1915 +                    break;
  1.1916 +                case SDLK_LMETA:
  1.1917 +                    modstate |= KMOD_LMETA;
  1.1918 +                    break;
  1.1919 +                case SDLK_RMETA:
  1.1920 +                    modstate |= KMOD_RMETA;
  1.1921 +                    break;
  1.1922 +                default:
  1.1923 +                    break;
  1.1924 +                }
  1.1925 +            }
  1.1926 +        }
  1.1927 +    }
  1.1928  
  1.1929 -	/* Hack - set toggle key state */
  1.1930 -	if ( modstate & KMOD_CAPS ) {
  1.1931 -		kstate[SDLK_CAPSLOCK] = SDL_PRESSED;
  1.1932 -	} else {
  1.1933 -		kstate[SDLK_CAPSLOCK] = SDL_RELEASED;
  1.1934 -	}
  1.1935 -	if ( modstate & KMOD_NUM ) {
  1.1936 -		kstate[SDLK_NUMLOCK] = SDL_PRESSED;
  1.1937 -	} else {
  1.1938 -		kstate[SDLK_NUMLOCK] = SDL_RELEASED;
  1.1939 -	}
  1.1940 +    /* Hack - set toggle key state */
  1.1941 +    if (modstate & KMOD_CAPS) {
  1.1942 +        kstate[SDLK_CAPSLOCK] = SDL_PRESSED;
  1.1943 +    } else {
  1.1944 +        kstate[SDLK_CAPSLOCK] = SDL_RELEASED;
  1.1945 +    }
  1.1946 +    if (modstate & KMOD_NUM) {
  1.1947 +        kstate[SDLK_NUMLOCK] = SDL_PRESSED;
  1.1948 +    } else {
  1.1949 +        kstate[SDLK_NUMLOCK] = SDL_RELEASED;
  1.1950 +    }
  1.1951  
  1.1952 -	/* Set the final modifier state */
  1.1953 -	SDL_SetModState(modstate);
  1.1954 +    /* Set the final modifier state */
  1.1955 +    SDL_SetModState (modstate);
  1.1956  }
  1.1957  
  1.1958 -void X11_InitOSKeymap(_THIS)
  1.1959 +void
  1.1960 +X11_InitOSKeymap (_THIS)
  1.1961  {
  1.1962 -	X11_InitKeymap();
  1.1963 +    X11_InitKeymap ();
  1.1964  }
  1.1965  
  1.1966 -void X11_SaveScreenSaver(Display *display, int *saved_timeout, BOOL *dpms)
  1.1967 +void
  1.1968 +X11_SaveScreenSaver (Display * display, int *saved_timeout, BOOL * dpms)
  1.1969  {
  1.1970 -	int timeout, interval, prefer_blank, allow_exp;
  1.1971 -	XGetScreenSaver(display, &timeout, &interval, &prefer_blank, &allow_exp);
  1.1972 -	*saved_timeout = timeout;
  1.1973 +    int timeout, interval, prefer_blank, allow_exp;
  1.1974 +    XGetScreenSaver (display, &timeout, &interval, &prefer_blank, &allow_exp);
  1.1975 +    *saved_timeout = timeout;
  1.1976  
  1.1977  #if SDL_VIDEO_DRIVER_X11_DPMS
  1.1978 -	if ( SDL_X11_HAVE_DPMS ) {
  1.1979 -		int dummy;
  1.1980 -	  	if ( DPMSQueryExtension(display, &dummy, &dummy) ) {
  1.1981 -			CARD16 state;
  1.1982 -			DPMSInfo(display, &state, dpms);
  1.1983 -		}
  1.1984 -	}
  1.1985 +    if (SDL_X11_HAVE_DPMS) {
  1.1986 +        int dummy;
  1.1987 +        if (DPMSQueryExtension (display, &dummy, &dummy)) {
  1.1988 +            CARD16 state;
  1.1989 +            DPMSInfo (display, &state, dpms);
  1.1990 +        }
  1.1991 +    }
  1.1992  #else
  1.1993 -	*dpms = 0;
  1.1994 +    *dpms = 0;
  1.1995  #endif /* SDL_VIDEO_DRIVER_X11_DPMS */
  1.1996  }
  1.1997  
  1.1998 -void X11_DisableScreenSaver(Display *display)
  1.1999 +void
  1.2000 +X11_DisableScreenSaver (Display * display)
  1.2001  {
  1.2002 -	int timeout, interval, prefer_blank, allow_exp;
  1.2003 -	XGetScreenSaver(display, &timeout, &interval, &prefer_blank, &allow_exp);
  1.2004 -	timeout = 0;
  1.2005 -	XSetScreenSaver(display, timeout, interval, prefer_blank, allow_exp);
  1.2006 +    int timeout, interval, prefer_blank, allow_exp;
  1.2007 +    XGetScreenSaver (display, &timeout, &interval, &prefer_blank, &allow_exp);
  1.2008 +    timeout = 0;
  1.2009 +    XSetScreenSaver (display, timeout, interval, prefer_blank, allow_exp);
  1.2010  
  1.2011  #if SDL_VIDEO_DRIVER_X11_DPMS
  1.2012 -	if ( SDL_X11_HAVE_DPMS ) {
  1.2013 -		int dummy;
  1.2014 -	  	if ( DPMSQueryExtension(display, &dummy, &dummy) ) {
  1.2015 -			DPMSDisable(display);
  1.2016 -		}
  1.2017 -	}
  1.2018 +    if (SDL_X11_HAVE_DPMS) {
  1.2019 +        int dummy;
  1.2020 +        if (DPMSQueryExtension (display, &dummy, &dummy)) {
  1.2021 +            DPMSDisable (display);
  1.2022 +        }
  1.2023 +    }
  1.2024  #endif /* SDL_VIDEO_DRIVER_X11_DPMS */
  1.2025  }
  1.2026  
  1.2027 -void X11_RestoreScreenSaver(Display *display, int saved_timeout, BOOL dpms)
  1.2028 +void
  1.2029 +X11_RestoreScreenSaver (Display * display, int saved_timeout, BOOL dpms)
  1.2030  {
  1.2031 -	int timeout, interval, prefer_blank, allow_exp;
  1.2032 -	XGetScreenSaver(display, &timeout, &interval, &prefer_blank, &allow_exp);
  1.2033 -	timeout = saved_timeout;
  1.2034 -	XSetScreenSaver(display, timeout, interval, prefer_blank, allow_exp);
  1.2035 +    int timeout, interval, prefer_blank, allow_exp;
  1.2036 +    XGetScreenSaver (display, &timeout, &interval, &prefer_blank, &allow_exp);
  1.2037 +    timeout = saved_timeout;
  1.2038 +    XSetScreenSaver (display, timeout, interval, prefer_blank, allow_exp);
  1.2039  
  1.2040  #if SDL_VIDEO_DRIVER_X11_DPMS
  1.2041 -	if ( SDL_X11_HAVE_DPMS ) {
  1.2042 -		int dummy;
  1.2043 -	  	if ( DPMSQueryExtension(display, &dummy, &dummy) ) {
  1.2044 -			if ( dpms ) {
  1.2045 -				DPMSEnable(display);
  1.2046 -			}
  1.2047 -		}
  1.2048 -	}
  1.2049 +    if (SDL_X11_HAVE_DPMS) {
  1.2050 +        int dummy;
  1.2051 +        if (DPMSQueryExtension (display, &dummy, &dummy)) {
  1.2052 +            if (dpms) {
  1.2053 +                DPMSEnable (display);
  1.2054 +            }
  1.2055 +        }
  1.2056 +    }
  1.2057  #endif /* SDL_VIDEO_DRIVER_X11_DPMS */
  1.2058  }
  1.2059 +
  1.2060 +/* vi: set ts=4 sw=4 expandtab: */