Merge branch 'test_keymap'

This commit is contained in:
kanjitalk755 2020-02-10 09:58:54 +09:00
commit 7b13571587
1 changed files with 19 additions and 39 deletions

View File

@ -68,6 +68,9 @@
#define DEBUG 0
#include "debug.h"
#define CODE_INVALID -1
#define CODE_HOTKEY -2
// Supported video modes
using std::vector;
static vector<VIDEO_MODE> VideoModes;
@ -1207,7 +1210,7 @@ static void keycode_init(void)
// Default translation table
for (int i=0; i<256; i++)
keycode_table[i] = -1;
keycode_table[i] = CODE_INVALID;
// Search for server vendor string, then read keycodes
const char * video_driver = SDL_GetCurrentVideoDriver();
@ -1893,27 +1896,6 @@ void video_set_cursor(void)
* Keyboard-related utilify functions
*/
static bool is_modifier_key(SDL_KeyboardEvent const & e)
{
switch (e.keysym.sym) {
case SDLK_NUMLOCKCLEAR:
case SDLK_CAPSLOCK:
case SDLK_SCROLLLOCK:
case SDLK_RSHIFT:
case SDLK_LSHIFT:
case SDLK_RCTRL:
case SDLK_LCTRL:
case SDLK_RALT:
case SDLK_LALT:
case SDLK_RGUI:
case SDLK_LGUI:
case SDLK_MODE:
case SDLK_APPLICATION:
return true;
}
return false;
}
static bool is_hotkey_down(SDL_Keysym const & ks)
{
int hotkey = PrefsFindInt32("hotkey");
@ -1925,8 +1907,8 @@ static bool is_hotkey_down(SDL_Keysym const & ks)
/*
* Translate key event to Mac keycode, returns -1 if no keycode was found
* and -2 if the key was recognized as a hotkey
* Translate key event to Mac keycode, returns CODE_INVALID if no keycode was found
* and CODE_HOTKEY if the key was recognized as a hotkey
*/
static int kc_decode(SDL_Keysym const & ks, bool key_down)
@ -1982,8 +1964,8 @@ static int kc_decode(SDL_Keysym const & ks, bool key_down)
case SDLK_PERIOD: case SDLK_GREATER: return 0x2f;
case SDLK_SLASH: case SDLK_QUESTION: return 0x2c;
case SDLK_TAB: if (is_hotkey_down(ks)) {if (!key_down) drv->suspend(); return -2;} else return 0x30;
case SDLK_RETURN: if (is_hotkey_down(ks)) {if (!key_down) toggle_fullscreen = true; return -2;} else return 0x24;
case SDLK_TAB: if (is_hotkey_down(ks)) {if (!key_down) drv->suspend(); return CODE_HOTKEY;} else return 0x30;
case SDLK_RETURN: if (is_hotkey_down(ks)) {if (!key_down) toggle_fullscreen = true; return CODE_HOTKEY;} else return 0x24;
case SDLK_SPACE: return 0x31;
case SDLK_BACKSPACE: return 0x33;
@ -2018,9 +2000,9 @@ static int kc_decode(SDL_Keysym const & ks, bool key_down)
case SDLK_LEFT: return 0x3b;
case SDLK_RIGHT: return 0x3c;
case SDLK_ESCAPE: if (is_hotkey_down(ks)) {if (!key_down) { quit_full_screen = true; emerg_quit = true; } return -2;} else return 0x35;
case SDLK_ESCAPE: if (is_hotkey_down(ks)) {if (!key_down) { quit_full_screen = true; emerg_quit = true; } return CODE_HOTKEY;} else return 0x35;
case SDLK_F1: if (is_hotkey_down(ks)) {if (!key_down) SysMountFirstFloppy(); return -2;} else return 0x7a;
case SDLK_F1: if (is_hotkey_down(ks)) {if (!key_down) SysMountFirstFloppy(); return CODE_HOTKEY;} else return 0x7a;
case SDLK_F2: return 0x78;
case SDLK_F3: return 0x63;
case SDLK_F4: return 0x76;
@ -2056,7 +2038,7 @@ static int kc_decode(SDL_Keysym const & ks, bool key_down)
case SDLK_KP_EQUALS: return 0x51;
}
D(bug("Unhandled SDL keysym: %d\n", ks.sym));
return -1;
return CODE_INVALID;
}
static int event2keycode(SDL_KeyboardEvent const &ev, bool key_down)
@ -2209,11 +2191,10 @@ static void handle_events(void)
// Keyboard
case SDL_KEYDOWN: {
int code = -1;
if (use_keycodes && !is_modifier_key(event.key)) {
if (event2keycode(event.key, true) != -2) // This is called to process the hotkeys
code = keycode_table[event.key.keysym.scancode & 0xff];
} else
int code = CODE_INVALID;
if (use_keycodes && event2keycode(event.key, true) != CODE_HOTKEY)
code = keycode_table[event.key.keysym.scancode & 0xff];
if (code == CODE_INVALID)
code = event2keycode(event.key, true);
if (code >= 0) {
if (!emul_suspended) {
@ -2240,11 +2221,10 @@ static void handle_events(void)
break;
}
case SDL_KEYUP: {
int code = -1;
if (use_keycodes && !is_modifier_key(event.key)) {
if (event2keycode(event.key, false) != -2) // This is called to process the hotkeys
code = keycode_table[event.key.keysym.scancode & 0xff];
} else
int code = CODE_INVALID;
if (use_keycodes && event2keycode(event.key, false) != CODE_HOTKEY)
code = keycode_table[event.key.keysym.scancode & 0xff];
if (code == CODE_INVALID)
code = event2keycode(event.key, false);
if (code >= 0) {
ADBKeyUp(code);