| 1 | /* |
| 2 | Simple DirectMedia Layer |
| 3 | Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org> |
| 4 | |
| 5 | This software is provided 'as-is', without any express or implied |
| 6 | warranty. In no event will the authors be held liable for any damages |
| 7 | arising from the use of this software. |
| 8 | |
| 9 | Permission is granted to anyone to use this software for any purpose, |
| 10 | including commercial applications, and to alter it and redistribute it |
| 11 | freely, subject to the following restrictions: |
| 12 | |
| 13 | 1. The origin of this software must not be misrepresented; you must not |
| 14 | claim that you wrote the original software. If you use this software |
| 15 | in a product, an acknowledgment in the product documentation would be |
| 16 | appreciated but is not required. |
| 17 | 2. Altered source versions must be plainly marked as such, and must not be |
| 18 | misrepresented as being the original software. |
| 19 | 3. This notice may not be removed or altered from any source distribution. |
| 20 | */ |
| 21 | #include "SDL_internal.h" |
| 22 | |
| 23 | #if defined(SDL_INPUT_LINUXEV) || defined(SDL_VIDEO_DRIVER_WAYLAND) || defined(SDL_VIDEO_DRIVER_X11) |
| 24 | |
| 25 | #include "SDL_scancode_tables_c.h" |
| 26 | |
| 27 | #include "scancodes_darwin.h" |
| 28 | #include "scancodes_linux.h" |
| 29 | #include "scancodes_xfree86.h" |
| 30 | |
| 31 | static const struct |
| 32 | { |
| 33 | SDL_ScancodeTable table; |
| 34 | SDL_Scancode const *scancodes; |
| 35 | int num_entries; |
| 36 | } SDL_scancode_tables[] = { |
| 37 | { SDL_SCANCODE_TABLE_DARWIN, darwin_scancode_table, SDL_arraysize(darwin_scancode_table) }, |
| 38 | { SDL_SCANCODE_TABLE_LINUX, linux_scancode_table, SDL_arraysize(linux_scancode_table) }, |
| 39 | { SDL_SCANCODE_TABLE_XFREE86_1, xfree86_scancode_table, SDL_arraysize(xfree86_scancode_table) }, |
| 40 | { SDL_SCANCODE_TABLE_XFREE86_2, xfree86_scancode_table2, SDL_arraysize(xfree86_scancode_table2) }, |
| 41 | { SDL_SCANCODE_TABLE_XVNC, xvnc_scancode_table, SDL_arraysize(xvnc_scancode_table) }, |
| 42 | }; |
| 43 | |
| 44 | const SDL_Scancode *SDL_GetScancodeTable(SDL_ScancodeTable table, int *num_entries) |
| 45 | { |
| 46 | int i; |
| 47 | |
| 48 | for (i = 0; i < SDL_arraysize(SDL_scancode_tables); ++i) { |
| 49 | if (table == SDL_scancode_tables[i].table) { |
| 50 | *num_entries = SDL_scancode_tables[i].num_entries; |
| 51 | return SDL_scancode_tables[i].scancodes; |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | *num_entries = 0; |
| 56 | return NULL; |
| 57 | } |
| 58 | |
| 59 | SDL_Scancode SDL_GetScancodeFromTable(SDL_ScancodeTable table, int keycode) |
| 60 | { |
| 61 | SDL_Scancode scancode = SDL_SCANCODE_UNKNOWN; |
| 62 | int num_entries; |
| 63 | const SDL_Scancode *scancodes = SDL_GetScancodeTable(table, &num_entries); |
| 64 | |
| 65 | if (keycode >= 0 && keycode < num_entries) { |
| 66 | scancode = scancodes[keycode]; |
| 67 | } |
| 68 | return scancode; |
| 69 | } |
| 70 | |
| 71 | #endif // SDL_INPUT_LINUXEV || SDL_VIDEO_DRIVER_WAYLAND || SDL_VIDEO_DRIVER_X11 |
| 72 | |