From cc651c7c99f04c60f1c3422fb9edc8b11e82cd51 Mon Sep 17 00:00:00 2001 From: german77 Date: Sun, 24 Oct 2021 01:02:56 -0500 Subject: web_applet: Replace HIDButton with NpadButton --- src/yuzu/applets/qt_controller.cpp | 3 +- src/yuzu/applets/qt_web_browser.cpp | 65 ++++++++++++++++++++----------------- src/yuzu/applets/qt_web_browser.h | 12 ++++--- 3 files changed, 44 insertions(+), 36 deletions(-) diff --git a/src/yuzu/applets/qt_controller.cpp b/src/yuzu/applets/qt_controller.cpp index 32cb5b5ff..59289c6a5 100644 --- a/src/yuzu/applets/qt_controller.cpp +++ b/src/yuzu/applets/qt_controller.cpp @@ -28,7 +28,8 @@ namespace { constexpr std::size_t HANDHELD_INDEX = 8; -void UpdateController(Core::HID::EmulatedController* controller, Core::HID::NpadType controller_type, bool connected) { +void UpdateController(Core::HID::EmulatedController* controller, + Core::HID::NpadType controller_type, bool connected) { if (controller->IsConnected()) { controller->Disconnect(); } diff --git a/src/yuzu/applets/qt_web_browser.cpp b/src/yuzu/applets/qt_web_browser.cpp index 8e190f9fe..cb3c5d826 100644 --- a/src/yuzu/applets/qt_web_browser.cpp +++ b/src/yuzu/applets/qt_web_browser.cpp @@ -16,6 +16,7 @@ #include "common/fs/path_util.h" #include "common/param_package.h" #include "core/core.h" +#include "core/hid/hid_types.h" #include "core/hid/input_interpreter.h" #include "input_common/drivers/keyboard.h" #include "input_common/main.h" @@ -28,19 +29,19 @@ namespace { -constexpr int HIDButtonToKey(HIDButton button) { +constexpr int HIDButtonToKey(Core::HID::NpadButton button) { switch (button) { - case HIDButton::DLeft: - case HIDButton::LStickLeft: + case Core::HID::NpadButton::Left: + case Core::HID::NpadButton::StickLLeft: return Qt::Key_Left; - case HIDButton::DUp: - case HIDButton::LStickUp: + case Core::HID::NpadButton::Up: + case Core::HID::NpadButton::StickLUp: return Qt::Key_Up; - case HIDButton::DRight: - case HIDButton::LStickRight: + case Core::HID::NpadButton::Right: + case Core::HID::NpadButton::StickLRight: return Qt::Key_Right; - case HIDButton::DDown: - case HIDButton::LStickDown: + case Core::HID::NpadButton::Down: + case Core::HID::NpadButton::StickLDown: return Qt::Key_Down; default: return 0; @@ -209,25 +210,25 @@ void QtNXWebEngineView::keyReleaseEvent(QKeyEvent* event) { } } -template +template void QtNXWebEngineView::HandleWindowFooterButtonPressedOnce() { - const auto f = [this](HIDButton button) { + const auto f = [this](Core::HID::NpadButton button) { if (input_interpreter->IsButtonPressedOnce(button)) { page()->runJavaScript( QStringLiteral("yuzu_key_callbacks[%1] == null;").arg(static_cast(button)), [this, button](const QVariant& variant) { if (variant.toBool()) { switch (button) { - case HIDButton::A: + case Core::HID::NpadButton::A: SendMultipleKeyPressEvents(); break; - case HIDButton::B: + case Core::HID::NpadButton::B: SendKeyPressEvent(Qt::Key_B); break; - case HIDButton::X: + case Core::HID::NpadButton::X: SendKeyPressEvent(Qt::Key_X); break; - case HIDButton::Y: + case Core::HID::NpadButton::Y: SendKeyPressEvent(Qt::Key_Y); break; default: @@ -245,9 +246,9 @@ void QtNXWebEngineView::HandleWindowFooterButtonPressedOnce() { (f(T), ...); } -template +template void QtNXWebEngineView::HandleWindowKeyButtonPressedOnce() { - const auto f = [this](HIDButton button) { + const auto f = [this](Core::HID::NpadButton button) { if (input_interpreter->IsButtonPressedOnce(button)) { SendKeyPressEvent(HIDButtonToKey(button)); } @@ -256,9 +257,9 @@ void QtNXWebEngineView::HandleWindowKeyButtonPressedOnce() { (f(T), ...); } -template +template void QtNXWebEngineView::HandleWindowKeyButtonHold() { - const auto f = [this](HIDButton button) { + const auto f = [this](Core::HID::NpadButton button) { if (input_interpreter->IsButtonHeld(button)) { SendKeyPressEvent(HIDButtonToKey(button)); } @@ -309,17 +310,21 @@ void QtNXWebEngineView::InputThread() { while (input_thread_running) { input_interpreter->PollInput(); - HandleWindowFooterButtonPressedOnce(); - - HandleWindowKeyButtonPressedOnce(); - - HandleWindowKeyButtonHold(); + HandleWindowFooterButtonPressedOnce(); + + HandleWindowKeyButtonPressedOnce< + 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>(); + + HandleWindowKeyButtonHold< + 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>(); std::this_thread::sleep_for(std::chrono::milliseconds(50)); } diff --git a/src/yuzu/applets/qt_web_browser.h b/src/yuzu/applets/qt_web_browser.h index 7e9f703fc..fa18aecac 100644 --- a/src/yuzu/applets/qt_web_browser.h +++ b/src/yuzu/applets/qt_web_browser.h @@ -16,8 +16,6 @@ #include "core/frontend/applets/web_browser.h" -enum class HIDButton : u8; - class GMainWindow; class InputInterpreter; class UrlRequestInterceptor; @@ -26,6 +24,10 @@ namespace Core { class System; } +namespace Core::HID { +enum class NpadButton : u64; +} + namespace InputCommon { class InputSubsystem; } @@ -114,7 +116,7 @@ private: * * @tparam HIDButton The list of buttons contained in yuzu_key_callbacks */ - template + template void HandleWindowFooterButtonPressedOnce(); /** @@ -123,7 +125,7 @@ private: * * @tparam HIDButton The list of buttons that can be converted into keyboard input. */ - template + template void HandleWindowKeyButtonPressedOnce(); /** @@ -132,7 +134,7 @@ private: * * @tparam HIDButton The list of buttons that can be converted into keyboard input. */ - template + template void HandleWindowKeyButtonHold(); /** -- cgit v1.2.3