diff options
| author | 2021-03-16 13:01:03 -0400 | |
|---|---|---|
| committer | 2021-04-15 01:53:17 -0400 | |
| commit | 578e6c5a57bc29aed27e604ac0ede34f87bae86d (patch) | |
| tree | 7b2ec7df82c7bc93f5b058486b6fd1a567838a3c | |
| parent | applets/swkbd: Implement the Normal and Inline Software Keyboard Applet (diff) | |
| download | yuzu-578e6c5a57bc29aed27e604ac0ede34f87bae86d.tar.gz yuzu-578e6c5a57bc29aed27e604ac0ede34f87bae86d.tar.xz yuzu-578e6c5a57bc29aed27e604ac0ede34f87bae86d.zip | |
applets/swkbd: Implement the Default Software Keyboard frontend
| -rw-r--r-- | src/core/frontend/applets/software_keyboard.cpp | 140 | ||||
| -rw-r--r-- | src/core/frontend/applets/software_keyboard.h | 98 |
2 files changed, 236 insertions, 2 deletions
diff --git a/src/core/frontend/applets/software_keyboard.cpp b/src/core/frontend/applets/software_keyboard.cpp index 73e7a89b9..12c76c9ee 100644 --- a/src/core/frontend/applets/software_keyboard.cpp +++ b/src/core/frontend/applets/software_keyboard.cpp | |||
| @@ -1,11 +1,149 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | 1 | // Copyright 2021 yuzu Emulator Project |
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <thread> | ||
| 6 | |||
| 7 | #include "common/logging/log.h" | ||
| 8 | #include "common/string_util.h" | ||
| 5 | #include "core/frontend/applets/software_keyboard.h" | 9 | #include "core/frontend/applets/software_keyboard.h" |
| 6 | 10 | ||
| 7 | namespace Core::Frontend { | 11 | namespace Core::Frontend { |
| 8 | 12 | ||
| 9 | SoftwareKeyboardApplet::~SoftwareKeyboardApplet() = default; | 13 | SoftwareKeyboardApplet::~SoftwareKeyboardApplet() = default; |
| 10 | 14 | ||
| 15 | DefaultSoftwareKeyboardApplet::~DefaultSoftwareKeyboardApplet() = default; | ||
| 16 | |||
| 17 | void DefaultSoftwareKeyboardApplet::InitializeKeyboard( | ||
| 18 | bool is_inline, KeyboardInitializeParameters initialize_parameters, | ||
| 19 | std::function<void(Service::AM::Applets::SwkbdResult, std::u16string)> submit_normal_callback_, | ||
| 20 | std::function<void(Service::AM::Applets::SwkbdReplyType, std::u16string, s32)> | ||
| 21 | submit_inline_callback_) { | ||
| 22 | if (is_inline) { | ||
| 23 | LOG_WARNING( | ||
| 24 | Service_AM, | ||
| 25 | "(STUBBED) called, backend requested to initialize the inline software keyboard."); | ||
| 26 | |||
| 27 | submit_inline_callback = std::move(submit_inline_callback_); | ||
| 28 | } else { | ||
| 29 | LOG_WARNING( | ||
| 30 | Service_AM, | ||
| 31 | "(STUBBED) called, backend requested to initialize the normal software keyboard."); | ||
| 32 | |||
| 33 | submit_normal_callback = std::move(submit_normal_callback_); | ||
| 34 | } | ||
| 35 | |||
| 36 | parameters = std::move(initialize_parameters); | ||
| 37 | |||
| 38 | LOG_INFO(Service_AM, | ||
| 39 | "\nKeyboardInitializeParameters:" | ||
| 40 | "\nok_text={}" | ||
| 41 | "\nheader_text={}" | ||
| 42 | "\nsub_text={}" | ||
| 43 | "\nguide_text={}" | ||
| 44 | "\ninitial_text={}" | ||
| 45 | "\nmax_text_length={}" | ||
| 46 | "\nmin_text_length={}" | ||
| 47 | "\ninitial_cursor_position={}" | ||
| 48 | "\ntype={}" | ||
| 49 | "\npassword_mode={}" | ||
| 50 | "\ntext_draw_type={}" | ||
| 51 | "\nkey_disable_flags={}" | ||
| 52 | "\nuse_blur_background={}" | ||
| 53 | "\nenable_backspace_button={}" | ||
| 54 | "\nenable_return_button={}" | ||
| 55 | "\ndisable_cancel_button={}", | ||
| 56 | Common::UTF16ToUTF8(parameters.ok_text), Common::UTF16ToUTF8(parameters.header_text), | ||
| 57 | Common::UTF16ToUTF8(parameters.sub_text), Common::UTF16ToUTF8(parameters.guide_text), | ||
| 58 | Common::UTF16ToUTF8(parameters.initial_text), parameters.max_text_length, | ||
| 59 | parameters.min_text_length, parameters.initial_cursor_position, parameters.type, | ||
| 60 | parameters.password_mode, parameters.text_draw_type, parameters.key_disable_flags.raw, | ||
| 61 | parameters.use_blur_background, parameters.enable_backspace_button, | ||
| 62 | parameters.enable_return_button, parameters.disable_cancel_button); | ||
| 63 | } | ||
| 64 | |||
| 65 | void DefaultSoftwareKeyboardApplet::ShowNormalKeyboard() const { | ||
| 66 | LOG_WARNING(Service_AM, | ||
| 67 | "(STUBBED) called, backend requested to show the normal software keyboard."); | ||
| 68 | |||
| 69 | SubmitNormalText(u"yuzu"); | ||
| 70 | } | ||
| 71 | |||
| 72 | void DefaultSoftwareKeyboardApplet::ShowTextCheckDialog( | ||
| 73 | Service::AM::Applets::SwkbdTextCheckResult text_check_result, | ||
| 74 | std::u16string text_check_message) const { | ||
| 75 | LOG_WARNING(Service_AM, "(STUBBED) called, backend requested to show the text check dialog."); | ||
| 76 | } | ||
| 77 | |||
| 78 | void DefaultSoftwareKeyboardApplet::ShowInlineKeyboard( | ||
| 79 | InlineAppearParameters appear_parameters) const { | ||
| 80 | LOG_WARNING(Service_AM, | ||
| 81 | "(STUBBED) called, backend requested to show the inline software keyboard."); | ||
| 82 | |||
| 83 | LOG_INFO(Service_AM, | ||
| 84 | "\nInlineAppearParameters:" | ||
| 85 | "\nmax_text_length={}" | ||
| 86 | "\nmin_text_length={}" | ||
| 87 | "\nkey_top_scale_x={}" | ||
| 88 | "\nkey_top_scale_y={}" | ||
| 89 | "\nkey_top_translate_x={}" | ||
| 90 | "\nkey_top_translate_y={}" | ||
| 91 | "\ntype={}" | ||
| 92 | "\nkey_disable_flags={}" | ||
| 93 | "\nkey_top_as_floating={}" | ||
| 94 | "\nenable_backspace_button={}" | ||
| 95 | "\nenable_return_button={}" | ||
| 96 | "\ndisable_cancel_button={}", | ||
| 97 | appear_parameters.max_text_length, appear_parameters.min_text_length, | ||
| 98 | appear_parameters.key_top_scale_x, appear_parameters.key_top_scale_y, | ||
| 99 | appear_parameters.key_top_translate_x, appear_parameters.key_top_translate_y, | ||
| 100 | appear_parameters.type, appear_parameters.key_disable_flags.raw, | ||
| 101 | appear_parameters.key_top_as_floating, appear_parameters.enable_backspace_button, | ||
| 102 | appear_parameters.enable_return_button, appear_parameters.disable_cancel_button); | ||
| 103 | |||
| 104 | std::thread([this] { SubmitInlineText(u"yuzu"); }).detach(); | ||
| 105 | } | ||
| 106 | |||
| 107 | void DefaultSoftwareKeyboardApplet::HideInlineKeyboard() const { | ||
| 108 | LOG_WARNING(Service_AM, | ||
| 109 | "(STUBBED) called, backend requested to hide the inline software keyboard."); | ||
| 110 | } | ||
| 111 | |||
| 112 | void DefaultSoftwareKeyboardApplet::InlineTextChanged(InlineTextParameters text_parameters) const { | ||
| 113 | LOG_WARNING(Service_AM, | ||
| 114 | "(STUBBED) called, backend requested to change the inline keyboard text."); | ||
| 115 | |||
| 116 | LOG_INFO(Service_AM, | ||
| 117 | "\nInlineTextParameters:" | ||
| 118 | "\ninput_text={}" | ||
| 119 | "\ncursor_position={}", | ||
| 120 | Common::UTF16ToUTF8(text_parameters.input_text), text_parameters.cursor_position); | ||
| 121 | |||
| 122 | submit_inline_callback(Service::AM::Applets::SwkbdReplyType::ChangedString, | ||
| 123 | text_parameters.input_text, text_parameters.cursor_position); | ||
| 124 | } | ||
| 125 | |||
| 126 | void DefaultSoftwareKeyboardApplet::ExitKeyboard() const { | ||
| 127 | LOG_WARNING(Service_AM, "(STUBBED) called, backend requested to exit the software keyboard."); | ||
| 128 | } | ||
| 129 | |||
| 130 | void DefaultSoftwareKeyboardApplet::SubmitNormalText(std::u16string text) const { | ||
| 131 | submit_normal_callback(Service::AM::Applets::SwkbdResult::Ok, text); | ||
| 132 | } | ||
| 133 | |||
| 134 | void DefaultSoftwareKeyboardApplet::SubmitInlineText(std::u16string_view text) const { | ||
| 135 | std::this_thread::sleep_for(std::chrono::milliseconds(500)); | ||
| 136 | |||
| 137 | for (std::size_t index = 0; index < text.size(); ++index) { | ||
| 138 | submit_inline_callback(Service::AM::Applets::SwkbdReplyType::ChangedString, | ||
| 139 | std::u16string(text.data(), text.data() + index + 1), | ||
| 140 | static_cast<s32>(index) + 1); | ||
| 141 | |||
| 142 | std::this_thread::sleep_for(std::chrono::milliseconds(250)); | ||
| 143 | } | ||
| 144 | |||
| 145 | submit_inline_callback(Service::AM::Applets::SwkbdReplyType::DecidedEnter, std::u16string(text), | ||
| 146 | static_cast<s32>(text.size())); | ||
| 147 | } | ||
| 148 | |||
| 11 | } // namespace Core::Frontend | 149 | } // namespace Core::Frontend |
diff --git a/src/core/frontend/applets/software_keyboard.h b/src/core/frontend/applets/software_keyboard.h index 54528837e..506eb35bb 100644 --- a/src/core/frontend/applets/software_keyboard.h +++ b/src/core/frontend/applets/software_keyboard.h | |||
| @@ -1,20 +1,116 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | 1 | // Copyright 2021 yuzu Emulator Project |
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <functional> | ||
| 8 | #include <thread> | ||
| 9 | |||
| 7 | #include "common/common_types.h" | 10 | #include "common/common_types.h" |
| 8 | 11 | ||
| 12 | #include "core/hle/service/am/applets/software_keyboard_types.h" | ||
| 13 | |||
| 9 | namespace Core::Frontend { | 14 | namespace Core::Frontend { |
| 10 | 15 | ||
| 16 | struct KeyboardInitializeParameters { | ||
| 17 | std::u16string ok_text; | ||
| 18 | std::u16string header_text; | ||
| 19 | std::u16string sub_text; | ||
| 20 | std::u16string guide_text; | ||
| 21 | std::u16string initial_text; | ||
| 22 | u32 max_text_length; | ||
| 23 | u32 min_text_length; | ||
| 24 | s32 initial_cursor_position; | ||
| 25 | Service::AM::Applets::SwkbdType type; | ||
| 26 | Service::AM::Applets::SwkbdPasswordMode password_mode; | ||
| 27 | Service::AM::Applets::SwkbdTextDrawType text_draw_type; | ||
| 28 | Service::AM::Applets::SwkbdKeyDisableFlags key_disable_flags; | ||
| 29 | bool use_blur_background; | ||
| 30 | bool enable_backspace_button; | ||
| 31 | bool enable_return_button; | ||
| 32 | bool disable_cancel_button; | ||
| 33 | }; | ||
| 34 | |||
| 35 | struct InlineAppearParameters { | ||
| 36 | u32 max_text_length; | ||
| 37 | u32 min_text_length; | ||
| 38 | f32 key_top_scale_x; | ||
| 39 | f32 key_top_scale_y; | ||
| 40 | f32 key_top_translate_x; | ||
| 41 | f32 key_top_translate_y; | ||
| 42 | Service::AM::Applets::SwkbdType type; | ||
| 43 | Service::AM::Applets::SwkbdKeyDisableFlags key_disable_flags; | ||
| 44 | bool key_top_as_floating; | ||
| 45 | bool enable_backspace_button; | ||
| 46 | bool enable_return_button; | ||
| 47 | bool disable_cancel_button; | ||
| 48 | }; | ||
| 49 | |||
| 50 | struct InlineTextParameters { | ||
| 51 | std::u16string input_text; | ||
| 52 | s32 cursor_position; | ||
| 53 | }; | ||
| 54 | |||
| 11 | class SoftwareKeyboardApplet { | 55 | class SoftwareKeyboardApplet { |
| 12 | public: | 56 | public: |
| 13 | virtual ~SoftwareKeyboardApplet(); | 57 | virtual ~SoftwareKeyboardApplet(); |
| 58 | |||
| 59 | virtual void InitializeKeyboard( | ||
| 60 | bool is_inline, KeyboardInitializeParameters initialize_parameters, | ||
| 61 | std::function<void(Service::AM::Applets::SwkbdResult, std::u16string)> | ||
| 62 | submit_normal_callback_, | ||
| 63 | std::function<void(Service::AM::Applets::SwkbdReplyType, std::u16string, s32)> | ||
| 64 | submit_inline_callback_) = 0; | ||
| 65 | |||
| 66 | virtual void ShowNormalKeyboard() const = 0; | ||
| 67 | |||
| 68 | virtual void ShowTextCheckDialog(Service::AM::Applets::SwkbdTextCheckResult text_check_result, | ||
| 69 | std::u16string text_check_message) const = 0; | ||
| 70 | |||
| 71 | virtual void ShowInlineKeyboard(InlineAppearParameters appear_parameters) const = 0; | ||
| 72 | |||
| 73 | virtual void HideInlineKeyboard() const = 0; | ||
| 74 | |||
| 75 | virtual void InlineTextChanged(InlineTextParameters text_parameters) const = 0; | ||
| 76 | |||
| 77 | virtual void ExitKeyboard() const = 0; | ||
| 14 | }; | 78 | }; |
| 15 | 79 | ||
| 16 | class DefaultSoftwareKeyboardApplet final : public SoftwareKeyboardApplet { | 80 | class DefaultSoftwareKeyboardApplet final : public SoftwareKeyboardApplet { |
| 17 | public: | 81 | public: |
| 82 | ~DefaultSoftwareKeyboardApplet() override; | ||
| 83 | |||
| 84 | void InitializeKeyboard( | ||
| 85 | bool is_inline, KeyboardInitializeParameters initialize_parameters, | ||
| 86 | std::function<void(Service::AM::Applets::SwkbdResult, std::u16string)> | ||
| 87 | submit_normal_callback_, | ||
| 88 | std::function<void(Service::AM::Applets::SwkbdReplyType, std::u16string, s32)> | ||
| 89 | submit_inline_callback_) override; | ||
| 90 | |||
| 91 | void ShowNormalKeyboard() const override; | ||
| 92 | |||
| 93 | void ShowTextCheckDialog(Service::AM::Applets::SwkbdTextCheckResult text_check_result, | ||
| 94 | std::u16string text_check_message) const override; | ||
| 95 | |||
| 96 | void ShowInlineKeyboard(InlineAppearParameters appear_parameters) const override; | ||
| 97 | |||
| 98 | void HideInlineKeyboard() const override; | ||
| 99 | |||
| 100 | void InlineTextChanged(InlineTextParameters text_parameters) const override; | ||
| 101 | |||
| 102 | void ExitKeyboard() const override; | ||
| 103 | |||
| 104 | private: | ||
| 105 | void SubmitNormalText(std::u16string text) const; | ||
| 106 | void SubmitInlineText(std::u16string_view text) const; | ||
| 107 | |||
| 108 | KeyboardInitializeParameters parameters; | ||
| 109 | |||
| 110 | mutable std::function<void(Service::AM::Applets::SwkbdResult, std::u16string)> | ||
| 111 | submit_normal_callback; | ||
| 112 | mutable std::function<void(Service::AM::Applets::SwkbdReplyType, std::u16string, s32)> | ||
| 113 | submit_inline_callback; | ||
| 18 | }; | 114 | }; |
| 19 | 115 | ||
| 20 | } // namespace Core::Frontend | 116 | } // namespace Core::Frontend |