From 89af5d16a49ac38b38346530d0525ddf30f01c1e Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 28 Feb 2013 20:01:17 -0800 Subject: [PATCH 1/5] Updated the link to the USB usage page document --- include/SDL_scancode.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/SDL_scancode.h b/include/SDL_scancode.h index b05ca5cca..26b8f36b5 100644 --- a/include/SDL_scancode.h +++ b/include/SDL_scancode.h @@ -38,7 +38,7 @@ * SDL_Event structure. * * The values in this enumeration are based on the USB usage page standard: - * http://www.usb.org/developers/devclass_docs/Hut1_12.pdf + * http://www.usb.org/developers/devclass_docs/Hut1_12v2.pdf */ typedef enum { From 756ff05cb3a48643dadde8770a7e839cf652a755 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 28 Feb 2013 21:40:08 -0800 Subject: [PATCH 2/5] Cleaned up and fixed the Windows keyboard mapping code. Use KP_PERIOD instead of KP_DECIMAL Don't remap keys which are always keycode named versions of scancodes --- src/video/windows/SDL_windowsevents.c | 27 ++++---- src/video/windows/SDL_windowskeyboard.c | 92 +++++++------------------ src/video/windows/SDL_windowskeyboard.h | 3 - src/video/windows/SDL_windowsvideo.h | 1 - 4 files changed, 35 insertions(+), 88 deletions(-) diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c index 5c2be9ad8..9887a0bcb 100644 --- a/src/video/windows/SDL_windowsevents.c +++ b/src/video/windows/SDL_windowsevents.c @@ -28,13 +28,12 @@ #include "SDL_vkeys.h" #include "../../events/SDL_events_c.h" #include "../../events/SDL_touch_c.h" +#include "../../events/scancodes_windows.h" /* Dropfile support */ #include - - /*#define WMMSG_DEBUG*/ #ifdef WMMSG_DEBUG #include @@ -68,7 +67,7 @@ #endif static SDL_Scancode -WindowsScanCodeToSDLScanCode( int lParam, int wParam, const SDL_Scancode *key_map ) +WindowsScanCodeToSDLScanCode( int lParam, int wParam ) { SDL_Scancode code; char bIsExtended; @@ -133,7 +132,7 @@ WindowsScanCodeToSDLScanCode( int lParam, int wParam, const SDL_Scancode *key_ma if ( nScanCode > 127 ) return SDL_SCANCODE_UNKNOWN; - code = key_map[nScanCode]; + code = windows_scancode_table[nScanCode]; bIsExtended = ( lParam & ( 1 << 24 ) ) != 0; if ( !bIsExtended ) @@ -159,7 +158,7 @@ WindowsScanCodeToSDLScanCode( int lParam, int wParam, const SDL_Scancode *key_ma case SDL_SCANCODE_INSERT: return SDL_SCANCODE_KP_0; case SDL_SCANCODE_DELETE: - return SDL_SCANCODE_KP_DECIMAL; + return SDL_SCANCODE_KP_PERIOD; case SDL_SCANCODE_PRINTSCREEN: return SDL_SCANCODE_KP_MULTIPLY; default: @@ -393,7 +392,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) case WM_SYSKEYDOWN: case WM_KEYDOWN: { - SDL_Scancode code = WindowsScanCodeToSDLScanCode( lParam, wParam, data->videodata->key_layout ); + SDL_Scancode code = WindowsScanCodeToSDLScanCode( lParam, wParam ); if ( code != SDL_SCANCODE_UNKNOWN ) { SDL_SendKeyboardKey(SDL_PRESSED, code ); } @@ -404,15 +403,13 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) case WM_SYSKEYUP: case WM_KEYUP: { - SDL_Scancode code = WindowsScanCodeToSDLScanCode( lParam, wParam, data->videodata->key_layout ); - if ( code != SDL_SCANCODE_UNKNOWN ) { - if (wParam == VK_SNAPSHOT - && SDL_GetKeyboardState(NULL)[SDL_SCANCODE_PRINTSCREEN] == - SDL_RELEASED) { - SDL_SendKeyboardKey(SDL_PRESSED, - code); - } - SDL_SendKeyboardKey(SDL_RELEASED, code ); + SDL_Scancode code = WindowsScanCodeToSDLScanCode( lParam, wParam ); + if ( code != SDL_SCANCODE_UNKNOWN ) { + if (code == SDL_SCANCODE_PRINTSCREEN && + SDL_GetKeyboardState(NULL)[code] == SDL_RELEASED) { + SDL_SendKeyboardKey(SDL_PRESSED, code); + } + SDL_SendKeyboardKey(SDL_RELEASED, code); } } returnCode = 0; diff --git a/src/video/windows/SDL_windowskeyboard.c b/src/video/windows/SDL_windowskeyboard.c index fd2510413..74f078f86 100644 --- a/src/video/windows/SDL_windowskeyboard.c +++ b/src/video/windows/SDL_windowskeyboard.c @@ -48,50 +48,10 @@ static void IME_Quit(SDL_VideoData *videodata); #endif /* Alphabetic scancodes for PC keyboards */ -BYTE alpha_scancodes[26] = { - 30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38, 50, 49, 24, - 25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44 -}; - -BYTE keypad_scancodes[10] = { - 82, 79, 80, 81, 75, 76, 77, 71, 72, 73 -}; - void WIN_InitKeyboard(_THIS) { SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; - int i; - - /* Make sure the alpha scancodes are correct. T isn't usually remapped */ - if (MapVirtualKey('T', MAPVK_VK_TO_VSC) != alpha_scancodes['T' - 'A']) { -#if 0 - printf - ("Fixing alpha scancode map, assuming US QWERTY layout!\nPlease send the following 26 lines of output to the SDL mailing list , including a description of your keyboard hardware.\n"); -#endif - for (i = 0; i < SDL_arraysize(alpha_scancodes); ++i) { - alpha_scancodes[i] = MapVirtualKey('A' + i, MAPVK_VK_TO_VSC); -#if 0 - printf("%d = %d\n", i, alpha_scancodes[i]); -#endif - } - } - if (MapVirtualKey(VK_NUMPAD0, MAPVK_VK_TO_VSC) != keypad_scancodes[0]) { -#if 0 - printf - ("Fixing keypad scancode map!\nPlease send the following 10 lines of output to the SDL mailing list , including a description of your keyboard hardware.\n"); -#endif - for (i = 0; i < SDL_arraysize(keypad_scancodes); ++i) { - keypad_scancodes[i] = - MapVirtualKey(VK_NUMPAD0 + i, MAPVK_VK_TO_VSC); -#if 0 - printf("%d = %d\n", i, keypad_scancodes[i]); -#endif - } - } - - // windows scancode to SDL scancode table - data->key_layout = windows_scancode_table; data->ime_com_initialized = SDL_FALSE; data->ime_threadmgr = 0; @@ -151,42 +111,36 @@ WIN_UpdateKeymap() SDL_Scancode scancode; SDL_Keycode keymap[SDL_NUM_SCANCODES]; - for (i = 0; i < SDL_arraysize(keymap); ++i) - { - keymap[i] = SDL_SCANCODE_TO_KEYCODE( i ); - } + SDL_GetDefaultKeymap(keymap); for (i = 0; i < SDL_arraysize(windows_scancode_table); i++) { - int vk; + int vk; /* Make sure this scancode is a valid character scancode */ scancode = windows_scancode_table[i]; if (scancode == SDL_SCANCODE_UNKNOWN ) { continue; } - /* Don't allow the number keys right above the qwerty row to translate or the top left key (grave/backquote) */ - /* not mapping numbers fixes the AZERTY layout (french) causing non-shifted number to appear by default */ - if ( scancode == SDL_SCANCODE_GRAVE ) { - keymap[scancode] = SDLK_BACKQUOTE; - continue; - } - if ( scancode >= SDL_SCANCODE_1 && scancode <= SDL_SCANCODE_0 ) { - keymap[scancode] = SDLK_1 + ( scancode - SDL_SCANCODE_1 ); - continue; - } - - vk = MapVirtualKey(i, MAPVK_VSC_TO_VK); - if ( vk ) { - int ch; - ch = (MapVirtualKey( vk, MAPVK_VK_TO_CHAR ) & 0x7FFF); - if ( ch ) - { - if ( ch >= 'A' && ch <= 'Z' ) - keymap[scancode] = SDLK_a + ( ch - 'A' ); - else - keymap[scancode] = ch; - } - - } + + /* If this key is one of the non-mappable keys, ignore it */ + /* Don't allow the number keys right above the qwerty row to translate or the top left key (grave/backquote) */ + /* Not mapping numbers fixes the French layout, giving numeric keycodes for the number keys, which is the expected behavior */ + if ((keymap[scancode] & SDLK_SCANCODE_MASK) || + scancode == SDL_SCANCODE_GRAVE || + (scancode >= SDL_SCANCODE_1 && scancode <= SDL_SCANCODE_0) ) { + continue; + } + + vk = MapVirtualKey(i, MAPVK_VSC_TO_VK); + if ( vk ) { + int ch = (MapVirtualKey( vk, MAPVK_VK_TO_CHAR ) & 0x7FFF); + if ( ch ) { + if ( ch >= 'A' && ch <= 'Z' ) { + keymap[scancode] = SDLK_a + ( ch - 'A' ); + } else { + keymap[scancode] = ch; + } + } + } } SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES); diff --git a/src/video/windows/SDL_windowskeyboard.h b/src/video/windows/SDL_windowskeyboard.h index abe8a63e9..c79d1d0ff 100644 --- a/src/video/windows/SDL_windowskeyboard.h +++ b/src/video/windows/SDL_windowskeyboard.h @@ -23,9 +23,6 @@ #ifndef _SDL_windowskeyboard_h #define _SDL_windowskeyboard_h -extern BYTE alpha_scancodes[26]; -extern BYTE keypad_scancodes[10]; - extern void WIN_InitKeyboard(_THIS); extern void WIN_UpdateKeymap(void); extern void WIN_QuitKeyboard(_THIS); diff --git a/src/video/windows/SDL_windowsvideo.h b/src/video/windows/SDL_windowsvideo.h index 8a3c737ed..199a8ba8f 100644 --- a/src/video/windows/SDL_windowsvideo.h +++ b/src/video/windows/SDL_windowsvideo.h @@ -115,7 +115,6 @@ typedef struct SDL_VideoData { int render; - const SDL_Scancode *key_layout; DWORD clipboard_count; /* Touch input functions */ From 7acd94972b570b1eea8065ad2ad6d60e2f53389f Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 28 Feb 2013 21:48:12 -0800 Subject: [PATCH 3/5] The table is now a scancode mapping table, not a virtual key mapping table --- src/events/scancodes_windows.h | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/events/scancodes_windows.h b/src/events/scancodes_windows.h index 3aee7e609..7bf69b0ad 100644 --- a/src/events/scancodes_windows.h +++ b/src/events/scancodes_windows.h @@ -20,13 +20,8 @@ */ #include "../../include/SDL_scancode.h" -/* Win32 virtual key code to SDL scancode mapping table - Sources: - - msdn.microsoft.com -*/ +/* Windows scancode to SDL scancode mapping table */ /* *INDENT-OFF* */ -// this maps non-translated keyboard scan codes to engine key codes -// Google for 'Keyboard Scan Code Specification' static const SDL_Scancode windows_scancode_table[] = { // 0 1 2 3 4 5 6 7 @@ -55,5 +50,4 @@ static const SDL_Scancode windows_scancode_table[] = 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 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 }; - /* *INDENT-ON* */ From 25944df5cfd9e9f146e7b778923bde0f0612e4f4 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 28 Feb 2013 22:20:25 -0800 Subject: [PATCH 4/5] Fixed bug 1736 - Memory leak in X11_InitModes tomaszewski.p XRRListOutputProperties allocates Atom* array, which is not freed. XRRGetOutputProperty allocates 'unsigned char *prop' array, which is not freed. --- src/video/x11/SDL_x11modes.c | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/src/video/x11/SDL_x11modes.c b/src/video/x11/SDL_x11modes.c index e7822f057..d49555ad9 100644 --- a/src/video/x11/SDL_x11modes.c +++ b/src/video/x11/SDL_x11modes.c @@ -576,26 +576,31 @@ X11_InitModes(_THIS) int actual_format; unsigned long nitems, bytes_after; Atom actual_type; - + if (props[i] == EDID) { - XRRGetOutputProperty(data->display, res->outputs[output], props[i], - 0, 100, False, False, - AnyPropertyType, - &actual_type, &actual_format, - &nitems, &bytes_after, &prop); - - MonitorInfo *info = decode_edid(prop); - if (info) { -#ifdef X11MODES_DEBUG - printf("Found EDID data for %s\n", output_info->name); - dump_monitor_info(info); -#endif - SDL_strlcpy(display_name, info->dsc_product_name, sizeof(display_name)); - free(info); + if (XRRGetOutputProperty(data->display, + res->outputs[output], props[i], + 0, 100, False, False, + AnyPropertyType, + &actual_type, &actual_format, + &nitems, &bytes_after, &prop) == Success ) { + MonitorInfo *info = decode_edid(prop); + if (info) { + #ifdef X11MODES_DEBUG + printf("Found EDID data for %s\n", output_info->name); + dump_monitor_info(info); + #endif + SDL_strlcpy(display_name, info->dsc_product_name, sizeof(display_name)); + free(info); + } + SDL_free(prop); } break; } } + if (props) { + SDL_free(props); + } if (*display_name && inches) { size_t len = SDL_strlen(display_name); From 7481ef38694b641f9ea2b272059418c6b8778e4a Mon Sep 17 00:00:00 2001 From: Gabriel Jacobo Date: Fri, 1 Mar 2013 13:28:07 -0300 Subject: [PATCH 5/5] Use XFree to release X11 allocated data --- src/video/x11/SDL_x11modes.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/video/x11/SDL_x11modes.c b/src/video/x11/SDL_x11modes.c index d49555ad9..347e7bbdf 100644 --- a/src/video/x11/SDL_x11modes.c +++ b/src/video/x11/SDL_x11modes.c @@ -593,13 +593,13 @@ X11_InitModes(_THIS) SDL_strlcpy(display_name, info->dsc_product_name, sizeof(display_name)); free(info); } - SDL_free(prop); + XFree(prop); } break; } } if (props) { - SDL_free(props); + XFree(props); } if (*display_name && inches) {