Skip to content

Commit

Permalink
Merge pull request #4333 from maron2000/usescancodes
Browse files Browse the repository at this point in the history
Set usescancodes=true when non-US keyboards are detected (Linux/MacOS builds)
  • Loading branch information
joncampbell123 committed Jul 17, 2023
2 parents ad58da4 + b72bf1b commit 14e103a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
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

0 comments on commit 14e103a

Please sign in to comment.