diff options
author | Tarek Soliman | 2011-10-21 22:54:33 -0500 |
---|---|---|
committer | Tarek Soliman | 2011-10-27 10:46:22 -0500 |
commit | a5082ffa5d12483f2e65fe653509989b1314164c (patch) | |
tree | 4520e7b2893856274100b23187f105499ab238f6 | |
parent | ac85d134b31f770f27d085c0fe4c307e278c1875 (diff) | |
download | scummvm-rg350-a5082ffa5d12483f2e65fe653509989b1314164c.tar.gz scummvm-rg350-a5082ffa5d12483f2e65fe653509989b1314164c.tar.bz2 scummvm-rg350-a5082ffa5d12483f2e65fe653509989b1314164c.zip |
KEYMAPPER: Skip GUI keymap when displaying active keymap in keymapper dialog
This fixes a problem where opening the keymapper dialog would cause the current game
keymap to be displayed as the active keymap but then changing the keymap selection
back to it would cause the GUI keymap to be displayed as the active one. The GUI keymap
was indeed at the top of the stack but that's not the desired effect.
Also move the pushing and popping of the keymap to Dialog::Open/Close
Also constantify the GUI keymap name
-rw-r--r-- | backends/keymapper/keymapper.h | 2 | ||||
-rw-r--r-- | backends/keymapper/remap-dialog.cpp | 12 | ||||
-rw-r--r-- | gui/dialog.cpp | 9 | ||||
-rw-r--r-- | gui/gui-manager.cpp | 26 | ||||
-rw-r--r-- | gui/gui-manager.h | 2 |
5 files changed, 31 insertions, 20 deletions
diff --git a/backends/keymapper/keymapper.h b/backends/keymapper/keymapper.h index 347b9e0ec0..4722de5774 100644 --- a/backends/keymapper/keymapper.h +++ b/backends/keymapper/keymapper.h @@ -36,6 +36,8 @@ namespace Common { +const char *const kGuiKeymapName = "gui"; + class Keymapper : public Common::EventMapper, private Common::ArtificialEventSource { public: diff --git a/backends/keymapper/remap-dialog.cpp b/backends/keymapper/remap-dialog.cpp index 0882c69080..adbf199960 100644 --- a/backends/keymapper/remap-dialog.cpp +++ b/backends/keymapper/remap-dialog.cpp @@ -307,8 +307,14 @@ void RemapDialog::loadKeymap() { List<const HardwareKey*> freeKeys(_keymapper->getHardwareKeys()); + int topIndex = activeKeymaps.size() - 1; + // skip all gui maps + // TODO: Don't use the keymap name as a way to discriminate GUI maps + while (topIndex > 0 && activeKeymaps[topIndex].keymap->getName().equals(kGuiKeymapName)) + --topIndex; + // add most active keymap's keys - Keymapper::MapRecord top = activeKeymaps.top(); + Keymapper::MapRecord top = activeKeymaps[topIndex]; List<Action*>::iterator actIt; debug(3, "RemapDialog::loadKeymap top keymap: %s", top.keymap->getName().c_str()); for (actIt = top.keymap->getActions().begin(); actIt != top.keymap->getActions().end(); ++actIt) { @@ -322,8 +328,8 @@ void RemapDialog::loadKeymap() { } // loop through remaining finding mappings for unmapped keys - if (top.inherit) { - for (int i = activeKeymaps.size() - 2; i >= 0; --i) { + if (top.inherit && topIndex >= 0) { + for (int i = topIndex - 1; i >= 0; --i) { Keymapper::MapRecord mr = activeKeymaps[i]; debug(3, "RemapDialog::loadKeymap keymap: %s", mr.keymap->getName().c_str()); List<const HardwareKey*>::iterator keyIt = freeKeys.begin(); diff --git a/gui/dialog.cpp b/gui/dialog.cpp index 2ec8641257..9f18baec9e 100644 --- a/gui/dialog.cpp +++ b/gui/dialog.cpp @@ -75,7 +75,6 @@ int Dialog::runModal() { } void Dialog::open() { - _result = 0; _visible = true; g_gui.openDialog(this); @@ -87,6 +86,10 @@ void Dialog::open() { } setFocusWidget(w); +#ifdef ENABLE_KEYMAPPER + g_gui.initKeymap(); + g_gui.pushKeymap(); +#endif } void Dialog::close() { @@ -98,6 +101,10 @@ void Dialog::close() { } releaseFocus(); g_gui.closeTopDialog(); +#ifdef ENABLE_KEYMAPPER + g_gui.popKeymap(); +#endif + } void Dialog::reflowLayout() { diff --git a/gui/gui-manager.cpp b/gui/gui-manager.cpp index 212d68430c..0910d06fb2 100644 --- a/gui/gui-manager.cpp +++ b/gui/gui-manager.cpp @@ -107,11 +107,11 @@ void GuiManager::initKeymap() { Keymapper *mapper = _system->getEventManager()->getKeymapper(); // Do not try to recreate same keymap over again - if (mapper->getKeymap("gui", tmp) != 0) + if (mapper->getKeymap(kGuiKeymapName, tmp) != 0) return; Action *act; - Keymap *guiMap = new Keymap("gui"); + Keymap *guiMap = new Keymap(kGuiKeymapName); act = new Action(guiMap, "CLOS", _("Close"), kGenericActionType, kStartKeyType); act->addKeyEvent(KeyState(KEYCODE_ESCAPE, ASCII_ESCAPE, 0)); @@ -127,6 +127,14 @@ void GuiManager::initKeymap() { mapper->addGlobalKeymap(guiMap); } + +void GuiManager::pushKeymap() { + _system->getEventManager()->getKeymapper()->pushKeymap(Common::kGuiKeymapName); +} + +void GuiManager::popKeymap() { + _system->getEventManager()->getKeymapper()->popKeymap(); +} #endif bool GuiManager::loadNewTheme(Common::String id, ThemeEngine::GraphicsMode gfx, bool forced) { @@ -270,16 +278,6 @@ void GuiManager::runLoop() { uint32 lastRedraw = 0; const uint32 waitTime = 1000 / 45; -#ifdef ENABLE_KEYMAPPER - // Due to circular reference with event manager and GUI - // we cannot init keymap on the GUI creation. Thus, let's - // try to do it on every launch, checking whether the - // map is already existing - initKeymap(); - - eventMan->getKeymapper()->pushKeymap("gui"); -#endif - bool tooltipCheck = false; while (!_dialogStack.empty() && activeDialog == getTopDialog()) { @@ -391,10 +389,6 @@ void GuiManager::runLoop() { _system->delayMillis(10); } -#ifdef ENABLE_KEYMAPPER - eventMan->getKeymapper()->popKeymap(); -#endif - if (didSaveState) { _theme->disable(); restoreState(); diff --git a/gui/gui-manager.h b/gui/gui-manager.h index 10f9e6a29f..addd2e6611 100644 --- a/gui/gui-manager.h +++ b/gui/gui-manager.h @@ -126,6 +126,8 @@ protected: byte _cursor[2048]; void initKeymap(); + void pushKeymap(); + void popKeymap(); void saveState(); void restoreState(); |