diff --git a/CMakeLists.txt b/CMakeLists.txt index 62ced8270e..418f674667 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1171,10 +1171,6 @@ if(WIN32) target_link_libraries(Common winmm d3d9 dsound) endif() -if(TARGET SDL2::SDL2 AND NOT IOS) - target_link_libraries(Common SDL2::SDL2) -endif() - list(APPEND NativeAppSource android/jni/TestRunner.cpp UI/DiscordIntegration.cpp diff --git a/Common/System/System.h b/Common/System/System.h index bc9a340859..22ce537665 100644 --- a/Common/System/System.h +++ b/Common/System/System.h @@ -47,6 +47,12 @@ enum SystemDeviceType { DEVICE_TYPE_DESKTOP = 2, // Desktop computer }; +enum SystemKeyboardLayout { + KEYBOARD_LAYOUT_QWERTY = 0, + KEYBOARD_LAYOUT_QWERTZ = 1, + KEYBOARD_LAYOUT_AZERTY = 2, +}; + enum SystemProperty { SYSPROP_NAME, SYSPROP_LANGREGION, @@ -104,6 +110,8 @@ enum SystemProperty { SYSPROP_ANDROID_SCOPED_STORAGE, SYSPROP_CAN_JIT, + + SYSPROP_KEYBOARD_LAYOUT, }; std::string System_GetProperty(SystemProperty prop); diff --git a/Core/KeyMap.cpp b/Core/KeyMap.cpp index 6b9627eaa6..acd8eb91b7 100644 --- a/Core/KeyMap.cpp +++ b/Core/KeyMap.cpp @@ -19,12 +19,6 @@ #include #include -#if defined(SDL) -#include -#elif defined(USING_WIN_UI) -#include "CommonWindows.h" -#endif - #include "ppsspp_config.h" #include "Common/System/NativeApp.h" diff --git a/Core/KeyMapDefaults.cpp b/Core/KeyMapDefaults.cpp index 7862341e36..f06ae9e012 100644 --- a/Core/KeyMapDefaults.cpp +++ b/Core/KeyMapDefaults.cpp @@ -1,14 +1,9 @@ -#if defined(SDL) -#include -#elif defined(USING_WIN_UI) -#include "CommonWindows.h" -#endif - #include "ppsspp_config.h" #include "Common/CommonFuncs.h" #include "Common/Input/KeyCodes.h" #include "Common/Input/InputState.h" +#include "Common/System/System.h" #include "Core/KeyMapDefaults.h" #include "Core/KeyMap.h" @@ -303,39 +298,18 @@ void SetDefaultKeyMap(DefaultMaps dmap, bool replace) { switch (dmap) { case DEFAULT_MAPPING_KEYBOARD: { - bool azerty = false; - bool qwertz = false; -#if defined(SDL) - char q, w, y; - q = SDL_GetKeyFromScancode(SDL_SCANCODE_Q); - w = SDL_GetKeyFromScancode(SDL_SCANCODE_W); - y = SDL_GetKeyFromScancode(SDL_SCANCODE_Y); - if (q == 'a' && w == 'z' && y == 'y') - azerty = true; - else if (q == 'q' && w == 'w' && y == 'z') - qwertz = true; -#elif defined(USING_WIN_UI) - HKL localeId = GetKeyboardLayout(0); - // TODO: Is this list complete enough? - switch ((int)(intptr_t)localeId & 0xFFFF) { - case 0x407: - qwertz = true; - break; - case 0x040c: - case 0x080c: - case 0x1009: - azerty = true; - break; - default: - break; - } -#endif - if (azerty) { - SetDefaultKeyMap(DEVICE_ID_KEYBOARD, defaultAzertyKeyboardKeyMap, ARRAY_SIZE(defaultAzertyKeyboardKeyMap), replace); - } else if (qwertz) { + int keyboardLayout = System_GetPropertyInt(SYSPROP_KEYBOARD_LAYOUT); + switch (keyboardLayout) { + case KEYBOARD_LAYOUT_QWERTZ: SetDefaultKeyMap(DEVICE_ID_KEYBOARD, defaultQwertzKeyboardKeyMap, ARRAY_SIZE(defaultQwertzKeyboardKeyMap), replace); - } else { + break; + case KEYBOARD_LAYOUT_AZERTY: + SetDefaultKeyMap(DEVICE_ID_KEYBOARD, defaultAzertyKeyboardKeyMap, ARRAY_SIZE(defaultAzertyKeyboardKeyMap), replace); + break; + case KEYBOARD_LAYOUT_QWERTY: + default: SetDefaultKeyMap(DEVICE_ID_KEYBOARD, defaultQwertyKeyboardKeyMap, ARRAY_SIZE(defaultQwertyKeyboardKeyMap), replace); + break; } } break; diff --git a/Qt/QtMain.cpp b/Qt/QtMain.cpp index 17d1b58de6..e3b3829177 100644 --- a/Qt/QtMain.cpp +++ b/Qt/QtMain.cpp @@ -30,6 +30,7 @@ #ifdef SDL #include "SDL/SDLJoystick.h" #include "SDL_audio.h" +#include "SDL_keyboard.h" #endif #include "Common/System/NativeApp.h" @@ -176,6 +177,19 @@ int System_GetPropertyInt(SystemProperty prop) { return g_retFmt.freq; case SYSPROP_AUDIO_FRAMES_PER_BUFFER: return g_retFmt.samples; + case SYSPROP_KEYBOARD_LAYOUT: + { + // TODO: Use Qt APIs for detecting this + char q, w, y; + q = SDL_GetKeyFromScancode(SDL_SCANCODE_Q); + w = SDL_GetKeyFromScancode(SDL_SCANCODE_W); + y = SDL_GetKeyFromScancode(SDL_SCANCODE_Y); + if (q == 'a' && w == 'z' && y == 'y') + return KEYBOARD_LAYOUT_AZERTY; + else if (q == 'q' && w == 'w' && y == 'z') + return KEYBOARD_LAYOUT_QWERTZ; + return KEYBOARD_LAYOUT_QWERTY; + } #endif case SYSPROP_DEVICE_TYPE: #if defined(__ANDROID__) diff --git a/SDL/SDLMain.cpp b/SDL/SDLMain.cpp index 09aa31b1ec..8795307309 100644 --- a/SDL/SDLMain.cpp +++ b/SDL/SDLMain.cpp @@ -375,6 +375,18 @@ int System_GetPropertyInt(SystemProperty prop) { #endif case SYSPROP_DISPLAY_COUNT: return SDL_GetNumVideoDisplays(); + case SYSPROP_KEYBOARD_LAYOUT: + { + char q, w, y; + q = SDL_GetKeyFromScancode(SDL_SCANCODE_Q); + w = SDL_GetKeyFromScancode(SDL_SCANCODE_W); + y = SDL_GetKeyFromScancode(SDL_SCANCODE_Y); + if (q == 'a' && w == 'z' && y == 'y') + return KEYBOARD_LAYOUT_AZERTY; + else if (q == 'q' && w == 'w' && y == 'z') + return KEYBOARD_LAYOUT_QWERTZ; + return KEYBOARD_LAYOUT_QWERTY; + } default: return -1; } diff --git a/Windows/main.cpp b/Windows/main.cpp index 6b0f2d1098..1885c72cf6 100644 --- a/Windows/main.cpp +++ b/Windows/main.cpp @@ -279,6 +279,21 @@ int System_GetPropertyInt(SystemProperty prop) { return DEVICE_TYPE_DESKTOP; case SYSPROP_DISPLAY_COUNT: return GetSystemMetrics(SM_CMONITORS); + case SYSPROP_KEYBOARD_LAYOUT: + { + HKL localeId = GetKeyboardLayout(0); + // TODO: Is this list complete enough? + switch ((int)(intptr_t)localeId & 0xFFFF) { + case 0x407: + return KEYBOARD_LAYOUT_QWERTZ; + case 0x040c: + case 0x080c: + case 0x1009: + return KEYBOARD_LAYOUT_AZERTY; + default: + return KEYBOARD_LAYOUT_QWERTY; + } + } default: return -1; }