From 496895d60c1686674942bb8b5f9e108ea5bb98e8 Mon Sep 17 00:00:00 2001 From: marauder2k7 Date: Fri, 13 Mar 2026 21:59:46 +0000 Subject: [PATCH] action map remap for mac Mac now automatically remaps keys and modifies the incoming string to reflect it automatically converts: Ctrl -> Cmd Alt -> Option if you absolutely need a specific set on macos you will still need to check the platform in script and set the required key otherwise this will allow menus to be built with just providing the windows key or the mac key and it will display correclty for the platform. --- Engine/source/platformSDL/sdlInput.cpp | 8 ++ Engine/source/platformSDL/sdlPlatformGL.cpp | 4 + Engine/source/sim/actionMap.cpp | 104 +++++++++++++++----- 3 files changed, 89 insertions(+), 27 deletions(-) diff --git a/Engine/source/platformSDL/sdlInput.cpp b/Engine/source/platformSDL/sdlInput.cpp index 67d86b277..34fa91ecc 100644 --- a/Engine/source/platformSDL/sdlInput.cpp +++ b/Engine/source/platformSDL/sdlInput.cpp @@ -77,6 +77,14 @@ void Input::init() smLastJoystickActivated = true; SDL_InitSubSystem( SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_GAMECONTROLLER | SDL_INIT_EVENTS ); + +#ifdef TORQUE_OS_MAC + // Disable Ctrl+Click being treated as right-click + SDL_SetHint(SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK, "0"); + + // Optionally, handle function keys as standard F1–F12 + SDL_SetHint(SDL_HINT_MAC_BACKGROUND_APP, "0"); +#endif // Init the current modifier keys setModifierKeys(0); diff --git a/Engine/source/platformSDL/sdlPlatformGL.cpp b/Engine/source/platformSDL/sdlPlatformGL.cpp index 22e719f58..a6ca387c8 100644 --- a/Engine/source/platformSDL/sdlPlatformGL.cpp +++ b/Engine/source/platformSDL/sdlPlatformGL.cpp @@ -19,6 +19,10 @@ namespace PlatformGL #ifdef TORQUE_DEBUG debugFlag |= SDL_GL_CONTEXT_DEBUG_FLAG; #endif + +#if SDL_VERSION_ATLEAST(2, 24, 0) + SDL_SetHint(SDL_HINT_MAC_OPENGL_ASYNC_DISPATCH, "1"); +#endif SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, debugFlag); SDL_GL_SetAttribute(SDL_GL_FRAMEBUFFER_SRGB_CAPABLE, 1); diff --git a/Engine/source/sim/actionMap.cpp b/Engine/source/sim/actionMap.cpp index 16d107eb3..c852dbf8d 100644 --- a/Engine/source/sim/actionMap.cpp +++ b/Engine/source/sim/actionMap.cpp @@ -466,23 +466,41 @@ bool ActionMap::createEventDescriptor(const char* pEventString, EventDescriptor* pObjectString = pSpace + 1; pSpace[0] = '\0'; - char* pModifier = dStrtok(copyBuffer, "-"); - while (pModifier != NULL) { - if (dStricmp(pModifier, "shift") == 0) { - pDescriptor->flags |= SI_SHIFT; - } else if (dStricmp(pModifier, "ctrl") == 0) { - pDescriptor->flags |= SI_CTRL; - } else if (dStricmp(pModifier, "alt") == 0) { - pDescriptor->flags |= SI_ALT; - } else if (dStricmp(pModifier, "cmd") == 0) { - pDescriptor->flags |= SI_ALT; - } else if (dStricmp(pModifier, "opt") == 0) { - pDescriptor->flags |= SI_MAC_OPT; - } - - pModifier = dStrtok(NULL, "-"); - } - } else { + char* pModifier = dStrtok(copyBuffer, "-"); + while (pModifier != NULL) + { +#if defined(TORQUE_OS_MAC) + if (dStricmp(pModifier, "ctrl") == 0 || dStricmp(pModifier, "cmd") == 0) + { + pDescriptor->flags |= SI_CTRL; // On Mac, map Ctrl/Cmd to the standard Mac command key + } + else if (dStricmp(pModifier, "shift") == 0) + { + pDescriptor->flags |= SI_SHIFT; + } + else if (dStricmp(pModifier, "alt") == 0 || dStricmp(pModifier, "opt") == 0) + { + pDescriptor->flags |= SI_MAC_OPT; + } +#else + if (dStricmp(pModifier, "ctrl") == 0 || (dStricmp(pModifier, "cmd") == 0) + { + pDescriptor->flags |= SI_CTRL; + } + else if (dStricmp(pModifier, "shift") == 0) + { + pDescriptor->flags |= SI_SHIFT; + } + else if (dStricmp(pModifier, "alt") == 0 || dStricmp(pModifier, "opt") == 0) + { + pDescriptor->flags |= SI_ALT; + } +#endif + pModifier = dStrtok(NULL, "-"); + } + } + else + { // No. pDescriptor->flags = 0; pObjectString = copyBuffer; @@ -492,6 +510,47 @@ bool ActionMap::createEventDescriptor(const char* pEventString, EventDescriptor* // AssertFatal(dStrlen(pObjectString) != 0, "Error, no key was specified!"); + // rebuild normalized modifier string from parsed flags + String newString; + +#if defined(TORQUE_OS_MAC) + + if (pDescriptor->flags & SI_ALT || pDescriptor->flags & SI_CTRL) + newString += "Cmd"; + + if (pDescriptor->flags & SI_MAC_OPT) + { + if (newString.length()) newString += "-"; + newString += "Opt"; + } + +#else + + if (pDescriptor->flags & SI_CTRL) + newString += "Ctrl"; + + if (pDescriptor->flags & SI_ALT) + { + if (newString.length()) newString += "-"; + newString += "Alt"; + } + +#endif + + if (pDescriptor->flags & SI_SHIFT) + { + if (newString.length()) newString += "-"; + newString += "Shift"; + } + + // rebuild full event string + if (newString.length()) + newString = String::ToString("%s %s", newString.c_str(), pObjectString).c_str(); + else + newString = String::ToString("%s", pObjectString).c_str(); + + dStrcpy(const_cast(pEventString), newString.c_str(), newString.length()+1); + if (dStrlen(pObjectString) == 1) { if (dIsDecentChar(*pObjectString)) // includes foreign chars @@ -544,16 +603,7 @@ bool ActionMap::createEventDescriptor(const char* pEventString, EventDescriptor* } } } - // Didn't find an ascii match. Check the virtual map table - //for (U32 j = 0; gVirtualMap[j].code != 0xFFFFFFFF; j++) - //{ - // if (dStricmp(pObjectString, gVirtualMap[j].pDescription) == 0) - // { - // pDescriptor->eventType = gVirtualMap[j].type; - // pDescriptor->eventCode = gVirtualMap[j].code; - // return true; - // } - //} + InputEventManager::VirtualMapData* data = INPUTMGR->findVirtualMap(pObjectString); if(data) {