Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set usescancodes=true when non-US keyboards are detected (Linux/MacOS builds) #4333

Merged
merged 6 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ Next
allocated block position. (maxpat78)
- Enhanced Dynamic and Differencing VHD support #4273 (maxpat78)
- Imported IBM Music Feature Card support from DOSBox Staging. (Allofich)
- Set usescancodes=true when non-US keyboards are detected. (Linux / MacOS
builds) (maron2000)
- Fix day of week detection (INT 21h 0x2Ah). (maron2000)
- Refine KEYB and CHCP command (maron2000)
2023.05.01
Expand Down
2 changes: 1 addition & 1 deletion include/keymap.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ enum {
DKM_DEU, // German keyboard layout (one concerned user, in issue tracker)
DKM_JPN_PC98, // Japanese PC98 keyboard layout (for PC-98 emulation)
DKM_JPN, // Japanese keyboard layout (one concerned user, in issue tracker, with suggestion for mapping Ro)

DKM_NON_US, // A non-US keyboard
DKM_MAX
};

Expand Down
40 changes: 38 additions & 2 deletions src/gui/sdl_mapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@

#include <output/output_ttf.h>

#if defined(MACOSX)
#include <Carbon/Carbon.h>
#endif

#define BMOD_Mod1 0x0001
#define BMOD_Mod2 0x0002
#define BMOD_Mod3 0x0004
Expand Down Expand Up @@ -999,7 +1003,7 @@ static SDLKey sdlkey_map[MAX_SCANCODES] = { // Convert hardware scancode (XKB =
SDLK_WORLD_14, //0x64 Henkan
SDLK_WORLD_15, //0x65 Hiragana/Katakana
SDLK_WORLD_13, //0x66 Muhenkan
Z,Z,Z,Z, //0x67-0x6a
Z,SDLK_KP_ENTER,SDLK_RCTRL,SDLK_KP_DIVIDE, //0x67-0x6a
Z, //SDLK_PRINTSCREEN, //0x6b
SDLK_RALT, //0x6c
Z, //0x6d unknown
Expand Down Expand Up @@ -1159,6 +1163,8 @@ static SDLKey sdlkey_map[MAX_SCANCODES] = {

#undef Z

unsigned int Linux_GetKeyboardLayout(void); // defined in sdlmain_linux.cpp

#if !defined(C_SDL2)
void setScanCode(Section_prop * section) {
usescancodes = -1;
Expand All @@ -1179,7 +1185,37 @@ void setScanCode(Section_prop * section) {
LOG_MSG("SDL_mapper: non-US keyboard detected, set usescancodes=true");
}
}
#endif // defined(WIN32)
#elif defined(__linux__)
else {
if(Linux_GetKeyboardLayout() == DKM_US) { /* Locale ID: en-us */
usescancodes = 0;
LOG_MSG("SDL_mapper: US keyboard detected, set usescancodes=false");
}
else {
usescancodes = 1;
LOG_MSG("SDL_mapper: non-US keyboard detected, set usescancodes=true");
}
}
#elif defined(MACOSX)
else {
char layout[128];
memset(layout, '\0', sizeof(layout));
TISInputSourceRef source = TISCopyCurrentKeyboardInputSource();
// get input source id - kTISPropertyInputSourceID
// get layout name - kTISPropertyLocalizedName
CFStringRef layoutID = CFStringRef(TISGetInputSourceProperty(source, kTISPropertyInputSourceID));
CFStringGetCString(layoutID, layout, sizeof(layout), kCFStringEncodingUTF8);
//LOG_MSG("SDL_mapper: %s\n", layout);
if(!strcasecmp(layout, "com.apple.keylayout.US")) { /* US keyboard layout */
usescancodes = 0;
LOG_MSG("SDL_mapper: US keyboard detected, set usescancodes=false");
}
else {
usescancodes = 1;
LOG_MSG("SDL_mapper: non-US keyboard detected, set usescancodes=true");
}
}
#endif //defined(MACOSX)
}
void loadScanCode();
const char* DOS_GetLoadedLayout(void);
Expand Down
2 changes: 1 addition & 1 deletion src/gui/sdlmain_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ void Linux_JPXKBFix(void) {
}

unsigned int Linux_GetKeyboardLayout(void) {
unsigned int ret = DKM_US;
unsigned int ret = DKM_NON_US; // a non-US keyboard

SDL_SysWMinfo wminfo;
memset(&wminfo,0,sizeof(wminfo));
Expand Down