diff options
| author | 2018-11-12 11:08:09 -0500 | |
|---|---|---|
| committer | 2018-11-18 10:53:47 -0500 | |
| commit | 8b433beff34c382e50334bb59c4f71394845558c (patch) | |
| tree | f52f432b2ee5f4ef3917c1c0e2fa052930d68f3a /src | |
| parent | am: Allow applets to push multiple and different channels of data (diff) | |
| download | yuzu-8b433beff34c382e50334bb59c4f71394845558c.tar.gz yuzu-8b433beff34c382e50334bb59c4f71394845558c.tar.xz yuzu-8b433beff34c382e50334bb59c4f71394845558c.zip | |
software_keyboard: Make GetText asynchronous
a
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/frontend/applets/software_keyboard.cpp | 7 | ||||
| -rw-r--r-- | src/core/frontend/applets/software_keyboard.h | 7 | ||||
| -rw-r--r-- | src/core/hle/service/am/am.cpp | 2 | ||||
| -rw-r--r-- | src/core/hle/service/am/applets/software_keyboard.cpp | 19 | ||||
| -rw-r--r-- | src/core/hle/service/am/applets/software_keyboard.h | 5 | ||||
| -rw-r--r-- | src/yuzu/applets/software_keyboard.cpp | 27 | ||||
| -rw-r--r-- | src/yuzu/applets/software_keyboard.h | 15 | ||||
| -rw-r--r-- | src/yuzu/main.cpp | 6 | ||||
| -rw-r--r-- | src/yuzu/main.h | 5 |
9 files changed, 64 insertions, 29 deletions
diff --git a/src/core/frontend/applets/software_keyboard.cpp b/src/core/frontend/applets/software_keyboard.cpp index 2445a980d..4105101b3 100644 --- a/src/core/frontend/applets/software_keyboard.cpp +++ b/src/core/frontend/applets/software_keyboard.cpp | |||
| @@ -9,12 +9,13 @@ | |||
| 9 | namespace Core::Frontend { | 9 | namespace Core::Frontend { |
| 10 | SoftwareKeyboardApplet::~SoftwareKeyboardApplet() = default; | 10 | SoftwareKeyboardApplet::~SoftwareKeyboardApplet() = default; |
| 11 | 11 | ||
| 12 | std::optional<std::u16string> DefaultSoftwareKeyboardApplet::GetText( | 12 | void DefaultSoftwareKeyboardApplet::RequestText( |
| 13 | std::function<void(std::optional<std::u16string>)> out, | ||
| 13 | SoftwareKeyboardParameters parameters) const { | 14 | SoftwareKeyboardParameters parameters) const { |
| 14 | if (parameters.initial_text.empty()) | 15 | if (parameters.initial_text.empty()) |
| 15 | return u"yuzu"; | 16 | out(u"yuzu"); |
| 16 | 17 | ||
| 17 | return parameters.initial_text; | 18 | out(parameters.initial_text); |
| 18 | } | 19 | } |
| 19 | 20 | ||
| 20 | void DefaultSoftwareKeyboardApplet::SendTextCheckDialog(std::u16string error_message) const { | 21 | void DefaultSoftwareKeyboardApplet::SendTextCheckDialog(std::u16string error_message) const { |
diff --git a/src/core/frontend/applets/software_keyboard.h b/src/core/frontend/applets/software_keyboard.h index 7387ee8d7..5420ea883 100644 --- a/src/core/frontend/applets/software_keyboard.h +++ b/src/core/frontend/applets/software_keyboard.h | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <functional> | ||
| 7 | #include <optional> | 8 | #include <optional> |
| 8 | #include <string> | 9 | #include <string> |
| 9 | #include "common/bit_field.h" | 10 | #include "common/bit_field.h" |
| @@ -36,13 +37,15 @@ class SoftwareKeyboardApplet { | |||
| 36 | public: | 37 | public: |
| 37 | virtual ~SoftwareKeyboardApplet(); | 38 | virtual ~SoftwareKeyboardApplet(); |
| 38 | 39 | ||
| 39 | virtual std::optional<std::u16string> GetText(SoftwareKeyboardParameters parameters) const = 0; | 40 | virtual void RequestText(std::function<void(std::optional<std::u16string>)> out, |
| 41 | SoftwareKeyboardParameters parameters) const = 0; | ||
| 40 | virtual void SendTextCheckDialog(std::u16string error_message) const = 0; | 42 | virtual void SendTextCheckDialog(std::u16string error_message) const = 0; |
| 41 | }; | 43 | }; |
| 42 | 44 | ||
| 43 | class DefaultSoftwareKeyboardApplet final : public SoftwareKeyboardApplet { | 45 | class DefaultSoftwareKeyboardApplet final : public SoftwareKeyboardApplet { |
| 44 | public: | 46 | public: |
| 45 | std::optional<std::u16string> GetText(SoftwareKeyboardParameters parameters) const override; | 47 | void RequestText(std::function<void(std::optional<std::u16string>)> out, |
| 48 | SoftwareKeyboardParameters parameters) const override; | ||
| 46 | void SendTextCheckDialog(std::u16string error_message) const override; | 49 | void SendTextCheckDialog(std::u16string error_message) const override; |
| 47 | }; | 50 | }; |
| 48 | 51 | ||
diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index 3f8d97d31..d040d4776 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp | |||
| @@ -718,7 +718,7 @@ void IStorageAccessor::Write(Kernel::HLERequestContext& ctx) { | |||
| 718 | const u64 offset{rp.Pop<u64>()}; | 718 | const u64 offset{rp.Pop<u64>()}; |
| 719 | const std::vector<u8> data{ctx.ReadBuffer()}; | 719 | const std::vector<u8> data{ctx.ReadBuffer()}; |
| 720 | 720 | ||
| 721 | const auto size = std::min(data.size(), backing.buffer.size() - offset); | 721 | const auto size = std::min<std::size_t>(data.size(), backing.buffer.size() - offset); |
| 722 | 722 | ||
| 723 | std::memcpy(&backing.buffer[offset], data.data(), size); | 723 | std::memcpy(&backing.buffer[offset], data.data(), size); |
| 724 | 724 | ||
diff --git a/src/core/hle/service/am/applets/software_keyboard.cpp b/src/core/hle/service/am/applets/software_keyboard.cpp index 7352f3bdf..66b34d5ac 100644 --- a/src/core/hle/service/am/applets/software_keyboard.cpp +++ b/src/core/hle/service/am/applets/software_keyboard.cpp | |||
| @@ -43,6 +43,10 @@ SoftwareKeyboard::SoftwareKeyboard() = default; | |||
| 43 | SoftwareKeyboard::~SoftwareKeyboard() = default; | 43 | SoftwareKeyboard::~SoftwareKeyboard() = default; |
| 44 | 44 | ||
| 45 | void SoftwareKeyboard::Initialize(std::vector<std::shared_ptr<IStorage>> storage_) { | 45 | void SoftwareKeyboard::Initialize(std::vector<std::shared_ptr<IStorage>> storage_) { |
| 46 | complete = false; | ||
| 47 | initial_text.clear(); | ||
| 48 | final_data.clear(); | ||
| 49 | |||
| 46 | Applet::Initialize(std::move(storage_)); | 50 | Applet::Initialize(std::move(storage_)); |
| 47 | 51 | ||
| 48 | ASSERT(storage_stack.size() >= 2); | 52 | ASSERT(storage_stack.size() >= 2); |
| @@ -96,20 +100,25 @@ void SoftwareKeyboard::Execute(AppletStorageProxyFunction out_data, | |||
| 96 | 100 | ||
| 97 | const auto parameters = ConvertToFrontendParameters(config, initial_text); | 101 | const auto parameters = ConvertToFrontendParameters(config, initial_text); |
| 98 | 102 | ||
| 99 | const auto res = frontend.GetText(parameters); | 103 | this->out_data = out_data; |
| 104 | this->out_interactive_data = out_interactive_data; | ||
| 105 | frontend.RequestText([this](std::optional<std::u16string> text) { WriteText(text); }, | ||
| 106 | parameters); | ||
| 107 | } | ||
| 100 | 108 | ||
| 109 | void SoftwareKeyboard::WriteText(std::optional<std::u16string> text) { | ||
| 101 | std::vector<u8> output(SWKBD_OUTPUT_BUFFER_SIZE); | 110 | std::vector<u8> output(SWKBD_OUTPUT_BUFFER_SIZE); |
| 102 | 111 | ||
| 103 | if (res.has_value()) { | 112 | if (text.has_value()) { |
| 104 | if (config.text_check) { | 113 | if (config.text_check) { |
| 105 | const auto size = static_cast<u32>(res->size() * 2 + 4); | 114 | const auto size = static_cast<u32>(text->size() * 2 + 4); |
| 106 | std::memcpy(output.data(), &size, sizeof(u32)); | 115 | std::memcpy(output.data(), &size, sizeof(u32)); |
| 107 | } else { | 116 | } else { |
| 108 | output[0] = 1; | 117 | output[0] = 1; |
| 109 | } | 118 | } |
| 110 | 119 | ||
| 111 | std::memcpy(output.data() + 4, res->data(), | 120 | std::memcpy(output.data() + 4, text->data(), |
| 112 | std::min(res->size() * 2, SWKBD_OUTPUT_BUFFER_SIZE - 4)); | 121 | std::min(text->size() * 2, SWKBD_OUTPUT_BUFFER_SIZE - 4)); |
| 113 | } else { | 122 | } else { |
| 114 | complete = true; | 123 | complete = true; |
| 115 | out_data(IStorage{output}); | 124 | out_data(IStorage{output}); |
diff --git a/src/core/hle/service/am/applets/software_keyboard.h b/src/core/hle/service/am/applets/software_keyboard.h index 66de4bc59..b08bff3d7 100644 --- a/src/core/hle/service/am/applets/software_keyboard.h +++ b/src/core/hle/service/am/applets/software_keyboard.h | |||
| @@ -57,11 +57,16 @@ public: | |||
| 57 | void Execute(AppletStorageProxyFunction out_data, | 57 | void Execute(AppletStorageProxyFunction out_data, |
| 58 | AppletStorageProxyFunction out_interactive_data) override; | 58 | AppletStorageProxyFunction out_interactive_data) override; |
| 59 | 59 | ||
| 60 | void WriteText(std::optional<std::u16string> text); | ||
| 61 | |||
| 60 | private: | 62 | private: |
| 61 | KeyboardConfig config; | 63 | KeyboardConfig config; |
| 62 | std::u16string initial_text; | 64 | std::u16string initial_text; |
| 63 | bool complete = false; | 65 | bool complete = false; |
| 64 | std::vector<u8> final_data; | 66 | std::vector<u8> final_data; |
| 67 | |||
| 68 | AppletStorageProxyFunction out_data; | ||
| 69 | AppletStorageProxyFunction out_interactive_data; | ||
| 65 | }; | 70 | }; |
| 66 | 71 | ||
| 67 | } // namespace Service::AM::Applets | 72 | } // namespace Service::AM::Applets |
diff --git a/src/yuzu/applets/software_keyboard.cpp b/src/yuzu/applets/software_keyboard.cpp index 92992ef87..9fb179f5c 100644 --- a/src/yuzu/applets/software_keyboard.cpp +++ b/src/yuzu/applets/software_keyboard.cpp | |||
| @@ -105,20 +105,27 @@ bool QtSoftwareKeyboardDialog::GetStatus() const { | |||
| 105 | return ok; | 105 | return ok; |
| 106 | } | 106 | } |
| 107 | 107 | ||
| 108 | QtSoftwareKeyboard::QtSoftwareKeyboard(GMainWindow& parent) : main_window(parent) {} | 108 | QtSoftwareKeyboard::QtSoftwareKeyboard(GMainWindow& main_window) { |
| 109 | connect(this, &QtSoftwareKeyboard::MainWindowGetText, &main_window, | ||
| 110 | &GMainWindow::SoftwareKeyboardGetText, Qt::QueuedConnection); | ||
| 111 | connect(this, &QtSoftwareKeyboard::MainWindowTextCheckDialog, &main_window, | ||
| 112 | &GMainWindow::SoftwareKeyboardInvokeCheckDialog, Qt::BlockingQueuedConnection); | ||
| 113 | connect(&main_window, &GMainWindow::SoftwareKeyboardFinishedText, this, | ||
| 114 | &QtSoftwareKeyboard::MainWindowFinishedText, Qt::QueuedConnection); | ||
| 115 | } | ||
| 109 | 116 | ||
| 110 | QtSoftwareKeyboard::~QtSoftwareKeyboard() = default; | 117 | QtSoftwareKeyboard::~QtSoftwareKeyboard() = default; |
| 111 | 118 | ||
| 112 | std::optional<std::u16string> QtSoftwareKeyboard::GetText( | 119 | void QtSoftwareKeyboard::RequestText(std::function<void(std::optional<std::u16string>)> out, |
| 113 | Core::Frontend::SoftwareKeyboardParameters parameters) const { | 120 | Core::Frontend::SoftwareKeyboardParameters parameters) const { |
| 114 | std::optional<std::u16string> success; | 121 | text_output = out; |
| 115 | QMetaObject::invokeMethod(&main_window, "SoftwareKeyboardGetText", Qt::BlockingQueuedConnection, | 122 | emit MainWindowGetText(parameters); |
| 116 | Q_RETURN_ARG(std::optional<std::u16string>, success), | ||
| 117 | Q_ARG(Core::Frontend::SoftwareKeyboardParameters, parameters)); | ||
| 118 | return success; | ||
| 119 | } | 123 | } |
| 120 | 124 | ||
| 121 | void QtSoftwareKeyboard::SendTextCheckDialog(std::u16string error_message) const { | 125 | void QtSoftwareKeyboard::SendTextCheckDialog(std::u16string error_message) const { |
| 122 | QMetaObject::invokeMethod(&main_window, "SoftwareKeyboardInvokeCheckDialog", | 126 | emit MainWindowTextCheckDialog(error_message); |
| 123 | Qt::BlockingQueuedConnection, Q_ARG(std::u16string, error_message)); | 127 | } |
| 128 | |||
| 129 | void QtSoftwareKeyboard::MainWindowFinishedText(std::optional<std::u16string> text) { | ||
| 130 | text_output(text); | ||
| 124 | } | 131 | } |
diff --git a/src/yuzu/applets/software_keyboard.h b/src/yuzu/applets/software_keyboard.h index 8d95ca511..670b05dc9 100644 --- a/src/yuzu/applets/software_keyboard.h +++ b/src/yuzu/applets/software_keyboard.h | |||
| @@ -54,14 +54,23 @@ private: | |||
| 54 | }; | 54 | }; |
| 55 | 55 | ||
| 56 | class QtSoftwareKeyboard final : public QObject, public Core::Frontend::SoftwareKeyboardApplet { | 56 | class QtSoftwareKeyboard final : public QObject, public Core::Frontend::SoftwareKeyboardApplet { |
| 57 | Q_OBJECT | ||
| 58 | |||
| 57 | public: | 59 | public: |
| 58 | explicit QtSoftwareKeyboard(GMainWindow& parent); | 60 | explicit QtSoftwareKeyboard(GMainWindow& parent); |
| 59 | ~QtSoftwareKeyboard() override; | 61 | ~QtSoftwareKeyboard() override; |
| 60 | 62 | ||
| 61 | std::optional<std::u16string> GetText( | 63 | void RequestText(std::function<void(std::optional<std::u16string>)> out, |
| 62 | Core::Frontend::SoftwareKeyboardParameters parameters) const override; | 64 | Core::Frontend::SoftwareKeyboardParameters parameters) const override; |
| 63 | void SendTextCheckDialog(std::u16string error_message) const override; | 65 | void SendTextCheckDialog(std::u16string error_message) const override; |
| 64 | 66 | ||
| 67 | signals: | ||
| 68 | void MainWindowGetText(Core::Frontend::SoftwareKeyboardParameters parameters) const; | ||
| 69 | void MainWindowTextCheckDialog(std::u16string error_message) const; | ||
| 70 | |||
| 71 | public slots: | ||
| 72 | void MainWindowFinishedText(std::optional<std::u16string> text); | ||
| 73 | |||
| 65 | private: | 74 | private: |
| 66 | GMainWindow& main_window; | 75 | mutable std::function<void(std::optional<std::u16string>)> text_output; |
| 67 | }; | 76 | }; |
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index a11eb7f86..28c53cc87 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp | |||
| @@ -207,7 +207,7 @@ GMainWindow::~GMainWindow() { | |||
| 207 | delete render_window; | 207 | delete render_window; |
| 208 | } | 208 | } |
| 209 | 209 | ||
| 210 | std::optional<std::u16string> GMainWindow::SoftwareKeyboardGetText( | 210 | void GMainWindow::SoftwareKeyboardGetText( |
| 211 | const Core::Frontend::SoftwareKeyboardParameters& parameters) { | 211 | const Core::Frontend::SoftwareKeyboardParameters& parameters) { |
| 212 | QtSoftwareKeyboardDialog dialog(this, parameters); | 212 | QtSoftwareKeyboardDialog dialog(this, parameters); |
| 213 | dialog.setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | | 213 | dialog.setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | |
| @@ -216,9 +216,9 @@ std::optional<std::u16string> GMainWindow::SoftwareKeyboardGetText( | |||
| 216 | dialog.exec(); | 216 | dialog.exec(); |
| 217 | 217 | ||
| 218 | if (!dialog.GetStatus()) | 218 | if (!dialog.GetStatus()) |
| 219 | return std::nullopt; | 219 | emit SoftwareKeyboardFinishedText(std::nullopt); |
| 220 | 220 | ||
| 221 | return dialog.GetText(); | 221 | emit SoftwareKeyboardFinishedText(dialog.GetText()); |
| 222 | } | 222 | } |
| 223 | 223 | ||
| 224 | void GMainWindow::SoftwareKeyboardInvokeCheckDialog(std::u16string error_message) { | 224 | void GMainWindow::SoftwareKeyboardInvokeCheckDialog(std::u16string error_message) { |
diff --git a/src/yuzu/main.h b/src/yuzu/main.h index 8fbe998ea..d83169805 100644 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h | |||
| @@ -99,9 +99,10 @@ signals: | |||
| 99 | // Signal that tells widgets to update icons to use the current theme | 99 | // Signal that tells widgets to update icons to use the current theme |
| 100 | void UpdateThemedIcons(); | 100 | void UpdateThemedIcons(); |
| 101 | 101 | ||
| 102 | void SoftwareKeyboardFinishedText(std::optional<std::u16string> text); | ||
| 103 | |||
| 102 | public slots: | 104 | public slots: |
| 103 | std::optional<std::u16string> SoftwareKeyboardGetText( | 105 | void SoftwareKeyboardGetText(const Core::Frontend::SoftwareKeyboardParameters& parameters); |
| 104 | const Core::Frontend::SoftwareKeyboardParameters& parameters); | ||
| 105 | void SoftwareKeyboardInvokeCheckDialog(std::u16string error_message); | 106 | void SoftwareKeyboardInvokeCheckDialog(std::u16string error_message); |
| 106 | 107 | ||
| 107 | private: | 108 | private: |