Skip to content

Controller mapping fixes #17412

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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