this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix TIC-80 when using a French AZERTY layout (#2663)

* Initial naive implementation

* Reorganize code

* Generalize & future-proof

Detects more keyboard layouts etc.

* Unbreak other platforms

* Refactor keyboard layouts into an enum

authored by

Alice and committed by
GitHub
e60a708b 3af8080a

+49 -7
+10
include/tic80.h
··· 166 166 u32 data; 167 167 } tic80_keyboard; 168 168 169 + typedef enum { 170 + tic_layout_unknown = 0, 171 + tic_layout_qwerty, 172 + tic_layout_azerty, 173 + tic_layout_qwertz, 174 + tic_layout_qzerty, 175 + tic_layout_de_neo, 176 + tic_layout_de_bone 177 + } tic_layout; 178 + 169 179 typedef struct 170 180 { 171 181 tic80_gamepads gamepads;
+8 -2
src/studio/studio.c
··· 1825 1825 { 1826 1826 if (enterWasPressedOnce(studio)) gotoFullscreen(studio); 1827 1827 #if defined(BUILD_EDITORS) 1828 - else if(studio->mode != TIC_RUN_MODE) 1828 + else if(studio->mode != TIC_RUN_MODE && studio->config->data.keyboardLayout != tic_layout_azerty) 1829 1829 { 1830 1830 if(keyWasPressedOnce(studio, tic_key_grave)) setStudioMode(studio, TIC_CONSOLE_MODE); 1831 1831 else if(keyWasPressedOnce(studio, tic_key_1)) setStudioMode(studio, TIC_CODE_MODE); ··· 2652 2652 2653 2653 #endif 2654 2654 2655 + void studio_keymapchanged(Studio* studio, tic_layout keyboardLayout) 2656 + { 2657 + studio->config->data.keyboardLayout = keyboardLayout; 2658 + } 2659 + 2655 2660 bool studio_alive(Studio* studio) 2656 2661 { 2657 2662 return studio->alive; ··· 2683 2688 } 2684 2689 #endif 2685 2690 2686 - Studio* studio_create(s32 argc, char **argv, s32 samplerate, tic80_pixel_color_format format, const char* folder, s32 maxscale) 2691 + Studio* studio_create(s32 argc, char **argv, s32 samplerate, tic80_pixel_color_format format, const char* folder, s32 maxscale, tic_layout keyboardLayout) 2687 2692 { 2688 2693 setbuf(stdout, NULL); 2689 2694 ··· 2857 2862 studio->config->data.fft = args.fft; 2858 2863 studio->config->data.fftcaptureplaybackdevices = args.fftcaptureplaybackdevices; 2859 2864 studio->config->data.fftdevice = args.fftdevice; 2865 + studio->config->data.keyboardLayout = keyboardLayout; 2860 2866 #endif 2861 2867 2862 2868 studioConfigChanged(studio);
+4 -1
src/studio/system.h
··· 152 152 int fft; 153 153 int fftcaptureplaybackdevices; 154 154 const char *fftdevice; 155 + 156 + tic_layout keyboardLayout; 155 157 } StudioConfig; 156 158 157 159 typedef struct Studio Studio; ··· 162 164 void studio_tick(Studio* studio, tic80_input input); 163 165 void studio_sound(Studio* studio); 164 166 void studio_load(Studio* studio, const char* file); 167 + void studio_keymapchanged(Studio *studio, tic_layout keyboardLayout); 165 168 bool studio_alive(Studio* studio); 166 169 void studio_exit(Studio* studio); 167 170 void studio_delete(Studio* studio); 168 171 const StudioConfig* studio_config(Studio* studio); 169 172 170 - Studio* studio_create(s32 argc, char **argv, s32 samplerate, tic80_pixel_color_format format, const char* appFolder, s32 maxscale); 173 + Studio* studio_create(s32 argc, char **argv, s32 samplerate, tic80_pixel_color_format format, const char* appFolder, s32 maxscale, tic_layout keyboardLayout); 171 174 172 175 #ifdef __cplusplus 173 176 }
+2 -2
src/system/baremetalpi/kernel.cpp
··· 392 392 char* argv[] = { &arg0[0], NULL }; 393 393 int argc = 1; 394 394 malloc(88); 395 - platform.studio = studio_create(argc, argv, 44100, TIC80_PIXEL_COLOR_BGRA8888, "tic80", INT32_MAX); 395 + platform.studio = studio_create(argc, argv, 44100, TIC80_PIXEL_COLOR_BGRA8888, "tic80", INT32_MAX, tic_layout_qwerty); 396 396 malloc(99); 397 397 398 398 } ··· 404 404 char* argv[] = { &arg0[0], &arg1[0], NULL }; 405 405 int argc = 2; 406 406 dbg("Without keyboard\n"); 407 - platform.studio = studio_create(argc, argv, 44100, TIC80_PIXEL_COLOR_BGRA8888, "tic80", INT32_MAX); 407 + platform.studio = studio_create(argc, argv, 44100, TIC80_PIXEL_COLOR_BGRA8888, "tic80", INT32_MAX, tic_layout_qwerty); 408 408 } 409 409 dbg("studio_create OK\n"); 410 410
+1 -1
src/system/n3ds/main.c
··· 580 580 n3ds_draw_init(); 581 581 n3ds_keyboard_init(&platform.keyboard); 582 582 583 - platform.studio = studio_create(argc_used, argv_used, AUDIO_FREQ, TIC80_PIXEL_COLOR_ABGR8888, "./", INT32_MAX); 583 + platform.studio = studio_create(argc_used, argv_used, AUDIO_FREQ, TIC80_PIXEL_COLOR_ABGR8888, "./", INT32_MAX, tic_layout_qwerty); 584 584 585 585 n3ds_sound_init(AUDIO_FREQ); 586 586
+24 -1
src/system/sdl/main.c
··· 1062 1062 #endif 1063 1063 } 1064 1064 1065 + tic_layout detect_keyboard_layout() 1066 + { 1067 + char q = SDL_GetKeyFromScancode(SDL_SCANCODE_Q); 1068 + char w = SDL_GetKeyFromScancode(SDL_SCANCODE_W); 1069 + char y = SDL_GetKeyFromScancode(SDL_SCANCODE_Y); 1070 + 1071 + tic_layout layout = tic_layout_unknown; 1072 + 1073 + if (q == 'q' && w == 'w' && y == 'y') layout = tic_layout_qwerty; // US etc. 1074 + if (q == 'a' && w == 'z' && y == 'y') layout = tic_layout_azerty; // French 1075 + if (q == 'q' && w == 'w' && y == 'z') layout = tic_layout_qwertz; // German etc. 1076 + if (q == 'q' && w == 'z' && y == 'y') layout = tic_layout_qzerty; // Italian 1077 + // Don't ask me why it detects k instead of l 1078 + if (q == 'x' && w == 'v' && y == 'k') layout = tic_layout_de_neo; // xvlcwk - German Neo 1079 + // ...or why it detects p instead of u 1080 + if (q == 'j' && w == 'd' && y == 'p') layout = tic_layout_de_bone; // jduaxp - German Bone 1081 + 1082 + return layout; 1083 + } 1084 + 1065 1085 static void pollEvents() 1066 1086 { 1067 1087 // check if releative mode was enabled ··· 1192 1212 break; 1193 1213 case SDL_KEYUP: 1194 1214 handleKeydown(event.key.keysym.sym, false, platform.keyboard.state, platform.keyboard.pressed); 1215 + break; 1216 + case SDL_KEYMAPCHANGED: 1217 + studio_keymapchanged(platform.studio, detect_keyboard_layout()); 1195 1218 break; 1196 1219 case SDL_TEXTINPUT: 1197 1220 if(strlen(event.text.text) == 1) ··· 1894 1917 SDL_Log("Unable to initialize SDL Game Controller: %i, %s\n", result, SDL_GetError()); 1895 1918 } 1896 1919 1897 - platform.studio = studio_create(argc, argv, TIC80_SAMPLERATE, SCREEN_FORMAT, folder, determineMaximumScale()); 1920 + platform.studio = studio_create(argc, argv, TIC80_SAMPLERATE, SCREEN_FORMAT, folder, determineMaximumScale(), detect_keyboard_layout()); 1898 1921 1899 1922 SCOPE(studio_delete(platform.studio)) 1900 1923 {