Merge pull request #14807 from iota97/double-bind

Double binding fix
This commit is contained in:
Henrik Rydgård 2021-09-08 21:23:56 +02:00 committed by GitHub
commit 5e4c478f43
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 4 deletions

View file

@ -603,6 +603,25 @@ bool IsKeyMapped(int device, int key) {
return false;
}
bool ReplaceSingleKeyMapping(int btn, int index, KeyDef key) {
// Check for duplicate
for (int i = 0; i < g_controllerMap[btn].size(); ++i) {
if (i != index && g_controllerMap[btn][i] == key) {
g_controllerMap[btn].erase(g_controllerMap[btn].begin()+index);
g_controllerMapGeneration++;
UpdateNativeMenuKeys();
return false;
}
}
KeyMap::g_controllerMap[btn][index] = key;
g_controllerMapGeneration++;
g_seenDeviceIds.insert(key.deviceId);
UpdateNativeMenuKeys();
return true;
}
void SetKeyMapping(int btn, KeyDef key, bool replace) {
if (key.keyCode < 0)
return;

View file

@ -128,6 +128,8 @@ namespace KeyMap {
// Configure the key mapping.
// Any configuration will be saved to the Core config.
void SetKeyMapping(int psp_key, KeyDef key, bool replace);
// Return false if bind was a duplicate and got removed
bool ReplaceSingleKeyMapping(int btn, int index, KeyDef key);
// Configure an axis mapping, saves the configuration.
// Direction is negative or positive.

View file

@ -166,13 +166,17 @@ void SingleControlMapper::MappedCallback(KeyDef kdf) {
replaceAllButton_->SetFocus();
break;
case REPLACEONE:
KeyMap::g_controllerMap[pspKey_][actionIndex_] = kdf;
KeyMap::g_controllerMapGeneration++;
if (actionIndex_ < rows_.size())
{
bool success = KeyMap::ReplaceSingleKeyMapping(pspKey_, actionIndex_, kdf);
if (!success) {
replaceAllButton_->SetFocus(); // Last got removed as a duplicate
} else if (actionIndex_ < rows_.size()) {
rows_[actionIndex_]->SetFocus();
else
} else {
SetFocus();
}
break;
}
default:
SetFocus();
break;