mirror of
https://github.com/yuzu-emu/yuzu.git
synced 2024-08-21 15:53:23 +02:00
applets/web: Fix keyboard to emulated controller input
This commit is contained in:
parent
2ddd83cdfe
commit
51cddcb8b8
@ -15,6 +15,8 @@
|
|||||||
#include "common/file_util.h"
|
#include "common/file_util.h"
|
||||||
#include "core/core.h"
|
#include "core/core.h"
|
||||||
#include "core/frontend/input_interpreter.h"
|
#include "core/frontend/input_interpreter.h"
|
||||||
|
#include "input_common/keyboard.h"
|
||||||
|
#include "input_common/main.h"
|
||||||
#include "yuzu/applets/web_browser.h"
|
#include "yuzu/applets/web_browser.h"
|
||||||
#include "yuzu/applets/web_browser_scripts.h"
|
#include "yuzu/applets/web_browser_scripts.h"
|
||||||
#include "yuzu/main.h"
|
#include "yuzu/main.h"
|
||||||
@ -45,8 +47,10 @@ constexpr int HIDButtonToKey(HIDButton button) {
|
|||||||
|
|
||||||
} // Anonymous namespace
|
} // Anonymous namespace
|
||||||
|
|
||||||
QtNXWebEngineView::QtNXWebEngineView(QWidget* parent, Core::System& system)
|
QtNXWebEngineView::QtNXWebEngineView(QWidget* parent, Core::System& system,
|
||||||
: QWebEngineView(parent), url_interceptor(std::make_unique<UrlRequestInterceptor>()),
|
InputCommon::InputSubsystem* input_subsystem_)
|
||||||
|
: QWebEngineView(parent), input_subsystem{input_subsystem_},
|
||||||
|
url_interceptor(std::make_unique<UrlRequestInterceptor>()),
|
||||||
input_interpreter(std::make_unique<InputInterpreter>(system)) {
|
input_interpreter(std::make_unique<InputInterpreter>(system)) {
|
||||||
QWebEngineScript nx_font_css;
|
QWebEngineScript nx_font_css;
|
||||||
QWebEngineScript load_nx_font;
|
QWebEngineScript load_nx_font;
|
||||||
@ -203,6 +207,14 @@ void QtNXWebEngineView::hide() {
|
|||||||
QWidget::hide();
|
QWidget::hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QtNXWebEngineView::keyPressEvent(QKeyEvent* event) {
|
||||||
|
input_subsystem->GetKeyboard()->PressKey(event->key());
|
||||||
|
}
|
||||||
|
|
||||||
|
void QtNXWebEngineView::keyReleaseEvent(QKeyEvent* event) {
|
||||||
|
input_subsystem->GetKeyboard()->ReleaseKey(event->key());
|
||||||
|
}
|
||||||
|
|
||||||
template <HIDButton... T>
|
template <HIDButton... T>
|
||||||
void QtNXWebEngineView::HandleWindowFooterButtonPressedOnce() {
|
void QtNXWebEngineView::HandleWindowFooterButtonPressedOnce() {
|
||||||
const auto f = [this](HIDButton button) {
|
const auto f = [this](HIDButton button) {
|
||||||
@ -282,6 +294,7 @@ void QtNXWebEngineView::StartInputThread() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void QtNXWebEngineView::StopInputThread() {
|
void QtNXWebEngineView::StopInputThread() {
|
||||||
|
QWidget::releaseKeyboard();
|
||||||
input_thread_running = false;
|
input_thread_running = false;
|
||||||
if (input_thread.joinable()) {
|
if (input_thread.joinable()) {
|
||||||
input_thread.join();
|
input_thread.join();
|
||||||
@ -292,6 +305,8 @@ void QtNXWebEngineView::InputThread() {
|
|||||||
// Wait for 1 second before allowing any inputs to be processed.
|
// Wait for 1 second before allowing any inputs to be processed.
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||||
|
|
||||||
|
QWidget::grabKeyboard();
|
||||||
|
|
||||||
while (input_thread_running) {
|
while (input_thread_running) {
|
||||||
input_interpreter->PollInput();
|
input_interpreter->PollInput();
|
||||||
|
|
||||||
|
@ -26,6 +26,10 @@ namespace Core {
|
|||||||
class System;
|
class System;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace InputCommon {
|
||||||
|
class InputSubsystem;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef YUZU_USE_QT_WEB_ENGINE
|
#ifdef YUZU_USE_QT_WEB_ENGINE
|
||||||
|
|
||||||
enum class UserAgent {
|
enum class UserAgent {
|
||||||
@ -41,7 +45,8 @@ class QtNXWebEngineView : public QWebEngineView {
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit QtNXWebEngineView(QWidget* parent, Core::System& system);
|
explicit QtNXWebEngineView(QWidget* parent, Core::System& system,
|
||||||
|
InputCommon::InputSubsystem* input_subsystem_);
|
||||||
~QtNXWebEngineView() override;
|
~QtNXWebEngineView() override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -86,6 +91,10 @@ public:
|
|||||||
public slots:
|
public slots:
|
||||||
void hide();
|
void hide();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void keyPressEvent(QKeyEvent* event) override;
|
||||||
|
void keyReleaseEvent(QKeyEvent* event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* Handles button presses to execute functions assigned in yuzu_key_callbacks.
|
* Handles button presses to execute functions assigned in yuzu_key_callbacks.
|
||||||
@ -138,6 +147,8 @@ private:
|
|||||||
/// The thread where input is being polled and processed.
|
/// The thread where input is being polled and processed.
|
||||||
void InputThread();
|
void InputThread();
|
||||||
|
|
||||||
|
InputCommon::InputSubsystem* input_subsystem;
|
||||||
|
|
||||||
std::unique_ptr<UrlRequestInterceptor> url_interceptor;
|
std::unique_ptr<UrlRequestInterceptor> url_interceptor;
|
||||||
|
|
||||||
std::unique_ptr<InputInterpreter> input_interpreter;
|
std::unique_ptr<InputInterpreter> input_interpreter;
|
||||||
|
@ -376,7 +376,7 @@ void GMainWindow::WebBrowserOpenLocalWebPage(std::string_view main_url,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QtNXWebEngineView web_browser_view(this, Core::System::GetInstance());
|
QtNXWebEngineView web_browser_view(this, Core::System::GetInstance(), input_subsystem.get());
|
||||||
|
|
||||||
ui.action_Pause->setEnabled(false);
|
ui.action_Pause->setEnabled(false);
|
||||||
ui.action_Restart->setEnabled(false);
|
ui.action_Restart->setEnabled(false);
|
||||||
|
Loading…
Reference in New Issue
Block a user