Qt Keyscan update for left/right meta keys. MacOSX menu accelerator fix.

This commit is contained in:
mjbudd77 2022-02-27 20:41:25 -05:00
parent 5e6fd870fe
commit c0dff9bbfe
2 changed files with 38 additions and 6 deletions

View File

@ -100,6 +100,10 @@
#include "Qt/nes_shm.h" #include "Qt/nes_shm.h"
#include "Qt/TasEditor/TasEditorWindow.h" #include "Qt/TasEditor/TasEditorWindow.h"
#ifdef __APPLE__
void qt_set_sequence_auto_mnemonic(bool enable);
#endif
consoleWin_t::consoleWin_t(QWidget *parent) consoleWin_t::consoleWin_t(QWidget *parent)
: QMainWindow( parent ) : QMainWindow( parent )
{ {
@ -110,6 +114,10 @@ consoleWin_t::consoleWin_t(QWidget *parent)
//QString libpath = QLibraryInfo::location(QLibraryInfo::PluginsPath); //QString libpath = QLibraryInfo::location(QLibraryInfo::PluginsPath);
//printf("LibPath: '%s'\n", libpath.toStdString().c_str() ); //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() ); printf("Running on Platform: %s\n", QGuiApplication::platformName().toStdString().c_str() );
QApplication::setStyle( new fceuStyle() ); QApplication::setStyle( new fceuStyle() );
@ -4671,6 +4679,8 @@ void consoleMenuBar::keyPressEvent(QKeyEvent *event)
{ {
QMenuBar::keyPressEvent(event); QMenuBar::keyPressEvent(event);
pushKeyEvent( event, 1 );
// Force de-focus of menu bar when escape key is pressed. // Force de-focus of menu bar when escape key is pressed.
// This prevents the menubar from hi-jacking keyboard input focus // This prevents the menubar from hi-jacking keyboard input focus
// when using menu accelerators // when using menu accelerators
@ -4685,6 +4695,8 @@ void consoleMenuBar::keyReleaseEvent(QKeyEvent *event)
{ {
QMenuBar::keyReleaseEvent(event); QMenuBar::keyReleaseEvent(event);
pushKeyEvent( event, 0 );
event->accept(); event->accept();
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View File

@ -34,6 +34,7 @@ using namespace Qt;
static uint32_t ShiftKeyCodeR = VK_RSHIFT; static uint32_t ShiftKeyCodeR = VK_RSHIFT;
static uint32_t CtrlKeyCodeR = VK_RCONTROL; static uint32_t CtrlKeyCodeR = VK_RCONTROL;
static uint32_t AltKeyCodeR = VK_RMENU; static uint32_t AltKeyCodeR = VK_RMENU;
static uint32_t MetaKeyCodeR = VK_RWIN;
#elif defined(__linux__) #elif defined(__linux__)
@ -42,21 +43,25 @@ static uint32_t AltKeyCodeR = VK_RMENU;
static uint32_t ShiftKeyCodeR = XKB_KEY_Shift_R; static uint32_t ShiftKeyCodeR = XKB_KEY_Shift_R;
static uint32_t CtrlKeyCodeR = XKB_KEY_Control_R; static uint32_t CtrlKeyCodeR = XKB_KEY_Control_R;
static uint32_t AltKeyCodeR = XKB_KEY_Alt_R; static uint32_t AltKeyCodeR = XKB_KEY_Alt_R;
static uint32_t MetaKeyCodeR = XKB_KEY_Meta_R;
#elif defined(_HAS_X11) #elif defined(_HAS_X11)
#include <X11/keysym.h> #include <X11/keysym.h>
static uint32_t ShiftKeyCodeR = XK_Shift_R; static uint32_t ShiftKeyCodeR = XK_Shift_R;
static uint32_t CtrlKeyCodeR = XK_Control_R; static uint32_t CtrlKeyCodeR = XK_Control_R;
static uint32_t AltKeyCodeR = XK_Alt_R; static uint32_t AltKeyCodeR = XK_Alt_R;
static uint32_t MetaKeyCodeR = XK_Meta_R;
#else #else
static uint32_t ShiftKeyCodeR = 0xffe2; static uint32_t ShiftKeyCodeR = 0xffe2;
static uint32_t CtrlKeyCodeR = 0xffe4; static uint32_t CtrlKeyCodeR = 0xffe4;
static uint32_t AltKeyCodeR = 0xffea; static uint32_t AltKeyCodeR = 0xffea;
static uint32_t MetaKeyCodeR = 0xffe8;
#endif #endif
#else #else
static uint32_t ShiftKeyCodeR = 0xffe2; static uint32_t ShiftKeyCodeR = 0xffe2;
static uint32_t CtrlKeyCodeR = 0xffe4; static uint32_t CtrlKeyCodeR = 0xffe4;
static uint32_t AltKeyCodeR = 0xffea; static uint32_t AltKeyCodeR = 0xffea;
static uint32_t MetaKeyCodeR = 0xffe8;
#endif #endif
SDL_Scancode convQtKey2SDLScanCode(Qt::Key q, uint32_t nativeVirtualKey) SDL_Scancode convQtKey2SDLScanCode(Qt::Key q, uint32_t nativeVirtualKey)
@ -142,7 +147,14 @@ SDL_Scancode convQtKey2SDLScanCode(Qt::Key q, uint32_t nativeVirtualKey)
} }
break; break;
case Key_Meta: case Key_Meta:
s = SDL_SCANCODE_LGUI; if ( nativeVirtualKey == MetaKeyCodeR )
{
s = SDL_SCANCODE_RGUI;
}
else
{
s = SDL_SCANCODE_LGUI;
}
break; break;
case Key_Alt: case Key_Alt:
if ( nativeVirtualKey == AltKeyCodeR ) if ( nativeVirtualKey == AltKeyCodeR )
@ -635,7 +647,14 @@ SDL_Keycode convQtKey2SDLKeyCode(Qt::Key q, uint32_t nativeVirtualKey)
} }
break; break;
case Key_Meta: case Key_Meta:
s = SDLK_LGUI; if ( nativeVirtualKey == MetaKeyCodeR )
{
s = SDLK_RGUI;
}
else
{
s = SDLK_LGUI;
}
break; break;
case Key_Alt: case Key_Alt:
if ( nativeVirtualKey == AltKeyCodeR ) if ( nativeVirtualKey == AltKeyCodeR )
@ -1157,9 +1176,10 @@ int pushKeyEvent(QKeyEvent *event, int pressDown)
sdlev.key.keysym.scancode = SDL_GetScancodeFromKey(sdlev.key.keysym.sym); sdlev.key.keysym.scancode = SDL_GetScancodeFromKey(sdlev.key.keysym.sym);
printf("Native ScanCode: x%08X %i \n", event->nativeScanCode(), event->nativeScanCode() ); //printf("Key %s\n", (sdlev.type == SDL_KEYUP) ? "UP" : "DOWN" );
printf("Virtual ScanCode: x%08X %i \n", event->nativeVirtualKey(), event->nativeVirtualKey() ); //printf(" Native ScanCode: x%08X %i \n", event->nativeScanCode(), event->nativeScanCode() );
printf("Scancode: 0x%08X %i \n", sdlev.key.keysym.scancode, sdlev.key.keysym.scancode ); //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... // SDL Docs say this code should never happen, but it does...
// so force it to alternative scancode algorithm if it occurs. // 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 ( sdlev.key.keysym.scancode == SDL_SCANCODE_UNKNOWN )
{ // If scancode is unknown, the key may be dual function via the shift key. { // 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 ); //printf("Dual Scancode: 0x%08X %i \n", sdlev.key.keysym.scancode, sdlev.key.keysym.scancode );
} }