Merge pull request #9192 from german77/i_had_to_copy_each_one_again

yuzu: Change QtKeyToSwitchKey switch case to array
This commit is contained in:
bunnei 2022-11-10 13:44:41 -08:00 committed by GitHub
commit bb55d2e701
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 120 additions and 217 deletions

View File

@ -401,224 +401,127 @@ void GRenderWindow::closeEvent(QCloseEvent* event) {
} }
int GRenderWindow::QtKeyToSwitchKey(Qt::Key qt_key) { int GRenderWindow::QtKeyToSwitchKey(Qt::Key qt_key) {
switch (qt_key) { static constexpr std::array<std::pair<Qt::Key, Settings::NativeKeyboard::Keys>, 106> key_map = {
case Qt::Key_A: std::pair<Qt::Key, Settings::NativeKeyboard::Keys>{Qt::Key_A, Settings::NativeKeyboard::A},
return Settings::NativeKeyboard::A; {Qt::Key_A, Settings::NativeKeyboard::A},
case Qt::Key_B: {Qt::Key_B, Settings::NativeKeyboard::B},
return Settings::NativeKeyboard::B; {Qt::Key_C, Settings::NativeKeyboard::C},
case Qt::Key_C: {Qt::Key_D, Settings::NativeKeyboard::D},
return Settings::NativeKeyboard::C; {Qt::Key_E, Settings::NativeKeyboard::E},
case Qt::Key_D: {Qt::Key_F, Settings::NativeKeyboard::F},
return Settings::NativeKeyboard::D; {Qt::Key_G, Settings::NativeKeyboard::G},
case Qt::Key_E: {Qt::Key_H, Settings::NativeKeyboard::H},
return Settings::NativeKeyboard::E; {Qt::Key_I, Settings::NativeKeyboard::I},
case Qt::Key_F: {Qt::Key_J, Settings::NativeKeyboard::J},
return Settings::NativeKeyboard::F; {Qt::Key_K, Settings::NativeKeyboard::K},
case Qt::Key_G: {Qt::Key_L, Settings::NativeKeyboard::L},
return Settings::NativeKeyboard::G; {Qt::Key_M, Settings::NativeKeyboard::M},
case Qt::Key_H: {Qt::Key_N, Settings::NativeKeyboard::N},
return Settings::NativeKeyboard::H; {Qt::Key_O, Settings::NativeKeyboard::O},
case Qt::Key_I: {Qt::Key_P, Settings::NativeKeyboard::P},
return Settings::NativeKeyboard::I; {Qt::Key_Q, Settings::NativeKeyboard::Q},
case Qt::Key_J: {Qt::Key_R, Settings::NativeKeyboard::R},
return Settings::NativeKeyboard::J; {Qt::Key_S, Settings::NativeKeyboard::S},
case Qt::Key_K: {Qt::Key_T, Settings::NativeKeyboard::T},
return Settings::NativeKeyboard::K; {Qt::Key_U, Settings::NativeKeyboard::U},
case Qt::Key_L: {Qt::Key_V, Settings::NativeKeyboard::V},
return Settings::NativeKeyboard::L; {Qt::Key_W, Settings::NativeKeyboard::W},
case Qt::Key_M: {Qt::Key_X, Settings::NativeKeyboard::X},
return Settings::NativeKeyboard::M; {Qt::Key_Y, Settings::NativeKeyboard::Y},
case Qt::Key_N: {Qt::Key_Z, Settings::NativeKeyboard::Z},
return Settings::NativeKeyboard::N; {Qt::Key_1, Settings::NativeKeyboard::N1},
case Qt::Key_O: {Qt::Key_2, Settings::NativeKeyboard::N2},
return Settings::NativeKeyboard::O; {Qt::Key_3, Settings::NativeKeyboard::N3},
case Qt::Key_P: {Qt::Key_4, Settings::NativeKeyboard::N4},
return Settings::NativeKeyboard::P; {Qt::Key_5, Settings::NativeKeyboard::N5},
case Qt::Key_Q: {Qt::Key_6, Settings::NativeKeyboard::N6},
return Settings::NativeKeyboard::Q; {Qt::Key_7, Settings::NativeKeyboard::N7},
case Qt::Key_R: {Qt::Key_8, Settings::NativeKeyboard::N8},
return Settings::NativeKeyboard::R; {Qt::Key_9, Settings::NativeKeyboard::N9},
case Qt::Key_S: {Qt::Key_0, Settings::NativeKeyboard::N0},
return Settings::NativeKeyboard::S; {Qt::Key_Return, Settings::NativeKeyboard::Return},
case Qt::Key_T: {Qt::Key_Escape, Settings::NativeKeyboard::Escape},
return Settings::NativeKeyboard::T; {Qt::Key_Backspace, Settings::NativeKeyboard::Backspace},
case Qt::Key_U: {Qt::Key_Tab, Settings::NativeKeyboard::Tab},
return Settings::NativeKeyboard::U; {Qt::Key_Space, Settings::NativeKeyboard::Space},
case Qt::Key_V: {Qt::Key_Minus, Settings::NativeKeyboard::Minus},
return Settings::NativeKeyboard::V; {Qt::Key_Plus, Settings::NativeKeyboard::Plus},
case Qt::Key_W: {Qt::Key_questiondown, Settings::NativeKeyboard::Plus},
return Settings::NativeKeyboard::W; {Qt::Key_BracketLeft, Settings::NativeKeyboard::OpenBracket},
case Qt::Key_X: {Qt::Key_BraceLeft, Settings::NativeKeyboard::OpenBracket},
return Settings::NativeKeyboard::X; {Qt::Key_BracketRight, Settings::NativeKeyboard::CloseBracket},
case Qt::Key_Y: {Qt::Key_BraceRight, Settings::NativeKeyboard::CloseBracket},
return Settings::NativeKeyboard::Y; {Qt::Key_Bar, Settings::NativeKeyboard::Pipe},
case Qt::Key_Z: {Qt::Key_Dead_Tilde, Settings::NativeKeyboard::Tilde},
return Settings::NativeKeyboard::Z; {Qt::Key_Ntilde, Settings::NativeKeyboard::Semicolon},
case Qt::Key_1: {Qt::Key_Semicolon, Settings::NativeKeyboard::Semicolon},
return Settings::NativeKeyboard::N1; {Qt::Key_Apostrophe, Settings::NativeKeyboard::Quote},
case Qt::Key_2: {Qt::Key_Dead_Grave, Settings::NativeKeyboard::Backquote},
return Settings::NativeKeyboard::N2; {Qt::Key_Comma, Settings::NativeKeyboard::Comma},
case Qt::Key_3: {Qt::Key_Period, Settings::NativeKeyboard::Period},
return Settings::NativeKeyboard::N3; {Qt::Key_Slash, Settings::NativeKeyboard::Slash},
case Qt::Key_4: {Qt::Key_CapsLock, Settings::NativeKeyboard::CapsLockKey},
return Settings::NativeKeyboard::N4; {Qt::Key_F1, Settings::NativeKeyboard::F1},
case Qt::Key_5: {Qt::Key_F2, Settings::NativeKeyboard::F2},
return Settings::NativeKeyboard::N5; {Qt::Key_F3, Settings::NativeKeyboard::F3},
case Qt::Key_6: {Qt::Key_F4, Settings::NativeKeyboard::F4},
return Settings::NativeKeyboard::N6; {Qt::Key_F5, Settings::NativeKeyboard::F5},
case Qt::Key_7: {Qt::Key_F6, Settings::NativeKeyboard::F6},
return Settings::NativeKeyboard::N7; {Qt::Key_F7, Settings::NativeKeyboard::F7},
case Qt::Key_8: {Qt::Key_F8, Settings::NativeKeyboard::F8},
return Settings::NativeKeyboard::N8; {Qt::Key_F9, Settings::NativeKeyboard::F9},
case Qt::Key_9: {Qt::Key_F10, Settings::NativeKeyboard::F10},
return Settings::NativeKeyboard::N9; {Qt::Key_F11, Settings::NativeKeyboard::F11},
case Qt::Key_0: {Qt::Key_F12, Settings::NativeKeyboard::F12},
return Settings::NativeKeyboard::N0; {Qt::Key_Print, Settings::NativeKeyboard::PrintScreen},
case Qt::Key_Return: {Qt::Key_ScrollLock, Settings::NativeKeyboard::ScrollLockKey},
return Settings::NativeKeyboard::Return; {Qt::Key_Pause, Settings::NativeKeyboard::Pause},
case Qt::Key_Escape: {Qt::Key_Insert, Settings::NativeKeyboard::Insert},
return Settings::NativeKeyboard::Escape; {Qt::Key_Home, Settings::NativeKeyboard::Home},
case Qt::Key_Backspace: {Qt::Key_PageUp, Settings::NativeKeyboard::PageUp},
return Settings::NativeKeyboard::Backspace; {Qt::Key_Delete, Settings::NativeKeyboard::Delete},
case Qt::Key_Tab: {Qt::Key_End, Settings::NativeKeyboard::End},
return Settings::NativeKeyboard::Tab; {Qt::Key_PageDown, Settings::NativeKeyboard::PageDown},
case Qt::Key_Space: {Qt::Key_Right, Settings::NativeKeyboard::Right},
return Settings::NativeKeyboard::Space; {Qt::Key_Left, Settings::NativeKeyboard::Left},
case Qt::Key_Minus: {Qt::Key_Down, Settings::NativeKeyboard::Down},
return Settings::NativeKeyboard::Minus; {Qt::Key_Up, Settings::NativeKeyboard::Up},
case Qt::Key_Plus: {Qt::Key_NumLock, Settings::NativeKeyboard::NumLockKey},
case Qt::Key_questiondown:
return Settings::NativeKeyboard::Plus;
case Qt::Key_BracketLeft:
case Qt::Key_BraceLeft:
return Settings::NativeKeyboard::OpenBracket;
case Qt::Key_BracketRight:
case Qt::Key_BraceRight:
return Settings::NativeKeyboard::CloseBracket;
case Qt::Key_Bar:
return Settings::NativeKeyboard::Pipe;
case Qt::Key_Dead_Tilde:
return Settings::NativeKeyboard::Tilde;
case Qt::Key_Ntilde:
case Qt::Key_Semicolon:
return Settings::NativeKeyboard::Semicolon;
case Qt::Key_Apostrophe:
return Settings::NativeKeyboard::Quote;
case Qt::Key_Dead_Grave:
return Settings::NativeKeyboard::Backquote;
case Qt::Key_Comma:
return Settings::NativeKeyboard::Comma;
case Qt::Key_Period:
return Settings::NativeKeyboard::Period;
case Qt::Key_Slash:
return Settings::NativeKeyboard::Slash;
case Qt::Key_CapsLock:
return Settings::NativeKeyboard::CapsLock;
case Qt::Key_F1:
return Settings::NativeKeyboard::F1;
case Qt::Key_F2:
return Settings::NativeKeyboard::F2;
case Qt::Key_F3:
return Settings::NativeKeyboard::F3;
case Qt::Key_F4:
return Settings::NativeKeyboard::F4;
case Qt::Key_F5:
return Settings::NativeKeyboard::F5;
case Qt::Key_F6:
return Settings::NativeKeyboard::F6;
case Qt::Key_F7:
return Settings::NativeKeyboard::F7;
case Qt::Key_F8:
return Settings::NativeKeyboard::F8;
case Qt::Key_F9:
return Settings::NativeKeyboard::F9;
case Qt::Key_F10:
return Settings::NativeKeyboard::F10;
case Qt::Key_F11:
return Settings::NativeKeyboard::F11;
case Qt::Key_F12:
return Settings::NativeKeyboard::F12;
case Qt::Key_Print:
return Settings::NativeKeyboard::PrintScreen;
case Qt::Key_ScrollLock:
return Settings::NativeKeyboard::ScrollLock;
case Qt::Key_Pause:
return Settings::NativeKeyboard::Pause;
case Qt::Key_Insert:
return Settings::NativeKeyboard::Insert;
case Qt::Key_Home:
return Settings::NativeKeyboard::Home;
case Qt::Key_PageUp:
return Settings::NativeKeyboard::PageUp;
case Qt::Key_Delete:
return Settings::NativeKeyboard::Delete;
case Qt::Key_End:
return Settings::NativeKeyboard::End;
case Qt::Key_PageDown:
return Settings::NativeKeyboard::PageDown;
case Qt::Key_Right:
return Settings::NativeKeyboard::Right;
case Qt::Key_Left:
return Settings::NativeKeyboard::Left;
case Qt::Key_Down:
return Settings::NativeKeyboard::Down;
case Qt::Key_Up:
return Settings::NativeKeyboard::Up;
case Qt::Key_NumLock:
return Settings::NativeKeyboard::NumLock;
// Numpad keys are missing here // Numpad keys are missing here
case Qt::Key_F13: {Qt::Key_F13, Settings::NativeKeyboard::F13},
return Settings::NativeKeyboard::F13; {Qt::Key_F14, Settings::NativeKeyboard::F14},
case Qt::Key_F14: {Qt::Key_F15, Settings::NativeKeyboard::F15},
return Settings::NativeKeyboard::F14; {Qt::Key_F16, Settings::NativeKeyboard::F16},
case Qt::Key_F15: {Qt::Key_F17, Settings::NativeKeyboard::F17},
return Settings::NativeKeyboard::F15; {Qt::Key_F18, Settings::NativeKeyboard::F18},
case Qt::Key_F16: {Qt::Key_F19, Settings::NativeKeyboard::F19},
return Settings::NativeKeyboard::F16; {Qt::Key_F20, Settings::NativeKeyboard::F20},
case Qt::Key_F17: {Qt::Key_F21, Settings::NativeKeyboard::F21},
return Settings::NativeKeyboard::F17; {Qt::Key_F22, Settings::NativeKeyboard::F22},
case Qt::Key_F18: {Qt::Key_F23, Settings::NativeKeyboard::F23},
return Settings::NativeKeyboard::F18; {Qt::Key_F24, Settings::NativeKeyboard::F24},
case Qt::Key_F19: // {Qt::..., Settings::NativeKeyboard::KPComma},
return Settings::NativeKeyboard::F19; // {Qt::..., Settings::NativeKeyboard::Ro},
case Qt::Key_F20: {Qt::Key_Hiragana_Katakana, Settings::NativeKeyboard::KatakanaHiragana},
return Settings::NativeKeyboard::F20; {Qt::Key_yen, Settings::NativeKeyboard::Yen},
case Qt::Key_F21: {Qt::Key_Henkan, Settings::NativeKeyboard::Henkan},
return Settings::NativeKeyboard::F21; {Qt::Key_Muhenkan, Settings::NativeKeyboard::Muhenkan},
case Qt::Key_F22: // {Qt::..., Settings::NativeKeyboard::NumPadCommaPc98},
return Settings::NativeKeyboard::F22; {Qt::Key_Hangul, Settings::NativeKeyboard::HangulEnglish},
case Qt::Key_F23: {Qt::Key_Hangul_Hanja, Settings::NativeKeyboard::Hanja},
return Settings::NativeKeyboard::F23; {Qt::Key_Katakana, Settings::NativeKeyboard::KatakanaKey},
case Qt::Key_F24: {Qt::Key_Hiragana, Settings::NativeKeyboard::HiraganaKey},
return Settings::NativeKeyboard::F24; {Qt::Key_Zenkaku_Hankaku, Settings::NativeKeyboard::ZenkakuHankaku},
// case Qt:::
// return Settings::NativeKeyboard::KPComma;
// case Qt:::
// return Settings::NativeKeyboard::Ro;
case Qt::Key_Hiragana_Katakana:
return Settings::NativeKeyboard::KatakanaHiragana;
case Qt::Key_yen:
return Settings::NativeKeyboard::Yen;
case Qt::Key_Henkan:
return Settings::NativeKeyboard::Henkan;
case Qt::Key_Muhenkan:
return Settings::NativeKeyboard::Muhenkan;
// case Qt:::
// return Settings::NativeKeyboard::NumPadCommaPc98;
case Qt::Key_Hangul:
return Settings::NativeKeyboard::HangulEnglish;
case Qt::Key_Hangul_Hanja:
return Settings::NativeKeyboard::Hanja;
case Qt::Key_Katakana:
return Settings::NativeKeyboard::KatakanaKey;
case Qt::Key_Hiragana:
return Settings::NativeKeyboard::HiraganaKey;
case Qt::Key_Zenkaku_Hankaku:
return Settings::NativeKeyboard::ZenkakuHankaku;
// Modifier keys are handled by the modifier property // Modifier keys are handled by the modifier property
default: };
return Settings::NativeKeyboard::None;
for (const auto& [qkey, nkey] : key_map) {
if (qt_key == qkey) {
return nkey;
} }
}
return Settings::NativeKeyboard::None;
} }
int GRenderWindow::QtModifierToSwitchModifier(Qt::KeyboardModifiers qt_modifiers) { int GRenderWindow::QtModifierToSwitchModifier(Qt::KeyboardModifiers qt_modifiers) {