Display and control your Android device
Handle AltGr as Right-Alt
Romain Vimont949d952d1843
diff --git a/app/src/input_manager.c b/app/src/input_manager.cindex fbc30400..af6ef906 100644--- a/app/src/input_manager.c+++ b/app/src/input_manager.c@@ -361,8 +361,8 @@ sc_input_manager_process_text_input(struct sc_input_manager *im,return;}- if (sc_shortcut_mods_is_shortcut_mod(im->sdl_shortcut_mods,- SDL_GetModState())) {+ uint16_t mod = sc_sdl_mod_normalize(SDL_GetModState());+ if (sc_shortcut_mods_is_shortcut_mod(im->sdl_shortcut_mods, mod)) {// A shortcut must never generate text eventsreturn;}@@ -423,10 +423,10 @@ sc_input_manager_process_key(struct sc_input_manager *im,bool disconnected = im->disconnected;SDL_Keycode sdl_keycode = event->key;- uint16_t mod = event->mod;+ uint16_t mod = sc_sdl_mod_normalize(event->mod);bool down = event->type == SDL_EVENT_KEY_DOWN;- bool ctrl = event->mod & SDL_KMOD_CTRL;- bool shift = event->mod & SDL_KMOD_SHIFT;+ bool ctrl = mod & SDL_KMOD_CTRL;+ bool shift = mod & SDL_KMOD_SHIFT;bool repeat = event->repeat;// Either the modifier includes a shortcut modifier, or the key@@ -451,8 +451,8 @@ sc_input_manager_process_key(struct sc_input_manager *im,switch (sdl_keycode) {case SDLK_F11:if (video && !repeat && down) {- bool alt = event->mod & SDL_KMOD_ALT;- bool super = event->mod & SDL_KMOD_GUI;+ bool alt = mod & SDL_KMOD_ALT;+ bool super = mod & SDL_KMOD_GUI;if (!ctrl && !shift && !alt && !super) {sc_screen_toggle_fullscreen(im->screen);}@@ -719,7 +719,7 @@ sc_input_manager_process_key(struct sc_input_manager *im,.keycode = keycode,.scancode = scancode,.repeat = event->repeat,- .mods_state = sc_mods_state_from_sdl(event->mod),+ .mods_state = sc_mods_state_from_sdl(mod),};assert(im->kp->ops->process_key);diff --git a/app/src/shortcut_mod.h b/app/src/shortcut_mod.hindex c53b0ff9..40d122aa 100644--- a/app/src/shortcut_mod.h+++ b/app/src/shortcut_mod.h@@ -12,6 +12,17 @@#define SC_SDL_SHORTCUT_MODS_MASK (SDL_KMOD_CTRL | SDL_KMOD_ALT | SDL_KMOD_GUI)+// On some platforms, depending on the keyboard layout, SDL reports AltGr as+// SDLK_MODE with the modifier SDL_KMOD_MODE instead of SDLK_RALT/SDL_KMOD_RALT+// (the scancode is still SDL_SCANCODE_RALT). Treat AltGr as Right-Alt.+static inline uint16_t+sc_sdl_mod_normalize(uint16_t sdl_mod) {+ if (sdl_mod & SDL_KMOD_MODE) {+ sdl_mod |= SDL_KMOD_RALT;+ }+ return sdl_mod;+}+// input: OR of enum sc_shortcut_mod// output: OR of SDL_Keymodstatic inline uint16_t@@ -53,7 +64,8 @@ sc_shortcut_mods_is_shortcut_key(uint16_t sdl_shortcut_mods,return (sdl_shortcut_mods & SDL_KMOD_LCTRL && keycode == SDLK_LCTRL)|| (sdl_shortcut_mods & SDL_KMOD_RCTRL && keycode == SDLK_RCTRL)|| (sdl_shortcut_mods & SDL_KMOD_LALT && keycode == SDLK_LALT)- || (sdl_shortcut_mods & SDL_KMOD_RALT && keycode == SDLK_RALT)+ || (sdl_shortcut_mods & SDL_KMOD_RALT && (keycode == SDLK_RALT+ || keycode == SDLK_MODE))|| (sdl_shortcut_mods & SDL_KMOD_LGUI && keycode == SDLK_LGUI)|| (sdl_shortcut_mods & SDL_KMOD_RGUI && keycode == SDLK_RGUI);}