Qt_applets: Use new input

This commit is contained in:
german77
2021-09-20 20:19:28 -05:00
committed by Narr the Reg
parent 6e2c84042d
commit 8fff6d6c67
5 changed files with 67 additions and 48 deletions

View File

@ -10,7 +10,8 @@
#include "common/settings.h"
#include "common/string_util.h"
#include "core/core.h"
#include "core/frontend/input_interpreter.h"
#include "core/hid/hid_types.h"
#include "core/hid/input_interpreter.h"
#include "ui_qt_software_keyboard.h"
#include "yuzu/applets/qt_software_keyboard.h"
#include "yuzu/main.h"
@ -484,7 +485,7 @@ void QtSoftwareKeyboardDialog::open() {
void QtSoftwareKeyboardDialog::reject() {
// Pressing the ESC key in a dialog calls QDialog::reject().
// We will override this behavior to the "Cancel" action on the software keyboard.
TranslateButtonPress(HIDButton::X);
TranslateButtonPress(Core::HID::NpadButton::X);
}
void QtSoftwareKeyboardDialog::keyPressEvent(QKeyEvent* event) {
@ -722,7 +723,7 @@ void QtSoftwareKeyboardDialog::SetTextDrawType() {
connect(
ui->line_edit_osk, &QLineEdit::returnPressed, this,
[this] { TranslateButtonPress(HIDButton::Plus); }, Qt::QueuedConnection);
[this] { TranslateButtonPress(Core::HID::NpadButton::Plus); }, Qt::QueuedConnection);
ui->line_edit_osk->setPlaceholderText(
QString::fromStdU16String(initialize_parameters.guide_text));
@ -1208,9 +1209,9 @@ void QtSoftwareKeyboardDialog::SetupMouseHover() {
}
}
template <HIDButton... T>
template <Core::HID::NpadButton... T>
void QtSoftwareKeyboardDialog::HandleButtonPressedOnce() {
const auto f = [this](HIDButton button) {
const auto f = [this](Core::HID::NpadButton button) {
if (input_interpreter->IsButtonPressedOnce(button)) {
TranslateButtonPress(button);
}
@ -1219,9 +1220,9 @@ void QtSoftwareKeyboardDialog::HandleButtonPressedOnce() {
(f(T), ...);
}
template <HIDButton... T>
template <Core::HID::NpadButton... T>
void QtSoftwareKeyboardDialog::HandleButtonHold() {
const auto f = [this](HIDButton button) {
const auto f = [this](Core::HID::NpadButton button) {
if (input_interpreter->IsButtonHeld(button)) {
TranslateButtonPress(button);
}
@ -1230,9 +1231,9 @@ void QtSoftwareKeyboardDialog::HandleButtonHold() {
(f(T), ...);
}
void QtSoftwareKeyboardDialog::TranslateButtonPress(HIDButton button) {
void QtSoftwareKeyboardDialog::TranslateButtonPress(Core::HID::NpadButton button) {
switch (button) {
case HIDButton::A:
case Core::HID::NpadButton::A:
switch (bottom_osk_index) {
case BottomOSKIndex::LowerCase:
case BottomOSKIndex::UpperCase:
@ -1245,7 +1246,7 @@ void QtSoftwareKeyboardDialog::TranslateButtonPress(HIDButton button) {
break;
}
break;
case HIDButton::B:
case Core::HID::NpadButton::B:
switch (bottom_osk_index) {
case BottomOSKIndex::LowerCase:
ui->button_backspace->click();
@ -1260,7 +1261,7 @@ void QtSoftwareKeyboardDialog::TranslateButtonPress(HIDButton button) {
break;
}
break;
case HIDButton::X:
case Core::HID::NpadButton::X:
if (is_inline) {
emit SubmitInlineText(SwkbdReplyType::DecidedCancel, current_text, cursor_position);
} else {
@ -1271,7 +1272,7 @@ void QtSoftwareKeyboardDialog::TranslateButtonPress(HIDButton button) {
emit SubmitNormalText(SwkbdResult::Cancel, std::move(text));
}
break;
case HIDButton::Y:
case Core::HID::NpadButton::Y:
switch (bottom_osk_index) {
case BottomOSKIndex::LowerCase:
ui->button_space->click();
@ -1284,8 +1285,8 @@ void QtSoftwareKeyboardDialog::TranslateButtonPress(HIDButton button) {
break;
}
break;
case HIDButton::LStick:
case HIDButton::RStick:
case Core::HID::NpadButton::StickL:
case Core::HID::NpadButton::StickR:
switch (bottom_osk_index) {
case BottomOSKIndex::LowerCase:
ui->button_shift->click();
@ -1298,13 +1299,13 @@ void QtSoftwareKeyboardDialog::TranslateButtonPress(HIDButton button) {
break;
}
break;
case HIDButton::L:
case Core::HID::NpadButton::L:
MoveTextCursorDirection(Direction::Left);
break;
case HIDButton::R:
case Core::HID::NpadButton::R:
MoveTextCursorDirection(Direction::Right);
break;
case HIDButton::Plus:
case Core::HID::NpadButton::Plus:
switch (bottom_osk_index) {
case BottomOSKIndex::LowerCase:
ui->button_ok->click();
@ -1319,24 +1320,24 @@ void QtSoftwareKeyboardDialog::TranslateButtonPress(HIDButton button) {
break;
}
break;
case HIDButton::DLeft:
case HIDButton::LStickLeft:
case HIDButton::RStickLeft:
case Core::HID::NpadButton::Left:
case Core::HID::NpadButton::StickLLeft:
case Core::HID::NpadButton::StickRLeft:
MoveButtonDirection(Direction::Left);
break;
case HIDButton::DUp:
case HIDButton::LStickUp:
case HIDButton::RStickUp:
case Core::HID::NpadButton::Up:
case Core::HID::NpadButton::StickLUp:
case Core::HID::NpadButton::StickRUp:
MoveButtonDirection(Direction::Up);
break;
case HIDButton::DRight:
case HIDButton::LStickRight:
case HIDButton::RStickRight:
case Core::HID::NpadButton::Right:
case Core::HID::NpadButton::StickLRight:
case Core::HID::NpadButton::StickRRight:
MoveButtonDirection(Direction::Right);
break;
case HIDButton::DDown:
case HIDButton::LStickDown:
case HIDButton::RStickDown:
case Core::HID::NpadButton::Down:
case Core::HID::NpadButton::StickLDown:
case Core::HID::NpadButton::StickRDown:
MoveButtonDirection(Direction::Down);
break;
default:
@ -1467,19 +1468,25 @@ void QtSoftwareKeyboardDialog::InputThread() {
while (input_thread_running) {
input_interpreter->PollInput();
HandleButtonPressedOnce<HIDButton::A, HIDButton::B, HIDButton::X, HIDButton::Y,
HIDButton::LStick, HIDButton::RStick, HIDButton::L, HIDButton::R,
HIDButton::Plus, HIDButton::DLeft, HIDButton::DUp,
HIDButton::DRight, HIDButton::DDown, HIDButton::LStickLeft,
HIDButton::LStickUp, HIDButton::LStickRight, HIDButton::LStickDown,
HIDButton::RStickLeft, HIDButton::RStickUp, HIDButton::RStickRight,
HIDButton::RStickDown>();
HandleButtonPressedOnce<
Core::HID::NpadButton::A, Core::HID::NpadButton::B, Core::HID::NpadButton::X,
Core::HID::NpadButton::Y, Core::HID::NpadButton::StickL, Core::HID::NpadButton::StickR,
Core::HID::NpadButton::L, Core::HID::NpadButton::R, Core::HID::NpadButton::Plus,
Core::HID::NpadButton::Left, Core::HID::NpadButton::Up, Core::HID::NpadButton::Right,
Core::HID::NpadButton::Down, Core::HID::NpadButton::StickLLeft,
Core::HID::NpadButton::StickLUp, Core::HID::NpadButton::StickLRight,
Core::HID::NpadButton::StickLDown, Core::HID::NpadButton::StickRLeft,
Core::HID::NpadButton::StickRUp, Core::HID::NpadButton::StickRRight,
Core::HID::NpadButton::StickRDown>();
HandleButtonHold<HIDButton::B, HIDButton::L, HIDButton::R, HIDButton::DLeft, HIDButton::DUp,
HIDButton::DRight, HIDButton::DDown, HIDButton::LStickLeft,
HIDButton::LStickUp, HIDButton::LStickRight, HIDButton::LStickDown,
HIDButton::RStickLeft, HIDButton::RStickUp, HIDButton::RStickRight,
HIDButton::RStickDown>();
HandleButtonHold<Core::HID::NpadButton::B, Core::HID::NpadButton::L,
Core::HID::NpadButton::R, Core::HID::NpadButton::Left,
Core::HID::NpadButton::Up, Core::HID::NpadButton::Right,
Core::HID::NpadButton::Down, Core::HID::NpadButton::StickLLeft,
Core::HID::NpadButton::StickLUp, Core::HID::NpadButton::StickLRight,
Core::HID::NpadButton::StickLDown, Core::HID::NpadButton::StickRLeft,
Core::HID::NpadButton::StickRUp, Core::HID::NpadButton::StickRRight,
Core::HID::NpadButton::StickRDown>();
std::this_thread::sleep_for(std::chrono::milliseconds(50));
}