aboutsummaryrefslogtreecommitdiff
path: root/backends
diff options
context:
space:
mode:
authorJody Northup2009-08-14 08:11:18 +0000
committerJody Northup2009-08-14 08:11:18 +0000
commit44e79803648ba7704e97031752506ad42176990d (patch)
treeee66857a57124de13f2d30c2d40a42e16f20343d /backends
parent7d9890ff2efb7547a4e141ccb7885f8b0b96f4c9 (diff)
downloadscummvm-rg350-44e79803648ba7704e97031752506ad42176990d.tar.gz
scummvm-rg350-44e79803648ba7704e97031752506ad42176990d.tar.bz2
scummvm-rg350-44e79803648ba7704e97031752506ad42176990d.zip
Added proper saving/loading of mapped key modifiers. Fixed modifier recognition in a much less hackish manner, (but still using a minor hack as a stopgap until KeyState can be replaced as the primary lookup type for the keymapper).
svn-id: r43363
Diffstat (limited to 'backends')
-rw-r--r--backends/keymapper/keymap.cpp22
-rw-r--r--backends/keymapper/keymapper.cpp14
-rw-r--r--backends/keymapper/remap-dialog.cpp28
3 files changed, 49 insertions, 15 deletions
diff --git a/backends/keymapper/keymap.cpp b/backends/keymapper/keymap.cpp
index 95b64f88e7..fe6f133254 100644
--- a/backends/keymapper/keymap.cpp
+++ b/backends/keymapper/keymap.cpp
@@ -127,6 +127,10 @@ void Keymap::loadMappings(const HardwareKeySet *hwKeys) {
ConfigManager::Domain::iterator it;
String prefix = KEYMAP_KEY_PREFIX + _name + "_";
+ uint32 modId = 0;
+ char hwId[HWKEY_ID_SIZE+1];
+ memset(hwId,0,HWKEY_ID_SIZE+1);
+
for (it = _configDomain->begin(); it != _configDomain->end(); it++) {
const String& key = it->_key;
@@ -145,15 +149,17 @@ void Keymap::loadMappings(const HardwareKeySet *hwKeys) {
continue;
}
- const HardwareKey *hwKey = hwKeys->findHardwareKey(it->_value.c_str());
+ sscanf(it->_value.c_str(),"%d,%s",&modId,hwId);
+ const HardwareKey *hwKey = hwKeys->findHardwareKey(hwId);
if (!hwKey) {
warning("HardwareKey with ID %s not known", it->_value.c_str());
_configDomain->erase(key);
continue;
}
-
- ua->mapKey(hwKey);
+ HardwareKey *mappedKey = new HardwareKey(*hwKey);
+ mappedKey->key.flags = modId;
+ ua->mapKey(mappedKey);
}
}
@@ -171,13 +177,19 @@ void Keymap::saveMappings() {
String actId((*it)->id, (*it)->id + actIdLen);
char hwId[HWKEY_ID_SIZE+1];
-
memset(hwId, 0, HWKEY_ID_SIZE+1);
+ char modId[4];
+ memset(modId, 0, 4);
+
if ((*it)->getMappedKey()) {
memcpy(hwId, (*it)->getMappedKey()->hwKeyId, HWKEY_ID_SIZE);
+ sprintf(modId,"%d",(*it)->getMappedKey()->key.flags);
}
- _configDomain->setVal(prefix + actId, hwId);
+ String val = modId;
+ val += ',';
+ val += hwId;
+ _configDomain->setVal(prefix + actId, val);
}
}
diff --git a/backends/keymapper/keymapper.cpp b/backends/keymapper/keymapper.cpp
index a121ebafee..24b4d7e5f8 100644
--- a/backends/keymapper/keymapper.cpp
+++ b/backends/keymapper/keymapper.cpp
@@ -192,18 +192,28 @@ bool Keymapper::mapKey(const KeyState& key, bool keyDown) {
Action *action = 0;
if (keyDown) {
+ // HACK: Temporary fix for modifier recognition, get the hwkey's keystate
+ // to correct for keydown and keyup generating different ascii codes in SDL
+ // to be solved more permanently by using a structure other than KeyState
+ const HardwareKey *hwkey = findHardwareKey(key);
+ if (!hwkey)
+ return false;
+
+ KeyState k = hwkey->key;
+ k.flags = key.flags;
+
// Search for key in active keymap stack
for (int i = _activeMaps.size() - 1; i >= 0; --i) {
MapRecord mr = _activeMaps[i];
- action = mr.keymap->getMappedAction(key);
+ action = mr.keymap->getMappedAction(k);
if (action || mr.inherit == false)
break;
}
if (action)
- _keysDown[key] = action;
+ _keysDown[k] = action;
} else {
HashMap<KeyState, Action*>::iterator it = _keysDown.find(key);
diff --git a/backends/keymapper/remap-dialog.cpp b/backends/keymapper/remap-dialog.cpp
index 9341c82747..aca2630d6d 100644
--- a/backends/keymapper/remap-dialog.cpp
+++ b/backends/keymapper/remap-dialog.cpp
@@ -239,15 +239,14 @@ void RemapDialog::handleKeyDown(Common::KeyState state) {
void RemapDialog::handleKeyUp(Common::KeyState state) {
if (_activeRemapAction) {
const HardwareKey *hwkey = _keymapper->findHardwareKey(state);
- const HardwareMod *hwmod = _keymapper->findHardwareMod(state);
- debug(0, "Key: %d, %d (%c), %x", state.keycode, state.ascii, (state.ascii ? state.ascii : ' '), state.flags);
+ debug( "Key: %d, %d (%c), %x", state.keycode, state.ascii, (state.ascii ? state.ascii : ' '), state.flags);
if (hwkey) {
- HardwareKey *temphwkey = new HardwareKey(*hwkey);
- temphwkey->description = hwkey->description;
- temphwkey->key.flags = hwmod->modFlags;
- _activeRemapAction->mapKey(temphwkey);
+ HardwareKey *mappedkey = new HardwareKey(*hwkey);
+ mappedkey->description = hwkey->description;
+ mappedkey->key.flags = (state.flags & hwkey->modMask);
+ _activeRemapAction->mapKey(mappedkey);
_activeRemapAction->getParent()->saveMappings();
_changes = true;
stopRemapping();
@@ -363,8 +362,21 @@ void RemapDialog::refreshKeymap() {
const HardwareKey *mappedKey = info.action->getMappedKey();
if (mappedKey)
- widg.keyButton->setLabel(mappedKey->description);
- else
+ {
+ Common::String description = "";
+ if (mappedKey->key.flags)
+ {
+ byte flags = mappedKey->key.flags;
+ if (flags & KBD_CTRL)
+ description += "Ctrl+";
+ if (flags & KBD_SHIFT)
+ description += "Shift+";
+ if (flags & KBD_ALT)
+ description += "Alt+";
+ }
+ description += mappedKey->description;
+ widg.keyButton->setLabel(description);
+ } else
widg.keyButton->setLabel("-");
widg.actionText->setVisible(true);