Skip to content

Commit b6e1e6e

Browse files
author
gbeauche
committed
Force processing of modifier keys through SDL keysyms. Fix mapping of
Option & Command keys on MacOS X. Fix scroll lock on MacOS X too.
1 parent 4ea24ed commit b6e1e6e

File tree

1 file changed

+55
-11
lines changed

1 file changed

+55
-11
lines changed

BasiliskII/src/SDL/video_sdl.cpp

+55-11
Original file line numberDiff line numberDiff line change
@@ -787,8 +787,8 @@ static void keycode_init(void)
787787

788788
if (video_driver_found) {
789789
// Skip aliases
790-
static const char alias_str[] = "alias";
791-
if (strncmp(line, alias_str, sizeof(alias_str) - 1) == 0)
790+
static const char sdl_str[] = "sdl";
791+
if (strncmp(line, sdl_str, sizeof(sdl_str) - 1) == 0)
792792
continue;
793793

794794
// Read keycode
@@ -799,9 +799,9 @@ static void keycode_init(void)
799799
break;
800800
} else {
801801
// Search for SDL video driver string
802-
static const char alias_sdl_str[] = "alias SDL";
803-
if (strncmp(line, alias_sdl_str, sizeof(alias_sdl_str) - 1) == 0) {
804-
char *p = line + sizeof(alias_sdl_str);
802+
static const char sdl_str[] = "sdl";
803+
if (strncmp(line, sdl_str, sizeof(sdl_str) - 1) == 0) {
804+
char *p = line + sizeof(sdl_str);
805805
if (strstr(video_driver, p) == video_driver)
806806
video_driver_found = true;
807807
}
@@ -1629,15 +1629,43 @@ void VideoInstallAccel(void)
16291629

16301630

16311631
/*
1632-
* Translate key event to Mac keycode, returns -1 if no keycode was found
1633-
* and -2 if the key was recognized as a hotkey
1632+
* Keyboard-related utilify functions
16341633
*/
16351634

1635+
static bool is_modifier_key(SDL_KeyboardEvent const & e)
1636+
{
1637+
switch (e.keysym.sym) {
1638+
case SDLK_NUMLOCK:
1639+
case SDLK_CAPSLOCK:
1640+
case SDLK_SCROLLOCK:
1641+
case SDLK_RSHIFT:
1642+
case SDLK_LSHIFT:
1643+
case SDLK_RCTRL:
1644+
case SDLK_LCTRL:
1645+
case SDLK_RALT:
1646+
case SDLK_LALT:
1647+
case SDLK_RMETA:
1648+
case SDLK_LMETA:
1649+
case SDLK_LSUPER:
1650+
case SDLK_RSUPER:
1651+
case SDLK_MODE:
1652+
case SDLK_COMPOSE:
1653+
return true;
1654+
}
1655+
return false;
1656+
}
1657+
16361658
static bool is_ctrl_down(SDL_keysym const & ks)
16371659
{
16381660
return ctrl_down || (ks.mod & KMOD_CTRL);
16391661
}
16401662

1663+
1664+
/*
1665+
* Translate key event to Mac keycode, returns -1 if no keycode was found
1666+
* and -2 if the key was recognized as a hotkey
1667+
*/
1668+
16411669
static int kc_decode(SDL_keysym const & ks, bool key_down)
16421670
{
16431671
switch (ks.sym) {
@@ -1707,10 +1735,17 @@ static int kc_decode(SDL_keysym const & ks, bool key_down)
17071735
case SDLK_RCTRL: return 0x36;
17081736
case SDLK_LSHIFT: return 0x38;
17091737
case SDLK_RSHIFT: return 0x38;
1738+
#if (defined(__APPLE__) && defined(__MACH__))
1739+
case SDLK_LALT: return 0x3a;
1740+
case SDLK_RALT: return 0x3a;
1741+
case SDLK_LMETA: return 0x37;
1742+
case SDLK_RMETA: return 0x37;
1743+
#else
17101744
case SDLK_LALT: return 0x37;
17111745
case SDLK_RALT: return 0x37;
17121746
case SDLK_LMETA: return 0x3a;
17131747
case SDLK_RMETA: return 0x3a;
1748+
#endif
17141749
case SDLK_MENU: return 0x32;
17151750
case SDLK_CAPSLOCK: return 0x39;
17161751
case SDLK_NUMLOCK: return 0x47;
@@ -1817,7 +1852,7 @@ static void handle_events(void)
18171852
// Keyboard
18181853
case SDL_KEYDOWN: {
18191854
int code = -1;
1820-
if (use_keycodes) {
1855+
if (use_keycodes && !is_modifier_key(event.key)) {
18211856
if (event2keycode(event.key, true) != -2) // This is called to process the hotkeys
18221857
code = keycode_table[event.key.keysym.scancode & 0xff];
18231858
} else
@@ -1845,13 +1880,22 @@ static void handle_events(void)
18451880
}
18461881
case SDL_KEYUP: {
18471882
int code = -1;
1848-
if (use_keycodes) {
1883+
if (use_keycodes && !is_modifier_key(event.key)) {
18491884
if (event2keycode(event.key, false) != -2) // This is called to process the hotkeys
18501885
code = keycode_table[event.key.keysym.scancode & 0xff];
18511886
} else
18521887
code = event2keycode(event.key, false);
1853-
if (code >= 0 && code != 0x39) { // Don't propagate Caps Lock releases
1854-
ADBKeyUp(code);
1888+
if (code >= 0) {
1889+
if (code == 0x39) { // Caps Lock released
1890+
if (caps_on) {
1891+
ADBKeyUp(code);
1892+
caps_on = false;
1893+
} else {
1894+
ADBKeyDown(code);
1895+
caps_on = true;
1896+
}
1897+
} else
1898+
ADBKeyUp(code);
18551899
if (code == 0x36)
18561900
ctrl_down = false;
18571901
}

0 commit comments

Comments
 (0)