From c0dff9bbfe0a741b231bb7f9baf3ff49a0819bc3 Mon Sep 17 00:00:00 2001 From: mjbudd77 Date: Sun, 27 Feb 2022 20:41:25 -0500 Subject: [PATCH] Qt Keyscan update for left/right meta keys. MacOSX menu accelerator fix. --- src/drivers/Qt/ConsoleWindow.cpp | 12 ++++++++++++ src/drivers/Qt/keyscan.cpp | 32 ++++++++++++++++++++++++++------ 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/drivers/Qt/ConsoleWindow.cpp b/src/drivers/Qt/ConsoleWindow.cpp index eb488c4f..ec42d5f0 100644 --- a/src/drivers/Qt/ConsoleWindow.cpp +++ b/src/drivers/Qt/ConsoleWindow.cpp @@ -100,6 +100,10 @@ #include "Qt/nes_shm.h" #include "Qt/TasEditor/TasEditorWindow.h" +#ifdef __APPLE__ +void qt_set_sequence_auto_mnemonic(bool enable); +#endif + consoleWin_t::consoleWin_t(QWidget *parent) : QMainWindow( parent ) { @@ -110,6 +114,10 @@ consoleWin_t::consoleWin_t(QWidget *parent) //QString libpath = QLibraryInfo::location(QLibraryInfo::PluginsPath); //printf("LibPath: '%s'\n", libpath.toStdString().c_str() ); +#ifdef __APPLE__ + qt_set_sequence_auto_mnemonic(true); +#endif + printf("Running on Platform: %s\n", QGuiApplication::platformName().toStdString().c_str() ); QApplication::setStyle( new fceuStyle() ); @@ -4671,6 +4679,8 @@ void consoleMenuBar::keyPressEvent(QKeyEvent *event) { QMenuBar::keyPressEvent(event); + pushKeyEvent( event, 1 ); + // Force de-focus of menu bar when escape key is pressed. // This prevents the menubar from hi-jacking keyboard input focus // when using menu accelerators @@ -4685,6 +4695,8 @@ void consoleMenuBar::keyReleaseEvent(QKeyEvent *event) { QMenuBar::keyReleaseEvent(event); + pushKeyEvent( event, 0 ); + event->accept(); } //----------------------------------------------------------------------------- diff --git a/src/drivers/Qt/keyscan.cpp b/src/drivers/Qt/keyscan.cpp index 64e130f5..183e7172 100644 --- a/src/drivers/Qt/keyscan.cpp +++ b/src/drivers/Qt/keyscan.cpp @@ -34,6 +34,7 @@ using namespace Qt; static uint32_t ShiftKeyCodeR = VK_RSHIFT; static uint32_t CtrlKeyCodeR = VK_RCONTROL; static uint32_t AltKeyCodeR = VK_RMENU; +static uint32_t MetaKeyCodeR = VK_RWIN; #elif defined(__linux__) @@ -42,21 +43,25 @@ static uint32_t AltKeyCodeR = VK_RMENU; static uint32_t ShiftKeyCodeR = XKB_KEY_Shift_R; static uint32_t CtrlKeyCodeR = XKB_KEY_Control_R; static uint32_t AltKeyCodeR = XKB_KEY_Alt_R; + static uint32_t MetaKeyCodeR = XKB_KEY_Meta_R; #elif defined(_HAS_X11) #include static uint32_t ShiftKeyCodeR = XK_Shift_R; static uint32_t CtrlKeyCodeR = XK_Control_R; static uint32_t AltKeyCodeR = XK_Alt_R; + static uint32_t MetaKeyCodeR = XK_Meta_R; #else static uint32_t ShiftKeyCodeR = 0xffe2; static uint32_t CtrlKeyCodeR = 0xffe4; static uint32_t AltKeyCodeR = 0xffea; + static uint32_t MetaKeyCodeR = 0xffe8; #endif #else static uint32_t ShiftKeyCodeR = 0xffe2; static uint32_t CtrlKeyCodeR = 0xffe4; static uint32_t AltKeyCodeR = 0xffea; +static uint32_t MetaKeyCodeR = 0xffe8; #endif SDL_Scancode convQtKey2SDLScanCode(Qt::Key q, uint32_t nativeVirtualKey) @@ -142,7 +147,14 @@ SDL_Scancode convQtKey2SDLScanCode(Qt::Key q, uint32_t nativeVirtualKey) } break; case Key_Meta: - s = SDL_SCANCODE_LGUI; + if ( nativeVirtualKey == MetaKeyCodeR ) + { + s = SDL_SCANCODE_RGUI; + } + else + { + s = SDL_SCANCODE_LGUI; + } break; case Key_Alt: if ( nativeVirtualKey == AltKeyCodeR ) @@ -635,7 +647,14 @@ SDL_Keycode convQtKey2SDLKeyCode(Qt::Key q, uint32_t nativeVirtualKey) } break; case Key_Meta: - s = SDLK_LGUI; + if ( nativeVirtualKey == MetaKeyCodeR ) + { + s = SDLK_RGUI; + } + else + { + s = SDLK_LGUI; + } break; case Key_Alt: if ( nativeVirtualKey == AltKeyCodeR ) @@ -1157,9 +1176,10 @@ int pushKeyEvent(QKeyEvent *event, int pressDown) sdlev.key.keysym.scancode = SDL_GetScancodeFromKey(sdlev.key.keysym.sym); - printf("Native ScanCode: x%08X %i \n", event->nativeScanCode(), event->nativeScanCode() ); - printf("Virtual ScanCode: x%08X %i \n", event->nativeVirtualKey(), event->nativeVirtualKey() ); - printf("Scancode: 0x%08X %i \n", sdlev.key.keysym.scancode, sdlev.key.keysym.scancode ); + //printf("Key %s\n", (sdlev.type == SDL_KEYUP) ? "UP" : "DOWN" ); + //printf(" Native ScanCode: x%08X %i \n", event->nativeScanCode(), event->nativeScanCode() ); + //printf(" Virtual ScanCode: x%08X %i \n", event->nativeVirtualKey(), event->nativeVirtualKey() ); + //printf(" Scancode: 0x%08X %i \n", sdlev.key.keysym.scancode, sdlev.key.keysym.scancode ); // SDL Docs say this code should never happen, but it does... // so force it to alternative scancode algorithm if it occurs. @@ -1172,7 +1192,7 @@ int pushKeyEvent(QKeyEvent *event, int pressDown) if ( sdlev.key.keysym.scancode == SDL_SCANCODE_UNKNOWN ) { // If scancode is unknown, the key may be dual function via the shift key. - sdlev.key.keysym.scancode = convQtKey2SDLScanCode( (Qt::Key)event->key() ); + sdlev.key.keysym.scancode = convQtKey2SDLScanCode( (Qt::Key)event->key(), vkey ); //printf("Dual Scancode: 0x%08X %i \n", sdlev.key.keysym.scancode, sdlev.key.keysym.scancode ); }