diff options
| author | 2021-01-30 14:38:00 -0500 | |
|---|---|---|
| committer | 2021-04-15 01:53:16 -0400 | |
| commit | 0f40c8c6340aa858cd2e2ffe2e6c54885e0a3649 (patch) | |
| tree | 64577d64b355f354ab35e058b077f17be358f303 /src/core | |
| parent | Merge pull request #6199 from lioncash/log-ns (diff) | |
| download | yuzu-0f40c8c6340aa858cd2e2ffe2e6c54885e0a3649.tar.gz yuzu-0f40c8c6340aa858cd2e2ffe2e6c54885e0a3649.tar.xz yuzu-0f40c8c6340aa858cd2e2ffe2e6c54885e0a3649.zip | |
applets: Remove the previous software keyboard applet implementation
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/frontend/applets/software_keyboard.cpp | 20 | ||||
| -rw-r--r-- | src/core/frontend/applets/software_keyboard.h | 34 | ||||
| -rw-r--r-- | src/core/hle/service/am/applets/software_keyboard.cpp | 182 | ||||
| -rw-r--r-- | src/core/hle/service/am/applets/software_keyboard.h | 51 |
4 files changed, 7 insertions, 280 deletions
diff --git a/src/core/frontend/applets/software_keyboard.cpp b/src/core/frontend/applets/software_keyboard.cpp index 856ed33da..73e7a89b9 100644 --- a/src/core/frontend/applets/software_keyboard.cpp +++ b/src/core/frontend/applets/software_keyboard.cpp | |||
| @@ -2,28 +2,10 @@ | |||
| 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 "common/logging/backend.h" | ||
| 6 | #include "common/string_util.h" | ||
| 7 | #include "core/frontend/applets/software_keyboard.h" | 5 | #include "core/frontend/applets/software_keyboard.h" |
| 8 | 6 | ||
| 9 | namespace Core::Frontend { | 7 | namespace Core::Frontend { |
| 10 | SoftwareKeyboardApplet::~SoftwareKeyboardApplet() = default; | ||
| 11 | |||
| 12 | void DefaultSoftwareKeyboardApplet::RequestText( | ||
| 13 | std::function<void(std::optional<std::u16string>)> out, | ||
| 14 | SoftwareKeyboardParameters parameters) const { | ||
| 15 | if (parameters.initial_text.empty()) | ||
| 16 | out(u"yuzu"); | ||
| 17 | 8 | ||
| 18 | out(parameters.initial_text); | 9 | SoftwareKeyboardApplet::~SoftwareKeyboardApplet() = default; |
| 19 | } | ||
| 20 | 10 | ||
| 21 | void DefaultSoftwareKeyboardApplet::SendTextCheckDialog( | ||
| 22 | std::u16string error_message, std::function<void()> finished_check) const { | ||
| 23 | LOG_WARNING(Service_AM, | ||
| 24 | "(STUBBED) called - Default fallback software keyboard does not support text " | ||
| 25 | "check! (error_message={})", | ||
| 26 | Common::UTF16ToUTF8(error_message)); | ||
| 27 | finished_check(); | ||
| 28 | } | ||
| 29 | } // namespace Core::Frontend | 11 | } // namespace Core::Frontend |
diff --git a/src/core/frontend/applets/software_keyboard.h b/src/core/frontend/applets/software_keyboard.h index f9b202664..54528837e 100644 --- a/src/core/frontend/applets/software_keyboard.h +++ b/src/core/frontend/applets/software_keyboard.h | |||
| @@ -4,51 +4,17 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <functional> | ||
| 8 | #include <optional> | ||
| 9 | #include <string> | ||
| 10 | #include "common/bit_field.h" | ||
| 11 | #include "common/common_types.h" | 7 | #include "common/common_types.h" |
| 12 | 8 | ||
| 13 | namespace Core::Frontend { | 9 | namespace Core::Frontend { |
| 14 | struct SoftwareKeyboardParameters { | ||
| 15 | std::u16string submit_text; | ||
| 16 | std::u16string header_text; | ||
| 17 | std::u16string sub_text; | ||
| 18 | std::u16string guide_text; | ||
| 19 | std::u16string initial_text; | ||
| 20 | std::size_t max_length; | ||
| 21 | bool password; | ||
| 22 | bool cursor_at_beginning; | ||
| 23 | |||
| 24 | union { | ||
| 25 | u8 value; | ||
| 26 | |||
| 27 | BitField<1, 1, u8> disable_space; | ||
| 28 | BitField<2, 1, u8> disable_address; | ||
| 29 | BitField<3, 1, u8> disable_percent; | ||
| 30 | BitField<4, 1, u8> disable_slash; | ||
| 31 | BitField<6, 1, u8> disable_number; | ||
| 32 | BitField<7, 1, u8> disable_download_code; | ||
| 33 | }; | ||
| 34 | }; | ||
| 35 | 10 | ||
| 36 | class SoftwareKeyboardApplet { | 11 | class SoftwareKeyboardApplet { |
| 37 | public: | 12 | public: |
| 38 | virtual ~SoftwareKeyboardApplet(); | 13 | virtual ~SoftwareKeyboardApplet(); |
| 39 | |||
| 40 | virtual void RequestText(std::function<void(std::optional<std::u16string>)> out, | ||
| 41 | SoftwareKeyboardParameters parameters) const = 0; | ||
| 42 | virtual void SendTextCheckDialog(std::u16string error_message, | ||
| 43 | std::function<void()> finished_check) const = 0; | ||
| 44 | }; | 14 | }; |
| 45 | 15 | ||
| 46 | class DefaultSoftwareKeyboardApplet final : public SoftwareKeyboardApplet { | 16 | class DefaultSoftwareKeyboardApplet final : public SoftwareKeyboardApplet { |
| 47 | public: | 17 | public: |
| 48 | void RequestText(std::function<void(std::optional<std::u16string>)> out, | ||
| 49 | SoftwareKeyboardParameters parameters) const override; | ||
| 50 | void SendTextCheckDialog(std::u16string error_message, | ||
| 51 | std::function<void()> finished_check) const override; | ||
| 52 | }; | 18 | }; |
| 53 | 19 | ||
| 54 | } // namespace Core::Frontend | 20 | } // namespace Core::Frontend |
diff --git a/src/core/hle/service/am/applets/software_keyboard.cpp b/src/core/hle/service/am/applets/software_keyboard.cpp index 79b209c6b..f966cf67b 100644 --- a/src/core/hle/service/am/applets/software_keyboard.cpp +++ b/src/core/hle/service/am/applets/software_keyboard.cpp | |||
| @@ -2,199 +2,27 @@ | |||
| 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 <cstring> | ||
| 6 | #include "common/assert.h" | ||
| 7 | #include "common/string_util.h" | ||
| 8 | #include "core/core.h" | 5 | #include "core/core.h" |
| 9 | #include "core/frontend/applets/software_keyboard.h" | 6 | #include "core/frontend/applets/software_keyboard.h" |
| 10 | #include "core/hle/result.h" | ||
| 11 | #include "core/hle/service/am/am.h" | 7 | #include "core/hle/service/am/am.h" |
| 12 | #include "core/hle/service/am/applets/software_keyboard.h" | 8 | #include "core/hle/service/am/applets/software_keyboard.h" |
| 13 | 9 | ||
| 14 | namespace Service::AM::Applets { | 10 | namespace Service::AM::Applets { |
| 15 | 11 | ||
| 16 | namespace { | ||
| 17 | enum class Request : u32 { | ||
| 18 | Finalize = 0x4, | ||
| 19 | SetUserWordInfo = 0x6, | ||
| 20 | SetCustomizeDic = 0x7, | ||
| 21 | Calc = 0xa, | ||
| 22 | SetCustomizedDictionaries = 0xb, | ||
| 23 | UnsetCustomizedDictionaries = 0xc, | ||
| 24 | UnknownD = 0xd, | ||
| 25 | UnknownE = 0xe, | ||
| 26 | }; | ||
| 27 | constexpr std::size_t SWKBD_INLINE_INIT_SIZE = 0x8; | ||
| 28 | constexpr std::size_t SWKBD_OUTPUT_BUFFER_SIZE = 0x7D8; | ||
| 29 | constexpr std::size_t SWKBD_OUTPUT_INTERACTIVE_BUFFER_SIZE = 0x7D4; | ||
| 30 | constexpr std::size_t DEFAULT_MAX_LENGTH = 500; | ||
| 31 | constexpr bool INTERACTIVE_STATUS_OK = false; | ||
| 32 | } // Anonymous namespace | ||
| 33 | static Core::Frontend::SoftwareKeyboardParameters ConvertToFrontendParameters( | ||
| 34 | KeyboardConfig config, std::u16string initial_text) { | ||
| 35 | Core::Frontend::SoftwareKeyboardParameters params{}; | ||
| 36 | |||
| 37 | params.submit_text = Common::UTF16StringFromFixedZeroTerminatedBuffer( | ||
| 38 | config.submit_text.data(), config.submit_text.size()); | ||
| 39 | params.header_text = Common::UTF16StringFromFixedZeroTerminatedBuffer( | ||
| 40 | config.header_text.data(), config.header_text.size()); | ||
| 41 | params.sub_text = Common::UTF16StringFromFixedZeroTerminatedBuffer(config.sub_text.data(), | ||
| 42 | config.sub_text.size()); | ||
| 43 | params.guide_text = Common::UTF16StringFromFixedZeroTerminatedBuffer(config.guide_text.data(), | ||
| 44 | config.guide_text.size()); | ||
| 45 | params.initial_text = std::move(initial_text); | ||
| 46 | params.max_length = config.length_limit == 0 ? DEFAULT_MAX_LENGTH : config.length_limit; | ||
| 47 | params.password = static_cast<bool>(config.is_password); | ||
| 48 | params.cursor_at_beginning = static_cast<bool>(config.initial_cursor_position); | ||
| 49 | params.value = static_cast<u8>(config.keyset_disable_bitmask); | ||
| 50 | |||
| 51 | return params; | ||
| 52 | } | ||
| 53 | |||
| 54 | SoftwareKeyboard::SoftwareKeyboard(Core::System& system_, | 12 | SoftwareKeyboard::SoftwareKeyboard(Core::System& system_, |
| 55 | const Core::Frontend::SoftwareKeyboardApplet& frontend_) | 13 | const Core::Frontend::SoftwareKeyboardApplet& frontend_) |
| 56 | : Applet{system_.Kernel()}, frontend{frontend_}, system{system_} {} | 14 | : Applet{system_.Kernel()}, frontend{frontend_}, system{system_} {} |
| 57 | 15 | ||
| 58 | SoftwareKeyboard::~SoftwareKeyboard() = default; | 16 | SoftwareKeyboard::~SoftwareKeyboard() = default; |
| 59 | 17 | ||
| 60 | void SoftwareKeyboard::Initialize() { | 18 | void SoftwareKeyboard::Initialize() {} |
| 61 | complete = false; | ||
| 62 | is_inline = false; | ||
| 63 | initial_text.clear(); | ||
| 64 | final_data.clear(); | ||
| 65 | |||
| 66 | Applet::Initialize(); | ||
| 67 | |||
| 68 | const auto keyboard_config_storage = broker.PopNormalDataToApplet(); | ||
| 69 | ASSERT(keyboard_config_storage != nullptr); | ||
| 70 | const auto& keyboard_config = keyboard_config_storage->GetData(); | ||
| 71 | |||
| 72 | if (keyboard_config.size() == SWKBD_INLINE_INIT_SIZE) { | ||
| 73 | is_inline = true; | ||
| 74 | return; | ||
| 75 | } | ||
| 76 | |||
| 77 | ASSERT(keyboard_config.size() >= sizeof(KeyboardConfig)); | ||
| 78 | std::memcpy(&config, keyboard_config.data(), sizeof(KeyboardConfig)); | ||
| 79 | |||
| 80 | const auto work_buffer_storage = broker.PopNormalDataToApplet(); | ||
| 81 | ASSERT_OR_EXECUTE(work_buffer_storage != nullptr, { return; }); | ||
| 82 | const auto& work_buffer = work_buffer_storage->GetData(); | ||
| 83 | |||
| 84 | if (config.initial_string_size == 0) | ||
| 85 | return; | ||
| 86 | |||
| 87 | std::vector<char16_t> string(config.initial_string_size); | ||
| 88 | std::memcpy(string.data(), work_buffer.data() + config.initial_string_offset, | ||
| 89 | string.size() * 2); | ||
| 90 | initial_text = Common::UTF16StringFromFixedZeroTerminatedBuffer(string.data(), string.size()); | ||
| 91 | } | ||
| 92 | |||
| 93 | bool SoftwareKeyboard::TransactionComplete() const { | ||
| 94 | return complete; | ||
| 95 | } | ||
| 96 | |||
| 97 | ResultCode SoftwareKeyboard::GetStatus() const { | ||
| 98 | return RESULT_SUCCESS; | ||
| 99 | } | ||
| 100 | |||
| 101 | void SoftwareKeyboard::ExecuteInteractive() { | ||
| 102 | if (complete) | ||
| 103 | return; | ||
| 104 | |||
| 105 | const auto storage = broker.PopInteractiveDataToApplet(); | ||
| 106 | ASSERT(storage != nullptr); | ||
| 107 | const auto data = storage->GetData(); | ||
| 108 | if (!is_inline) { | ||
| 109 | const auto status = static_cast<bool>(data[0]); | ||
| 110 | if (status == INTERACTIVE_STATUS_OK) { | ||
| 111 | complete = true; | ||
| 112 | } else { | ||
| 113 | std::array<char16_t, SWKBD_OUTPUT_INTERACTIVE_BUFFER_SIZE / 2 - 2> string; | ||
| 114 | std::memcpy(string.data(), data.data() + 4, string.size() * 2); | ||
| 115 | frontend.SendTextCheckDialog( | ||
| 116 | Common::UTF16StringFromFixedZeroTerminatedBuffer(string.data(), string.size()), | ||
| 117 | [this] { broker.SignalStateChanged(); }); | ||
| 118 | } | ||
| 119 | } else { | ||
| 120 | Request request{}; | ||
| 121 | std::memcpy(&request, data.data(), sizeof(Request)); | ||
| 122 | |||
| 123 | switch (request) { | ||
| 124 | case Request::Finalize: | ||
| 125 | complete = true; | ||
| 126 | broker.SignalStateChanged(); | ||
| 127 | break; | ||
| 128 | case Request::Calc: { | ||
| 129 | broker.PushNormalDataFromApplet(std::make_shared<IStorage>(system, std::vector<u8>{1})); | ||
| 130 | broker.SignalStateChanged(); | ||
| 131 | break; | ||
| 132 | } | ||
| 133 | default: | ||
| 134 | UNIMPLEMENTED_MSG("Request {:X} is not implemented", request); | ||
| 135 | break; | ||
| 136 | } | ||
| 137 | } | ||
| 138 | } | ||
| 139 | |||
| 140 | void SoftwareKeyboard::Execute() { | ||
| 141 | if (complete) { | ||
| 142 | broker.PushNormalDataFromApplet(std::make_shared<IStorage>(system, std::move(final_data))); | ||
| 143 | broker.SignalStateChanged(); | ||
| 144 | return; | ||
| 145 | } | ||
| 146 | |||
| 147 | const auto parameters = ConvertToFrontendParameters(config, initial_text); | ||
| 148 | if (!is_inline) { | ||
| 149 | frontend.RequestText( | ||
| 150 | [this](std::optional<std::u16string> text) { WriteText(std::move(text)); }, parameters); | ||
| 151 | } | ||
| 152 | } | ||
| 153 | |||
| 154 | void SoftwareKeyboard::WriteText(std::optional<std::u16string> text) { | ||
| 155 | std::vector<u8> output_main(SWKBD_OUTPUT_BUFFER_SIZE); | ||
| 156 | |||
| 157 | if (text.has_value()) { | ||
| 158 | std::vector<u8> output_sub(SWKBD_OUTPUT_BUFFER_SIZE); | ||
| 159 | |||
| 160 | if (config.utf_8) { | ||
| 161 | const u64 size = text->size() + sizeof(u64); | ||
| 162 | const auto new_text = Common::UTF16ToUTF8(*text); | ||
| 163 | 19 | ||
| 164 | std::memcpy(output_sub.data(), &size, sizeof(u64)); | 20 | bool SoftwareKeyboard::TransactionComplete() const {} |
| 165 | std::memcpy(output_sub.data() + 8, new_text.data(), | ||
| 166 | std::min(new_text.size(), SWKBD_OUTPUT_BUFFER_SIZE - 8)); | ||
| 167 | 21 | ||
| 168 | output_main[0] = INTERACTIVE_STATUS_OK; | 22 | ResultCode SoftwareKeyboard::GetStatus() const {} |
| 169 | std::memcpy(output_main.data() + 4, new_text.data(), | ||
| 170 | std::min(new_text.size(), SWKBD_OUTPUT_BUFFER_SIZE - 4)); | ||
| 171 | } else { | ||
| 172 | const u64 size = text->size() * 2 + sizeof(u64); | ||
| 173 | std::memcpy(output_sub.data(), &size, sizeof(u64)); | ||
| 174 | std::memcpy(output_sub.data() + 8, text->data(), | ||
| 175 | std::min(text->size() * 2, SWKBD_OUTPUT_BUFFER_SIZE - 8)); | ||
| 176 | 23 | ||
| 177 | output_main[0] = INTERACTIVE_STATUS_OK; | 24 | void SoftwareKeyboard::ExecuteInteractive() {} |
| 178 | std::memcpy(output_main.data() + 4, text->data(), | ||
| 179 | std::min(text->size() * 2, SWKBD_OUTPUT_BUFFER_SIZE - 4)); | ||
| 180 | } | ||
| 181 | 25 | ||
| 182 | complete = !config.text_check; | 26 | void SoftwareKeyboard::Execute() {} |
| 183 | final_data = output_main; | ||
| 184 | 27 | ||
| 185 | if (complete) { | ||
| 186 | broker.PushNormalDataFromApplet( | ||
| 187 | std::make_shared<IStorage>(system, std::move(output_main))); | ||
| 188 | broker.SignalStateChanged(); | ||
| 189 | } else { | ||
| 190 | broker.PushInteractiveDataFromApplet( | ||
| 191 | std::make_shared<IStorage>(system, std::move(output_sub))); | ||
| 192 | } | ||
| 193 | } else { | ||
| 194 | output_main[0] = 1; | ||
| 195 | complete = true; | ||
| 196 | broker.PushNormalDataFromApplet(std::make_shared<IStorage>(system, std::move(output_main))); | ||
| 197 | broker.SignalStateChanged(); | ||
| 198 | } | ||
| 199 | } | ||
| 200 | } // namespace Service::AM::Applets | 28 | } // namespace Service::AM::Applets |
diff --git a/src/core/hle/service/am/applets/software_keyboard.h b/src/core/hle/service/am/applets/software_keyboard.h index 1d260fef8..c161ec9ac 100644 --- a/src/core/hle/service/am/applets/software_keyboard.h +++ b/src/core/hle/service/am/applets/software_keyboard.h | |||
| @@ -4,59 +4,17 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <array> | ||
| 8 | #include <string> | ||
| 9 | #include <vector> | ||
| 10 | |||
| 11 | #include "common/common_funcs.h" | 7 | #include "common/common_funcs.h" |
| 12 | #include "common/common_types.h" | 8 | #include "common/common_types.h" |
| 13 | #include "common/swap.h" | 9 | #include "core/hle/result.h" |
| 14 | #include "core/hle/service/am/am.h" | ||
| 15 | #include "core/hle/service/am/applets/applets.h" | 10 | #include "core/hle/service/am/applets/applets.h" |
| 16 | 11 | ||
| 17 | union ResultCode; | ||
| 18 | |||
| 19 | namespace Core { | 12 | namespace Core { |
| 20 | class System; | 13 | class System; |
| 21 | } | 14 | } |
| 22 | 15 | ||
| 23 | namespace Service::AM::Applets { | 16 | namespace Service::AM::Applets { |
| 24 | 17 | ||
| 25 | enum class KeysetDisable : u32 { | ||
| 26 | Space = 0x02, | ||
| 27 | Address = 0x04, | ||
| 28 | Percent = 0x08, | ||
| 29 | Slashes = 0x10, | ||
| 30 | Numbers = 0x40, | ||
| 31 | DownloadCode = 0x80, | ||
| 32 | }; | ||
| 33 | |||
| 34 | struct KeyboardConfig { | ||
| 35 | INSERT_PADDING_BYTES(4); | ||
| 36 | std::array<char16_t, 9> submit_text; | ||
| 37 | u16_le left_symbol_key; | ||
| 38 | u16_le right_symbol_key; | ||
| 39 | INSERT_PADDING_BYTES(1); | ||
| 40 | KeysetDisable keyset_disable_bitmask; | ||
| 41 | u32_le initial_cursor_position; | ||
| 42 | std::array<char16_t, 65> header_text; | ||
| 43 | std::array<char16_t, 129> sub_text; | ||
| 44 | std::array<char16_t, 257> guide_text; | ||
| 45 | u32_le length_limit; | ||
| 46 | INSERT_PADDING_BYTES(4); | ||
| 47 | u32_le is_password; | ||
| 48 | INSERT_PADDING_BYTES(5); | ||
| 49 | bool utf_8; | ||
| 50 | bool draw_background; | ||
| 51 | u32_le initial_string_offset; | ||
| 52 | u32_le initial_string_size; | ||
| 53 | u32_le user_dictionary_offset; | ||
| 54 | u32_le user_dictionary_size; | ||
| 55 | bool text_check; | ||
| 56 | u64_le text_check_callback; | ||
| 57 | }; | ||
| 58 | static_assert(sizeof(KeyboardConfig) == 0x3E0, "KeyboardConfig has incorrect size."); | ||
| 59 | |||
| 60 | class SoftwareKeyboard final : public Applet { | 18 | class SoftwareKeyboard final : public Applet { |
| 61 | public: | 19 | public: |
| 62 | explicit SoftwareKeyboard(Core::System& system_, | 20 | explicit SoftwareKeyboard(Core::System& system_, |
| @@ -70,16 +28,9 @@ public: | |||
| 70 | void ExecuteInteractive() override; | 28 | void ExecuteInteractive() override; |
| 71 | void Execute() override; | 29 | void Execute() override; |
| 72 | 30 | ||
| 73 | void WriteText(std::optional<std::u16string> text); | ||
| 74 | |||
| 75 | private: | 31 | private: |
| 76 | const Core::Frontend::SoftwareKeyboardApplet& frontend; | 32 | const Core::Frontend::SoftwareKeyboardApplet& frontend; |
| 77 | 33 | ||
| 78 | KeyboardConfig config; | ||
| 79 | std::u16string initial_text; | ||
| 80 | bool complete = false; | ||
| 81 | bool is_inline = false; | ||
| 82 | std::vector<u8> final_data; | ||
| 83 | Core::System& system; | 34 | Core::System& system; |
| 84 | }; | 35 | }; |
| 85 | 36 | ||