Compare commits

...

4 Commits

Author SHA1 Message Date
bunnei
40af1bea63 applets: software_keyboard: Block calling thread until text is available.
- Fixes a bug where guest thread is resumed too early (Little Town Hero).
2020-01-26 01:08:47 -05:00
bunnei
64a39b838d services: am: Clear events on PopOutData and PopInteractiveOutData. 2020-01-26 01:08:47 -05:00
bunnei
d0b11cc116 applets: software_keyboard: Signal state change on end of interactive session. 2020-01-26 01:08:46 -05:00
bunnei
32f7d292a1 applets: software_keyboard: Minor cleanup. 2020-01-26 01:08:46 -05:00
9 changed files with 42 additions and 26 deletions

View File

@@ -10,8 +10,7 @@ namespace Core::Frontend {
SoftwareKeyboardApplet::~SoftwareKeyboardApplet() = default;
void DefaultSoftwareKeyboardApplet::RequestText(
std::function<void(std::optional<std::u16string>)> out,
SoftwareKeyboardParameters parameters) const {
std::function<void(std::optional<std::u16string>)> out, SoftwareKeyboardParameters parameters) {
if (parameters.initial_text.empty())
out(u"yuzu");

View File

@@ -38,7 +38,7 @@ public:
virtual ~SoftwareKeyboardApplet();
virtual void RequestText(std::function<void(std::optional<std::u16string>)> out,
SoftwareKeyboardParameters parameters) const = 0;
SoftwareKeyboardParameters parameters) = 0;
virtual void SendTextCheckDialog(std::u16string error_message,
std::function<void()> finished_check) const = 0;
};
@@ -46,7 +46,7 @@ public:
class DefaultSoftwareKeyboardApplet final : public SoftwareKeyboardApplet {
public:
void RequestText(std::function<void(std::optional<std::u16string>)> out,
SoftwareKeyboardParameters parameters) const override;
SoftwareKeyboardParameters parameters) override;
void SendTextCheckDialog(std::u16string error_message,
std::function<void()> finished_check) const override;
};

View File

@@ -778,11 +778,9 @@ private:
void GetAppletStateChangedEvent(Kernel::HLERequestContext& ctx) {
LOG_DEBUG(Service_AM, "called");
const auto event = applet->GetBroker().GetStateChangedEvent();
IPC::ResponseBuilder rb{ctx, 2, 1};
rb.Push(RESULT_SUCCESS);
rb.PushCopyObjects(event);
rb.PushCopyObjects(applet->GetBroker().GetStateChangedEvent()->GetReadableEvent());
}
void IsCompleted(Kernel::HLERequestContext& ctx) {
@@ -836,6 +834,8 @@ private:
return;
}
applet->GetBroker().GetNormalDataEvent()->Clear();
rb.Push(RESULT_SUCCESS);
rb.PushIpcInterface<IStorage>(std::move(*storage));
}
@@ -868,6 +868,8 @@ private:
return;
}
applet->GetBroker().GetInteractiveDataEvent()->Clear();
rb.Push(RESULT_SUCCESS);
rb.PushIpcInterface<IStorage>(std::move(*storage));
}
@@ -877,7 +879,7 @@ private:
IPC::ResponseBuilder rb{ctx, 2, 1};
rb.Push(RESULT_SUCCESS);
rb.PushCopyObjects(applet->GetBroker().GetNormalDataEvent());
rb.PushCopyObjects(applet->GetBroker().GetNormalDataEvent()->GetReadableEvent());
}
void GetPopInteractiveOutDataEvent(Kernel::HLERequestContext& ctx) {
@@ -885,7 +887,7 @@ private:
IPC::ResponseBuilder rb{ctx, 2, 1};
rb.Push(RESULT_SUCCESS);
rb.PushCopyObjects(applet->GetBroker().GetInteractiveDataEvent());
rb.PushCopyObjects(applet->GetBroker().GetInteractiveDataEvent()->GetReadableEvent());
}
std::shared_ptr<Applets::Applet> applet;

View File

@@ -108,16 +108,16 @@ void AppletDataBroker::SignalStateChanged() const {
state_changed_event.writable->Signal();
}
std::shared_ptr<Kernel::ReadableEvent> AppletDataBroker::GetNormalDataEvent() const {
return pop_out_data_event.readable;
std::shared_ptr<Kernel::WritableEvent> AppletDataBroker::GetNormalDataEvent() const {
return pop_out_data_event.writable;
}
std::shared_ptr<Kernel::ReadableEvent> AppletDataBroker::GetInteractiveDataEvent() const {
return pop_interactive_out_data_event.readable;
std::shared_ptr<Kernel::WritableEvent> AppletDataBroker::GetInteractiveDataEvent() const {
return pop_interactive_out_data_event.writable;
}
std::shared_ptr<Kernel::ReadableEvent> AppletDataBroker::GetStateChangedEvent() const {
return state_changed_event.readable;
std::shared_ptr<Kernel::WritableEvent> AppletDataBroker::GetStateChangedEvent() const {
return state_changed_event.writable;
}
Applet::Applet(Kernel::KernelCore& kernel_) : broker{kernel_} {}

View File

@@ -86,9 +86,9 @@ public:
void SignalStateChanged() const;
std::shared_ptr<Kernel::ReadableEvent> GetNormalDataEvent() const;
std::shared_ptr<Kernel::ReadableEvent> GetInteractiveDataEvent() const;
std::shared_ptr<Kernel::ReadableEvent> GetStateChangedEvent() const;
std::shared_ptr<Kernel::WritableEvent> GetNormalDataEvent() const;
std::shared_ptr<Kernel::WritableEvent> GetInteractiveDataEvent() const;
std::shared_ptr<Kernel::WritableEvent> GetStateChangedEvent() const;
private:
// Queues are named from applet's perspective

View File

@@ -40,8 +40,8 @@ static Core::Frontend::SoftwareKeyboardParameters ConvertToFrontendParameters(
}
SoftwareKeyboard::SoftwareKeyboard(Core::System& system_,
const Core::Frontend::SoftwareKeyboardApplet& frontend_)
: Applet{system_.Kernel()}, frontend(frontend_) {}
Core::Frontend::SoftwareKeyboardApplet& frontend)
: Applet{system_.Kernel()}, frontend{frontend} {}
SoftwareKeyboard::~SoftwareKeyboard() = default;
@@ -103,6 +103,7 @@ void SoftwareKeyboard::ExecuteInteractive() {
void SoftwareKeyboard::Execute() {
if (complete) {
broker.PushNormalDataFromApplet(IStorage{final_data});
broker.SignalStateChanged();
return;
}
@@ -119,7 +120,7 @@ void SoftwareKeyboard::WriteText(std::optional<std::u16string> text) {
std::vector<u8> output_sub(SWKBD_OUTPUT_BUFFER_SIZE);
if (config.utf_8) {
const u64 size = text->size() + 8;
const u64 size = text->size() + sizeof(u64);
const auto new_text = Common::UTF16ToUTF8(*text);
std::memcpy(output_sub.data(), &size, sizeof(u64));
@@ -130,7 +131,7 @@ void SoftwareKeyboard::WriteText(std::optional<std::u16string> text) {
std::memcpy(output_main.data() + 4, new_text.data(),
std::min(new_text.size(), SWKBD_OUTPUT_BUFFER_SIZE - 4));
} else {
const u64 size = text->size() * 2 + 8;
const u64 size = text->size() * 2 + sizeof(u64);
std::memcpy(output_sub.data(), &size, sizeof(u64));
std::memcpy(output_sub.data() + 8, text->data(),
std::min(text->size() * 2, SWKBD_OUTPUT_BUFFER_SIZE - 8));

View File

@@ -60,7 +60,7 @@ static_assert(sizeof(KeyboardConfig) == 0x3E0, "KeyboardConfig has incorrect siz
class SoftwareKeyboard final : public Applet {
public:
explicit SoftwareKeyboard(Core::System& system_,
const Core::Frontend::SoftwareKeyboardApplet& frontend_);
Core::Frontend::SoftwareKeyboardApplet& frontend);
~SoftwareKeyboard() override;
void Initialize() override;
@@ -73,7 +73,7 @@ public:
void WriteText(std::optional<std::u16string> text);
private:
const Core::Frontend::SoftwareKeyboardApplet& frontend;
Core::Frontend::SoftwareKeyboardApplet& frontend;
KeyboardConfig config;
std::u16string initial_text;

View File

@@ -129,9 +129,13 @@ QtSoftwareKeyboard::QtSoftwareKeyboard(GMainWindow& main_window) {
QtSoftwareKeyboard::~QtSoftwareKeyboard() = default;
void QtSoftwareKeyboard::RequestText(std::function<void(std::optional<std::u16string>)> out,
Core::Frontend::SoftwareKeyboardParameters parameters) const {
Core::Frontend::SoftwareKeyboardParameters parameters) {
text_output = std::move(out);
emit MainWindowGetText(parameters);
// Block calling thread until user input is available
std::unique_lock<std::mutex> lock{mutex};
condition_variable.wait(lock);
}
void QtSoftwareKeyboard::SendTextCheckDialog(std::u16string error_message,
@@ -144,10 +148,14 @@ void QtSoftwareKeyboard::MainWindowFinishedText(std::optional<std::u16string> te
// Acquire the HLE mutex
std::lock_guard lock{HLE::g_hle_lock};
text_output(std::move(text));
// Signal that text is ready
condition_variable.notify_one();
}
void QtSoftwareKeyboard::MainWindowFinishedCheckDialog() {
// Acquire the HLE mutex
std::lock_guard lock{HLE::g_hle_lock};
finished_check();
}

View File

@@ -4,6 +4,9 @@
#pragma once
#include <condition_variable>
#include <mutex>
#include <QDialog>
#include <QValidator>
#include "core/frontend/applets/software_keyboard.h"
@@ -59,7 +62,7 @@ public:
~QtSoftwareKeyboard() override;
void RequestText(std::function<void(std::optional<std::u16string>)> out,
Core::Frontend::SoftwareKeyboardParameters parameters) const override;
Core::Frontend::SoftwareKeyboardParameters parameters) override;
void SendTextCheckDialog(std::u16string error_message,
std::function<void()> finished_check) const override;
@@ -73,4 +76,7 @@ private:
mutable std::function<void(std::optional<std::u16string>)> text_output;
mutable std::function<void()> finished_check;
std::mutex mutex;
std::condition_variable condition_variable;
};