mirror of
https://github.com/yuzu-emu/yuzu-android.git
synced 2025-06-29 15:07:52 -05:00
Merge pull request #5270 from german77/multiTouch
HID: Add multitouch support
This commit is contained in:
@ -394,7 +394,7 @@ void GRenderWindow::mousePressEvent(QMouseEvent* event) {
|
||||
input_subsystem->GetMouse()->PressButton(x, y, event->button());
|
||||
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
this->TouchPressed(x, y);
|
||||
this->TouchPressed(x, y, 0);
|
||||
}
|
||||
|
||||
emit MouseActivity();
|
||||
@ -409,7 +409,7 @@ void GRenderWindow::mouseMoveEvent(QMouseEvent* event) {
|
||||
auto pos = event->pos();
|
||||
const auto [x, y] = ScaleTouch(pos);
|
||||
input_subsystem->GetMouse()->MouseMove(x, y);
|
||||
this->TouchMoved(x, y);
|
||||
this->TouchMoved(x, y, 0);
|
||||
|
||||
emit MouseActivity();
|
||||
}
|
||||
@ -423,36 +423,72 @@ void GRenderWindow::mouseReleaseEvent(QMouseEvent* event) {
|
||||
input_subsystem->GetMouse()->ReleaseButton(event->button());
|
||||
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
this->TouchReleased();
|
||||
this->TouchReleased(0);
|
||||
}
|
||||
}
|
||||
|
||||
void GRenderWindow::TouchBeginEvent(const QTouchEvent* event) {
|
||||
// TouchBegin always has exactly one touch point, so take the .first()
|
||||
const auto [x, y] = ScaleTouch(event->touchPoints().first().pos());
|
||||
this->TouchPressed(x, y);
|
||||
QList<QTouchEvent::TouchPoint> touch_points = event->touchPoints();
|
||||
for (const auto& touch_point : touch_points) {
|
||||
if (!TouchUpdate(touch_point)) {
|
||||
TouchStart(touch_point);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GRenderWindow::TouchUpdateEvent(const QTouchEvent* event) {
|
||||
QPointF pos;
|
||||
int active_points = 0;
|
||||
|
||||
// average all active touch points
|
||||
for (const auto& tp : event->touchPoints()) {
|
||||
if (tp.state() & (Qt::TouchPointPressed | Qt::TouchPointMoved | Qt::TouchPointStationary)) {
|
||||
active_points++;
|
||||
pos += tp.pos();
|
||||
QList<QTouchEvent::TouchPoint> touch_points = event->touchPoints();
|
||||
for (const auto& touch_point : touch_points) {
|
||||
if (!TouchUpdate(touch_point)) {
|
||||
TouchStart(touch_point);
|
||||
}
|
||||
}
|
||||
// Release all inactive points
|
||||
for (std::size_t id = 0; id < touch_ids.size(); ++id) {
|
||||
if (!TouchExist(touch_ids[id], touch_points)) {
|
||||
touch_ids[id] = 0;
|
||||
this->TouchReleased(id + 1);
|
||||
}
|
||||
}
|
||||
|
||||
pos /= active_points;
|
||||
|
||||
const auto [x, y] = ScaleTouch(pos);
|
||||
this->TouchMoved(x, y);
|
||||
}
|
||||
|
||||
void GRenderWindow::TouchEndEvent() {
|
||||
this->TouchReleased();
|
||||
for (std::size_t id = 0; id < touch_ids.size(); ++id) {
|
||||
if (touch_ids[id] != 0) {
|
||||
touch_ids[id] = 0;
|
||||
this->TouchReleased(id + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool GRenderWindow::TouchStart(const QTouchEvent::TouchPoint& touch_point) {
|
||||
for (std::size_t id = 0; id < touch_ids.size(); ++id) {
|
||||
if (touch_ids[id] == 0) {
|
||||
touch_ids[id] = touch_point.id() + 1;
|
||||
const auto [x, y] = ScaleTouch(touch_point.pos());
|
||||
this->TouchPressed(x, y, id + 1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool GRenderWindow::TouchUpdate(const QTouchEvent::TouchPoint& touch_point) {
|
||||
for (std::size_t id = 0; id < touch_ids.size(); ++id) {
|
||||
if (touch_ids[id] == static_cast<std::size_t>(touch_point.id() + 1)) {
|
||||
const auto [x, y] = ScaleTouch(touch_point.pos());
|
||||
this->TouchMoved(x, y, id + 1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool GRenderWindow::TouchExist(std::size_t id,
|
||||
const QList<QTouchEvent::TouchPoint>& touch_points) const {
|
||||
return std::any_of(touch_points.begin(), touch_points.end(), [id](const auto& point) {
|
||||
return id == static_cast<std::size_t>(point.id() + 1);
|
||||
});
|
||||
}
|
||||
|
||||
bool GRenderWindow::event(QEvent* event) {
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
#include <QImage>
|
||||
#include <QThread>
|
||||
#include <QTouchEvent>
|
||||
#include <QWidget>
|
||||
#include <QWindow>
|
||||
|
||||
@ -21,7 +22,6 @@
|
||||
class GRenderWindow;
|
||||
class GMainWindow;
|
||||
class QKeyEvent;
|
||||
class QTouchEvent;
|
||||
class QStringList;
|
||||
|
||||
namespace InputCommon {
|
||||
@ -191,6 +191,10 @@ private:
|
||||
void TouchUpdateEvent(const QTouchEvent* event);
|
||||
void TouchEndEvent();
|
||||
|
||||
bool TouchStart(const QTouchEvent::TouchPoint& touch_point);
|
||||
bool TouchUpdate(const QTouchEvent::TouchPoint& touch_point);
|
||||
bool TouchExist(std::size_t id, const QList<QTouchEvent::TouchPoint>& touch_points) const;
|
||||
|
||||
void OnMinimalClientAreaChangeRequest(std::pair<u32, u32> minimal_size) override;
|
||||
|
||||
bool InitializeOpenGL();
|
||||
@ -215,6 +219,8 @@ private:
|
||||
|
||||
bool first_frame = false;
|
||||
|
||||
std::array<std::size_t, 16> touch_ids{};
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent* event) override;
|
||||
bool eventFilter(QObject* object, QEvent* event) override;
|
||||
|
@ -464,13 +464,7 @@ void Config::ReadMouseValues() {
|
||||
void Config::ReadTouchscreenValues() {
|
||||
Settings::values.touchscreen.enabled =
|
||||
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 =
|
||||
ReadSetting(QStringLiteral("touchscreen_angle"), 0).toUInt();
|
||||
Settings::values.touchscreen.diameter_x =
|
||||
@ -563,7 +557,8 @@ void Config::ReadMotionTouchValues() {
|
||||
.toString()
|
||||
.toStdString();
|
||||
Settings::values.touch_device =
|
||||
ReadSetting(QStringLiteral("touch_device"), QStringLiteral("engine:emu_window"))
|
||||
ReadSetting(QStringLiteral("touch_device"),
|
||||
QStringLiteral("min_x:100,min_y:50,max_x:1800,max_y:850"))
|
||||
.toString()
|
||||
.toStdString();
|
||||
Settings::values.use_touch_from_button =
|
||||
@ -1088,10 +1083,7 @@ void Config::SaveTouchscreenValues() {
|
||||
const auto& touchscreen = Settings::values.touchscreen;
|
||||
|
||||
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_diameter_x"), touchscreen.diameter_x, 15);
|
||||
WriteSetting(QStringLiteral("touchscreen_diameter_y"), touchscreen.diameter_y, 15);
|
||||
|
@ -81,19 +81,11 @@ void CalibrationConfigurationDialog::UpdateButtonText(const QString& 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,
|
||||
InputCommon::InputSubsystem* input_subsystem_)
|
||||
: QDialog(parent), input_subsystem{input_subsystem_},
|
||||
ui(std::make_unique<Ui::ConfigureMotionTouch>()) {
|
||||
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->setText(
|
||||
@ -112,10 +104,7 @@ ConfigureMotionTouch::~ConfigureMotionTouch() = default;
|
||||
void ConfigureMotionTouch::SetConfiguration() {
|
||||
const Common::ParamPackage motion_param(Settings::values.motion_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);
|
||||
touch_from_button_maps = Settings::values.touch_from_button_maps;
|
||||
for (const auto& touch_map : touch_from_button_maps) {
|
||||
@ -148,30 +137,21 @@ void ConfigureMotionTouch::SetConfiguration() {
|
||||
}
|
||||
|
||||
void ConfigureMotionTouch::UpdateUiDisplay() {
|
||||
const QString touch_engine = ui->touch_provider->currentData().toString();
|
||||
const QString cemuhook_udp = QStringLiteral("cemuhookudp");
|
||||
|
||||
ui->motion_sensitivity_label->setVisible(true);
|
||||
ui->motion_sensitivity->setVisible(true);
|
||||
|
||||
if (touch_engine == cemuhook_udp) {
|
||||
ui->touch_calibration->setVisible(true);
|
||||
ui->touch_calibration_config->setVisible(true);
|
||||
ui->touch_calibration_label->setVisible(true);
|
||||
ui->touch_calibration->setText(
|
||||
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->touch_calibration->setVisible(true);
|
||||
ui->touch_calibration_config->setVisible(true);
|
||||
ui->touch_calibration_label->setVisible(true);
|
||||
ui->touch_calibration->setText(
|
||||
QStringLiteral("(%1, %2) - (%3, %4)").arg(min_x).arg(min_y).arg(max_x).arg(max_y));
|
||||
|
||||
ui->udp_config_group_box->setVisible(true);
|
||||
}
|
||||
|
||||
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_add, &QPushButton::clicked, this, &ConfigureMotionTouch::OnUDPAddServer);
|
||||
connect(ui->udp_remove, &QPushButton::clicked, this, &ConfigureMotionTouch::OnUDPDeleteServer);
|
||||
@ -327,16 +307,11 @@ void ConfigureMotionTouch::ApplyConfiguration() {
|
||||
return;
|
||||
}
|
||||
|
||||
std::string touch_engine = ui->touch_provider->currentData().toString().toStdString();
|
||||
|
||||
Common::ParamPackage touch_param{};
|
||||
if (touch_engine == "cemuhookudp") {
|
||||
touch_param.Set("min_x", min_x);
|
||||
touch_param.Set("min_y", min_y);
|
||||
touch_param.Set("max_x", max_x);
|
||||
touch_param.Set("max_y", max_y);
|
||||
}
|
||||
touch_param.Set("engine", std::move(touch_engine));
|
||||
touch_param.Set("min_x", min_x);
|
||||
touch_param.Set("min_y", min_y);
|
||||
touch_param.Set("max_x", max_x);
|
||||
touch_param.Set("max_y", max_y);
|
||||
|
||||
Settings::values.touch_device = touch_param.Serialize();
|
||||
Settings::values.use_touch_from_button = ui->touch_from_button_checkbox->isChecked();
|
||||
|
@ -65,26 +65,12 @@
|
||||
<string>Touch</string>
|
||||
</property>
|
||||
<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>
|
||||
<layout class="QHBoxLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="touch_calibration_label">
|
||||
<property name="text">
|
||||
<string>Calibration:</string>
|
||||
<string>UDP Calibration:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -33,21 +33,18 @@ void ConfigureTouchscreenAdvanced::RetranslateUI() {
|
||||
}
|
||||
|
||||
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_y = ui->diameter_y_box->value();
|
||||
Settings::values.touchscreen.rotation_angle = ui->angle_box->value();
|
||||
}
|
||||
|
||||
void ConfigureTouchscreenAdvanced::LoadConfiguration() {
|
||||
ui->finger_box->setValue(Settings::values.touchscreen.finger);
|
||||
ui->diameter_x_box->setValue(Settings::values.touchscreen.diameter_x);
|
||||
ui->diameter_y_box->setValue(Settings::values.touchscreen.diameter_y);
|
||||
ui->angle_box->setValue(Settings::values.touchscreen.rotation_angle);
|
||||
}
|
||||
|
||||
void ConfigureTouchscreenAdvanced::RestoreDefaults() {
|
||||
ui->finger_box->setValue(0);
|
||||
ui->diameter_x_box->setValue(15);
|
||||
ui->diameter_y_box->setValue(15);
|
||||
ui->angle_box->setValue(0);
|
||||
|
@ -65,20 +65,13 @@
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<item row="1" column="1">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Touch Diameter Y</string>
|
||||
</property>
|
||||
</widget>
|
||||
</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">
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
@ -92,37 +85,27 @@
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Touch Diameter X</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<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">
|
||||
<item row="2" column="1">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Rotational Angle</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<item row="0" column="2">
|
||||
<widget class="QSpinBox" name="diameter_x_box"/>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<item row="1" column="2">
|
||||
<widget class="QSpinBox" name="diameter_y_box"/>
|
||||
</item>
|
||||
<item row="3" column="2">
|
||||
<item row="2" column="2">
|
||||
<widget class="QSpinBox" name="angle_box"/>
|
||||
</item>
|
||||
</layout>
|
||||
|
Reference in New Issue
Block a user