Allow all touch inputs at the same time and remove config options that are not longer necesary

This commit is contained in:
german 2021-01-01 10:40:02 -06:00
parent d583e01f54
commit 390ee10eef
8 changed files with 36 additions and 99 deletions

View File

@ -40,11 +40,12 @@ void Controller_Touchscreen::OnUpdate(const Core::Timing::CoreTiming& core_timin
cur_entry.sampling_number = last_entry.sampling_number + 1; cur_entry.sampling_number = last_entry.sampling_number + 1;
cur_entry.sampling_number2 = cur_entry.sampling_number; cur_entry.sampling_number2 = cur_entry.sampling_number;
updateTouchInputEvent(touch_device->GetStatus(), mouse_finger_id); updateTouchInputEvent(touch_mouse_device->GetStatus(), mouse_finger_id);
updateTouchInputEvent(touch_btn_device->GetStatus(), keyboar_finger_id); updateTouchInputEvent(touch_btn_device->GetStatus(), keyboard_finger_id);
updateTouchInputEvent(touch_udp_device->GetStatus(), udp_finger_id);
std::array<Finger, 16> sorted_fingers; std::array<Finger, 16> sorted_fingers;
s32_le active_fingers = 0; size_t active_fingers = 0;
for (Finger finger : fingers) { for (Finger finger : fingers) {
if (finger.pressed) { if (finger.pressed) {
sorted_fingers[active_fingers++] = finger; sorted_fingers[active_fingers++] = finger;
@ -52,7 +53,7 @@ void Controller_Touchscreen::OnUpdate(const Core::Timing::CoreTiming& core_timin
} }
const u64 tick = core_timing.GetCPUTicks(); const u64 tick = core_timing.GetCPUTicks();
cur_entry.entry_count = active_fingers; cur_entry.entry_count = static_cast<s32_le>(active_fingers);
for (size_t id = 0; id < MAX_FINGERS; id++) { for (size_t id = 0; id < MAX_FINGERS; id++) {
auto& touch_entry = cur_entry.states[id]; auto& touch_entry = cur_entry.states[id];
if (id < active_fingers) { if (id < active_fingers) {
@ -81,7 +82,8 @@ void Controller_Touchscreen::OnUpdate(const Core::Timing::CoreTiming& core_timin
} }
void Controller_Touchscreen::OnLoadInputDevices() { void Controller_Touchscreen::OnLoadInputDevices() {
touch_device = Input::CreateDevice<Input::TouchDevice>(Settings::values.touchscreen.device); touch_mouse_device = Input::CreateDevice<Input::TouchDevice>("engine:emu_window");
touch_udp_device = Input::CreateDevice<Input::TouchDevice>("engine:cemuhookudp");
if (Settings::values.use_touch_from_button) { if (Settings::values.use_touch_from_button) {
touch_btn_device = Input::CreateDevice<Input::TouchDevice>("engine:touch_from_button"); touch_btn_device = Input::CreateDevice<Input::TouchDevice>("engine:touch_from_button");
} else { } else {
@ -90,7 +92,7 @@ void Controller_Touchscreen::OnLoadInputDevices() {
} }
void Controller_Touchscreen::updateTouchInputEvent( void Controller_Touchscreen::updateTouchInputEvent(
const std::tuple<float, float, bool>& touch_input, int& finger_id) { const std::tuple<float, float, bool>& touch_input, size_t& finger_id) {
bool pressed = false; bool pressed = false;
float x, y; float x, y;
std::tie(x, y, pressed) = touch_input; std::tie(x, y, pressed) = touch_input;
@ -110,7 +112,7 @@ void Controller_Touchscreen::updateTouchInputEvent(
fingers[finger_id].x = x; fingers[finger_id].x = x;
fingers[finger_id].y = y; fingers[finger_id].y = y;
fingers[finger_id].pressed = true; fingers[finger_id].pressed = true;
fingers[finger_id].id = finger_id; fingers[finger_id].id = static_cast<u32_le>(finger_id);
fingers[finger_id].attribute.start_touch.Assign(1); fingers[finger_id].attribute.start_touch.Assign(1);
} }
} else { } else {

View File

@ -30,7 +30,12 @@ public:
void OnLoadInputDevices() override; void OnLoadInputDevices() override;
private: private:
void updateTouchInputEvent(const std::tuple<float, float, bool>& touch_input, int& finger_id); // If the touch is new it tries to assing a new finger id, if there is no fingers avaliable no
// changes will be made. Updates the coordinates if the finger id it's already set. If the touch
// ends delays the output by one frame to set the end_touch flag before finally freeing the
// finger id
void updateTouchInputEvent(const std::tuple<float, float, bool>& touch_input,
size_t& finger_id);
static const size_t MAX_FINGERS = 16; static const size_t MAX_FINGERS = 16;
struct Attributes { struct Attributes {
@ -80,10 +85,12 @@ private:
}; };
TouchScreenSharedMemory shared_memory{}; TouchScreenSharedMemory shared_memory{};
std::unique_ptr<Input::TouchDevice> touch_device; std::unique_ptr<Input::TouchDevice> touch_mouse_device;
std::unique_ptr<Input::TouchDevice> touch_udp_device;
std::unique_ptr<Input::TouchDevice> touch_btn_device; std::unique_ptr<Input::TouchDevice> touch_btn_device;
int mouse_finger_id{-1}; size_t mouse_finger_id{-1};
int keyboar_finger_id{-1}; size_t keyboard_finger_id{-1};
size_t udp_finger_id{-1};
std::array<Finger, MAX_FINGERS> fingers; std::array<Finger, MAX_FINGERS> fingers;
}; };
} // namespace Service::HID } // namespace Service::HID

View File

@ -464,13 +464,7 @@ void Config::ReadMouseValues() {
void Config::ReadTouchscreenValues() { void Config::ReadTouchscreenValues() {
Settings::values.touchscreen.enabled = Settings::values.touchscreen.enabled =
ReadSetting(QStringLiteral("touchscreen_enabled"), true).toBool(); ReadSetting(QStringLiteral("touchscreen_enabled"), true).toBool();
Settings::values.touchscreen.device =
ReadSetting(QStringLiteral("touchscreen_device"), QStringLiteral("engine:emu_window"))
.toString()
.toStdString();
Settings::values.touchscreen.finger =
ReadSetting(QStringLiteral("touchscreen_finger"), 0).toUInt();
Settings::values.touchscreen.rotation_angle = Settings::values.touchscreen.rotation_angle =
ReadSetting(QStringLiteral("touchscreen_angle"), 0).toUInt(); ReadSetting(QStringLiteral("touchscreen_angle"), 0).toUInt();
Settings::values.touchscreen.diameter_x = Settings::values.touchscreen.diameter_x =
@ -1087,10 +1081,7 @@ void Config::SaveTouchscreenValues() {
const auto& touchscreen = Settings::values.touchscreen; const auto& touchscreen = Settings::values.touchscreen;
WriteSetting(QStringLiteral("touchscreen_enabled"), touchscreen.enabled, true); WriteSetting(QStringLiteral("touchscreen_enabled"), touchscreen.enabled, true);
WriteSetting(QStringLiteral("touchscreen_device"), QString::fromStdString(touchscreen.device),
QStringLiteral("engine:emu_window"));
WriteSetting(QStringLiteral("touchscreen_finger"), touchscreen.finger, 0);
WriteSetting(QStringLiteral("touchscreen_angle"), touchscreen.rotation_angle, 0); WriteSetting(QStringLiteral("touchscreen_angle"), touchscreen.rotation_angle, 0);
WriteSetting(QStringLiteral("touchscreen_diameter_x"), touchscreen.diameter_x, 15); WriteSetting(QStringLiteral("touchscreen_diameter_x"), touchscreen.diameter_x, 15);
WriteSetting(QStringLiteral("touchscreen_diameter_y"), touchscreen.diameter_y, 15); WriteSetting(QStringLiteral("touchscreen_diameter_y"), touchscreen.diameter_y, 15);

View File

@ -81,19 +81,11 @@ void CalibrationConfigurationDialog::UpdateButtonText(const QString& text) {
cancel_button->setText(text); cancel_button->setText(text);
} }
constexpr std::array<std::pair<const char*, const char*>, 2> TouchProviders = {{
{"emu_window", QT_TRANSLATE_NOOP("ConfigureMotionTouch", "Emulator Window")},
{"cemuhookudp", QT_TRANSLATE_NOOP("ConfigureMotionTouch", "CemuhookUDP")},
}};
ConfigureMotionTouch::ConfigureMotionTouch(QWidget* parent, ConfigureMotionTouch::ConfigureMotionTouch(QWidget* parent,
InputCommon::InputSubsystem* input_subsystem_) InputCommon::InputSubsystem* input_subsystem_)
: QDialog(parent), input_subsystem{input_subsystem_}, : QDialog(parent), input_subsystem{input_subsystem_},
ui(std::make_unique<Ui::ConfigureMotionTouch>()) { ui(std::make_unique<Ui::ConfigureMotionTouch>()) {
ui->setupUi(this); ui->setupUi(this);
for (const auto& [provider, name] : TouchProviders) {
ui->touch_provider->addItem(tr(name), QString::fromUtf8(provider));
}
ui->udp_learn_more->setOpenExternalLinks(true); ui->udp_learn_more->setOpenExternalLinks(true);
ui->udp_learn_more->setText( ui->udp_learn_more->setText(
@ -112,10 +104,7 @@ ConfigureMotionTouch::~ConfigureMotionTouch() = default;
void ConfigureMotionTouch::SetConfiguration() { void ConfigureMotionTouch::SetConfiguration() {
const Common::ParamPackage motion_param(Settings::values.motion_device); const Common::ParamPackage motion_param(Settings::values.motion_device);
const Common::ParamPackage touch_param(Settings::values.touch_device); const Common::ParamPackage touch_param(Settings::values.touch_device);
const std::string touch_engine = touch_param.Get("engine", "emu_window");
ui->touch_provider->setCurrentIndex(
ui->touch_provider->findData(QString::fromStdString(touch_engine)));
ui->touch_from_button_checkbox->setChecked(Settings::values.use_touch_from_button); ui->touch_from_button_checkbox->setChecked(Settings::values.use_touch_from_button);
touch_from_button_maps = Settings::values.touch_from_button_maps; touch_from_button_maps = Settings::values.touch_from_button_maps;
for (const auto& touch_map : touch_from_button_maps) { for (const auto& touch_map : touch_from_button_maps) {
@ -148,30 +137,21 @@ void ConfigureMotionTouch::SetConfiguration() {
} }
void ConfigureMotionTouch::UpdateUiDisplay() { void ConfigureMotionTouch::UpdateUiDisplay() {
const QString touch_engine = ui->touch_provider->currentData().toString();
const QString cemuhook_udp = QStringLiteral("cemuhookudp"); const QString cemuhook_udp = QStringLiteral("cemuhookudp");
ui->motion_sensitivity_label->setVisible(true); ui->motion_sensitivity_label->setVisible(true);
ui->motion_sensitivity->setVisible(true); ui->motion_sensitivity->setVisible(true);
if (touch_engine == cemuhook_udp) { ui->touch_calibration->setVisible(true);
ui->touch_calibration->setVisible(true); ui->touch_calibration_config->setVisible(true);
ui->touch_calibration_config->setVisible(true); ui->touch_calibration_label->setVisible(true);
ui->touch_calibration_label->setVisible(true); ui->touch_calibration->setText(
ui->touch_calibration->setText( QStringLiteral("(%1, %2) - (%3, %4)").arg(min_x).arg(min_y).arg(max_x).arg(max_y));
QStringLiteral("(%1, %2) - (%3, %4)").arg(min_x).arg(min_y).arg(max_x).arg(max_y));
} else {
ui->touch_calibration->setVisible(false);
ui->touch_calibration_config->setVisible(false);
ui->touch_calibration_label->setVisible(false);
}
ui->udp_config_group_box->setVisible(true); ui->udp_config_group_box->setVisible(true);
} }
void ConfigureMotionTouch::ConnectEvents() { void ConfigureMotionTouch::ConnectEvents() {
connect(ui->touch_provider, qOverload<int>(&QComboBox::currentIndexChanged), this,
[this](int index) { UpdateUiDisplay(); });
connect(ui->udp_test, &QPushButton::clicked, this, &ConfigureMotionTouch::OnCemuhookUDPTest); connect(ui->udp_test, &QPushButton::clicked, this, &ConfigureMotionTouch::OnCemuhookUDPTest);
connect(ui->udp_add, &QPushButton::clicked, this, &ConfigureMotionTouch::OnUDPAddServer); connect(ui->udp_add, &QPushButton::clicked, this, &ConfigureMotionTouch::OnUDPAddServer);
connect(ui->udp_remove, &QPushButton::clicked, this, &ConfigureMotionTouch::OnUDPDeleteServer); connect(ui->udp_remove, &QPushButton::clicked, this, &ConfigureMotionTouch::OnUDPDeleteServer);
@ -327,16 +307,11 @@ void ConfigureMotionTouch::ApplyConfiguration() {
return; return;
} }
std::string touch_engine = ui->touch_provider->currentData().toString().toStdString();
Common::ParamPackage touch_param{}; Common::ParamPackage touch_param{};
if (touch_engine == "cemuhookudp") { touch_param.Set("min_x", min_x);
touch_param.Set("min_x", min_x); touch_param.Set("min_y", min_y);
touch_param.Set("min_y", min_y); touch_param.Set("max_x", max_x);
touch_param.Set("max_x", max_x); touch_param.Set("max_y", max_y);
touch_param.Set("max_y", max_y);
}
touch_param.Set("engine", std::move(touch_engine));
Settings::values.touch_device = touch_param.Serialize(); Settings::values.touch_device = touch_param.Serialize();
Settings::values.use_touch_from_button = ui->touch_from_button_checkbox->isChecked(); Settings::values.use_touch_from_button = ui->touch_from_button_checkbox->isChecked();

View File

@ -65,26 +65,12 @@
<string>Touch</string> <string>Touch</string>
</property> </property>
<layout class="QVBoxLayout"> <layout class="QVBoxLayout">
<item>
<layout class="QHBoxLayout">
<item>
<widget class="QLabel" name="touch_provider_label">
<property name="text">
<string>Touch Provider:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="touch_provider"/>
</item>
</layout>
</item>
<item> <item>
<layout class="QHBoxLayout"> <layout class="QHBoxLayout">
<item> <item>
<widget class="QLabel" name="touch_calibration_label"> <widget class="QLabel" name="touch_calibration_label">
<property name="text"> <property name="text">
<string>Calibration:</string> <string>UDP Calibration:</string>
</property> </property>
</widget> </widget>
</item> </item>

View File

@ -33,21 +33,18 @@ void ConfigureTouchscreenAdvanced::RetranslateUI() {
} }
void ConfigureTouchscreenAdvanced::ApplyConfiguration() { void ConfigureTouchscreenAdvanced::ApplyConfiguration() {
Settings::values.touchscreen.finger = ui->finger_box->value();
Settings::values.touchscreen.diameter_x = ui->diameter_x_box->value(); Settings::values.touchscreen.diameter_x = ui->diameter_x_box->value();
Settings::values.touchscreen.diameter_y = ui->diameter_y_box->value(); Settings::values.touchscreen.diameter_y = ui->diameter_y_box->value();
Settings::values.touchscreen.rotation_angle = ui->angle_box->value(); Settings::values.touchscreen.rotation_angle = ui->angle_box->value();
} }
void ConfigureTouchscreenAdvanced::LoadConfiguration() { void ConfigureTouchscreenAdvanced::LoadConfiguration() {
ui->finger_box->setValue(Settings::values.touchscreen.finger);
ui->diameter_x_box->setValue(Settings::values.touchscreen.diameter_x); ui->diameter_x_box->setValue(Settings::values.touchscreen.diameter_x);
ui->diameter_y_box->setValue(Settings::values.touchscreen.diameter_y); ui->diameter_y_box->setValue(Settings::values.touchscreen.diameter_y);
ui->angle_box->setValue(Settings::values.touchscreen.rotation_angle); ui->angle_box->setValue(Settings::values.touchscreen.rotation_angle);
} }
void ConfigureTouchscreenAdvanced::RestoreDefaults() { void ConfigureTouchscreenAdvanced::RestoreDefaults() {
ui->finger_box->setValue(0);
ui->diameter_x_box->setValue(15); ui->diameter_x_box->setValue(15);
ui->diameter_y_box->setValue(15); ui->diameter_y_box->setValue(15);
ui->angle_box->setValue(0); ui->angle_box->setValue(0);

View File

@ -65,20 +65,13 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="2" column="1"> <item row="1" column="1">
<widget class="QLabel" name="label_4"> <widget class="QLabel" name="label_4">
<property name="text"> <property name="text">
<string>Touch Diameter Y</string> <string>Touch Diameter Y</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1">
<widget class="QLabel" name="label">
<property name="text">
<string>Finger</string>
</property>
</widget>
</item>
<item row="0" column="3"> <item row="0" column="3">
<spacer name="horizontalSpacer_2"> <spacer name="horizontalSpacer_2">
<property name="orientation"> <property name="orientation">
@ -92,37 +85,27 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="1" column="1"> <item row="0" column="1">
<widget class="QLabel" name="label_3"> <widget class="QLabel" name="label_3">
<property name="text"> <property name="text">
<string>Touch Diameter X</string> <string>Touch Diameter X</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="2"> <item row="2" column="1">
<widget class="QSpinBox" name="finger_box">
<property name="minimumSize">
<size>
<width>80</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="label_5"> <widget class="QLabel" name="label_5">
<property name="text"> <property name="text">
<string>Rotational Angle</string> <string>Rotational Angle</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="2"> <item row="0" column="2">
<widget class="QSpinBox" name="diameter_x_box"/> <widget class="QSpinBox" name="diameter_x_box"/>
</item> </item>
<item row="2" column="2"> <item row="1" column="2">
<widget class="QSpinBox" name="diameter_y_box"/> <widget class="QSpinBox" name="diameter_y_box"/>
</item> </item>
<item row="3" column="2"> <item row="2" column="2">
<widget class="QSpinBox" name="angle_box"/> <widget class="QSpinBox" name="angle_box"/>
</item> </item>
</layout> </layout>

View File

@ -296,10 +296,6 @@ void Config::ReadValues() {
sdl2_config->GetBoolean("ControlsGeneral", "motion_enabled", true)); sdl2_config->GetBoolean("ControlsGeneral", "motion_enabled", true));
Settings::values.touchscreen.enabled = Settings::values.touchscreen.enabled =
sdl2_config->GetBoolean("ControlsGeneral", "touch_enabled", true); sdl2_config->GetBoolean("ControlsGeneral", "touch_enabled", true);
Settings::values.touchscreen.device =
sdl2_config->Get("ControlsGeneral", "touch_device", "engine:emu_window");
Settings::values.touchscreen.finger =
sdl2_config->GetInteger("ControlsGeneral", "touch_finger", 0);
Settings::values.touchscreen.rotation_angle = Settings::values.touchscreen.rotation_angle =
sdl2_config->GetInteger("ControlsGeneral", "touch_angle", 0); sdl2_config->GetInteger("ControlsGeneral", "touch_angle", 0);
Settings::values.touchscreen.diameter_x = Settings::values.touchscreen.diameter_x =