From 4ff6acf6ba4994a1b25bdee15c792848ba41aa93 Mon Sep 17 00:00:00 2001 From: RipleyTom Date: Tue, 5 Nov 2019 17:34:04 +0100 Subject: [PATCH] Fixes evdev settings & multiple pads handling --- rpcs3/evdev_joystick_handler.cpp | 18 +++++++++++++----- rpcs3/evdev_joystick_handler.h | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/rpcs3/evdev_joystick_handler.cpp b/rpcs3/evdev_joystick_handler.cpp index 78663f006e..2e8a0b1e9d 100644 --- a/rpcs3/evdev_joystick_handler.cpp +++ b/rpcs3/evdev_joystick_handler.cpp @@ -256,11 +256,11 @@ std::unordered_map> evdev_joystick_handler::GetButtonV std::shared_ptr evdev_joystick_handler::get_evdev_device(const std::string& device) { // Add device if not yet present - m_pad_index = add_device(device, nullptr, true); - if (m_pad_index < 0) + int pad_index = add_device(device, nullptr, true); + if (pad_index < 0) return nullptr; - auto dev = bindings[m_pad_index]; + auto dev = bindings[pad_index]; // Check if our device is connected if (!update_device(dev.first)) @@ -611,8 +611,8 @@ std::vector evdev_joystick_handler::ListDevices() int evdev_joystick_handler::add_device(const std::string& device, const std::shared_ptr& pad, bool in_settings) { - if (in_settings && m_pad_index >= 0) - return m_pad_index; + if (in_settings && settings_added.count(device)) + return settings_added.at(device); // Now we need to find the device with the same name, and make sure not to grab any duplicates. std::unordered_map unique_names; @@ -662,6 +662,12 @@ int evdev_joystick_handler::add_device(const std::string& device, const std::sha continue; } + if (in_settings) + { + m_dev = std::make_shared(); + settings_added[device] = bindings.size(); + } + // Alright, now that we've confirmed we haven't added this joystick yet, les do dis. m_dev->device = dev; m_dev->path = path; @@ -881,6 +887,8 @@ bool evdev_joystick_handler::bindPadToDevice(std::shared_ptr pad, const std int i = 0; // increment to know the axis location (17-24). Be careful if you ever add more find_key() calls in here (BUTTON_COUNT = 17) int last_type = EV_ABS; + m_dev = std::make_shared(); + int index = static_cast(bindings.size()); m_pad_configs[index].load(); m_dev->config = &m_pad_configs[index]; diff --git a/rpcs3/evdev_joystick_handler.h b/rpcs3/evdev_joystick_handler.h index cfab686d3a..065b79cb3d 100644 --- a/rpcs3/evdev_joystick_handler.h +++ b/rpcs3/evdev_joystick_handler.h @@ -355,7 +355,7 @@ private: positive_axis m_pos_axis_config; std::vector m_positive_axis; std::vector blacklist; - int m_pad_index = -1; + std::unordered_map settings_added; std::shared_ptr m_dev; bool m_is_button_or_trigger; bool m_is_negative;