diff --git a/src/studio/studio.c b/src/studio/studio.c index 6dbe8a420..1fec12cee 100644 --- a/src/studio/studio.c +++ b/src/studio/studio.c @@ -1825,7 +1825,7 @@ static void processShortcuts(Studio* studio) { if (enterWasPressedOnce(studio)) gotoFullscreen(studio); #if defined(BUILD_EDITORS) - else if(studio->mode != TIC_RUN_MODE) + else if(studio->mode != TIC_RUN_MODE && strcmp(studio->config->data.keyboardLayout, "azerty") != 0) { if(keyWasPressedOnce(studio, tic_key_grave)) setStudioMode(studio, TIC_CONSOLE_MODE); else if(keyWasPressedOnce(studio, tic_key_1)) setStudioMode(studio, TIC_CODE_MODE); @@ -2652,6 +2652,11 @@ static void setPopupHide(void* data) #endif +void studio_keymapchanged(Studio* studio, char* keyboardLayout) +{ + studio->config->data.keyboardLayout = keyboardLayout; +} + bool studio_alive(Studio* studio) { return studio->alive; @@ -2683,7 +2688,7 @@ static bool onEnumModule(const char* name, const char* title, const char* hash, } #endif -Studio* studio_create(s32 argc, char **argv, s32 samplerate, tic80_pixel_color_format format, const char* folder, s32 maxscale) +Studio* studio_create(s32 argc, char **argv, s32 samplerate, tic80_pixel_color_format format, const char* folder, s32 maxscale, char* keyboardLayout) { setbuf(stdout, NULL); @@ -2857,6 +2862,7 @@ Studio* studio_create(s32 argc, char **argv, s32 samplerate, tic80_pixel_color_f studio->config->data.fft = args.fft; studio->config->data.fftcaptureplaybackdevices = args.fftcaptureplaybackdevices; studio->config->data.fftdevice = args.fftdevice; + studio->config->data.keyboardLayout = keyboardLayout; #endif studioConfigChanged(studio); diff --git a/src/studio/system.h b/src/studio/system.h index a1ba3a81e..43293614c 100644 --- a/src/studio/system.h +++ b/src/studio/system.h @@ -152,6 +152,8 @@ typedef struct int fft; int fftcaptureplaybackdevices; const char *fftdevice; + + char* keyboardLayout; } StudioConfig; typedef struct Studio Studio; @@ -162,12 +164,13 @@ const tic_mem* studio_mem(Studio* studio); void studio_tick(Studio* studio, tic80_input input); void studio_sound(Studio* studio); void studio_load(Studio* studio, const char* file); +void studio_keymapchanged(Studio *studio, char* keyboardLayout); bool studio_alive(Studio* studio); void studio_exit(Studio* studio); void studio_delete(Studio* studio); const StudioConfig* studio_config(Studio* studio); -Studio* studio_create(s32 argc, char **argv, s32 samplerate, tic80_pixel_color_format format, const char* appFolder, s32 maxscale); +Studio* studio_create(s32 argc, char **argv, s32 samplerate, tic80_pixel_color_format format, const char* appFolder, s32 maxscale, char* keyboardLayout); #ifdef __cplusplus } diff --git a/src/system/baremetalpi/kernel.cpp b/src/system/baremetalpi/kernel.cpp index abc181b8c..0f6f96c32 100644 --- a/src/system/baremetalpi/kernel.cpp +++ b/src/system/baremetalpi/kernel.cpp @@ -392,7 +392,7 @@ TShutdownMode Run(void) char* argv[] = { &arg0[0], NULL }; int argc = 1; malloc(88); - platform.studio = studio_create(argc, argv, 44100, TIC80_PIXEL_COLOR_BGRA8888, "tic80", INT32_MAX); + platform.studio = studio_create(argc, argv, 44100, TIC80_PIXEL_COLOR_BGRA8888, "tic80", INT32_MAX, "qwerty"); malloc(99); } @@ -404,7 +404,7 @@ TShutdownMode Run(void) char* argv[] = { &arg0[0], &arg1[0], NULL }; int argc = 2; dbg("Without keyboard\n"); - platform.studio = studio_create(argc, argv, 44100, TIC80_PIXEL_COLOR_BGRA8888, "tic80", INT32_MAX); + platform.studio = studio_create(argc, argv, 44100, TIC80_PIXEL_COLOR_BGRA8888, "tic80", INT32_MAX, "qwerty"); } dbg("studio_create OK\n"); diff --git a/src/system/n3ds/main.c b/src/system/n3ds/main.c index 3b51f122e..45f4def3d 100644 --- a/src/system/n3ds/main.c +++ b/src/system/n3ds/main.c @@ -580,7 +580,7 @@ int main(int argc, char **argv) { n3ds_draw_init(); n3ds_keyboard_init(&platform.keyboard); - platform.studio = studio_create(argc_used, argv_used, AUDIO_FREQ, TIC80_PIXEL_COLOR_ABGR8888, "./", INT32_MAX); + platform.studio = studio_create(argc_used, argv_used, AUDIO_FREQ, TIC80_PIXEL_COLOR_ABGR8888, "./", INT32_MAX, "qwerty"); n3ds_sound_init(AUDIO_FREQ); diff --git a/src/system/sdl/main.c b/src/system/sdl/main.c index fc0f1f9af..095cd9ea9 100644 --- a/src/system/sdl/main.c +++ b/src/system/sdl/main.c @@ -1062,6 +1062,26 @@ static void handleKeydown(SDL_Keycode keycode, bool down, bool* state, bool* pre #endif } +char* detect_keyboard_layout() +{ + char q = SDL_GetKeyFromScancode(SDL_SCANCODE_Q); + char w = SDL_GetKeyFromScancode(SDL_SCANCODE_W); + char y = SDL_GetKeyFromScancode(SDL_SCANCODE_Y); + + char* layout = "unknown"; + + if (q == 'q' && w == 'w' && y == 'y') layout = "qwerty"; // US etc. + if (q == 'a' && w == 'z' && y == 'y') layout = "azerty"; // French + if (q == 'q' && w == 'w' && y == 'z') layout = "qwertz"; // German etc. + if (q == 'q' && w == 'z' && y == 'y') layout = "qzerty"; // Italian + // Don't ask me why it detects k instead of l + if (q == 'x' && w == 'v' && y == 'k') layout = "xvlcwk"; // German Neo 2 + // ...or why it detects p instead of u + if (q == 'j' && w == 'd' && y == 'p') layout = "jduaxp"; // German Bone + + return layout; +} + static void pollEvents() { // check if releative mode was enabled @@ -1193,6 +1213,9 @@ static void pollEvents() case SDL_KEYUP: handleKeydown(event.key.keysym.sym, false, platform.keyboard.state, platform.keyboard.pressed); break; + case SDL_KEYMAPCHANGED: + studio_keymapchanged(platform.studio, detect_keyboard_layout()); + break; case SDL_TEXTINPUT: if(strlen(event.text.text) == 1) platform.keyboard.text = event.text.text[0]; @@ -1894,7 +1917,7 @@ static s32 start(s32 argc, char **argv, const char* folder) SDL_Log("Unable to initialize SDL Game Controller: %i, %s\n", result, SDL_GetError()); } - platform.studio = studio_create(argc, argv, TIC80_SAMPLERATE, SCREEN_FORMAT, folder, determineMaximumScale()); + platform.studio = studio_create(argc, argv, TIC80_SAMPLERATE, SCREEN_FORMAT, folder, determineMaximumScale(), detect_keyboard_layout()); SCOPE(studio_delete(platform.studio)) { diff --git a/src/system/sokol/sokol.c b/src/system/sokol/sokol.c index b89345b9b..66b962839 100644 --- a/src/system/sokol/sokol.c +++ b/src/system/sokol/sokol.c @@ -414,7 +414,7 @@ sapp_desc sokol_main(s32 argc, char* argv[]) platform.audio.desc.num_channels = TIC80_SAMPLE_CHANNELS; saudio_setup(&platform.audio.desc); - platform.studio = studio_create(argc, argv, saudio_sample_rate(), TIC80_PIXEL_COLOR_RGBA8888, "./", INT32_MAX); + platform.studio = studio_create(argc, argv, saudio_sample_rate(), TIC80_PIXEL_COLOR_RGBA8888, "./", INT32_MAX, "qwerty"); if(studio_config(platform.studio)->cli) {