Skip to content

Commit

Permalink
Merge pull request #17412 from hrydgard/controller-mapping-fixes
Browse files Browse the repository at this point in the history
Controller mapping fixes
  • Loading branch information
hrydgard committed May 5, 2023
2 parents 3318088 + cd33b79 commit fea78f9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
4 changes: 3 additions & 1 deletion Common/VR/PPSSPPVR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
18 changes: 14 additions & 4 deletions Core/KeyMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down Expand Up @@ -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++;

Expand Down Expand Up @@ -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);
}
Expand Down
14 changes: 14 additions & 0 deletions UI/ControlMappingScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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_)
Expand Down

0 comments on commit fea78f9

Please sign in to comment.