summaryrefslogtreecommitdiff
path: root/src/yuzu/main.cpp
diff options
context:
space:
mode:
authorMorph <39850852+Morph1984@users.noreply.github.com>2021-03-27 15:15:32 -0400
committerMorph <39850852+Morph1984@users.noreply.github.com>2021-04-15 01:53:17 -0400
commit7eff91ff20765ba4e7f94a92de6fc0ffa2fc4f2f (patch)
tree91688790eb58a41ea8ba4e7e5ba7f07825516a18 /src/yuzu/main.cpp
parentb45930a0edbf762310f85fafa3724dc4766c2197 (diff)
applets/swkbd: Implement the Qt Software Keyboard frontend
The Qt Software Keyboard frontend attempts to mimic the software keyboard rendered by the Nintendo Switch. This frontend implements multiple keyboard types, such as the normal software keyboard, the numeric pad software keyboard and the inline software keyboard. Keyboard and controller input is also supported in this frontend. Keyboard input is handled as native keyboard input, and so the on-screen keyboard cannot be navigated with the keyboard arrow keys as the arrow keys are used to move the text cursor. Controller input is translated into mouse hover movements on the onscreen keyboard or their respective button actions (B for backspace, A for entering the selected button, L/R for moving the text cursor, etc). The text check dialogs can also be confirmed with controller input through the use of the OverlayDialog Massive thanks to Rei for creating all the UI for the various keyboards and OverlayDialog. This would not have been possible without his excellent work. Co-authored-by: Its-Rei <kupfel@gmail.com>
Diffstat (limited to 'src/yuzu/main.cpp')
-rw-r--r--src/yuzu/main.cpp112
1 files changed, 112 insertions, 0 deletions
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index ce83dee27..5f6cdc0c6 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -466,6 +466,114 @@ void GMainWindow::ProfileSelectorSelectProfile() {
emit ProfileSelectorFinishedSelection(uuid);
}
+void GMainWindow::SoftwareKeyboardInitialize(
+ bool is_inline, Core::Frontend::KeyboardInitializeParameters initialize_parameters) {
+ if (software_keyboard) {
+ LOG_ERROR(Frontend, "The software keyboard is already initialized!");
+ return;
+ }
+
+ software_keyboard = new QtSoftwareKeyboardDialog(render_window, Core::System::GetInstance(),
+ is_inline, std::move(initialize_parameters));
+
+ if (is_inline) {
+ connect(
+ software_keyboard, &QtSoftwareKeyboardDialog::SubmitInlineText, this,
+ [this](Service::AM::Applets::SwkbdReplyType reply_type, std::u16string submitted_text,
+ s32 cursor_position) {
+ emit SoftwareKeyboardSubmitInlineText(reply_type, submitted_text, cursor_position);
+ },
+ Qt::QueuedConnection);
+ } else {
+ connect(
+ software_keyboard, &QtSoftwareKeyboardDialog::SubmitNormalText, this,
+ [this](Service::AM::Applets::SwkbdResult result, std::u16string submitted_text) {
+ emit SoftwareKeyboardSubmitNormalText(result, submitted_text);
+ },
+ Qt::QueuedConnection);
+ }
+}
+
+void GMainWindow::SoftwareKeyboardShowNormal() {
+ if (!software_keyboard) {
+ LOG_ERROR(Frontend, "The software keyboard is not initialized!");
+ return;
+ }
+
+ const auto& layout = render_window->GetFramebufferLayout();
+
+ const auto x = layout.screen.left;
+ const auto y = layout.screen.top;
+ const auto w = layout.screen.GetWidth();
+ const auto h = layout.screen.GetHeight();
+
+ software_keyboard->ShowNormalKeyboard(render_window->mapToGlobal(QPoint(x, y)), QSize(w, h));
+}
+
+void GMainWindow::SoftwareKeyboardShowTextCheck(
+ Service::AM::Applets::SwkbdTextCheckResult text_check_result,
+ std::u16string text_check_message) {
+ if (!software_keyboard) {
+ LOG_ERROR(Frontend, "The software keyboard is not initialized!");
+ return;
+ }
+
+ software_keyboard->ShowTextCheckDialog(text_check_result, text_check_message);
+}
+
+void GMainWindow::SoftwareKeyboardShowInline(
+ Core::Frontend::InlineAppearParameters appear_parameters) {
+ if (!software_keyboard) {
+ LOG_ERROR(Frontend, "The software keyboard is not initialized!");
+ return;
+ }
+
+ const auto& layout = render_window->GetFramebufferLayout();
+
+ const auto x =
+ static_cast<int>(layout.screen.left + (0.5f * layout.screen.GetWidth() *
+ ((2.0f * appear_parameters.key_top_translate_x) +
+ (1.0f - appear_parameters.key_top_scale_x))));
+ const auto y =
+ static_cast<int>(layout.screen.top + (layout.screen.GetHeight() *
+ ((2.0f * appear_parameters.key_top_translate_y) +
+ (1.0f - appear_parameters.key_top_scale_y))));
+ const auto w = static_cast<int>(layout.screen.GetWidth() * appear_parameters.key_top_scale_x);
+ const auto h = static_cast<int>(layout.screen.GetHeight() * appear_parameters.key_top_scale_y);
+
+ software_keyboard->ShowInlineKeyboard(std::move(appear_parameters),
+ render_window->mapToGlobal(QPoint(x, y)), QSize(w, h));
+}
+
+void GMainWindow::SoftwareKeyboardHideInline() {
+ if (!software_keyboard) {
+ LOG_ERROR(Frontend, "The software keyboard is not initialized!");
+ return;
+ }
+
+ software_keyboard->HideInlineKeyboard();
+}
+
+void GMainWindow::SoftwareKeyboardInlineTextChanged(
+ Core::Frontend::InlineTextParameters text_parameters) {
+ if (!software_keyboard) {
+ LOG_ERROR(Frontend, "The software keyboard is not initialized!");
+ return;
+ }
+
+ software_keyboard->InlineTextChanged(std::move(text_parameters));
+}
+
+void GMainWindow::SoftwareKeyboardExit() {
+ if (!software_keyboard) {
+ return;
+ }
+
+ software_keyboard->ExitKeyboard();
+
+ software_keyboard = nullptr;
+}
+
void GMainWindow::WebBrowserOpenWebPage(std::string_view main_url, std::string_view additional_args,
bool is_local) {
#ifdef YUZU_USE_QT_WEB_ENGINE
@@ -1009,6 +1117,10 @@ void GMainWindow::ConnectWidgetEvents() {
connect(this, &GMainWindow::EmulationStopping, render_window,
&GRenderWindow::OnEmulationStopping);
+ // Software Keyboard Applet
+ connect(this, &GMainWindow::EmulationStarting, this, &GMainWindow::SoftwareKeyboardExit);
+ connect(this, &GMainWindow::EmulationStopping, this, &GMainWindow::SoftwareKeyboardExit);
+
connect(&status_bar_update_timer, &QTimer::timeout, this, &GMainWindow::UpdateStatusBar);
}