Skip to content

Commit 72e336d

Browse files
committed
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.
1 parent c0561af commit 72e336d

3 files changed

Lines changed: 17 additions & 16 deletions

File tree

Engine/source/platformSDL/sdlInput.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ void Input::init()
7777
smLastJoystickActivated = true;
7878

7979
SDL_InitSubSystem( SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_GAMECONTROLLER | SDL_INIT_EVENTS );
80+
81+
#ifdef TORQUE_OS_MAC
82+
// Disable Ctrl+Click being treated as right-click
83+
SDL_SetHint(SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK, "0");
84+
85+
// Optionally, handle function keys as standard F1–F12
86+
SDL_SetHint(SDL_HINT_MAC_BACKGROUND_APP, "0");
87+
#endif
8088

8189
// Init the current modifier keys
8290
setModifierKeys(0);

Engine/source/platformSDL/sdlPlatformGL.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ namespace PlatformGL
1919
#ifdef TORQUE_DEBUG
2020
debugFlag |= SDL_GL_CONTEXT_DEBUG_FLAG;
2121
#endif
22+
23+
#if SDL_VERSION_ATLEAST(2, 24, 0)
24+
SDL_SetHint(SDL_HINT_MAC_OPENGL_ASYNC_DISPATCH, "1");
25+
#endif
2226
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
2327
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, debugFlag);
2428
SDL_GL_SetAttribute(SDL_GL_FRAMEBUFFER_SRGB_CAPABLE, 1);

Engine/source/sim/actionMap.cpp

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -472,25 +472,18 @@ bool ActionMap::createEventDescriptor(const char* pEventString, EventDescriptor*
472472
#if defined(TORQUE_OS_MAC)
473473
if (dStricmp(pModifier, "ctrl") == 0 || dStricmp(pModifier, "cmd") == 0)
474474
{
475-
pDescriptor->flags |= SI_ALT; // On Mac, map Ctrl/Cmd to the standard Mac command key
475+
pDescriptor->flags |= SI_CTRL; // On Mac, map Ctrl/Cmd to the standard Mac command key
476476
}
477477
else if (dStricmp(pModifier, "shift") == 0)
478478
{
479479
pDescriptor->flags |= SI_SHIFT;
480480
}
481-
else if (dStricmp(pModifier, "alt") == 0)
482-
{
483-
if (pDescriptor->flags & SI_ALT)
484-
pDescriptor->flags |= SI_MAC_OPT;
485-
else
486-
pDescriptor->flags |= SI_ALT;
487-
}
488-
else if (dStricmp(pModifier, "opt") == 0)
481+
else if (dStricmp(pModifier, "alt") == 0 || dStricmp(pModifier, "opt") == 0)
489482
{
490-
pDescriptor->flags |= SI_MAC_OPT;
483+
pDescriptor->flags |= SI_MAC_OPT;
491484
}
492485
#else
493-
if (dStricmp(pModifier, "ctrl") == 0)
486+
if (dStricmp(pModifier, "ctrl") == 0 || (dStricmp(pModifier, "cmd") == 0)
494487
{
495488
pDescriptor->flags |= SI_CTRL;
496489
}
@@ -502,10 +495,6 @@ bool ActionMap::createEventDescriptor(const char* pEventString, EventDescriptor*
502495
{
503496
pDescriptor->flags |= SI_ALT;
504497
}
505-
else if (dStricmp(pModifier, "cmd") == 0)
506-
{
507-
pDescriptor->flags |= SI_ALT; // Optional: some Windows scripts might use 'cmd'
508-
}
509498
#endif
510499
pModifier = dStrtok(NULL, "-");
511500
}
@@ -526,7 +515,7 @@ bool ActionMap::createEventDescriptor(const char* pEventString, EventDescriptor*
526515

527516
#if defined(TORQUE_OS_MAC)
528517

529-
if (pDescriptor->flags & SI_ALT)
518+
if (pDescriptor->flags & SI_ALT || pDescriptor->flags & SI_CTRL)
530519
newString += "Cmd";
531520

532521
if (pDescriptor->flags & SI_MAC_OPT)

0 commit comments

Comments
 (0)