diff options
| author | 2021-04-16 23:03:23 -0700 | |
|---|---|---|
| committer | 2021-04-16 23:03:23 -0700 | |
| commit | d5c1f3929c3348691bda405dd2a4248773d02f2d (patch) | |
| tree | 271ec5aceff2eab8214a06db0f33b0afac217f86 /src/core/frontend | |
| parent | Merge pull request #6201 from bunnei/remove-bintray (diff) | |
| parent | applets/swkbd: Implement the Qt Software Keyboard frontend (diff) | |
| download | yuzu-d5c1f3929c3348691bda405dd2a4248773d02f2d.tar.gz yuzu-d5c1f3929c3348691bda405dd2a4248773d02f2d.tar.xz yuzu-d5c1f3929c3348691bda405dd2a4248773d02f2d.zip | |
Merge pull request #6133 from Morph1984/project-eleuthia
Project Eleuthia - On-Screen Keyboard and Error Applet Overlays
Diffstat (limited to 'src/core/frontend')
| -rw-r--r-- | src/core/frontend/applets/software_keyboard.cpp | 148 | ||||
| -rw-r--r-- | src/core/frontend/applets/software_keyboard.h | 118 | ||||
| -rw-r--r-- | src/core/frontend/input_interpreter.cpp | 15 | ||||
| -rw-r--r-- | src/core/frontend/input_interpreter.h | 3 |
4 files changed, 241 insertions, 43 deletions
diff --git a/src/core/frontend/applets/software_keyboard.cpp b/src/core/frontend/applets/software_keyboard.cpp index 856ed33da..12c76c9ee 100644 --- a/src/core/frontend/applets/software_keyboard.cpp +++ b/src/core/frontend/applets/software_keyboard.cpp | |||
| @@ -1,29 +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 "common/logging/backend.h" | 5 | #include <thread> |
| 6 | |||
| 7 | #include "common/logging/log.h" | ||
| 6 | #include "common/string_util.h" | 8 | #include "common/string_util.h" |
| 7 | #include "core/frontend/applets/software_keyboard.h" | 9 | #include "core/frontend/applets/software_keyboard.h" |
| 8 | 10 | ||
| 9 | namespace Core::Frontend { | 11 | namespace Core::Frontend { |
| 12 | |||
| 10 | SoftwareKeyboardApplet::~SoftwareKeyboardApplet() = default; | 13 | SoftwareKeyboardApplet::~SoftwareKeyboardApplet() = default; |
| 11 | 14 | ||
| 12 | void DefaultSoftwareKeyboardApplet::RequestText( | 15 | DefaultSoftwareKeyboardApplet::~DefaultSoftwareKeyboardApplet() = default; |
| 13 | std::function<void(std::optional<std::u16string>)> out, | 16 | |
| 14 | SoftwareKeyboardParameters parameters) const { | 17 | void DefaultSoftwareKeyboardApplet::InitializeKeyboard( |
| 15 | if (parameters.initial_text.empty()) | 18 | bool is_inline, KeyboardInitializeParameters initialize_parameters, |
| 16 | out(u"yuzu"); | 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 | } | ||
| 17 | 106 | ||
| 18 | out(parameters.initial_text); | 107 | void DefaultSoftwareKeyboardApplet::HideInlineKeyboard() const { |
| 108 | LOG_WARNING(Service_AM, | ||
| 109 | "(STUBBED) called, backend requested to hide the inline software keyboard."); | ||
| 19 | } | 110 | } |
| 20 | 111 | ||
| 21 | void DefaultSoftwareKeyboardApplet::SendTextCheckDialog( | 112 | void DefaultSoftwareKeyboardApplet::InlineTextChanged(InlineTextParameters text_parameters) const { |
| 22 | std::u16string error_message, std::function<void()> finished_check) const { | ||
| 23 | LOG_WARNING(Service_AM, | 113 | LOG_WARNING(Service_AM, |
| 24 | "(STUBBED) called - Default fallback software keyboard does not support text " | 114 | "(STUBBED) called, backend requested to change the inline keyboard text."); |
| 25 | "check! (error_message={})", | 115 | |
| 26 | Common::UTF16ToUTF8(error_message)); | 116 | LOG_INFO(Service_AM, |
| 27 | finished_check(); | 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."); | ||
| 28 | } | 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 | |||
| 29 | } // 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 f9b202664..506eb35bb 100644 --- a/src/core/frontend/applets/software_keyboard.h +++ b/src/core/frontend/applets/software_keyboard.h | |||
| @@ -1,54 +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> | 7 | #include <functional> |
| 8 | #include <optional> | 8 | #include <thread> |
| 9 | #include <string> | 9 | |
| 10 | #include "common/bit_field.h" | ||
| 11 | #include "common/common_types.h" | 10 | #include "common/common_types.h" |
| 12 | 11 | ||
| 12 | #include "core/hle/service/am/applets/software_keyboard_types.h" | ||
| 13 | |||
| 13 | namespace Core::Frontend { | 14 | namespace Core::Frontend { |
| 14 | struct SoftwareKeyboardParameters { | 15 | |
| 15 | std::u16string submit_text; | 16 | struct KeyboardInitializeParameters { |
| 17 | std::u16string ok_text; | ||
| 16 | std::u16string header_text; | 18 | std::u16string header_text; |
| 17 | std::u16string sub_text; | 19 | std::u16string sub_text; |
| 18 | std::u16string guide_text; | 20 | std::u16string guide_text; |
| 19 | std::u16string initial_text; | 21 | std::u16string initial_text; |
| 20 | std::size_t max_length; | 22 | u32 max_text_length; |
| 21 | bool password; | 23 | u32 min_text_length; |
| 22 | bool cursor_at_beginning; | 24 | s32 initial_cursor_position; |
| 23 | 25 | Service::AM::Applets::SwkbdType type; | |
| 24 | union { | 26 | Service::AM::Applets::SwkbdPasswordMode password_mode; |
| 25 | u8 value; | 27 | Service::AM::Applets::SwkbdTextDrawType text_draw_type; |
| 26 | 28 | Service::AM::Applets::SwkbdKeyDisableFlags key_disable_flags; | |
| 27 | BitField<1, 1, u8> disable_space; | 29 | bool use_blur_background; |
| 28 | BitField<2, 1, u8> disable_address; | 30 | bool enable_backspace_button; |
| 29 | BitField<3, 1, u8> disable_percent; | 31 | bool enable_return_button; |
| 30 | BitField<4, 1, u8> disable_slash; | 32 | bool disable_cancel_button; |
| 31 | BitField<6, 1, u8> disable_number; | 33 | }; |
| 32 | BitField<7, 1, u8> disable_download_code; | 34 | |
| 33 | }; | 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; | ||
| 34 | }; | 53 | }; |
| 35 | 54 | ||
| 36 | class SoftwareKeyboardApplet { | 55 | class SoftwareKeyboardApplet { |
| 37 | public: | 56 | public: |
| 38 | virtual ~SoftwareKeyboardApplet(); | 57 | virtual ~SoftwareKeyboardApplet(); |
| 39 | 58 | ||
| 40 | virtual void RequestText(std::function<void(std::optional<std::u16string>)> out, | 59 | virtual void InitializeKeyboard( |
| 41 | SoftwareKeyboardParameters parameters) const = 0; | 60 | bool is_inline, KeyboardInitializeParameters initialize_parameters, |
| 42 | virtual void SendTextCheckDialog(std::u16string error_message, | 61 | std::function<void(Service::AM::Applets::SwkbdResult, std::u16string)> |
| 43 | std::function<void()> finished_check) const = 0; | 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; | ||
| 44 | }; | 78 | }; |
| 45 | 79 | ||
| 46 | class DefaultSoftwareKeyboardApplet final : public SoftwareKeyboardApplet { | 80 | class DefaultSoftwareKeyboardApplet final : public SoftwareKeyboardApplet { |
| 47 | public: | 81 | public: |
| 48 | void RequestText(std::function<void(std::optional<std::u16string>)> out, | 82 | ~DefaultSoftwareKeyboardApplet() override; |
| 49 | SoftwareKeyboardParameters parameters) const override; | 83 | |
| 50 | void SendTextCheckDialog(std::u16string error_message, | 84 | void InitializeKeyboard( |
| 51 | std::function<void()> finished_check) const override; | 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; | ||
| 52 | }; | 114 | }; |
| 53 | 115 | ||
| 54 | } // namespace Core::Frontend | 116 | } // namespace Core::Frontend |
diff --git a/src/core/frontend/input_interpreter.cpp b/src/core/frontend/input_interpreter.cpp index ec5fe660e..9f6a90e8f 100644 --- a/src/core/frontend/input_interpreter.cpp +++ b/src/core/frontend/input_interpreter.cpp | |||
| @@ -12,7 +12,9 @@ InputInterpreter::InputInterpreter(Core::System& system) | |||
| 12 | : npad{system.ServiceManager() | 12 | : npad{system.ServiceManager() |
| 13 | .GetService<Service::HID::Hid>("hid") | 13 | .GetService<Service::HID::Hid>("hid") |
| 14 | ->GetAppletResource() | 14 | ->GetAppletResource() |
| 15 | ->GetController<Service::HID::Controller_NPad>(Service::HID::HidController::NPad)} {} | 15 | ->GetController<Service::HID::Controller_NPad>(Service::HID::HidController::NPad)} { |
| 16 | ResetButtonStates(); | ||
| 17 | } | ||
| 16 | 18 | ||
| 17 | InputInterpreter::~InputInterpreter() = default; | 19 | InputInterpreter::~InputInterpreter() = default; |
| 18 | 20 | ||
| @@ -25,6 +27,17 @@ void InputInterpreter::PollInput() { | |||
| 25 | button_states[current_index] = button_state; | 27 | button_states[current_index] = button_state; |
| 26 | } | 28 | } |
| 27 | 29 | ||
| 30 | void InputInterpreter::ResetButtonStates() { | ||
| 31 | previous_index = 0; | ||
| 32 | current_index = 0; | ||
| 33 | |||
| 34 | button_states[0] = 0xFFFFFFFF; | ||
| 35 | |||
| 36 | for (std::size_t i = 1; i < button_states.size(); ++i) { | ||
| 37 | button_states[i] = 0; | ||
| 38 | } | ||
| 39 | } | ||
| 40 | |||
| 28 | bool InputInterpreter::IsButtonPressed(HIDButton button) const { | 41 | bool InputInterpreter::IsButtonPressed(HIDButton button) const { |
| 29 | return (button_states[current_index] & (1U << static_cast<u8>(button))) != 0; | 42 | return (button_states[current_index] & (1U << static_cast<u8>(button))) != 0; |
| 30 | } | 43 | } |
diff --git a/src/core/frontend/input_interpreter.h b/src/core/frontend/input_interpreter.h index 73fc47ffb..9495e3daf 100644 --- a/src/core/frontend/input_interpreter.h +++ b/src/core/frontend/input_interpreter.h | |||
| @@ -66,6 +66,9 @@ public: | |||
| 66 | /// Gets a button state from HID and inserts it into the array of button states. | 66 | /// Gets a button state from HID and inserts it into the array of button states. |
| 67 | void PollInput(); | 67 | void PollInput(); |
| 68 | 68 | ||
| 69 | /// Resets all the button states to their defaults. | ||
| 70 | void ResetButtonStates(); | ||
| 71 | |||
| 69 | /** | 72 | /** |
| 70 | * Checks whether the button is pressed. | 73 | * Checks whether the button is pressed. |
| 71 | * | 74 | * |