From f617e4715245b4a6f9394d90b80ed7b84313e24a Mon Sep 17 00:00:00 2001 From: Megamouse Date: Thu, 20 Dec 2018 13:00:38 +0100 Subject: [PATCH] Qt/Input: disable mapping for unconnected pads --- rpcs3/Emu/Io/PadHandler.h | 2 +- rpcs3/ds4_pad_handler.cpp | 6 ++--- rpcs3/ds4_pad_handler.h | 2 +- rpcs3/evdev_joystick_handler.cpp | 4 +-- rpcs3/evdev_joystick_handler.h | 2 +- rpcs3/mm_joystick_handler.cpp | 8 +++--- rpcs3/mm_joystick_handler.h | 2 +- rpcs3/rpcs3qt/pad_settings_dialog.cpp | 38 +++++++++++++++++++-------- rpcs3/rpcs3qt/pad_settings_dialog.h | 5 ++++ rpcs3/xinput_pad_handler.cpp | 6 ++--- rpcs3/xinput_pad_handler.h | 2 +- 11 files changed, 49 insertions(+), 28 deletions(-) diff --git a/rpcs3/Emu/Io/PadHandler.h b/rpcs3/Emu/Io/PadHandler.h index 7c077f23e5..a2b29e6403 100644 --- a/rpcs3/Emu/Io/PadHandler.h +++ b/rpcs3/Emu/Io/PadHandler.h @@ -448,7 +448,7 @@ public: PadHandlerBase(pad_handler type = pad_handler::null); virtual ~PadHandlerBase() = default; //Sets window to config the controller(optional) - virtual void GetNextButtonPress(const std::string& /*padId*/, const std::function& /*callback*/, bool /*get_blacklist*/ = false, std::vector /*buttons*/ = {}) {}; + virtual void GetNextButtonPress(const std::string& /*padId*/, const std::function& /*callback*/, const std::function& /*fail_callback*/, bool /*get_blacklist*/ = false, std::vector /*buttons*/ = {}) {}; virtual void TestVibration(const std::string& /*padId*/, u32 /*largeMotor*/, u32 /*smallMotor*/) {}; //Return list of devices for that handler virtual std::vector ListDevices() = 0; diff --git a/rpcs3/ds4_pad_handler.cpp b/rpcs3/ds4_pad_handler.cpp index a7204adb4c..387e763baa 100644 --- a/rpcs3/ds4_pad_handler.cpp +++ b/rpcs3/ds4_pad_handler.cpp @@ -150,14 +150,14 @@ void ds4_pad_handler::init_config(pad_config* cfg, const std::string& name) cfg->from_default(); } -void ds4_pad_handler::GetNextButtonPress(const std::string& padId, const std::function& callback, bool get_blacklist, std::vector buttons) +void ds4_pad_handler::GetNextButtonPress(const std::string& padId, const std::function& callback, const std::function& fail_callback, bool get_blacklist, std::vector buttons) { if (get_blacklist) blacklist.clear(); std::shared_ptr device = GetDevice(padId); if (device == nullptr || device->hidDevice == nullptr) - return; + return fail_callback(); // Now that we have found a device, get its status DS4DataStatus status = GetRawData(device); @@ -167,7 +167,7 @@ void ds4_pad_handler::GetNextButtonPress(const std::string& padId, const std::fu // this also can mean disconnected, either way deal with it on next loop and reconnect hid_close(device->hidDevice); device->hidDevice = nullptr; - return; + return fail_callback(); } // return if nothing new has happened. ignore this to get the current state for blacklist diff --git a/rpcs3/ds4_pad_handler.h b/rpcs3/ds4_pad_handler.h index 639e2eb8b9..076a04fa7b 100644 --- a/rpcs3/ds4_pad_handler.h +++ b/rpcs3/ds4_pad_handler.h @@ -142,7 +142,7 @@ public: std::vector ListDevices() override; bool bindPadToDevice(std::shared_ptr pad, const std::string& device) override; void ThreadProc() override; - void GetNextButtonPress(const std::string& padId, const std::function& buttonCallback, bool get_blacklist = false, std::vector buttons = {}) override; + void GetNextButtonPress(const std::string& padId, const std::function& buttonCallback, const std::function& fail_callback, bool get_blacklist = false, std::vector buttons = {}) override; void TestVibration(const std::string& padId, u32 largeMotor, u32 smallMotor) override; void init_config(pad_config* cfg, const std::string& name) override; diff --git a/rpcs3/evdev_joystick_handler.cpp b/rpcs3/evdev_joystick_handler.cpp index 8ea06cb53d..5df7301126 100644 --- a/rpcs3/evdev_joystick_handler.cpp +++ b/rpcs3/evdev_joystick_handler.cpp @@ -257,7 +257,7 @@ evdev_joystick_handler::EvdevDevice* evdev_joystick_handler::get_device(const st return &dev; } -void evdev_joystick_handler::GetNextButtonPress(const std::string& padId, const std::function& callback, bool get_blacklist, std::vector buttons) +void evdev_joystick_handler::GetNextButtonPress(const std::string& padId, const std::function& callback, const std::function& fail_callback, bool get_blacklist, std::vector buttons) { if (get_blacklist) blacklist.clear(); @@ -265,7 +265,7 @@ void evdev_joystick_handler::GetNextButtonPress(const std::string& padId, const // Get our evdev device EvdevDevice* device = get_device(padId); if (device == nullptr || device->device == nullptr) - return; + return fail_callback(); libevdev* dev = device->device; // Try to query the latest event from the joystick. diff --git a/rpcs3/evdev_joystick_handler.h b/rpcs3/evdev_joystick_handler.h index cb05584f0e..9518ded6ef 100644 --- a/rpcs3/evdev_joystick_handler.h +++ b/rpcs3/evdev_joystick_handler.h @@ -338,7 +338,7 @@ public: bool bindPadToDevice(std::shared_ptr pad, const std::string& device) override; void ThreadProc() override; void Close(); - void GetNextButtonPress(const std::string& padId, const std::function& callback, bool get_blacklist = false, std::vector buttons = {}) override; + void GetNextButtonPress(const std::string& padId, const std::function& callback, const std::function& fail_callback, bool get_blacklist = false, std::vector buttons = {}) override; void TestVibration(const std::string& padId, u32 largeMotor, u32 smallMotor) override; private: diff --git a/rpcs3/mm_joystick_handler.cpp b/rpcs3/mm_joystick_handler.cpp index 99f41af74f..dc021cc731 100644 --- a/rpcs3/mm_joystick_handler.cpp +++ b/rpcs3/mm_joystick_handler.cpp @@ -283,13 +283,13 @@ void mm_joystick_handler::ThreadProc() } } -void mm_joystick_handler::GetNextButtonPress(const std::string& padId, const std::function& callback, bool get_blacklist, std::vector buttons) +void mm_joystick_handler::GetNextButtonPress(const std::string& padId, const std::function& callback, const std::function& fail_callback, bool get_blacklist, std::vector buttons) { if (get_blacklist) blacklist.clear(); if (!Init()) - return; + return fail_callback(); static std::string cur_pad = ""; static int id = -1; @@ -301,7 +301,7 @@ void mm_joystick_handler::GetNextButtonPress(const std::string& padId, const std if (id < 0) { LOG_ERROR(GENERAL, "MMJOY GetNextButtonPress for device [%s] failed with id = %d", padId, id); - return; + return fail_callback(); } } @@ -316,7 +316,7 @@ void mm_joystick_handler::GetNextButtonPress(const std::string& padId, const std switch (status) { case JOYERR_UNPLUGGED: - break; + return fail_callback(); case JOYERR_NOERROR: auto data = GetButtonValues(js_info, js_caps); diff --git a/rpcs3/mm_joystick_handler.h b/rpcs3/mm_joystick_handler.h index e8de2afba0..616abb962f 100644 --- a/rpcs3/mm_joystick_handler.h +++ b/rpcs3/mm_joystick_handler.h @@ -108,7 +108,7 @@ public: std::vector ListDevices() override; bool bindPadToDevice(std::shared_ptr pad, const std::string& device) override; void ThreadProc() override; - void GetNextButtonPress(const std::string& padId, const std::function& callback, bool get_blacklist = false, std::vector buttons = {}) override; + void GetNextButtonPress(const std::string& padId, const std::function& callback, const std::function& fail_callback, bool get_blacklist = false, std::vector buttons = {}) override; void init_config(pad_config* cfg, const std::string& name) override; private: diff --git a/rpcs3/rpcs3qt/pad_settings_dialog.cpp b/rpcs3/rpcs3qt/pad_settings_dialog.cpp index 8ed90f4c58..1f7f9b44ee 100644 --- a/rpcs3/rpcs3qt/pad_settings_dialog.cpp +++ b/rpcs3/rpcs3qt/pad_settings_dialog.cpp @@ -318,6 +318,10 @@ void pad_settings_dialog::InitButtons() // Enable Button Remapping const auto& callback = [=](u16 val, std::string name, int preview_values[6]) { + if (!m_enable_buttons && !m_timer.isActive()) + { + SwitchButtons(true); + } if (m_handler->has_deadzones()) { ui->preview_trigger_left->setValue(preview_values[0]); @@ -349,8 +353,17 @@ void pad_settings_dialog::InitButtons() } }; + // Disable Button Remapping + const auto& fail_callback = [this]() + { + if (m_enable_buttons) + { + SwitchButtons(false); + } + }; + // Use timer to get button input - connect(&m_timer_input, &QTimer::timeout, [this, callback]() + connect(&m_timer_input, &QTimer::timeout, [this, callback, fail_callback]() { std::vector buttons = { @@ -359,7 +372,7 @@ void pad_settings_dialog::InitButtons() m_cfg_entries[button_ids::id_pad_rstick_left].key, m_cfg_entries[button_ids::id_pad_rstick_right].key, m_cfg_entries[button_ids::id_pad_rstick_down].key, m_cfg_entries[button_ids::id_pad_rstick_up].key }; - m_handler->GetNextButtonPress(m_device_name, callback, false, buttons); + m_handler->GetNextButtonPress(m_device_name, callback, fail_callback, false, buttons); }); } @@ -406,9 +419,6 @@ void pad_settings_dialog::ReloadButtons() updateButton(button_ids::id_pad_rstick_right, ui->b_rstick_right, &m_handler_cfg.rs_right); updateButton(button_ids::id_pad_rstick_up, ui->b_rstick_up, &m_handler_cfg.rs_up); - // Enable Vibration Checkboxes - ui->gb_vibration->setEnabled(m_handler->has_rumble()); - ui->chb_vibration_large->setChecked((bool)m_handler_cfg.enable_vibration_motor_large); ui->chb_vibration_small->setChecked((bool)m_handler_cfg.enable_vibration_motor_small); ui->chb_vibration_switch->setChecked((bool)m_handler_cfg.switch_vibration_motors); @@ -416,11 +426,11 @@ void pad_settings_dialog::ReloadButtons() m_min_force = m_handler->vibration_min; m_max_force = m_handler->vibration_max; - // Enable Deadzone Settings - const bool enable_deadzones = m_handler->has_deadzones(); + // Enable Vibration Checkboxes + m_enable_rumble = m_handler->has_rumble(); - ui->gb_sticks->setEnabled(enable_deadzones); - ui->gb_triggers->setEnabled(enable_deadzones); + // Enable Deadzone Settings + m_enable_deadzones = m_handler->has_deadzones(); // Enable Trigger Thresholds ui->slider_trigger_left->setRange(0, m_handler->trigger_max); @@ -652,6 +662,12 @@ void pad_settings_dialog::UpdateLabel(bool is_reset) void pad_settings_dialog::SwitchButtons(bool is_enabled) { + m_enable_buttons = is_enabled; + + ui->gb_vibration->setEnabled(is_enabled && m_enable_rumble); + ui->gb_sticks->setEnabled(is_enabled && m_enable_deadzones); + ui->gb_triggers->setEnabled(is_enabled && m_enable_deadzones); + for (int i = button_ids::id_pad_begin + 1; i < button_ids::id_pad_end; i++) { m_padButtons->button(i)->setEnabled(is_enabled); @@ -675,7 +691,7 @@ void pad_settings_dialog::OnPadButtonClicked(int id) UpdateLabel(true); return; case button_ids::id_blacklist: - m_handler->GetNextButtonPress(m_device_name, nullptr, true); + m_handler->GetNextButtonPress(m_device_name, nullptr, nullptr, true); return; default: break; @@ -835,7 +851,7 @@ void pad_settings_dialog::ChangeInputType() } // enable configuration and profile list if possible - SwitchButtons(config_enabled); + SwitchButtons(false || config_enabled && m_handler->m_type == pad_handler::keyboard); ui->b_addProfile->setEnabled(config_enabled); ui->chooseProfile->setEnabled(config_enabled); } diff --git a/rpcs3/rpcs3qt/pad_settings_dialog.h b/rpcs3/rpcs3qt/pad_settings_dialog.h index e0506fb7d7..9e133d150a 100644 --- a/rpcs3/rpcs3qt/pad_settings_dialog.h +++ b/rpcs3/rpcs3qt/pad_settings_dialog.h @@ -93,6 +93,11 @@ private: // TabWidget QTabWidget* m_tabs; + // Capabilities + bool m_enable_buttons{ false }; + bool m_enable_rumble{ false }; + bool m_enable_deadzones{ false }; + // Button Mapping QButtonGroup* m_padButtons; u32 m_button_id = id_pad_begin; diff --git a/rpcs3/xinput_pad_handler.cpp b/rpcs3/xinput_pad_handler.cpp index 2fd86ec4d5..5227b7dd42 100644 --- a/rpcs3/xinput_pad_handler.cpp +++ b/rpcs3/xinput_pad_handler.cpp @@ -74,14 +74,14 @@ void xinput_pad_handler::init_config(pad_config* cfg, const std::string& name) cfg->from_default(); } -void xinput_pad_handler::GetNextButtonPress(const std::string& padId, const std::function& callback, bool get_blacklist, std::vector buttons) +void xinput_pad_handler::GetNextButtonPress(const std::string& padId, const std::function& callback, const std::function& fail_callback, bool get_blacklist, std::vector buttons) { if (get_blacklist) blacklist.clear(); int device_number = GetDeviceNumber(padId); if (device_number < 0) - return; + return fail_callback(); DWORD dwResult; XINPUT_STATE state; @@ -90,7 +90,7 @@ void xinput_pad_handler::GetNextButtonPress(const std::string& padId, const std: // Simply get the state of the controller from XInput. dwResult = (*xinputGetState)(static_cast(device_number), &state); if (dwResult != ERROR_SUCCESS) - return; + return fail_callback(); // Check for each button in our list if its corresponding (maybe remapped) button or axis was pressed. // Return the new value if the button was pressed (aka. its value was bigger than 0 or the defined threshold) diff --git a/rpcs3/xinput_pad_handler.h b/rpcs3/xinput_pad_handler.h index 28e39590ca..57a7a044a2 100644 --- a/rpcs3/xinput_pad_handler.h +++ b/rpcs3/xinput_pad_handler.h @@ -107,7 +107,7 @@ public: std::vector ListDevices() override; bool bindPadToDevice(std::shared_ptr pad, const std::string& device) override; void ThreadProc() override; - void GetNextButtonPress(const std::string& padId, const std::function& callback, bool get_blacklist = false, std::vector buttons = {}) override; + void GetNextButtonPress(const std::string& padId, const std::function& callback, const std::function& fail_callback, bool get_blacklist = false, std::vector buttons = {}) override; void TestVibration(const std::string& padId, u32 largeMotor, u32 smallMotor) override; void init_config(pad_config* cfg, const std::string& name) override;