From 24dcb64c70a80161577ba432e90add381ddee3ed Mon Sep 17 00:00:00 2001 From: thrust26 Date: Tue, 28 May 2019 21:03:05 +0200 Subject: [PATCH] try to map correctly for MacOS. make remaining ALT hotkeys configurable --- src/common/KeyMap.cxx | 36 ++++++++++++++++++++----------- src/common/KeyMap.hxx | 6 +++++- src/common/PKeyboardHandler.cxx | 23 ++++++-------------- src/emucore/Event.hxx | 3 +++ src/emucore/EventHandler.cxx | 38 ++++++++++++++++++++++++++++++--- src/emucore/EventHandler.hxx | 4 ++-- src/gui/EventMappingWidget.cxx | 6 +++++- 7 files changed, 81 insertions(+), 35 deletions(-) diff --git a/src/common/KeyMap.cxx b/src/common/KeyMap.cxx index 21efed323..e34a5f1cc 100644 --- a/src/common/KeyMap.cxx +++ b/src/common/KeyMap.cxx @@ -88,20 +88,28 @@ bool KeyMap::check(const int mode, const int key, const int mod) const string KeyMap::getDesc(const Mapping& mapping) const { ostringstream buf; -#ifndef BSPF_MACOS - string modifier = "Ctrl"; +#ifdef BSPF_MACOS + string control = "Cmd"; + string alt = "Ctrl"; + int ALT = KBDM_GUI; + int LALT = KBDM_LGUI; + int RALT = KBDM_RGUI; #else - string modifier = "Cmd"; + string control = "Ctrl"; + string alt = "Alt"; + int ALT = KBDM_ALT; + int LALT = KBDM_LALT; + int RALT = KBDM_RALT; #endif - if ((mapping.mod & KBDM_CTRL) == KBDM_CTRL) buf << modifier; - else if (mapping.mod & KBDM_LCTRL) buf << "Left " << modifier; - else if (mapping.mod & KBDM_RCTRL) buf << "Right " << modifier; + if ((mapping.mod & KBDM_CTRL) == KBDM_CTRL) buf << control; + else if (mapping.mod & KBDM_LCTRL) buf << "Left " << control; + else if (mapping.mod & KBDM_RCTRL) buf << "Right " << control; - if ((mapping.mod & (KBDM_ALT)) && buf.tellp()) buf << "+"; - if ((mapping.mod & KBDM_ALT) == KBDM_ALT) buf << "Alt"; - else if (mapping.mod & KBDM_LALT) buf << "Left Alt"; - else if (mapping.mod & KBDM_RALT) buf << "Right Alt"; + if ((mapping.mod & (ALT)) && buf.tellp()) buf << "+"; + if ((mapping.mod & ALT) == ALT) buf << alt; + else if (mapping.mod & LALT) buf << alt; + else if (mapping.mod & RALT) buf << alt; if ((mapping.mod & (KBDM_SHIFT)) && buf.tellp()) buf << "+"; if ((mapping.mod & KBDM_SHIFT) == KBDM_SHIFT) buf << "Shift"; @@ -127,7 +135,7 @@ string KeyMap::getEventMappingDesc(const Event::Type event, const int mode) cons #ifndef BSPF_MACOS string modifier = "Ctrl"; #else - string modifier = "Cmd"; + string control = "Cmd"; #endif for (auto item : myMap) @@ -221,7 +229,11 @@ KeyMap::Mapping KeyMap::convertMod(const Mapping& mapping) const else { // limit to modifiers we want to support - m.mod = StellaMod(m.mod & (KBDM_SHIFT | KBDM_ALT | KBDM_CTRL)); +#if defined(BSPF_MACOS) || defined(MACOS_KEYS) + m.mod = StellaMod(m.mod & (KBDM_SHIFT | KBDM_CTRL | KBDM_GUI)); +#else + m.mod = StellaMod(m.mod & (KBDM_SHIFT | KBDM_CTRL | KBDM_ALT)); +#endif } return m; diff --git a/src/common/KeyMap.hxx b/src/common/KeyMap.hxx index cc576d03c..dd7c76681 100644 --- a/src/common/KeyMap.hxx +++ b/src/common/KeyMap.hxx @@ -50,8 +50,12 @@ class KeyMap return (key == other.key && mode == other.mode && (((mod | other.mod) & KBDM_SHIFT) ? (mod & other.mod & KBDM_SHIFT) : true) - && (((mod | other.mod) & KBDM_ALT ) ? (mod & other.mod & KBDM_ALT ) : true) && (((mod | other.mod) & KBDM_CTRL ) ? (mod & other.mod & KBDM_CTRL ) : true) +#if defined(BSPF_MACOS) || defined(MACOS_KEYS) + && (((mod | other.mod) & KBDM_GUI ) ? (mod & other.mod & KBDM_GUI ) : true) +#else + && (((mod | other.mod) & KBDM_ALT ) ? (mod & other.mod & KBDM_ALT ) : true) +#endif ); } }; diff --git a/src/common/PKeyboardHandler.cxx b/src/common/PKeyboardHandler.cxx index 385378c17..51b991f60 100644 --- a/src/common/PKeyboardHandler.cxx +++ b/src/common/PKeyboardHandler.cxx @@ -208,6 +208,13 @@ void PhysicalKeyboardHandler::setDefaultMapping(Event::Type event, EventMode mod setDefaultKey(Event::ToggleCollisions , KBDK_PERIOD, KBDM_SHIFT | KBDM_ALT); setDefaultKey(Event::ToggleBits , KBDK_PERIOD, KBDM_ALT); + setDefaultKey(Event::Rewind1Menu , KBDK_LEFT, KBDM_ALT); + setDefaultKey(Event::Rewind10Menu , KBDK_LEFT, KBDM_SHIFT | KBDM_ALT); + setDefaultKey(Event::RewindAllMenu , KBDK_DOWN, KBDM_ALT); + setDefaultKey(Event::Unwind1Menu , KBDK_RIGHT, KBDM_ALT); + setDefaultKey(Event::Unwind10Menu , KBDK_RIGHT, KBDM_SHIFT | KBDM_ALT); + setDefaultKey(Event::UnwindAllMenu , KBDK_UP, KBDM_ALT); + #if defined(RETRON77) setDefaultKey(Event::ConsoleColorToggle , KBDK_F4); // back ("COLOR","B/W") setDefaultKey(Event::ConsoleLeftDiffToggle , KBDK_F6); // front ("SKILL P1") @@ -366,22 +373,6 @@ bool PhysicalKeyboardHandler::handleAltEvent(StellaKey key, StellaMod mod, bool { switch(key) { - case KBDK_LEFT: // Alt-left(-shift) rewinds 1(10) states - myHandler.enterTimeMachineMenuMode((StellaModTest::isShift(mod) && pressed) ? 10 : 1, false); - break; - - case KBDK_RIGHT: // Alt-right(-shift) unwinds 1(10) states - myHandler.enterTimeMachineMenuMode((StellaModTest::isShift(mod) && pressed) ? 10 : 1, true); - break; - - case KBDK_DOWN: // Alt-down rewinds to start of list - myHandler.enterTimeMachineMenuMode(1000, false); - break; - - case KBDK_UP: // Alt-up rewinds to end of list - myHandler.enterTimeMachineMenuMode(1000, true); - break; - case KBDK_PAGEUP: // Alt-PageUp increases YStart myOSystem.console().changeYStart(+1); break; diff --git a/src/emucore/Event.hxx b/src/emucore/Event.hxx index 02b01c60d..ae10360d9 100644 --- a/src/emucore/Event.hxx +++ b/src/emucore/Event.hxx @@ -100,6 +100,9 @@ class Event HandleMouseControl, ToggleGrabMouse, ToggleSAPortOrder, DecreaseFormat, IncreaseFormat, ReloadConsole, + Rewind1Menu, Rewind10Menu, RewindAllMenu, + Unwind1Menu, Unwind10Menu, UnwindAllMenu, + LastType }; diff --git a/src/emucore/EventHandler.cxx b/src/emucore/EventHandler.cxx index 49bd70298..77ae9bcf8 100644 --- a/src/emucore/EventHandler.cxx +++ b/src/emucore/EventHandler.cxx @@ -628,6 +628,30 @@ void EventHandler::handleEvent(Event::Type event, bool pressed) if (pressed) myOSystem.state().unwindStates(); return; + case Event::Rewind1Menu: + if (pressed) enterTimeMachineMenuMode(1, false); + return; + + case Event::Rewind10Menu: + if (pressed) enterTimeMachineMenuMode(10, false); + return; + + case Event::RewindAllMenu: + if (pressed) enterTimeMachineMenuMode(1000, false); + return; + + case Event::Unwind1Menu: + if (pressed) enterTimeMachineMenuMode(1, true); + return; + + case Event::Unwind10Menu: + if (pressed) enterTimeMachineMenuMode(10, true); + return; + + case Event::UnwindAllMenu: + if (pressed) enterTimeMachineMenuMode(1000, true); + return; + case Event::TakeSnapshot: if(pressed) myOSystem.frameBuffer().tiaSurface().saveSnapShot(); return; @@ -1554,9 +1578,17 @@ EventHandler::ActionList EventHandler::ourEmulActionList[EMUL_ACTIONLIST_SIZE] = { Event::PauseMode, "Pause", "", false }, { Event::OptionsMenuMode, "Enter options menu UI", "", false }, { Event::CmdMenuMode, "Toggle command menu UI", "", false }, - { Event::TimeMachineMode, "Toggle time machine UI", "", false }, - { Event::Rewind, "Rewind game", "", false }, - { Event::Unwind, "Unwind game", "", false }, + + { Event::TimeMachineMode, "Toggle Time Machine UI", "", false }, + { Event::Rewind, "Rewind game one state", "", false }, + { Event::Unwind, "Unwind game one state", "", false }, + { Event::Rewind1Menu, "Rewind one state & enter TM UI", "", false }, + { Event::Rewind10Menu, "Rewind 10 states & enter TM UI", "", false }, + { Event::RewindAllMenu, "Rewind all states & enter TM UI", "", false }, + { Event::Unwind1Menu, "Unwind one state & enter TM UI", "", false }, + { Event::Unwind10Menu, "Unwind 10 states & enter TM UI", "", false }, + { Event::UnwindAllMenu, "Unwind all states & enter TM UI", "", false }, + { Event::DebuggerMode, "Toggle debugger mode", "", false }, { Event::ReloadConsole, "Reload current ROM/load next game", "", false }, { Event::ExitMode, "Exit current Stella mode", "", false }, diff --git a/src/emucore/EventHandler.hxx b/src/emucore/EventHandler.hxx index 18db20c59..ca14c20e9 100644 --- a/src/emucore/EventHandler.hxx +++ b/src/emucore/EventHandler.hxx @@ -368,9 +368,9 @@ class EventHandler COMBO_SIZE = 16, EVENTS_PER_COMBO = 8, #ifdef PNG_SUPPORT - EMUL_ACTIONLIST_SIZE = 129 + COMBO_SIZE, + EMUL_ACTIONLIST_SIZE = 135 + COMBO_SIZE, #else - EMUL_ACTIONLIST_SIZE = 129 - 2 + COMBO_SIZE, + EMUL_ACTIONLIST_SIZE = 135 - 2 + COMBO_SIZE, #endif MENU_ACTIONLIST_SIZE = 18 ; diff --git a/src/gui/EventMappingWidget.cxx b/src/gui/EventMappingWidget.cxx index 669a52612..eb15fa467 100644 --- a/src/gui/EventMappingWidget.cxx +++ b/src/gui/EventMappingWidget.cxx @@ -273,7 +273,11 @@ bool EventMappingWidget::handleKeyUp(StellaKey key, StellaMod mod) { // Remap keys in remap mode if (myRemapStatus && myActionSelected >= 0 - && (mod & (KBDM_ALT | KBDM_CTRL | KBDM_SHIFT)) == 0) +#if defined(BSPF_MACOS) || defined(MACOS_KEYS) + && (mod & (KBDM_CTRL | KBDM_SHIFT | KBDM_GUI)) == 0) +#else + && (mod & (KBDM_CTRL | KBDM_SHIFT | KBDM_ALT)) == 0) +#endif { Event::Type event = instance().eventHandler().eventAtIndex(myActionSelected, myEventMode);