Qt: Add controller sensor mapping

pull/3696/head
Stenzek 5 months ago
parent 668a930eb5
commit d66db164bd
No known key found for this signature in database

@ -432,6 +432,10 @@ void FullscreenUI::InputBindingDialog::Start(SettingsInterface* bsi, InputBindin
if (m_binding_type == InputBindingInfo::Type::Unknown)
return InputInterceptHook::CallbackResult::RemoveHookAndContinueProcessingEvent;
// ignore sensors for now
if (key.source_subtype == InputSubclass::ControllerSensor)
return InputInterceptHook::CallbackResult::StopProcessingEvent;
float initial_value = value;
float min_value = value;
InputInterceptHook::CallbackResult default_action = InputInterceptHook::CallbackResult::StopProcessingEvent;

@ -87,12 +87,12 @@ ControllerGlobalSettingsWidget::ControllerGlobalSettingsWidget(QWidget* parent,
m_ui.dinputLayout = nullptr;
m_ui.enableDInputSource = nullptr;
m_ui.dinputDescription = nullptr;
m_ui.pointerOptionsLayout->removeWidget(m_ui.enableRawInput);
m_ui.pointerLayout->removeWidget(m_ui.enableRawInput);
m_ui.pointerLayout->removeWidget(m_ui.rawInputDescription);
QtUtils::SafeDeleteWidget(m_ui.enableRawInput);
QtUtils::SafeDeleteWidget(m_ui.rawInputDescription);
#endif
ControllerSettingWidgetBinder::BindWidgetToInputProfileBool(sif, m_ui.enableMouseMapping, "UI",
"EnableMouseMapping", false);
ControllerSettingWidgetBinder::BindWidgetToInputProfileFloat(sif, m_ui.pointerXScale, "ControllerPorts",
"PointerXScale", 8.0f);
ControllerSettingWidgetBinder::BindWidgetToInputProfileFloat(sif, m_ui.pointerYScale, "ControllerPorts",
@ -132,7 +132,6 @@ ControllerGlobalSettingsWidget::ControllerGlobalSettingsWidget(QWidget* parent,
m_ui.groupsLayout->removeWidget(m_ui.pointerGroup);
QtUtils::SafeDeleteWidget(m_ui.pointerGroup);
m_ui.pointerLayout = nullptr;
m_ui.pointerDescription = nullptr;
m_ui.pointerXScaleDescription = nullptr;
m_ui.pointerXScaleLayout = nullptr;
m_ui.pointerXScale = nullptr;
@ -141,9 +140,25 @@ ControllerGlobalSettingsWidget::ControllerGlobalSettingsWidget(QWidget* parent,
m_ui.pointerYScaleLayout = nullptr;
m_ui.pointerYScale = nullptr;
m_ui.pointerYScaleLabel = nullptr;
m_ui.pointerOptionsLayout = nullptr;
m_ui.enableMouseMapping = nullptr;
m_ui.enableRawInput = nullptr;
m_ui.rawInputDescription = nullptr;
}
// Mapping options are only shown in global settings.
if (m_dialog->isEditingGlobalSettings())
{
ControllerSettingWidgetBinder::BindWidgetToInputProfileBool(sif, m_ui.enableMouseMapping, "UI",
"EnableMouseMapping", false);
ControllerSettingWidgetBinder::BindWidgetToInputProfileBool(sif, m_ui.enableSensorMapping, "UI",
"EnableSensorMapping", false);
}
else
{
QtUtils::SafeDeleteWidget(m_ui.mappingGroup);
m_ui.mappingLayout = nullptr;
m_ui.mappingDescription = nullptr;
m_ui.enableMouseMapping = nullptr;
m_ui.enableSensorMapping = nullptr;
}
m_ui.deviceList->setModel(g_core_thread->getInputDeviceListModel());

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>900</width>
<height>658</height>
<height>696</height>
</rect>
</property>
<layout class="QHBoxLayout" name="mainLayout" stretch="1,0">
@ -167,25 +167,15 @@
<property name="title">
<string>Mouse/Pointer Source</string>
</property>
<layout class="QGridLayout" name="pointerLayout" columnstretch="0,1">
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="pointerDescription">
<property name="text">
<string>Using raw input improves precision when you bind controller sticks to the mouse pointer. Also enables multiple mice to be used.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<layout class="QGridLayout" name="pointerLayout">
<item row="0" column="0">
<widget class="QLabel" name="pointerXScaleDescription">
<property name="text">
<string>Horizontal Sensitivity:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<item row="0" column="1">
<layout class="QHBoxLayout" name="pointerXScaleLayout">
<item>
<widget class="QSlider" name="pointerXScale">
@ -233,14 +223,14 @@
</item>
</layout>
</item>
<item row="2" column="0">
<item row="1" column="0">
<widget class="QLabel" name="pointerYScaleDescription">
<property name="text">
<string>Vertical Sensitivity:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<item row="1" column="1">
<layout class="QHBoxLayout" name="pointerYScaleLayout">
<item>
<widget class="QSlider" name="pointerYScale">
@ -288,29 +278,67 @@
</item>
</layout>
</item>
<item row="3" column="0" colspan="2">
<layout class="QHBoxLayout" name="pointerOptionsLayout">
<item>
<widget class="QCheckBox" name="enableMouseMapping">
<property name="toolTip">
<string>Allows the mouse to be mapped to emulated controls. By default movement of the mouse will be ignored.</string>
</property>
<property name="text">
<string>Enable Mouse Mapping</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="enableRawInput">
<property name="toolTip">
<string>Uses raw input for mice input. Enable if you wish to use multiple mice/lightguns.</string>
</property>
<property name="text">
<string>Use Raw Input</string>
</property>
</widget>
</item>
</layout>
<item row="2" column="0">
<widget class="QCheckBox" name="enableRawInput">
<property name="toolTip">
<string>Uses raw input for mice input. Enable if you wish to use multiple mice/lightguns.</string>
</property>
<property name="text">
<string>Use Raw Input</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="rawInputDescription">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Using raw input improves precision when you bind controller sticks to the mouse pointer. Also enables multiple mice to be used.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="mappingGroup">
<property name="title">
<string>Mapping Settings</string>
</property>
<layout class="QGridLayout" name="mappingLayout">
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="mappingDescription">
<property name="text">
<string>By default, mapping mouse movement and device sensors is disabled to avoid accidential bindings when manually mapping.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="enableMouseMapping">
<property name="toolTip">
<string>Allows the mouse to be mapped to emulated controls. By default movement of the mouse will be ignored.</string>
</property>
<property name="text">
<string>Enable Mouse Mapping</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="enableSensorMapping">
<property name="toolTip">
<string>Allows sensors such as accelerometers to be mapped to emulated controls. By default movement of the mouse will be ignored.</string>
</property>
<property name="text">
<string>Enable Sensor Mapping</string>
</property>
</widget>
</item>
</layout>
</widget>

@ -10,7 +10,6 @@
#include "core/core.h"
#include "common/bitutils.h"
#include "common/log.h"
#include "fmt/format.h"
@ -21,8 +20,6 @@
#include "moc_inputbindingdialog.cpp"
LOG_CHANNEL(Host);
InputBindingDialog::InputBindingDialog(SettingsInterface* sif, InputBindingInfo::Type bind_type,
std::string section_name, std::string key_name,
std::vector<std::string> bindings, QWidget* parent)
@ -77,14 +74,6 @@ InputBindingDialog::~InputBindingDialog()
Q_ASSERT(!isListeningForInput());
}
void InputBindingDialog::logInputEvent(InputBindingInfo::Type bind_type, InputBindingKey key, float value,
float initial_value, float min_value)
{
const TinyString key_str = InputManager::ConvertInputBindingKeyToString(bind_type, key);
DEV_LOG("Binding input event: key={} value={:.2f} initial_value={:.2f} min_value={:.2f}", key_str, value,
initial_value, min_value);
}
bool InputBindingDialog::eventFilter(QObject* watched, QEvent* event)
{
const QEvent::Type event_type = event->type();
@ -189,7 +178,8 @@ void InputBindingDialog::startListeningForInput(u32 timeout_in_seconds)
{
m_value_ranges.clear();
m_new_bindings.clear();
m_mouse_mapping_enabled = InputBindingWidget::isMouseMappingEnabled(m_sif);
m_mouse_mapping_enabled = InputBindingWidget::isMouseMappingEnabled();
m_sensor_mapping_enabled = InputBindingWidget::isSensorMappingEnabled();
m_input_listen_start_position = QCursor::pos();
m_input_listen_timer = new QTimer(this);
m_input_listen_timer->setSingleShot(false);
@ -306,7 +296,7 @@ void InputBindingDialog::saveListToSettings()
void InputBindingDialog::inputManagerHookCallback(InputBindingKey key, float value)
{
if (!isListeningForInput())
if (!isListeningForInput() || (!m_sensor_mapping_enabled && InputBindingWidget::isSensorBinding(key)))
return;
float initial_value = value;
@ -323,7 +313,7 @@ void InputBindingDialog::inputManagerHookCallback(InputBindingKey key, float val
m_value_ranges.emplace_back(key, std::make_pair(initial_value, min_value));
}
logInputEvent(m_bind_type, key, value, initial_value, min_value);
InputBindingWidget::logInputEvent(m_bind_type, key, value, initial_value, min_value);
const float abs_value = std::abs(value);
const float delta_from_initial = std::abs(std::abs(initial_value) - abs_value);

@ -25,9 +25,6 @@ public:
std::string key_name, std::vector<std::string> bindings, QWidget* parent);
~InputBindingDialog();
static void logInputEvent(InputBindingInfo::Type bind_type, InputBindingKey key, float value, float initial_value,
float min_value);
protected:
enum : u32
{
@ -73,4 +70,5 @@ protected:
u32 m_input_listen_remaining_seconds = 0;
QPoint m_input_listen_start_position{};
bool m_mouse_mapping_enabled = false;
bool m_sensor_mapping_enabled = false;
};

@ -11,6 +11,7 @@
#include "core/host.h"
#include "common/bitutils.h"
#include "common/log.h"
#include "common/string_util.h"
#include <QtCore/QTimer>
@ -23,6 +24,8 @@
#include "moc_inputbindingwidgets.cpp"
LOG_CHANNEL(Host);
InputBindingWidget::InputBindingWidget(QWidget* parent) : QPushButton(parent)
{
connect(this, &QPushButton::clicked, this, &InputBindingWidget::onClicked);
@ -44,11 +47,27 @@ InputBindingWidget::~InputBindingWidget()
Q_ASSERT(!isListeningForInput());
}
bool InputBindingWidget::isMouseMappingEnabled(SettingsInterface* sif)
bool InputBindingWidget::isMouseMappingEnabled()
{
return Core::GetBaseBoolSettingValue("UI", "EnableMouseMapping", false) && !InputManager::IsUsingRawInput();
}
bool InputBindingWidget::isSensorMappingEnabled()
{
return Core::GetBaseBoolSettingValue("UI", "EnableSensorMapping", false);
}
bool InputBindingWidget::isSensorBinding(InputBindingKey key)
{
return (key.source_subtype == InputSubclass::ControllerSensor);
}
void InputBindingWidget::logInputEvent(InputBindingInfo::Type bind_type, InputBindingKey key, float value,
float initial_value, float min_value)
{
return (sif ? sif->GetBoolValue("UI", "EnableMouseMapping", false) :
Core::GetBaseBoolSettingValue("UI", "EnableMouseMapping", false)) &&
!InputManager::IsUsingRawInput();
const TinyString key_str = InputManager::ConvertInputBindingKeyToString(bind_type, key);
DEV_LOG("Binding input event: key={} value={:.2f} initial_value={:.2f} min_value={:.2f}", key_str, value,
initial_value, min_value);
}
void InputBindingWidget::initialize(SettingsInterface* sif, InputBindingInfo::Type bind_type, std::string section_name,
@ -331,7 +350,8 @@ void InputBindingWidget::startListeningForInput(u32 timeout_in_seconds)
{
m_value_ranges.clear();
m_new_bindings.clear();
m_mouse_mapping_enabled = isMouseMappingEnabled(m_sif);
m_mouse_mapping_enabled = isMouseMappingEnabled();
m_sensor_mapping_enabled = isSensorMappingEnabled();
m_input_listen_start_position = QCursor::pos();
m_input_listen_timer = new QTimer(this);
m_input_listen_timer->setSingleShot(false);
@ -365,7 +385,7 @@ void InputBindingWidget::stopListeningForInput()
void InputBindingWidget::inputManagerHookCallback(InputBindingKey key, float value)
{
if (!isListeningForInput())
if (!isListeningForInput() || (!m_sensor_mapping_enabled && isSensorBinding(key)))
return;
float initial_value = value;
@ -382,7 +402,7 @@ void InputBindingWidget::inputManagerHookCallback(InputBindingKey key, float val
m_value_ranges.emplace_back(key, std::make_pair(initial_value, min_value));
}
InputBindingDialog::logInputEvent(m_bind_type, key, value, initial_value, min_value);
logInputEvent(m_bind_type, key, value, initial_value, min_value);
const float abs_value = std::abs(value);
const float delta_from_initial = std::abs(std::abs(initial_value) - abs_value);

@ -22,7 +22,11 @@ public:
std::string section_name, std::string key_name);
~InputBindingWidget();
static bool isMouseMappingEnabled(SettingsInterface* sif);
static bool isMouseMappingEnabled();
static bool isSensorMappingEnabled();
static bool isSensorBinding(InputBindingKey key);
static void logInputEvent(InputBindingInfo::Type bind_type, InputBindingKey key, float value, float initial_value,
float min_value);
void initialize(SettingsInterface* sif, InputBindingInfo::Type bind_type, std::string section_name,
std::string key_name);
@ -72,4 +76,5 @@ protected:
u32 m_input_listen_remaining_seconds = 0;
QPoint m_input_listen_start_position{};
bool m_mouse_mapping_enabled = false;
bool m_sensor_mapping_enabled = false;
};

Loading…
Cancel
Save