summaryrefslogtreecommitdiffstats
path: root/src/yuzu/applets/qt_software_keyboard.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/yuzu/applets/qt_software_keyboard.cpp')
-rw-r--r--src/yuzu/applets/qt_software_keyboard.cpp135
1 files changed, 80 insertions, 55 deletions
diff --git a/src/yuzu/applets/qt_software_keyboard.cpp b/src/yuzu/applets/qt_software_keyboard.cpp
index a83a11a95..c3857fc98 100644
--- a/src/yuzu/applets/qt_software_keyboard.cpp
+++ b/src/yuzu/applets/qt_software_keyboard.cpp
@@ -10,7 +10,10 @@
#include "common/settings.h"
#include "common/string_util.h"
#include "core/core.h"
-#include "core/frontend/input_interpreter.h"
+#include "core/hid/emulated_controller.h"
+#include "core/hid/hid_core.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"
@@ -472,11 +475,26 @@ void QtSoftwareKeyboardDialog::open() {
row = 0;
column = 0;
- const auto* const curr_button =
- keyboard_buttons[static_cast<int>(bottom_osk_index)][row][column];
+ switch (bottom_osk_index) {
+ case BottomOSKIndex::LowerCase:
+ case BottomOSKIndex::UpperCase: {
+ const auto* const curr_button =
+ keyboard_buttons[static_cast<std::size_t>(bottom_osk_index)][row][column];
+
+ // This is a workaround for setFocus() randomly not showing focus in the UI
+ QCursor::setPos(curr_button->mapToGlobal(curr_button->rect().center()));
+ break;
+ }
+ case BottomOSKIndex::NumberPad: {
+ const auto* const curr_button = numberpad_buttons[row][column];
- // This is a workaround for setFocus() randomly not showing focus in the UI
- QCursor::setPos(curr_button->mapToGlobal(curr_button->rect().center()));
+ // This is a workaround for setFocus() randomly not showing focus in the UI
+ QCursor::setPos(curr_button->mapToGlobal(curr_button->rect().center()));
+ break;
+ }
+ default:
+ break;
+ }
StartInputThread();
}
@@ -484,7 +502,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 +740,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));
@@ -795,9 +813,10 @@ void QtSoftwareKeyboardDialog::SetTextDrawType() {
}
void QtSoftwareKeyboardDialog::SetControllerImage() {
- const auto controller_type = Settings::values.players.GetValue()[8].connected
- ? Settings::values.players.GetValue()[8].controller_type
- : Settings::values.players.GetValue()[0].controller_type;
+ const auto* handheld = system.HIDCore().GetEmulatedController(Core::HID::NpadIdType::Handheld);
+ const auto* player_1 = system.HIDCore().GetEmulatedController(Core::HID::NpadIdType::Player1);
+ const auto controller_type =
+ handheld->IsConnected() ? handheld->GetNpadStyleIndex() : player_1->GetNpadStyleIndex();
const QString theme = [] {
if (QIcon::themeName().contains(QStringLiteral("dark")) ||
@@ -809,8 +828,8 @@ void QtSoftwareKeyboardDialog::SetControllerImage() {
}();
switch (controller_type) {
- case Settings::ControllerType::ProController:
- case Settings::ControllerType::GameCube:
+ case Core::HID::NpadStyleIndex::ProController:
+ case Core::HID::NpadStyleIndex::GameCube:
ui->icon_controller->setStyleSheet(
QStringLiteral("image: url(:/overlay/controller_pro%1.png);").arg(theme));
ui->icon_controller_shift->setStyleSheet(
@@ -818,7 +837,7 @@ void QtSoftwareKeyboardDialog::SetControllerImage() {
ui->icon_controller_num->setStyleSheet(
QStringLiteral("image: url(:/overlay/controller_pro%1.png);").arg(theme));
break;
- case Settings::ControllerType::DualJoyconDetached:
+ case Core::HID::NpadStyleIndex::JoyconDual:
ui->icon_controller->setStyleSheet(
QStringLiteral("image: url(:/overlay/controller_dual_joycon%1.png);").arg(theme));
ui->icon_controller_shift->setStyleSheet(
@@ -826,7 +845,7 @@ void QtSoftwareKeyboardDialog::SetControllerImage() {
ui->icon_controller_num->setStyleSheet(
QStringLiteral("image: url(:/overlay/controller_dual_joycon%1.png);").arg(theme));
break;
- case Settings::ControllerType::LeftJoycon:
+ case Core::HID::NpadStyleIndex::JoyconLeft:
ui->icon_controller->setStyleSheet(
QStringLiteral("image: url(:/overlay/controller_single_joycon_left%1.png);")
.arg(theme));
@@ -837,7 +856,7 @@ void QtSoftwareKeyboardDialog::SetControllerImage() {
QStringLiteral("image: url(:/overlay/controller_single_joycon_left%1.png);")
.arg(theme));
break;
- case Settings::ControllerType::RightJoycon:
+ case Core::HID::NpadStyleIndex::JoyconRight:
ui->icon_controller->setStyleSheet(
QStringLiteral("image: url(:/overlay/controller_single_joycon_right%1.png);")
.arg(theme));
@@ -848,7 +867,7 @@ void QtSoftwareKeyboardDialog::SetControllerImage() {
QStringLiteral("image: url(:/overlay/controller_single_joycon_right%1.png);")
.arg(theme));
break;
- case Settings::ControllerType::Handheld:
+ case Core::HID::NpadStyleIndex::Handheld:
ui->icon_controller->setStyleSheet(
QStringLiteral("image: url(:/overlay/controller_handheld%1.png);").arg(theme));
ui->icon_controller_shift->setStyleSheet(
@@ -1208,9 +1227,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 +1238,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 +1249,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 +1264,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 +1279,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 +1290,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 +1303,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 +1317,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 +1338,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 +1486,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>();
-
- 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>();
+ 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<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));
}