Use System_GetPropertyInt to report the keyboard layout

This commit is contained in:
Cameron Cawley 2022-01-10 00:11:08 +00:00
parent 37c2dd8dd4
commit 26203552b4
7 changed files with 60 additions and 47 deletions

View File

@ -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

View File

@ -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);

View File

@ -19,12 +19,6 @@
#include <set>
#include <unordered_map>
#if defined(SDL)
#include <SDL_keyboard.h>
#elif defined(USING_WIN_UI)
#include "CommonWindows.h"
#endif
#include "ppsspp_config.h"
#include "Common/System/NativeApp.h"

View File

@ -1,14 +1,9 @@
#if defined(SDL)
#include <SDL_keyboard.h>
#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;

View File

@ -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__)

View File

@ -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;
}

View File

@ -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;
}