Merge pull request #17412 from hrydgard/controller-mapping-fixes

Controller mapping fixes
This commit is contained in:
Henrik Rydgård 2023-05-05 23:20:59 +02:00 committed by GitHub
commit fea78f93b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 5 deletions

View File

@ -254,6 +254,7 @@ void UpdateVRInput(bool haptics, float dp_xscale, float dp_yscale) {
keyInput.deviceId = controllerIds[j];
//process the key action
if (m.pressed != pressed) {
if (pressed && haptics) {
INVR_Vibrate(100, j, 1000);
@ -446,7 +447,8 @@ void UpdateVRInput(bool haptics, float dp_xscale, float dp_yscale) {
mousePressed = pressed;
}
//mouse wheel emulation
// mouse wheel emulation
// TODO: Spams key-up events if nothing changed!
for (int j = 0; j < 2; j++) {
keyInput.deviceId = controllerIds[j];
float scroll = -IN_VRGetJoystickState(j).y;

View File

@ -48,14 +48,17 @@ std::set<std::string> g_seenPads;
std::map<int, std::string> g_padNames;
std::set<int> g_seenDeviceIds;
// Utility...
// Utility for UI navigation
void SingleInputMappingFromPspButton(int btn, std::vector<InputMapping> *mappings, bool ignoreMouse) {
std::vector<MultiInputMapping> multiMappings;
InputMappingsFromPspButton(btn, &multiMappings, ignoreMouse);
mappings->clear();
for (auto &mapping : multiMappings) {
_dbg_assert_(!mapping.empty());
mappings->push_back(mapping.mappings[0]);
if (!mapping.empty()) {
mappings->push_back(mapping.mappings[0]);
} else {
WARN_LOG(COMMON, "Encountered empty mapping in multi-mapping for button %d", btn);
}
}
}
@ -598,6 +601,11 @@ bool ReplaceSingleKeyMapping(int btn, int index, MultiInputMapping key) {
return false;
}
}
if (key.empty()) {
return false;
}
KeyMap::g_controllerMap[btn][index] = key;
g_controllerMapGeneration++;
@ -702,8 +710,10 @@ void LoadFromIni(IniFile &file) {
for (size_t j = 0; j < mappings.size(); j++) {
MultiInputMapping input = MultiInputMapping::FromConfigString(mappings[j]);
if (input.empty()) {
continue; // eat empty mappings, however they arose, so they can't keep haunting us.
}
SetInputMapping(psp_button_names[i].key, input, false);
for (auto mapping : input.mappings) {
g_seenDeviceIds.insert(mapping.deviceId);
}

View File

@ -163,6 +163,11 @@ void SingleControlMapper::Refresh() {
}
void SingleControlMapper::MappedCallback(MultiInputMapping kdf) {
if (kdf.empty()) {
// Don't want to try to add this.
return;
}
switch (action_) {
case ADD:
KeyMap::SetInputMapping(pspKey_, kdf, false);
@ -355,6 +360,13 @@ bool KeyMappingNewKeyDialog::key(const KeyInput &key) {
}
}
if (key.flags & KEY_UP) {
// If the key released wasn't part of the mapping, ignore it here. Some device can cause
// stray key-up events.
InputMapping upMapping(key.deviceId, key.keyCode);
if (!mapping_.mappings.contains(upMapping)) {
return true;
}
if (callback_)
callback_(mapping_);
TriggerFinish(DR_YES);
@ -386,7 +398,9 @@ bool KeyMappingNewMouseKeyDialog::key(const KeyInput &key) {
}
mapped_ = true;
MultiInputMapping kdf(InputMapping(key.deviceId, key.keyCode));
TriggerFinish(DR_YES);
g_Config.bMapMouse = false;
if (callback_)