Qt/Input: disable mapping for unconnected pads

This commit is contained in:
Megamouse 2018-12-20 13:00:38 +01:00
parent e80574cbd2
commit f617e47152
11 changed files with 49 additions and 28 deletions

View file

@ -448,7 +448,7 @@ public:
PadHandlerBase(pad_handler type = pad_handler::null); PadHandlerBase(pad_handler type = pad_handler::null);
virtual ~PadHandlerBase() = default; virtual ~PadHandlerBase() = default;
//Sets window to config the controller(optional) //Sets window to config the controller(optional)
virtual void GetNextButtonPress(const std::string& /*padId*/, const std::function<void(u16, std::string, int[])>& /*callback*/, bool /*get_blacklist*/ = false, std::vector<std::string> /*buttons*/ = {}) {}; virtual void GetNextButtonPress(const std::string& /*padId*/, const std::function<void(u16, std::string, int[])>& /*callback*/, const std::function<void()>& /*fail_callback*/, bool /*get_blacklist*/ = false, std::vector<std::string> /*buttons*/ = {}) {};
virtual void TestVibration(const std::string& /*padId*/, u32 /*largeMotor*/, u32 /*smallMotor*/) {}; virtual void TestVibration(const std::string& /*padId*/, u32 /*largeMotor*/, u32 /*smallMotor*/) {};
//Return list of devices for that handler //Return list of devices for that handler
virtual std::vector<std::string> ListDevices() = 0; virtual std::vector<std::string> ListDevices() = 0;

View file

@ -150,14 +150,14 @@ void ds4_pad_handler::init_config(pad_config* cfg, const std::string& name)
cfg->from_default(); cfg->from_default();
} }
void ds4_pad_handler::GetNextButtonPress(const std::string& padId, const std::function<void(u16, std::string, int[])>& callback, bool get_blacklist, std::vector<std::string> buttons) void ds4_pad_handler::GetNextButtonPress(const std::string& padId, const std::function<void(u16, std::string, int[])>& callback, const std::function<void()>& fail_callback, bool get_blacklist, std::vector<std::string> buttons)
{ {
if (get_blacklist) if (get_blacklist)
blacklist.clear(); blacklist.clear();
std::shared_ptr<DS4Device> device = GetDevice(padId); std::shared_ptr<DS4Device> device = GetDevice(padId);
if (device == nullptr || device->hidDevice == nullptr) if (device == nullptr || device->hidDevice == nullptr)
return; return fail_callback();
// Now that we have found a device, get its status // Now that we have found a device, get its status
DS4DataStatus status = GetRawData(device); 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 // this also can mean disconnected, either way deal with it on next loop and reconnect
hid_close(device->hidDevice); hid_close(device->hidDevice);
device->hidDevice = nullptr; device->hidDevice = nullptr;
return; return fail_callback();
} }
// return if nothing new has happened. ignore this to get the current state for blacklist // return if nothing new has happened. ignore this to get the current state for blacklist

View file

@ -142,7 +142,7 @@ public:
std::vector<std::string> ListDevices() override; std::vector<std::string> ListDevices() override;
bool bindPadToDevice(std::shared_ptr<Pad> pad, const std::string& device) override; bool bindPadToDevice(std::shared_ptr<Pad> pad, const std::string& device) override;
void ThreadProc() override; void ThreadProc() override;
void GetNextButtonPress(const std::string& padId, const std::function<void(u16, std::string, int[])>& buttonCallback, bool get_blacklist = false, std::vector<std::string> buttons = {}) override; void GetNextButtonPress(const std::string& padId, const std::function<void(u16, std::string, int[])>& buttonCallback, const std::function<void()>& fail_callback, bool get_blacklist = false, std::vector<std::string> buttons = {}) override;
void TestVibration(const std::string& padId, u32 largeMotor, u32 smallMotor) override; void TestVibration(const std::string& padId, u32 largeMotor, u32 smallMotor) override;
void init_config(pad_config* cfg, const std::string& name) override; void init_config(pad_config* cfg, const std::string& name) override;

View file

@ -257,7 +257,7 @@ evdev_joystick_handler::EvdevDevice* evdev_joystick_handler::get_device(const st
return &dev; return &dev;
} }
void evdev_joystick_handler::GetNextButtonPress(const std::string& padId, const std::function<void(u16, std::string, int[])>& callback, bool get_blacklist, std::vector<std::string> buttons) void evdev_joystick_handler::GetNextButtonPress(const std::string& padId, const std::function<void(u16, std::string, int[])>& callback, const std::function<void()>& fail_callback, bool get_blacklist, std::vector<std::string> buttons)
{ {
if (get_blacklist) if (get_blacklist)
blacklist.clear(); blacklist.clear();
@ -265,7 +265,7 @@ void evdev_joystick_handler::GetNextButtonPress(const std::string& padId, const
// Get our evdev device // Get our evdev device
EvdevDevice* device = get_device(padId); EvdevDevice* device = get_device(padId);
if (device == nullptr || device->device == nullptr) if (device == nullptr || device->device == nullptr)
return; return fail_callback();
libevdev* dev = device->device; libevdev* dev = device->device;
// Try to query the latest event from the joystick. // Try to query the latest event from the joystick.

View file

@ -338,7 +338,7 @@ public:
bool bindPadToDevice(std::shared_ptr<Pad> pad, const std::string& device) override; bool bindPadToDevice(std::shared_ptr<Pad> pad, const std::string& device) override;
void ThreadProc() override; void ThreadProc() override;
void Close(); void Close();
void GetNextButtonPress(const std::string& padId, const std::function<void(u16, std::string, int[])>& callback, bool get_blacklist = false, std::vector<std::string> buttons = {}) override; void GetNextButtonPress(const std::string& padId, const std::function<void(u16, std::string, int[])>& callback, const std::function<void()>& fail_callback, bool get_blacklist = false, std::vector<std::string> buttons = {}) override;
void TestVibration(const std::string& padId, u32 largeMotor, u32 smallMotor) override; void TestVibration(const std::string& padId, u32 largeMotor, u32 smallMotor) override;
private: private:

View file

@ -283,13 +283,13 @@ void mm_joystick_handler::ThreadProc()
} }
} }
void mm_joystick_handler::GetNextButtonPress(const std::string& padId, const std::function<void(u16, std::string, int[])>& callback, bool get_blacklist, std::vector<std::string> buttons) void mm_joystick_handler::GetNextButtonPress(const std::string& padId, const std::function<void(u16, std::string, int[])>& callback, const std::function<void()>& fail_callback, bool get_blacklist, std::vector<std::string> buttons)
{ {
if (get_blacklist) if (get_blacklist)
blacklist.clear(); blacklist.clear();
if (!Init()) if (!Init())
return; return fail_callback();
static std::string cur_pad = ""; static std::string cur_pad = "";
static int id = -1; static int id = -1;
@ -301,7 +301,7 @@ void mm_joystick_handler::GetNextButtonPress(const std::string& padId, const std
if (id < 0) if (id < 0)
{ {
LOG_ERROR(GENERAL, "MMJOY GetNextButtonPress for device [%s] failed with id = %d", padId, id); 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) switch (status)
{ {
case JOYERR_UNPLUGGED: case JOYERR_UNPLUGGED:
break; return fail_callback();
case JOYERR_NOERROR: case JOYERR_NOERROR:
auto data = GetButtonValues(js_info, js_caps); auto data = GetButtonValues(js_info, js_caps);

View file

@ -108,7 +108,7 @@ public:
std::vector<std::string> ListDevices() override; std::vector<std::string> ListDevices() override;
bool bindPadToDevice(std::shared_ptr<Pad> pad, const std::string& device) override; bool bindPadToDevice(std::shared_ptr<Pad> pad, const std::string& device) override;
void ThreadProc() override; void ThreadProc() override;
void GetNextButtonPress(const std::string& padId, const std::function<void(u16, std::string, int[])>& callback, bool get_blacklist = false, std::vector<std::string> buttons = {}) override; void GetNextButtonPress(const std::string& padId, const std::function<void(u16, std::string, int[])>& callback, const std::function<void()>& fail_callback, bool get_blacklist = false, std::vector<std::string> buttons = {}) override;
void init_config(pad_config* cfg, const std::string& name) override; void init_config(pad_config* cfg, const std::string& name) override;
private: private:

View file

@ -318,6 +318,10 @@ void pad_settings_dialog::InitButtons()
// Enable Button Remapping // Enable Button Remapping
const auto& callback = [=](u16 val, std::string name, int preview_values[6]) 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()) if (m_handler->has_deadzones())
{ {
ui->preview_trigger_left->setValue(preview_values[0]); 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 // 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<std::string> buttons = std::vector<std::string> 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_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_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_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); 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_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_small->setChecked((bool)m_handler_cfg.enable_vibration_motor_small);
ui->chb_vibration_switch->setChecked((bool)m_handler_cfg.switch_vibration_motors); 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_min_force = m_handler->vibration_min;
m_max_force = m_handler->vibration_max; m_max_force = m_handler->vibration_max;
// Enable Deadzone Settings // Enable Vibration Checkboxes
const bool enable_deadzones = m_handler->has_deadzones(); m_enable_rumble = m_handler->has_rumble();
ui->gb_sticks->setEnabled(enable_deadzones); // Enable Deadzone Settings
ui->gb_triggers->setEnabled(enable_deadzones); m_enable_deadzones = m_handler->has_deadzones();
// Enable Trigger Thresholds // Enable Trigger Thresholds
ui->slider_trigger_left->setRange(0, m_handler->trigger_max); 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) 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++) for (int i = button_ids::id_pad_begin + 1; i < button_ids::id_pad_end; i++)
{ {
m_padButtons->button(i)->setEnabled(is_enabled); m_padButtons->button(i)->setEnabled(is_enabled);
@ -675,7 +691,7 @@ void pad_settings_dialog::OnPadButtonClicked(int id)
UpdateLabel(true); UpdateLabel(true);
return; return;
case button_ids::id_blacklist: case button_ids::id_blacklist:
m_handler->GetNextButtonPress(m_device_name, nullptr, true); m_handler->GetNextButtonPress(m_device_name, nullptr, nullptr, true);
return; return;
default: default:
break; break;
@ -835,7 +851,7 @@ void pad_settings_dialog::ChangeInputType()
} }
// enable configuration and profile list if possible // 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->b_addProfile->setEnabled(config_enabled);
ui->chooseProfile->setEnabled(config_enabled); ui->chooseProfile->setEnabled(config_enabled);
} }

View file

@ -93,6 +93,11 @@ private:
// TabWidget // TabWidget
QTabWidget* m_tabs; QTabWidget* m_tabs;
// Capabilities
bool m_enable_buttons{ false };
bool m_enable_rumble{ false };
bool m_enable_deadzones{ false };
// Button Mapping // Button Mapping
QButtonGroup* m_padButtons; QButtonGroup* m_padButtons;
u32 m_button_id = id_pad_begin; u32 m_button_id = id_pad_begin;

View file

@ -74,14 +74,14 @@ void xinput_pad_handler::init_config(pad_config* cfg, const std::string& name)
cfg->from_default(); cfg->from_default();
} }
void xinput_pad_handler::GetNextButtonPress(const std::string& padId, const std::function<void(u16, std::string, int[])>& callback, bool get_blacklist, std::vector<std::string> buttons) void xinput_pad_handler::GetNextButtonPress(const std::string& padId, const std::function<void(u16, std::string, int[])>& callback, const std::function<void()>& fail_callback, bool get_blacklist, std::vector<std::string> buttons)
{ {
if (get_blacklist) if (get_blacklist)
blacklist.clear(); blacklist.clear();
int device_number = GetDeviceNumber(padId); int device_number = GetDeviceNumber(padId);
if (device_number < 0) if (device_number < 0)
return; return fail_callback();
DWORD dwResult; DWORD dwResult;
XINPUT_STATE state; 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. // Simply get the state of the controller from XInput.
dwResult = (*xinputGetState)(static_cast<u32>(device_number), &state); dwResult = (*xinputGetState)(static_cast<u32>(device_number), &state);
if (dwResult != ERROR_SUCCESS) 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. // 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) // Return the new value if the button was pressed (aka. its value was bigger than 0 or the defined threshold)

View file

@ -107,7 +107,7 @@ public:
std::vector<std::string> ListDevices() override; std::vector<std::string> ListDevices() override;
bool bindPadToDevice(std::shared_ptr<Pad> pad, const std::string& device) override; bool bindPadToDevice(std::shared_ptr<Pad> pad, const std::string& device) override;
void ThreadProc() override; void ThreadProc() override;
void GetNextButtonPress(const std::string& padId, const std::function<void(u16, std::string, int[])>& callback, bool get_blacklist = false, std::vector<std::string> buttons = {}) override; void GetNextButtonPress(const std::string& padId, const std::function<void(u16, std::string, int[])>& callback, const std::function<void()>& fail_callback, bool get_blacklist = false, std::vector<std::string> buttons = {}) override;
void TestVibration(const std::string& padId, u32 largeMotor, u32 smallMotor) override; void TestVibration(const std::string& padId, u32 largeMotor, u32 smallMotor) override;
void init_config(pad_config* cfg, const std::string& name) override; void init_config(pad_config* cfg, const std::string& name) override;