Merged
authorSam Lantinga <slouken@libsdl.org>
Fri, 01 Mar 2013 11:18:35 -0800
changeset 694718ccf3e4921d
parent 6946 d25107785792
parent 6941 9bb475091e51
child 6948 84a71440360d
Merged
src/video/windows/SDL_windowsevents.c
     1.1 --- a/include/SDL_scancode.h	Fri Mar 01 11:15:50 2013 -0800
     1.2 +++ b/include/SDL_scancode.h	Fri Mar 01 11:18:35 2013 -0800
     1.3 @@ -38,7 +38,7 @@
     1.4   *  SDL_Event structure.
     1.5   *  
     1.6   *  The values in this enumeration are based on the USB usage page standard:
     1.7 - *  http://www.usb.org/developers/devclass_docs/Hut1_12.pdf
     1.8 + *  http://www.usb.org/developers/devclass_docs/Hut1_12v2.pdf
     1.9   */
    1.10  typedef enum
    1.11  {
     2.1 --- a/src/events/scancodes_windows.h	Fri Mar 01 11:15:50 2013 -0800
     2.2 +++ b/src/events/scancodes_windows.h	Fri Mar 01 11:18:35 2013 -0800
     2.3 @@ -20,13 +20,8 @@
     2.4  */
     2.5  #include "../../include/SDL_scancode.h"
     2.6  
     2.7 -/* Win32 virtual key code to SDL scancode mapping table
     2.8 -   Sources:
     2.9 -   - msdn.microsoft.com
    2.10 -*/
    2.11 +/* Windows scancode to SDL scancode mapping table */
    2.12  /* *INDENT-OFF* */
    2.13 -// this maps non-translated keyboard scan codes to engine key codes
    2.14 -// Google for 'Keyboard Scan Code Specification'
    2.15  static const SDL_Scancode windows_scancode_table[] = 
    2.16  { 
    2.17  	//	0						1							2							3							4						5							6							7 
    2.18 @@ -55,5 +50,4 @@
    2.19  	SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,	SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,		// 7
    2.20  	SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,	SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN,		SDL_SCANCODE_UNKNOWN		// 7 
    2.21  };
    2.22 -
    2.23  /* *INDENT-ON* */
     3.1 --- a/src/video/windows/SDL_windowsevents.c	Fri Mar 01 11:15:50 2013 -0800
     3.2 +++ b/src/video/windows/SDL_windowsevents.c	Fri Mar 01 11:18:35 2013 -0800
     3.3 @@ -28,13 +28,12 @@
     3.4  #include "SDL_vkeys.h"
     3.5  #include "../../events/SDL_events_c.h"
     3.6  #include "../../events/SDL_touch_c.h"
     3.7 +#include "../../events/scancodes_windows.h"
     3.8  
     3.9  /* Dropfile support */
    3.10  #include <shellapi.h>
    3.11  
    3.12  
    3.13 -
    3.14 -
    3.15  /*#define WMMSG_DEBUG*/
    3.16  #ifdef WMMSG_DEBUG
    3.17  #include <stdio.h>	
    3.18 @@ -68,7 +67,7 @@
    3.19  #endif
    3.20  
    3.21  static SDL_Scancode 
    3.22 -WindowsScanCodeToSDLScanCode( int lParam, int wParam, const SDL_Scancode *key_map )
    3.23 +WindowsScanCodeToSDLScanCode( int lParam, int wParam )
    3.24  {
    3.25  	SDL_Scancode code;
    3.26  	char bIsExtended;
    3.27 @@ -133,7 +132,7 @@
    3.28  	if ( nScanCode > 127 )
    3.29  		return SDL_SCANCODE_UNKNOWN;
    3.30  
    3.31 -	code = key_map[nScanCode];
    3.32 +	code = windows_scancode_table[nScanCode];
    3.33  
    3.34  	bIsExtended = ( lParam & ( 1 << 24 ) ) != 0;
    3.35  	if ( !bIsExtended )
    3.36 @@ -159,7 +158,7 @@
    3.37  		case SDL_SCANCODE_INSERT:
    3.38  			return SDL_SCANCODE_KP_0;
    3.39  		case SDL_SCANCODE_DELETE:
    3.40 -			return SDL_SCANCODE_KP_DECIMAL;
    3.41 +			return SDL_SCANCODE_KP_PERIOD;
    3.42  		case SDL_SCANCODE_PRINTSCREEN:
    3.43  			return SDL_SCANCODE_KP_MULTIPLY;
    3.44  		default:
    3.45 @@ -453,7 +452,7 @@
    3.46      case WM_SYSKEYDOWN:
    3.47      case WM_KEYDOWN:
    3.48          {
    3.49 -			SDL_Scancode code =  WindowsScanCodeToSDLScanCode( lParam, wParam, data->videodata->key_layout );
    3.50 +			SDL_Scancode code = WindowsScanCodeToSDLScanCode( lParam, wParam );
    3.51  			if ( code != SDL_SCANCODE_UNKNOWN ) {
    3.52                  SDL_SendKeyboardKey(SDL_PRESSED, code );
    3.53              }
    3.54 @@ -464,15 +463,13 @@
    3.55      case WM_SYSKEYUP:
    3.56      case WM_KEYUP:
    3.57          {
    3.58 -			SDL_Scancode code =  WindowsScanCodeToSDLScanCode( lParam, wParam, data->videodata->key_layout );
    3.59 -			if ( code != SDL_SCANCODE_UNKNOWN ) {
    3.60 -				if (wParam == VK_SNAPSHOT
    3.61 -				    && SDL_GetKeyboardState(NULL)[SDL_SCANCODE_PRINTSCREEN] ==
    3.62 -				    SDL_RELEASED) {
    3.63 -				    SDL_SendKeyboardKey(SDL_PRESSED,
    3.64 -				                         code);
    3.65 -				}
    3.66 -                SDL_SendKeyboardKey(SDL_RELEASED, code );
    3.67 +            SDL_Scancode code = WindowsScanCodeToSDLScanCode( lParam, wParam );
    3.68 +            if ( code != SDL_SCANCODE_UNKNOWN ) {
    3.69 +                if (code == SDL_SCANCODE_PRINTSCREEN &&
    3.70 +                    SDL_GetKeyboardState(NULL)[code] == SDL_RELEASED) {
    3.71 +                    SDL_SendKeyboardKey(SDL_PRESSED, code);
    3.72 +                }
    3.73 +                SDL_SendKeyboardKey(SDL_RELEASED, code);
    3.74              }
    3.75          }
    3.76          returnCode = 0;
     4.1 --- a/src/video/windows/SDL_windowskeyboard.c	Fri Mar 01 11:15:50 2013 -0800
     4.2 +++ b/src/video/windows/SDL_windowskeyboard.c	Fri Mar 01 11:18:35 2013 -0800
     4.3 @@ -48,50 +48,10 @@
     4.4  #endif
     4.5  
     4.6  /* Alphabetic scancodes for PC keyboards */
     4.7 -BYTE alpha_scancodes[26] = {
     4.8 -    30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38, 50, 49, 24,
     4.9 -    25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44
    4.10 -};
    4.11 -
    4.12 -BYTE keypad_scancodes[10] = {
    4.13 -    82, 79, 80, 81, 75, 76, 77, 71, 72, 73
    4.14 -};
    4.15 -
    4.16  void
    4.17  WIN_InitKeyboard(_THIS)
    4.18  {
    4.19      SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
    4.20 -    int i;
    4.21 -
    4.22 -    /* Make sure the alpha scancodes are correct.  T isn't usually remapped */
    4.23 -    if (MapVirtualKey('T', MAPVK_VK_TO_VSC) != alpha_scancodes['T' - 'A']) {
    4.24 -#if 0
    4.25 -        printf
    4.26 -            ("Fixing alpha scancode map, assuming US QWERTY layout!\nPlease send the following 26 lines of output to the SDL mailing list <sdl@libsdl.org>, including a description of your keyboard hardware.\n");
    4.27 -#endif
    4.28 -        for (i = 0; i < SDL_arraysize(alpha_scancodes); ++i) {
    4.29 -            alpha_scancodes[i] = MapVirtualKey('A' + i, MAPVK_VK_TO_VSC);
    4.30 -#if 0
    4.31 -            printf("%d = %d\n", i, alpha_scancodes[i]);
    4.32 -#endif
    4.33 -        }
    4.34 -    }
    4.35 -    if (MapVirtualKey(VK_NUMPAD0, MAPVK_VK_TO_VSC) != keypad_scancodes[0]) {
    4.36 -#if 0
    4.37 -        printf
    4.38 -            ("Fixing keypad scancode map!\nPlease send the following 10 lines of output to the SDL mailing list <sdl@libsdl.org>, including a description of your keyboard hardware.\n");
    4.39 -#endif
    4.40 -        for (i = 0; i < SDL_arraysize(keypad_scancodes); ++i) {
    4.41 -            keypad_scancodes[i] =
    4.42 -                MapVirtualKey(VK_NUMPAD0 + i, MAPVK_VK_TO_VSC);
    4.43 -#if 0
    4.44 -            printf("%d = %d\n", i, keypad_scancodes[i]);
    4.45 -#endif
    4.46 -        }
    4.47 -    }
    4.48 -
    4.49 -	// windows scancode to SDL scancode table
    4.50 -    data->key_layout = windows_scancode_table;
    4.51  
    4.52      data->ime_com_initialized = SDL_FALSE;
    4.53      data->ime_threadmgr = 0;
    4.54 @@ -151,42 +111,36 @@
    4.55      SDL_Scancode scancode;
    4.56      SDL_Keycode keymap[SDL_NUM_SCANCODES];
    4.57  
    4.58 -	for (i = 0; i < SDL_arraysize(keymap); ++i)
    4.59 -	{
    4.60 -		keymap[i] = SDL_SCANCODE_TO_KEYCODE( i );
    4.61 -	}
    4.62 +    SDL_GetDefaultKeymap(keymap);
    4.63  
    4.64      for (i = 0; i < SDL_arraysize(windows_scancode_table); i++) {
    4.65 -		int vk;
    4.66 +        int vk;
    4.67          /* Make sure this scancode is a valid character scancode */
    4.68          scancode = windows_scancode_table[i];
    4.69          if (scancode == SDL_SCANCODE_UNKNOWN ) {
    4.70              continue;
    4.71          }
    4.72 -		/* Don't allow the number keys right above the qwerty row to translate or the top left key (grave/backquote) */
    4.73 -		/* not mapping numbers fixes the AZERTY layout (french) causing non-shifted number to appear by default */
    4.74 -		if ( scancode == SDL_SCANCODE_GRAVE ) {
    4.75 -			keymap[scancode]  = SDLK_BACKQUOTE;
    4.76 -			continue;
    4.77 -		}
    4.78 -		if ( scancode >= SDL_SCANCODE_1 && scancode <= SDL_SCANCODE_0 ) {
    4.79 -			 keymap[scancode] = SDLK_1 + ( scancode - SDL_SCANCODE_1 );
    4.80 -			continue;
    4.81 -		}
    4.82  
    4.83 -		vk =  MapVirtualKey(i, MAPVK_VSC_TO_VK);
    4.84 -		if ( vk ) {
    4.85 -			int ch;
    4.86 -			ch = (MapVirtualKey( vk, MAPVK_VK_TO_CHAR ) & 0x7FFF);
    4.87 -			 if ( ch )
    4.88 -			 {
    4.89 -				 if ( ch >= 'A' && ch <= 'Z' )
    4.90 -					keymap[scancode] =  SDLK_a + ( ch - 'A' );
    4.91 -				 else
    4.92 -					 keymap[scancode] = ch;
    4.93 -			 }
    4.94 +        /* If this key is one of the non-mappable keys, ignore it */
    4.95 +        /* Don't allow the number keys right above the qwerty row to translate or the top left key (grave/backquote) */
    4.96 +        /* Not mapping numbers fixes the French layout, giving numeric keycodes for the number keys, which is the expected behavior */
    4.97 +        if ((keymap[scancode] & SDLK_SCANCODE_MASK) ||
    4.98 +            scancode == SDL_SCANCODE_GRAVE ||
    4.99 +            (scancode >= SDL_SCANCODE_1 && scancode <= SDL_SCANCODE_0) ) {
   4.100 +            continue;
   4.101 +        }
   4.102  
   4.103 -		}
   4.104 +        vk =  MapVirtualKey(i, MAPVK_VSC_TO_VK);
   4.105 +        if ( vk ) {
   4.106 +            int ch = (MapVirtualKey( vk, MAPVK_VK_TO_CHAR ) & 0x7FFF);
   4.107 +            if ( ch ) {
   4.108 +                if ( ch >= 'A' && ch <= 'Z' ) {
   4.109 +                    keymap[scancode] =  SDLK_a + ( ch - 'A' );
   4.110 +                } else {
   4.111 +                    keymap[scancode] = ch;
   4.112 +                }
   4.113 +            }
   4.114 +        }
   4.115      }
   4.116  
   4.117      SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES);
     5.1 --- a/src/video/windows/SDL_windowskeyboard.h	Fri Mar 01 11:15:50 2013 -0800
     5.2 +++ b/src/video/windows/SDL_windowskeyboard.h	Fri Mar 01 11:18:35 2013 -0800
     5.3 @@ -23,9 +23,6 @@
     5.4  #ifndef _SDL_windowskeyboard_h
     5.5  #define _SDL_windowskeyboard_h
     5.6  
     5.7 -extern BYTE alpha_scancodes[26];
     5.8 -extern BYTE keypad_scancodes[10];
     5.9 -
    5.10  extern void WIN_InitKeyboard(_THIS);
    5.11  extern void WIN_UpdateKeymap(void);
    5.12  extern void WIN_QuitKeyboard(_THIS);
     6.1 --- a/src/video/windows/SDL_windowsvideo.h	Fri Mar 01 11:15:50 2013 -0800
     6.2 +++ b/src/video/windows/SDL_windowsvideo.h	Fri Mar 01 11:18:35 2013 -0800
     6.3 @@ -115,7 +115,6 @@
     6.4  {
     6.5      int render;
     6.6  
     6.7 -    const SDL_Scancode *key_layout;
     6.8  	DWORD clipboard_count;
     6.9  
    6.10  	/* Touch input functions */
     7.1 --- a/src/video/x11/SDL_x11modes.c	Fri Mar 01 11:15:50 2013 -0800
     7.2 +++ b/src/video/x11/SDL_x11modes.c	Fri Mar 01 11:18:35 2013 -0800
     7.3 @@ -576,26 +576,31 @@
     7.4                      int actual_format;
     7.5                      unsigned long nitems, bytes_after;
     7.6                      Atom actual_type;
     7.7 -   
     7.8 +
     7.9  	                if (props[i] == EDID) {
    7.10 -                        XRRGetOutputProperty(data->display, res->outputs[output], props[i],
    7.11 -                                             0, 100, False, False,
    7.12 -                                             AnyPropertyType,
    7.13 -                                             &actual_type, &actual_format,
    7.14 -                                             &nitems, &bytes_after, &prop);
    7.15 -
    7.16 -                        MonitorInfo *info = decode_edid(prop);
    7.17 -                        if (info) {
    7.18 -#ifdef X11MODES_DEBUG
    7.19 -                            printf("Found EDID data for %s\n", output_info->name);
    7.20 -                            dump_monitor_info(info);
    7.21 -#endif
    7.22 -                            SDL_strlcpy(display_name, info->dsc_product_name, sizeof(display_name));
    7.23 -                            free(info);
    7.24 +                        if (XRRGetOutputProperty(data->display,
    7.25 +                                                 res->outputs[output], props[i],
    7.26 +                                                 0, 100, False, False,
    7.27 +                                                 AnyPropertyType,
    7.28 +                                                 &actual_type, &actual_format,
    7.29 +                                                 &nitems, &bytes_after, &prop) == Success ) {
    7.30 +                            MonitorInfo *info = decode_edid(prop);
    7.31 +                            if (info) {
    7.32 +    #ifdef X11MODES_DEBUG
    7.33 +                                printf("Found EDID data for %s\n", output_info->name);
    7.34 +                                dump_monitor_info(info);
    7.35 +    #endif
    7.36 +                                SDL_strlcpy(display_name, info->dsc_product_name, sizeof(display_name));
    7.37 +                                free(info);
    7.38 +                            }
    7.39 +                            XFree(prop);
    7.40                          }
    7.41                          break;
    7.42                      }
    7.43                  }
    7.44 +                if (props) {
    7.45 +                    XFree(props);
    7.46 +                }
    7.47  
    7.48                  if (*display_name && inches) {
    7.49                      size_t len = SDL_strlen(display_name);