From 354bb068fc23c628867ec27196451793a22f8134 Mon Sep 17 00:00:00 2001 From: thrust26 Date: Thu, 30 May 2019 12:31:34 +0200 Subject: [PATCH] refactor 'ctrlcombo' into 'modcombo', suppresses all modifier key combinations --- src/common/KeyMap.cxx | 12 ++++++++---- src/common/KeyMap.hxx | 8 ++++++++ src/common/PKeyboardHandler.cxx | 5 ++--- src/common/PKeyboardHandler.hxx | 10 ++-------- src/emucore/EventHandler.cxx | 8 ++++---- src/emucore/Settings.cxx | 6 +++--- src/gui/InputDialog.cxx | 20 ++++++++++---------- src/gui/InputDialog.hxx | 2 +- 8 files changed, 38 insertions(+), 33 deletions(-) diff --git a/src/common/KeyMap.cxx b/src/common/KeyMap.cxx index 7386f2593..11b552e93 100644 --- a/src/common/KeyMap.cxx +++ b/src/common/KeyMap.cxx @@ -18,6 +18,7 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - KeyMap::KeyMap(void) + : myModEnabled(true) { } @@ -50,14 +51,17 @@ Event::Type KeyMap::get(const Mapping& mapping) const { Mapping m = convertMod(mapping); - auto find = myMap.find(m); - if (find != myMap.end()) - return find->second; + if (myModEnabled) + { + auto find = myMap.find(m); + if (find != myMap.end()) + return find->second; + } // mapping not found, try without modifiers m.mod = StellaMod(0); - find = myMap.find(m); + auto find = myMap.find(m); if (find != myMap.end()) return find->second; diff --git a/src/common/KeyMap.hxx b/src/common/KeyMap.hxx index 831c885db..cf1800fa4 100644 --- a/src/common/KeyMap.hxx +++ b/src/common/KeyMap.hxx @@ -98,6 +98,8 @@ class KeyMap // void clear() { myMap.clear(); } size_t size() { return myMap.size(); } + bool& enableMod() { return myModEnabled; } + private: //** Convert modifiers */ Mapping convertMod(const Mapping& mapping) const; @@ -113,6 +115,12 @@ class KeyMap }; std::unordered_map myMap; + + // Indicates whether the key-combos tied to a modifier key are + // being used or not (e.g. Ctrl by default is the fire button, + // pressing it with a movement key could inadvertantly activate + // a Ctrl combo when it isn't wanted) + bool myModEnabled; }; #endif diff --git a/src/common/PKeyboardHandler.cxx b/src/common/PKeyboardHandler.cxx index 64183163e..6c6f14b70 100644 --- a/src/common/PKeyboardHandler.cxx +++ b/src/common/PKeyboardHandler.cxx @@ -41,8 +41,7 @@ PhysicalKeyboardHandler::PhysicalKeyboardHandler( : myOSystem(system), myHandler(handler), myEvent(event), - myAltKeyCounter(0), - myUseCtrlKeyFlag(myOSystem.settings().getBool("ctrlcombo")) + myAltKeyCounter(0) { Int32 version = myOSystem.settings().getInt("event_ver"); @@ -54,6 +53,7 @@ PhysicalKeyboardHandler::PhysicalKeyboardHandler( list = myOSystem.settings().getString("keymap_ui"); myKeyMap.loadMapping(list, kMenuMode); } + myKeyMap.enableMod() = myOSystem.settings().getBool("modcombo"); setDefaultMapping(Event::NoType, kEmulationMode, true); setDefaultMapping(Event::NoType, kMenuMode, true); @@ -329,7 +329,6 @@ void PhysicalKeyboardHandler::handleEvent(StellaKey key, StellaMod mod, bool pre // and don't pass the key on if we've already taken care of it if(handleAltEvent(key, mod, pressed)) return; - // TODO: myUseCtrlKeyFlag? EventHandlerState estate = myHandler.state(); diff --git a/src/common/PKeyboardHandler.hxx b/src/common/PKeyboardHandler.hxx index 0a239814b..80ff90a91 100644 --- a/src/common/PKeyboardHandler.hxx +++ b/src/common/PKeyboardHandler.hxx @@ -63,8 +63,8 @@ class PhysicalKeyboardHandler /** See comments on 'myAltKeyCounter' for more information. */ uInt8& altKeyCount() { return myAltKeyCounter; } - /** See comments on 'myUseCtrlKeyFlag' for more information. */ - bool& useCtrlKey() { return myUseCtrlKeyFlag; } + /** See comments on KeyMap.myModEnabled for more information. */ + bool& useModKeys() { return myKeyMap.enableMod(); } private: bool handleAltEvent(StellaKey key, StellaMod mod, bool pressed); @@ -88,12 +88,6 @@ class PhysicalKeyboardHandler // TODO - This may be a bug in SDL, and might be removed in the future // It only seems to be an issue in Linux uInt8 myAltKeyCounter; - - // Indicates whether the key-combos tied to the Control key are - // being used or not (since Ctrl by default is the fire button, - // pressing it with a movement key could inadvertantly activate - // a Ctrl combo when it isn't wanted) - bool myUseCtrlKeyFlag; }; #endif diff --git a/src/emucore/EventHandler.cxx b/src/emucore/EventHandler.cxx index 465118b38..e5d39ca57 100644 --- a/src/emucore/EventHandler.cxx +++ b/src/emucore/EventHandler.cxx @@ -382,7 +382,7 @@ void EventHandler::handleEvent(Event::Type event, bool pressed) //////////////////////////////////////////////////////////////////////// case Event::Fry: - if(myPKeyHandler->useCtrlKey()) myFryingFlag = pressed; + /*if(myPKeyHandler->useModKeys())*/ myFryingFlag = pressed; return; case Event::ReloadConsole: @@ -1461,9 +1461,9 @@ void EventHandler::setState(EventHandlerState state) { myState = state; - // Normally, the usage of Control key is determined by 'ctrlcombo' + // Normally, the usage of modifier keys is determined by 'modcombo' // For certain ROMs it may be forced off, whatever the setting - myPKeyHandler->useCtrlKey() = myOSystem.settings().getBool("ctrlcombo"); + myPKeyHandler->useModKeys() = myOSystem.settings().getBool("modcombo"); // Only enable text input in GUI modes, since in emulation mode the // keyboard acts as one large joystick with many (single) buttons @@ -1474,7 +1474,7 @@ void EventHandler::setState(EventHandlerState state) myOSystem.sound().mute(false); enableTextEvents(false); if(myOSystem.console().leftController().type() == Controller::Type::CompuMate) - myPKeyHandler->useCtrlKey() = false; + myPKeyHandler->useModKeys() = false; break; case EventHandlerState::PAUSE: diff --git a/src/emucore/Settings.cxx b/src/emucore/Settings.cxx index e65fbdd96..e847489df 100644 --- a/src/emucore/Settings.cxx +++ b/src/emucore/Settings.cxx @@ -98,7 +98,7 @@ Settings::Settings() setPermanent("msense", "10"); setPermanent("tsense", "10"); setPermanent("saport", "lr"); - setPermanent("ctrlcombo", "true"); + setPermanent("modcombo", "true"); // Snapshot options setPermanent("snapsavedir", ""); @@ -442,8 +442,8 @@ void Settings::usage() const << " -tsense <1-20> Sensitivity of mouse emulated trackball movement\n" << " -saport How to assign virtual ports to multiple\n" << " Stelladaptor/2600-daptors\n" - << " -ctrlcombo <1|0> Use key combos involving the Control key\n" - << " (Control-Q for quit may be disabled!)\n" + << " -modcombo <1|0> Enable modifer key combos\n" + << " (Control-Q for quit may not work when disabled!)\n" << " -fastscbios <1|0> Disable Supercharger BIOS progress loading bars\n" << " -threads <1|0> Whether to using multi-threading during\n" << " emulation\n" diff --git a/src/gui/InputDialog.cxx b/src/gui/InputDialog.cxx index 6717639d0..f5353ea7d 100644 --- a/src/gui/InputDialog.cxx +++ b/src/gui/InputDialog.cxx @@ -217,11 +217,11 @@ void InputDialog::addDevicePortTab(const GUI::Font& font) myGrabMouse->clearFlags(Widget::FLAG_ENABLED); #endif - // Enable/disable control key-combos + // Enable/disable modifier key-combos ypos += lineHeight + VGAP; - myCtrlCombo = new CheckboxWidget(myTab, font, HBORDER, ypos, - "Use control key combos"); - wid.push_back(myCtrlCombo); + myModCombo = new CheckboxWidget(myTab, font, HBORDER, ypos, + "Use modifier key combos"); + wid.push_back(myModCombo); ypos += lineHeight + VGAP; // Stelladaptor mappings @@ -315,8 +315,8 @@ void InputDialog::loadConfig() // Grab mouse myGrabMouse->setState(instance().settings().getBool("grabmouse")); - // Enable/disable control key-combos - myCtrlCombo->setState(instance().settings().getBool("ctrlcombo")); + // Enable/disable modifier key-combos + myModCombo->setState(instance().settings().getBool("modcombo")); myTab->loadConfig(); } @@ -372,8 +372,8 @@ void InputDialog::saveConfig() instance().settings().setValue("grabmouse", myGrabMouse->getState()); instance().frameBuffer().enableGrabMouse(myGrabMouse->getState()); - // Enable/disable control key-combos - instance().settings().setValue("ctrlcombo", myCtrlCombo->getState()); + // Enable/disable modifier key-combos + instance().settings().setValue("modcombo", myModCombo->getState()); instance().eventHandler().saveKeyMapping(); instance().eventHandler().saveJoyMapping(); @@ -433,8 +433,8 @@ void InputDialog::setDefaults() // Grab mouse myGrabMouse->setState(true); - // Enable/disable control key-combos - myCtrlCombo->setState(true); + // Enable/disable modifier key-combos + myModCombo->setState(true); break; } diff --git a/src/gui/InputDialog.hxx b/src/gui/InputDialog.hxx index 5d815c1da..9281ba3e4 100644 --- a/src/gui/InputDialog.hxx +++ b/src/gui/InputDialog.hxx @@ -95,7 +95,7 @@ class InputDialog : public Dialog StaticTextWidget* myTrackBallLabel; CheckboxWidget* myAllowAll4; CheckboxWidget* myGrabMouse; - CheckboxWidget* myCtrlCombo; + CheckboxWidget* myModCombo; ButtonWidget* myJoyDlgButton; ButtonWidget* myEraseEEPROMButton;