summaryrefslogtreecommitdiffstats
path: root/src/core/frontend
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/frontend')
-rw-r--r--src/core/frontend/applets/profile_select.cpp2
-rw-r--r--src/core/frontend/applets/software_keyboard.cpp148
-rw-r--r--src/core/frontend/applets/software_keyboard.h118
-rw-r--r--src/core/frontend/emu_window.cpp25
-rw-r--r--src/core/frontend/emu_window.h28
-rw-r--r--src/core/frontend/framebuffer_layout.cpp2
-rw-r--r--src/core/frontend/input_interpreter.cpp15
-rw-r--r--src/core/frontend/input_interpreter.h3
8 files changed, 271 insertions, 70 deletions
diff --git a/src/core/frontend/applets/profile_select.cpp b/src/core/frontend/applets/profile_select.cpp
index 4df3574d2..8d960d1ca 100644
--- a/src/core/frontend/applets/profile_select.cpp
+++ b/src/core/frontend/applets/profile_select.cpp
@@ -2,9 +2,9 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
+#include "common/settings.h"
#include "core/frontend/applets/profile_select.h"
#include "core/hle/service/acc/profile_manager.h"
-#include "core/settings.h"
namespace Core::Frontend {
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 @@
-// Copyright 2018 yuzu emulator team
+// Copyright 2021 yuzu Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
-#include "common/logging/backend.h"
+#include <thread>
+
+#include "common/logging/log.h"
#include "common/string_util.h"
#include "core/frontend/applets/software_keyboard.h"
namespace Core::Frontend {
+
SoftwareKeyboardApplet::~SoftwareKeyboardApplet() = default;
-void DefaultSoftwareKeyboardApplet::RequestText(
- std::function<void(std::optional<std::u16string>)> out,
- SoftwareKeyboardParameters parameters) const {
- if (parameters.initial_text.empty())
- out(u"yuzu");
+DefaultSoftwareKeyboardApplet::~DefaultSoftwareKeyboardApplet() = default;
+
+void DefaultSoftwareKeyboardApplet::InitializeKeyboard(
+ bool is_inline, KeyboardInitializeParameters initialize_parameters,
+ std::function<void(Service::AM::Applets::SwkbdResult, std::u16string)> submit_normal_callback_,
+ std::function<void(Service::AM::Applets::SwkbdReplyType, std::u16string, s32)>
+ submit_inline_callback_) {
+ if (is_inline) {
+ LOG_WARNING(
+ Service_AM,
+ "(STUBBED) called, backend requested to initialize the inline software keyboard.");
+
+ submit_inline_callback = std::move(submit_inline_callback_);
+ } else {
+ LOG_WARNING(
+ Service_AM,
+ "(STUBBED) called, backend requested to initialize the normal software keyboard.");
+
+ submit_normal_callback = std::move(submit_normal_callback_);
+ }
+
+ parameters = std::move(initialize_parameters);
+
+ LOG_INFO(Service_AM,
+ "\nKeyboardInitializeParameters:"
+ "\nok_text={}"
+ "\nheader_text={}"
+ "\nsub_text={}"
+ "\nguide_text={}"
+ "\ninitial_text={}"
+ "\nmax_text_length={}"
+ "\nmin_text_length={}"
+ "\ninitial_cursor_position={}"
+ "\ntype={}"
+ "\npassword_mode={}"
+ "\ntext_draw_type={}"
+ "\nkey_disable_flags={}"
+ "\nuse_blur_background={}"
+ "\nenable_backspace_button={}"
+ "\nenable_return_button={}"
+ "\ndisable_cancel_button={}",
+ Common::UTF16ToUTF8(parameters.ok_text), Common::UTF16ToUTF8(parameters.header_text),
+ Common::UTF16ToUTF8(parameters.sub_text), Common::UTF16ToUTF8(parameters.guide_text),
+ Common::UTF16ToUTF8(parameters.initial_text), parameters.max_text_length,
+ parameters.min_text_length, parameters.initial_cursor_position, parameters.type,
+ parameters.password_mode, parameters.text_draw_type, parameters.key_disable_flags.raw,
+ parameters.use_blur_background, parameters.enable_backspace_button,
+ parameters.enable_return_button, parameters.disable_cancel_button);
+}
+
+void DefaultSoftwareKeyboardApplet::ShowNormalKeyboard() const {
+ LOG_WARNING(Service_AM,
+ "(STUBBED) called, backend requested to show the normal software keyboard.");
+
+ SubmitNormalText(u"yuzu");
+}
+
+void DefaultSoftwareKeyboardApplet::ShowTextCheckDialog(
+ Service::AM::Applets::SwkbdTextCheckResult text_check_result,
+ std::u16string text_check_message) const {
+ LOG_WARNING(Service_AM, "(STUBBED) called, backend requested to show the text check dialog.");
+}
+
+void DefaultSoftwareKeyboardApplet::ShowInlineKeyboard(
+ InlineAppearParameters appear_parameters) const {
+ LOG_WARNING(Service_AM,
+ "(STUBBED) called, backend requested to show the inline software keyboard.");
+
+ LOG_INFO(Service_AM,
+ "\nInlineAppearParameters:"
+ "\nmax_text_length={}"
+ "\nmin_text_length={}"
+ "\nkey_top_scale_x={}"
+ "\nkey_top_scale_y={}"
+ "\nkey_top_translate_x={}"
+ "\nkey_top_translate_y={}"
+ "\ntype={}"
+ "\nkey_disable_flags={}"
+ "\nkey_top_as_floating={}"
+ "\nenable_backspace_button={}"
+ "\nenable_return_button={}"
+ "\ndisable_cancel_button={}",
+ appear_parameters.max_text_length, appear_parameters.min_text_length,
+ appear_parameters.key_top_scale_x, appear_parameters.key_top_scale_y,
+ appear_parameters.key_top_translate_x, appear_parameters.key_top_translate_y,
+ appear_parameters.type, appear_parameters.key_disable_flags.raw,
+ appear_parameters.key_top_as_floating, appear_parameters.enable_backspace_button,
+ appear_parameters.enable_return_button, appear_parameters.disable_cancel_button);
+
+ std::thread([this] { SubmitInlineText(u"yuzu"); }).detach();
+}
- out(parameters.initial_text);
+void DefaultSoftwareKeyboardApplet::HideInlineKeyboard() const {
+ LOG_WARNING(Service_AM,
+ "(STUBBED) called, backend requested to hide the inline software keyboard.");
}
-void DefaultSoftwareKeyboardApplet::SendTextCheckDialog(
- std::u16string error_message, std::function<void()> finished_check) const {
+void DefaultSoftwareKeyboardApplet::InlineTextChanged(InlineTextParameters text_parameters) const {
LOG_WARNING(Service_AM,
- "(STUBBED) called - Default fallback software keyboard does not support text "
- "check! (error_message={})",
- Common::UTF16ToUTF8(error_message));
- finished_check();
+ "(STUBBED) called, backend requested to change the inline keyboard text.");
+
+ LOG_INFO(Service_AM,
+ "\nInlineTextParameters:"
+ "\ninput_text={}"
+ "\ncursor_position={}",
+ Common::UTF16ToUTF8(text_parameters.input_text), text_parameters.cursor_position);
+
+ submit_inline_callback(Service::AM::Applets::SwkbdReplyType::ChangedString,
+ text_parameters.input_text, text_parameters.cursor_position);
+}
+
+void DefaultSoftwareKeyboardApplet::ExitKeyboard() const {
+ LOG_WARNING(Service_AM, "(STUBBED) called, backend requested to exit the software keyboard.");
}
+
+void DefaultSoftwareKeyboardApplet::SubmitNormalText(std::u16string text) const {
+ submit_normal_callback(Service::AM::Applets::SwkbdResult::Ok, text);
+}
+
+void DefaultSoftwareKeyboardApplet::SubmitInlineText(std::u16string_view text) const {
+ std::this_thread::sleep_for(std::chrono::milliseconds(500));
+
+ for (std::size_t index = 0; index < text.size(); ++index) {
+ submit_inline_callback(Service::AM::Applets::SwkbdReplyType::ChangedString,
+ std::u16string(text.data(), text.data() + index + 1),
+ static_cast<s32>(index) + 1);
+
+ std::this_thread::sleep_for(std::chrono::milliseconds(250));
+ }
+
+ submit_inline_callback(Service::AM::Applets::SwkbdReplyType::DecidedEnter, std::u16string(text),
+ static_cast<s32>(text.size()));
+}
+
} // 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 @@
-// Copyright 2018 yuzu emulator team
+// Copyright 2021 yuzu Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#pragma once
#include <functional>
-#include <optional>
-#include <string>
-#include "common/bit_field.h"
+#include <thread>
+
#include "common/common_types.h"
+#include "core/hle/service/am/applets/software_keyboard_types.h"
+
namespace Core::Frontend {
-struct SoftwareKeyboardParameters {
- std::u16string submit_text;
+
+struct KeyboardInitializeParameters {
+ std::u16string ok_text;
std::u16string header_text;
std::u16string sub_text;
std::u16string guide_text;
std::u16string initial_text;
- std::size_t max_length;
- bool password;
- bool cursor_at_beginning;
-
- union {
- u8 value;
-
- BitField<1, 1, u8> disable_space;
- BitField<2, 1, u8> disable_address;
- BitField<3, 1, u8> disable_percent;
- BitField<4, 1, u8> disable_slash;
- BitField<6, 1, u8> disable_number;
- BitField<7, 1, u8> disable_download_code;
- };
+ u32 max_text_length;
+ u32 min_text_length;
+ s32 initial_cursor_position;
+ Service::AM::Applets::SwkbdType type;
+ Service::AM::Applets::SwkbdPasswordMode password_mode;
+ Service::AM::Applets::SwkbdTextDrawType text_draw_type;
+ Service::AM::Applets::SwkbdKeyDisableFlags key_disable_flags;
+ bool use_blur_background;
+ bool enable_backspace_button;
+ bool enable_return_button;
+ bool disable_cancel_button;
+};
+
+struct InlineAppearParameters {
+ u32 max_text_length;
+ u32 min_text_length;
+ f32 key_top_scale_x;
+ f32 key_top_scale_y;
+ f32 key_top_translate_x;
+ f32 key_top_translate_y;
+ Service::AM::Applets::SwkbdType type;
+ Service::AM::Applets::SwkbdKeyDisableFlags key_disable_flags;
+ bool key_top_as_floating;
+ bool enable_backspace_button;
+ bool enable_return_button;
+ bool disable_cancel_button;
+};
+
+struct InlineTextParameters {
+ std::u16string input_text;
+ s32 cursor_position;
};
class SoftwareKeyboardApplet {
public:
virtual ~SoftwareKeyboardApplet();
- virtual void RequestText(std::function<void(std::optional<std::u16string>)> out,
- SoftwareKeyboardParameters parameters) const = 0;
- virtual void SendTextCheckDialog(std::u16string error_message,
- std::function<void()> finished_check) const = 0;
+ virtual void InitializeKeyboard(
+ bool is_inline, KeyboardInitializeParameters initialize_parameters,
+ std::function<void(Service::AM::Applets::SwkbdResult, std::u16string)>
+ submit_normal_callback_,
+ std::function<void(Service::AM::Applets::SwkbdReplyType, std::u16string, s32)>
+ submit_inline_callback_) = 0;
+
+ virtual void ShowNormalKeyboard() const = 0;
+
+ virtual void ShowTextCheckDialog(Service::AM::Applets::SwkbdTextCheckResult text_check_result,
+ std::u16string text_check_message) const = 0;
+
+ virtual void ShowInlineKeyboard(InlineAppearParameters appear_parameters) const = 0;
+
+ virtual void HideInlineKeyboard() const = 0;
+
+ virtual void InlineTextChanged(InlineTextParameters text_parameters) const = 0;
+
+ virtual void ExitKeyboard() const = 0;
};
class DefaultSoftwareKeyboardApplet final : public SoftwareKeyboardApplet {
public:
- void RequestText(std::function<void(std::optional<std::u16string>)> out,
- SoftwareKeyboardParameters parameters) const override;
- void SendTextCheckDialog(std::u16string error_message,
- std::function<void()> finished_check) const override;
+ ~DefaultSoftwareKeyboardApplet() override;
+
+ void InitializeKeyboard(
+ bool is_inline, KeyboardInitializeParameters initialize_parameters,
+ std::function<void(Service::AM::Applets::SwkbdResult, std::u16string)>
+ submit_normal_callback_,
+ std::function<void(Service::AM::Applets::SwkbdReplyType, std::u16string, s32)>
+ submit_inline_callback_) override;
+
+ void ShowNormalKeyboard() const override;
+
+ void ShowTextCheckDialog(Service::AM::Applets::SwkbdTextCheckResult text_check_result,
+ std::u16string text_check_message) const override;
+
+ void ShowInlineKeyboard(InlineAppearParameters appear_parameters) const override;
+
+ void HideInlineKeyboard() const override;
+
+ void InlineTextChanged(InlineTextParameters text_parameters) const override;
+
+ void ExitKeyboard() const override;
+
+private:
+ void SubmitNormalText(std::u16string text) const;
+ void SubmitInlineText(std::u16string_view text) const;
+
+ KeyboardInitializeParameters parameters;
+
+ mutable std::function<void(Service::AM::Applets::SwkbdResult, std::u16string)>
+ submit_normal_callback;
+ mutable std::function<void(Service::AM::Applets::SwkbdReplyType, std::u16string, s32)>
+ submit_inline_callback;
};
} // namespace Core::Frontend
diff --git a/src/core/frontend/emu_window.cpp b/src/core/frontend/emu_window.cpp
index ee7a58b1c..cff49899a 100644
--- a/src/core/frontend/emu_window.cpp
+++ b/src/core/frontend/emu_window.cpp
@@ -4,9 +4,9 @@
#include <cmath>
#include <mutex>
+#include "common/settings.h"
#include "core/frontend/emu_window.h"
#include "core/frontend/input.h"
-#include "core/settings.h"
namespace Core::Frontend {
@@ -60,23 +60,23 @@ EmuWindow::~EmuWindow() {
* @param framebuffer_y Framebuffer y-coordinate to check
* @return True if the coordinates are within the touchpad, otherwise false
*/
-static bool IsWithinTouchscreen(const Layout::FramebufferLayout& layout, unsigned framebuffer_x,
- unsigned framebuffer_y) {
+static bool IsWithinTouchscreen(const Layout::FramebufferLayout& layout, u32 framebuffer_x,
+ u32 framebuffer_y) {
return (framebuffer_y >= layout.screen.top && framebuffer_y < layout.screen.bottom &&
framebuffer_x >= layout.screen.left && framebuffer_x < layout.screen.right);
}
-std::tuple<unsigned, unsigned> EmuWindow::ClipToTouchScreen(unsigned new_x, unsigned new_y) const {
+std::pair<u32, u32> EmuWindow::ClipToTouchScreen(u32 new_x, u32 new_y) const {
new_x = std::max(new_x, framebuffer_layout.screen.left);
new_x = std::min(new_x, framebuffer_layout.screen.right - 1);
new_y = std::max(new_y, framebuffer_layout.screen.top);
new_y = std::min(new_y, framebuffer_layout.screen.bottom - 1);
- return std::make_tuple(new_x, new_y);
+ return std::make_pair(new_x, new_y);
}
-void EmuWindow::TouchPressed(unsigned framebuffer_x, unsigned framebuffer_y, std::size_t id) {
+void EmuWindow::TouchPressed(u32 framebuffer_x, u32 framebuffer_y, size_t id) {
if (!IsWithinTouchscreen(framebuffer_layout, framebuffer_x, framebuffer_y)) {
return;
}
@@ -95,7 +95,7 @@ void EmuWindow::TouchPressed(unsigned framebuffer_x, unsigned framebuffer_y, std
touch_state->status[id] = std::make_tuple(x, y, true);
}
-void EmuWindow::TouchReleased(std::size_t id) {
+void EmuWindow::TouchReleased(size_t id) {
if (id >= touch_state->status.size()) {
return;
}
@@ -103,20 +103,23 @@ void EmuWindow::TouchReleased(std::size_t id) {
touch_state->status[id] = std::make_tuple(0.0f, 0.0f, false);
}
-void EmuWindow::TouchMoved(unsigned framebuffer_x, unsigned framebuffer_y, std::size_t id) {
+void EmuWindow::TouchMoved(u32 framebuffer_x, u32 framebuffer_y, size_t id) {
if (id >= touch_state->status.size()) {
return;
}
- if (!std::get<2>(touch_state->status[id]))
+
+ if (!std::get<2>(touch_state->status[id])) {
return;
+ }
- if (!IsWithinTouchscreen(framebuffer_layout, framebuffer_x, framebuffer_y))
+ if (!IsWithinTouchscreen(framebuffer_layout, framebuffer_x, framebuffer_y)) {
std::tie(framebuffer_x, framebuffer_y) = ClipToTouchScreen(framebuffer_x, framebuffer_y);
+ }
TouchPressed(framebuffer_x, framebuffer_y, id);
}
-void EmuWindow::UpdateCurrentFramebufferLayout(unsigned width, unsigned height) {
+void EmuWindow::UpdateCurrentFramebufferLayout(u32 width, u32 height) {
NotifyFramebufferLayoutChanged(Layout::DefaultFrameLayout(width, height));
}
diff --git a/src/core/frontend/emu_window.h b/src/core/frontend/emu_window.h
index 2436c6580..076148698 100644
--- a/src/core/frontend/emu_window.h
+++ b/src/core/frontend/emu_window.h
@@ -82,7 +82,7 @@ public:
bool fullscreen = false;
int res_width = 0;
int res_height = 0;
- std::pair<unsigned, unsigned> min_client_area_size;
+ std::pair<u32, u32> min_client_area_size;
};
/// Data describing host window system information
@@ -119,13 +119,13 @@ public:
* @param framebuffer_y Framebuffer y-coordinate that was pressed
* @param id Touch event ID
*/
- void TouchPressed(unsigned framebuffer_x, unsigned framebuffer_y, std::size_t id);
+ void TouchPressed(u32 framebuffer_x, u32 framebuffer_y, size_t id);
/**
* Signal that a touch released event has occurred (e.g. mouse click released)
* @param id Touch event ID
*/
- void TouchReleased(std::size_t id);
+ void TouchReleased(size_t id);
/**
* Signal that a touch movement event has occurred (e.g. mouse was moved over the emu window)
@@ -133,7 +133,7 @@ public:
* @param framebuffer_y Framebuffer y-coordinate
* @param id Touch event ID
*/
- void TouchMoved(unsigned framebuffer_x, unsigned framebuffer_y, std::size_t id);
+ void TouchMoved(u32 framebuffer_x, u32 framebuffer_y, size_t id);
/**
* Returns currently active configuration.
@@ -173,7 +173,7 @@ public:
* Convenience method to update the current frame layout
* Read from the current settings to determine which layout to use.
*/
- void UpdateCurrentFramebufferLayout(unsigned width, unsigned height);
+ void UpdateCurrentFramebufferLayout(u32 width, u32 height);
protected:
explicit EmuWindow();
@@ -208,7 +208,7 @@ protected:
* Update internal client area size with the given parameter.
* @note EmuWindow implementations will usually use this in window resize event handlers.
*/
- void NotifyClientAreaSizeChanged(const std::pair<unsigned, unsigned>& size) {
+ void NotifyClientAreaSizeChanged(std::pair<u32, u32> size) {
client_area_width = size.first;
client_area_height = size.second;
}
@@ -221,14 +221,19 @@ private:
* For the request to be honored, EmuWindow implementations will usually reimplement this
* function.
*/
- virtual void OnMinimalClientAreaChangeRequest(std::pair<unsigned, unsigned>) {
+ virtual void OnMinimalClientAreaChangeRequest(std::pair<u32, u32>) {
// By default, ignore this request and do nothing.
}
+ /**
+ * Clip the provided coordinates to be inside the touchscreen area.
+ */
+ std::pair<u32, u32> ClipToTouchScreen(u32 new_x, u32 new_y) const;
+
Layout::FramebufferLayout framebuffer_layout; ///< Current framebuffer layout
- unsigned client_area_width; ///< Current client width, should be set by window impl.
- unsigned client_area_height; ///< Current client height, should be set by window impl.
+ u32 client_area_width; ///< Current client width, should be set by window impl.
+ u32 client_area_height; ///< Current client height, should be set by window impl.
WindowConfig config; ///< Internal configuration (changes pending for being applied in
/// ProcessConfigurationChanges)
@@ -236,11 +241,6 @@ private:
class TouchState;
std::shared_ptr<TouchState> touch_state;
-
- /**
- * Clip the provided coordinates to be inside the touchscreen area.
- */
- std::tuple<unsigned, unsigned> ClipToTouchScreen(unsigned new_x, unsigned new_y) const;
};
} // namespace Core::Frontend
diff --git a/src/core/frontend/framebuffer_layout.cpp b/src/core/frontend/framebuffer_layout.cpp
index b9a270a55..0832463d6 100644
--- a/src/core/frontend/framebuffer_layout.cpp
+++ b/src/core/frontend/framebuffer_layout.cpp
@@ -5,8 +5,8 @@
#include <cmath>
#include "common/assert.h"
+#include "common/settings.h"
#include "core/frontend/framebuffer_layout.h"
-#include "core/settings.h"
namespace Layout {
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)
: npad{system.ServiceManager()
.GetService<Service::HID::Hid>("hid")
->GetAppletResource()
- ->GetController<Service::HID::Controller_NPad>(Service::HID::HidController::NPad)} {}
+ ->GetController<Service::HID::Controller_NPad>(Service::HID::HidController::NPad)} {
+ ResetButtonStates();
+}
InputInterpreter::~InputInterpreter() = default;
@@ -25,6 +27,17 @@ void InputInterpreter::PollInput() {
button_states[current_index] = button_state;
}
+void InputInterpreter::ResetButtonStates() {
+ previous_index = 0;
+ current_index = 0;
+
+ button_states[0] = 0xFFFFFFFF;
+
+ for (std::size_t i = 1; i < button_states.size(); ++i) {
+ button_states[i] = 0;
+ }
+}
+
bool InputInterpreter::IsButtonPressed(HIDButton button) const {
return (button_states[current_index] & (1U << static_cast<u8>(button))) != 0;
}
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:
/// Gets a button state from HID and inserts it into the array of button states.
void PollInput();
+ /// Resets all the button states to their defaults.
+ void ResetButtonStates();
+
/**
* Checks whether the button is pressed.
*