From aa2bdf2a1c2e1e004703b6e8bb61cb1cd7e257fc Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Wed, 23 Dec 2020 23:50:19 +0200 Subject: [PATCH] Better support for non-QWERTY Latin layouts --- SDL/gui.c | 4 ++-- SDL/gui.h | 9 +++++++++ SDL/main.c | 3 +-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/SDL/gui.c b/SDL/gui.c index 62656e8..3848d15 100644 --- a/SDL/gui.c +++ b/SDL/gui.c @@ -1206,7 +1206,7 @@ void run_gui(bool is_running) } case SDL_KEYDOWN: - if (event.key.keysym.scancode == SDL_SCANCODE_F && event.key.keysym.mod & MODIFIER) { + if (event_hotkey_code(&event) == SDL_SCANCODE_F && event.key.keysym.mod & MODIFIER) { if ((SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN_DESKTOP) == false) { SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP); } @@ -1215,7 +1215,7 @@ void run_gui(bool is_running) } update_viewport(); } - if (event.key.keysym.scancode == SDL_SCANCODE_O) { + if (event_hotkey_code(&event) == SDL_SCANCODE_O) { if (event.key.keysym.mod & MODIFIER) { char *filename = do_open_rom_dialog(); if (filename) { diff --git a/SDL/gui.h b/SDL/gui.h index c950907..f55464d 100644 --- a/SDL/gui.h +++ b/SDL/gui.h @@ -122,4 +122,13 @@ void connect_joypad(void); joypad_button_t get_joypad_button(uint8_t physical_button); joypad_axis_t get_joypad_axis(uint8_t physical_axis); +static SDL_Scancode event_hotkey_code(SDL_Event *event) +{ + if (event->key.keysym.sym >= SDLK_a && event->key.keysym.sym < SDLK_z) { + return SDL_SCANCODE_A + event->key.keysym.sym - SDLK_a; + } + + return event->key.keysym.scancode; +} + #endif diff --git a/SDL/main.c b/SDL/main.c index e79d0b3..45d016d 100644 --- a/SDL/main.c +++ b/SDL/main.c @@ -233,7 +233,7 @@ static void handle_events(GB_gameboy_t *gb) }; case SDL_KEYDOWN: - switch (event.key.keysym.scancode) { + switch (event_hotkey_code(&event)) { case SDL_SCANCODE_ESCAPE: { open_menu(); break; @@ -241,7 +241,6 @@ static void handle_events(GB_gameboy_t *gb) case SDL_SCANCODE_C: if (event.type == SDL_KEYDOWN && (event.key.keysym.mod & KMOD_CTRL)) { GB_debugger_break(gb); - } break;