From fb974a45513b5f9c9398aa97f86be564984c2ca3 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Tue, 24 Jan 2023 01:15:35 +0100 Subject: [PATCH] overlays/osk: clear on enter --- rpcs3/Emu/Cell/Modules/cellOskDialog.cpp | 2 +- rpcs3/Emu/Cell/Modules/cellOskDialog.h | 2 +- rpcs3/Emu/RSX/Overlays/overlay_osk.cpp | 32 ++++++++++++++++++++---- rpcs3/Emu/RSX/Overlays/overlay_osk.h | 2 +- rpcs3/rpcs3qt/osk_dialog_frame.cpp | 6 ++--- rpcs3/rpcs3qt/osk_dialog_frame.h | 2 +- 6 files changed, 34 insertions(+), 12 deletions(-) diff --git a/rpcs3/Emu/Cell/Modules/cellOskDialog.cpp b/rpcs3/Emu/Cell/Modules/cellOskDialog.cpp index cdefea158b..0d0f761979 100644 --- a/rpcs3/Emu/Cell/Modules/cellOskDialog.cpp +++ b/rpcs3/Emu/Cell/Modules/cellOskDialog.cpp @@ -746,7 +746,7 @@ error_code getText(vm::ptr OutputInfo, bool is std::lock_guard lock(info.text_mtx); info.valid_text = {}; - osk->Clear(); + osk->Clear(true); break; } default: diff --git a/rpcs3/Emu/Cell/Modules/cellOskDialog.h b/rpcs3/Emu/Cell/Modules/cellOskDialog.h index 579f681e23..a6f560f7f4 100644 --- a/rpcs3/Emu/Cell/Modules/cellOskDialog.h +++ b/rpcs3/Emu/Cell/Modules/cellOskDialog.h @@ -301,7 +301,7 @@ public: }; virtual void Create(const osk_params& params) = 0; - virtual void Clear() = 0; + virtual void Clear(bool clear_all_data) = 0; // Closes the dialog. // Set status to CELL_OSKDIALOG_CLOSE_CONFIRM or CELL_OSKDIALOG_CLOSE_CANCEL for user input. diff --git a/rpcs3/Emu/RSX/Overlays/overlay_osk.cpp b/rpcs3/Emu/RSX/Overlays/overlay_osk.cpp index 68e6800dc2..bbe4a92e37 100644 --- a/rpcs3/Emu/RSX/Overlays/overlay_osk.cpp +++ b/rpcs3/Emu/RSX/Overlays/overlay_osk.cpp @@ -24,6 +24,8 @@ namespace rsx void osk_dialog::Close(s32 status) { + osk.notice("Closing osk (status=%d)", status); + if (status == FAKE_CELL_OSKDIALOG_CLOSE_TERMINATE) { close(false, true); @@ -63,19 +65,37 @@ namespace rsx if (!m_use_separate_windows || continuous_mode == CELL_OSKDIALOG_CONTINUOUS_MODE_NONE) { close(true, true); + return; } + + // Clear text edit in continuous separate window mode. Keep actual data just in case. + Clear(false); }; fade_animation.active = true; } - void osk_dialog::Clear() + void osk_dialog::Clear(bool clear_all_data) { - std::lock_guard lock(m_preview_mutex); + osk.notice("Clearing osk (clear_all_data=%d)", clear_all_data); + + // Try to lock. Clear might be called recursively. + const bool locked = m_preview_mutex.try_lock(); m_preview.caret_position = 0; - m_preview.value.clear(); - on_text_changed(); + m_preview.set_text({}); + + if (clear_all_data) + { + on_text_changed(); + } + + if (locked) + { + m_preview_mutex.unlock(); + } + + m_update = true; } void osk_dialog::add_panel(const osk_panel& panel) @@ -961,10 +981,12 @@ namespace rsx void osk_dialog::on_text_changed() { - const auto ws = u32string_to_utf16(m_preview.value); + const std::u16string ws = u32string_to_utf16(m_preview.value); const usz length = std::min(osk_text.size(), ws.length() + 1) * sizeof(char16_t); memcpy(osk_text.data(), ws.c_str(), length); + osk.notice("on_text_changed: osk_text='%s'", utf16_to_ascii8(ws)); + // Muted contrast for placeholder text m_preview.fore_color.a = m_preview.value.empty() ? 0.5f : 1.f; diff --git a/rpcs3/Emu/RSX/Overlays/overlay_osk.h b/rpcs3/Emu/RSX/Overlays/overlay_osk.h index 5c647b1d0b..65d1a67c2d 100644 --- a/rpcs3/Emu/RSX/Overlays/overlay_osk.h +++ b/rpcs3/Emu/RSX/Overlays/overlay_osk.h @@ -107,7 +107,7 @@ namespace rsx void Create(const osk_params& params) override; void Close(s32 status) override; - void Clear() override; + void Clear(bool clear_all_data) override; void initialize_layout(const std::u32string& title, const std::u32string& initial_text); void add_panel(const osk_panel& panel); diff --git a/rpcs3/rpcs3qt/osk_dialog_frame.cpp b/rpcs3/rpcs3qt/osk_dialog_frame.cpp index eb10b86b18..d57cb7cee4 100644 --- a/rpcs3/rpcs3qt/osk_dialog_frame.cpp +++ b/rpcs3/rpcs3qt/osk_dialog_frame.cpp @@ -182,7 +182,7 @@ void osk_dialog_frame::Create(const osk_params& params) void osk_dialog_frame::SetOskText(const QString& text) { - std::memcpy(osk_text.data(), utils::bless(text.constData()), std::min(osk_text.size(), text.size() + 1ull) * sizeof(char16_t)); + std::memcpy(osk_text.data(), utils::bless(text.constData()), std::min(osk_text.size(), text.size() + usz{1}) * sizeof(char16_t)); } void osk_dialog_frame::Close(s32 status) @@ -204,9 +204,9 @@ void osk_dialog_frame::Close(s32 status) } } -void osk_dialog_frame::Clear() +void osk_dialog_frame::Clear(bool clear_all_data) { - if (m_dialog) + if (m_dialog && clear_all_data) { SetOskText(""); } diff --git a/rpcs3/rpcs3qt/osk_dialog_frame.h b/rpcs3/rpcs3qt/osk_dialog_frame.h index b3948159d3..c09ece59b7 100644 --- a/rpcs3/rpcs3qt/osk_dialog_frame.h +++ b/rpcs3/rpcs3qt/osk_dialog_frame.h @@ -18,7 +18,7 @@ public: ~osk_dialog_frame(); void Create(const osk_params& params) override; void Close(s32 status) override; - void Clear() override; + void Clear(bool clear_all_data) override; private: void SetOskText(const QString& text);