Merge pull request #3850 from zhaowenlan1779/swkbd
applets/swkbd: Software Keyboard Implementation
This commit is contained in:
commit
bf6da61da5
16 changed files with 774 additions and 34 deletions
|
@ -2,6 +2,7 @@
|
|||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include "common/assert.h"
|
||||
|
@ -69,22 +70,51 @@ ResultCode SoftwareKeyboard::StartImpl(Service::APT::AppletStartupParameter cons
|
|||
|
||||
DrawScreenKeyboard();
|
||||
|
||||
using namespace Frontend;
|
||||
frontend_applet = GetRegisteredSoftwareKeyboard();
|
||||
if (frontend_applet) {
|
||||
KeyboardConfig frontend_config = ToFrontendConfig(config);
|
||||
frontend_applet->Setup(&frontend_config);
|
||||
}
|
||||
|
||||
is_running = true;
|
||||
return RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
void SoftwareKeyboard::Update() {
|
||||
// TODO(Subv): Handle input using the touch events from the HID module
|
||||
|
||||
// TODO(Subv): Remove this hardcoded text
|
||||
std::u16string text = Common::UTF8ToUTF16("Citra");
|
||||
using namespace Frontend;
|
||||
KeyboardData data(*frontend_applet->ReceiveData());
|
||||
std::u16string text = Common::UTF8ToUTF16(data.text);
|
||||
memcpy(text_memory->GetPointer(), text.c_str(), text.length() * sizeof(char16_t));
|
||||
switch (config.num_buttons_m1) {
|
||||
case SoftwareKeyboardButtonConfig::SingleButton:
|
||||
config.return_code = SoftwareKeyboardResult::D0Click;
|
||||
break;
|
||||
case SoftwareKeyboardButtonConfig::DualButton:
|
||||
if (data.button == 0)
|
||||
config.return_code = SoftwareKeyboardResult::D1Click0;
|
||||
else
|
||||
config.return_code = SoftwareKeyboardResult::D1Click1;
|
||||
break;
|
||||
case SoftwareKeyboardButtonConfig::TripleButton:
|
||||
if (data.button == 0)
|
||||
config.return_code = SoftwareKeyboardResult::D2Click0;
|
||||
else if (data.button == 1)
|
||||
config.return_code = SoftwareKeyboardResult::D2Click1;
|
||||
else
|
||||
config.return_code = SoftwareKeyboardResult::D2Click2;
|
||||
break;
|
||||
case SoftwareKeyboardButtonConfig::NoButton:
|
||||
// TODO: find out what is actually returned
|
||||
config.return_code = SoftwareKeyboardResult::None;
|
||||
break;
|
||||
default:
|
||||
LOG_CRITICAL(Applet_SWKBD, "Unknown button config {}",
|
||||
static_cast<int>(config.num_buttons_m1));
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
// TODO(Subv): Ask for input and write it to the shared memory
|
||||
// TODO(Subv): Find out what are the possible values for the return code,
|
||||
// some games seem to check for a hardcoded 2
|
||||
config.return_code = 2;
|
||||
config.text_length = 6;
|
||||
config.text_length = static_cast<u16>(text.size());
|
||||
config.text_offset = 0;
|
||||
|
||||
// TODO(Subv): We're finalizing the applet immediately after it's started,
|
||||
|
@ -93,13 +123,7 @@ void SoftwareKeyboard::Update() {
|
|||
}
|
||||
|
||||
void SoftwareKeyboard::DrawScreenKeyboard() {
|
||||
auto bottom_screen = Service::GSP::GetFrameBufferInfo(0, 1);
|
||||
auto info = bottom_screen->framebuffer_info[bottom_screen->index];
|
||||
|
||||
// TODO(Subv): Draw the HLE keyboard, for now just zero-fill the framebuffer
|
||||
Memory::ZeroBlock(info.address_left, info.stride * 320);
|
||||
|
||||
Service::GSP::SetBufferSwap(1, info);
|
||||
// TODO(Subv): Draw the HLE keyboard, for now just do nothing
|
||||
}
|
||||
|
||||
void SoftwareKeyboard::Finalize() {
|
||||
|
@ -114,5 +138,44 @@ void SoftwareKeyboard::Finalize() {
|
|||
|
||||
is_running = false;
|
||||
}
|
||||
|
||||
Frontend::KeyboardConfig SoftwareKeyboard::ToFrontendConfig(
|
||||
const SoftwareKeyboardConfig& config) const {
|
||||
using namespace Frontend;
|
||||
KeyboardConfig frontend_config;
|
||||
frontend_config.button_config = static_cast<ButtonConfig>(config.num_buttons_m1);
|
||||
frontend_config.accept_mode = static_cast<AcceptedInput>(config.valid_input);
|
||||
frontend_config.multiline_mode = config.multiline;
|
||||
frontend_config.max_text_length = config.max_text_length;
|
||||
frontend_config.max_digits = config.max_digits;
|
||||
std::u16string buffer(config.hint_text.size(), 0);
|
||||
std::memcpy(buffer.data(), config.hint_text.data(), config.hint_text.size() * sizeof(u16));
|
||||
frontend_config.hint_text = Common::UTF16ToUTF8(buffer);
|
||||
frontend_config.has_custom_button_text =
|
||||
!std::all_of(config.button_text.begin(), config.button_text.end(),
|
||||
[](std::array<u16, HLE::Applets::MAX_BUTTON_TEXT_LEN + 1> x) {
|
||||
return std::all_of(x.begin(), x.end(), [](u16 x) { return x == 0; });
|
||||
});
|
||||
if (frontend_config.has_custom_button_text) {
|
||||
for (const auto& text : config.button_text) {
|
||||
buffer.resize(text.size());
|
||||
std::memcpy(buffer.data(), text.data(), text.size() * sizeof(u16));
|
||||
frontend_config.button_text.push_back(Common::UTF16ToUTF8(buffer));
|
||||
}
|
||||
}
|
||||
frontend_config.filters.prevent_digit =
|
||||
static_cast<bool>(config.filter_flags & SoftwareKeyboardFilter::Digits);
|
||||
frontend_config.filters.prevent_at =
|
||||
static_cast<bool>(config.filter_flags & SoftwareKeyboardFilter::At);
|
||||
frontend_config.filters.prevent_percent =
|
||||
static_cast<bool>(config.filter_flags & SoftwareKeyboardFilter::Percent);
|
||||
frontend_config.filters.prevent_backslash =
|
||||
static_cast<bool>(config.filter_flags & SoftwareKeyboardFilter::Backslash);
|
||||
frontend_config.filters.prevent_profanity =
|
||||
static_cast<bool>(config.filter_flags & SoftwareKeyboardFilter::Profanity);
|
||||
frontend_config.filters.enable_callback =
|
||||
static_cast<bool>(config.filter_flags & SoftwareKeyboardFilter::Callback);
|
||||
return frontend_config;
|
||||
}
|
||||
} // namespace Applets
|
||||
} // namespace HLE
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include "common/common_funcs.h"
|
||||
#include "common/common_types.h"
|
||||
#include "core/frontend/applets/swkbd.h"
|
||||
#include "core/hle/applets/applet.h"
|
||||
#include "core/hle/kernel/kernel.h"
|
||||
#include "core/hle/kernel/shared_memory.h"
|
||||
|
@ -15,33 +16,156 @@
|
|||
namespace HLE {
|
||||
namespace Applets {
|
||||
|
||||
/// Maximum number of buttons that can be in the keyboard.
|
||||
constexpr int MAX_BUTTON = 3;
|
||||
/// Maximum button text length, in UTF-16 code units.
|
||||
constexpr int MAX_BUTTON_TEXT_LEN = 16;
|
||||
/// Maximum hint text length, in UTF-16 code units.
|
||||
constexpr int MAX_HINT_TEXT_LEN = 64;
|
||||
/// Maximum filter callback error message length, in UTF-16 code units.
|
||||
constexpr int MAX_CALLBACK_MSG_LEN = 256;
|
||||
|
||||
/// Keyboard types
|
||||
enum class SoftwareKeyboardType : u32 {
|
||||
Normal, ///< Normal keyboard with several pages (QWERTY/accents/symbol/mobile)
|
||||
QWERTY, ///< QWERTY keyboard only.
|
||||
NumPad, ///< Number pad.
|
||||
Western, ///< On JPN systems, a text keyboard without Japanese input capabilities,
|
||||
/// otherwise same as SWKBD_TYPE_NORMAL.
|
||||
};
|
||||
|
||||
/// Keyboard dialog buttons.
|
||||
enum class SoftwareKeyboardButtonConfig : u32 {
|
||||
SingleButton, ///< Ok button
|
||||
DualButton, ///< Cancel | Ok buttons
|
||||
TripleButton, ///< Cancel | I Forgot | Ok buttons
|
||||
NoButton, ///< No button (returned by swkbdInputText in special cases)
|
||||
};
|
||||
|
||||
/// Accepted input types.
|
||||
enum class SoftwareKeyboardValidInput : u32 {
|
||||
Anything, ///< All inputs are accepted.
|
||||
NotEmpty, ///< Empty inputs are not accepted.
|
||||
NotEmptyNotBlank, ///< Empty or blank inputs (consisting solely of whitespace) are not
|
||||
/// accepted.
|
||||
NotBlank, ///< Blank inputs (consisting solely of whitespace) are not accepted, but empty
|
||||
/// inputs are.
|
||||
FixedLen, ///< The input must have a fixed length (specified by maxTextLength in
|
||||
/// swkbdInit).
|
||||
};
|
||||
|
||||
/// Keyboard password modes.
|
||||
enum class SoftwareKeyboardPasswordMode : u32 {
|
||||
None, ///< Characters are not concealed.
|
||||
Hide, ///< Characters are concealed immediately.
|
||||
HideDelay, ///< Characters are concealed a second after they've been typed.
|
||||
};
|
||||
|
||||
/// Keyboard input filtering flags. Allows the caller to specify what input is explicitly not
|
||||
/// allowed
|
||||
namespace SoftwareKeyboardFilter {
|
||||
enum Filter {
|
||||
Digits = 1, ///< Disallow the use of more than a certain number of digits (0 or more)
|
||||
At = 1 << 1, ///< Disallow the use of the @ sign.
|
||||
Percent = 1 << 2, ///< Disallow the use of the % sign.
|
||||
Backslash = 1 << 3, ///< Disallow the use of the \ sign.
|
||||
Profanity = 1 << 4, ///< Disallow profanity using Nintendo's profanity filter.
|
||||
Callback = 1 << 5, ///< Use a callback in order to check the input.
|
||||
};
|
||||
} // namespace SoftwareKeyboardFilter
|
||||
|
||||
/// Keyboard features.
|
||||
namespace SoftwareKeyboardFeature {
|
||||
enum Feature {
|
||||
Parental = 1, ///< Parental PIN mode.
|
||||
DarkenTopScreen = 1 << 1, ///< Darken the top screen when the keyboard is shown.
|
||||
PredictiveInput =
|
||||
1 << 2, ///< Enable predictive input (necessary for Kanji input in JPN systems).
|
||||
Multiline = 1 << 3, ///< Enable multiline input.
|
||||
FixedWidth = 1 << 4, ///< Enable fixed-width mode.
|
||||
AllowHome = 1 << 5, ///< Allow the usage of the HOME button.
|
||||
AllowReset = 1 << 6, ///< Allow the usage of a software-reset combination.
|
||||
AllowPower = 1 << 7, ///< Allow the usage of the POWER button.
|
||||
DefaultQWERTY = 1 << 9, ///< Default to the QWERTY page when the keyboard is shown.
|
||||
};
|
||||
} // namespace SoftwareKeyboardFeature
|
||||
|
||||
/// Keyboard filter callback return values.
|
||||
enum class SoftwareKeyboardCallbackResult : u32 {
|
||||
OK, ///< Specifies that the input is valid.
|
||||
Close, ///< Displays an error message, then closes the keyboard.
|
||||
Continue, ///< Displays an error message and continues displaying the keyboard.
|
||||
};
|
||||
|
||||
/// Keyboard return values.
|
||||
enum class SoftwareKeyboardResult : s32 {
|
||||
None = -1, ///< Dummy/unused.
|
||||
InvalidInput = -2, ///< Invalid parameters to swkbd.
|
||||
OutOfMem = -3, ///< Out of memory.
|
||||
|
||||
D0Click = 0, ///< The button was clicked in 1-button dialogs.
|
||||
D1Click0, ///< The left button was clicked in 2-button dialogs.
|
||||
D1Click1, ///< The right button was clicked in 2-button dialogs.
|
||||
D2Click0, ///< The left button was clicked in 3-button dialogs.
|
||||
D2Click1, ///< The middle button was clicked in 3-button dialogs.
|
||||
D2Click2, ///< The right button was clicked in 3-button dialogs.
|
||||
|
||||
HomePressed = 10, ///< The HOME button was pressed.
|
||||
ResetPressed, ///< The soft-reset key combination was pressed.
|
||||
PowerPressed, ///< The POWER button was pressed.
|
||||
|
||||
ParentalOK = 20, ///< The parental PIN was verified successfully.
|
||||
ParentalFail, ///< The parental PIN was incorrect.
|
||||
|
||||
BannedInput = 30, ///< The filter callback returned SoftwareKeyboardCallback::CLOSE.
|
||||
};
|
||||
|
||||
struct SoftwareKeyboardConfig {
|
||||
INSERT_PADDING_WORDS(0x8);
|
||||
|
||||
u16 max_text_length; ///< Maximum length of the input text
|
||||
|
||||
INSERT_PADDING_BYTES(0x6E);
|
||||
|
||||
char16_t display_text[65]; ///< Text to display when asking the user for input
|
||||
|
||||
INSERT_PADDING_BYTES(0xE);
|
||||
|
||||
u32 default_text_offset; ///< Offset of the default text in the output SharedMemory
|
||||
|
||||
INSERT_PADDING_WORDS(0x3);
|
||||
SoftwareKeyboardType type;
|
||||
SoftwareKeyboardButtonConfig num_buttons_m1;
|
||||
SoftwareKeyboardValidInput valid_input;
|
||||
SoftwareKeyboardPasswordMode password_mode;
|
||||
s32 is_parental_screen;
|
||||
s32 darken_top_screen;
|
||||
u32 filter_flags;
|
||||
u32 save_state_flags;
|
||||
u16 max_text_length;
|
||||
u16 dict_word_count;
|
||||
u16 max_digits;
|
||||
std::array<std::array<u16, MAX_BUTTON_TEXT_LEN + 1>, MAX_BUTTON> button_text;
|
||||
std::array<u16, 2> numpad_keys;
|
||||
std::array<u16, MAX_HINT_TEXT_LEN + 1>
|
||||
hint_text; ///< Text to display when asking the user for input
|
||||
bool predictive_input;
|
||||
bool multiline;
|
||||
bool fixed_width;
|
||||
bool allow_home;
|
||||
bool allow_reset;
|
||||
bool allow_power;
|
||||
bool unknown;
|
||||
bool default_qwerty;
|
||||
std::array<bool, 4> button_submits_text;
|
||||
u16 language;
|
||||
|
||||
u32 initial_text_offset; ///< Offset of the default text in the output SharedMemory
|
||||
u32 dict_offset;
|
||||
u32 initial_status_offset;
|
||||
u32 initial_learning_offset;
|
||||
u32 shared_memory_size; ///< Size of the SharedMemory
|
||||
u32 version;
|
||||
|
||||
INSERT_PADDING_WORDS(0x1);
|
||||
SoftwareKeyboardResult return_code;
|
||||
|
||||
u32 return_code; ///< Return code of the SoftwareKeyboard, usually 2, other values are unknown
|
||||
|
||||
INSERT_PADDING_WORDS(0x2);
|
||||
u32 status_offset;
|
||||
u32 learning_offset;
|
||||
|
||||
u32 text_offset; ///< Offset in the SharedMemory where the output text starts
|
||||
u16 text_length; ///< Length in characters of the output text
|
||||
|
||||
INSERT_PADDING_BYTES(0x2B6);
|
||||
int callback_result;
|
||||
std::array<u16, MAX_CALLBACK_MSG_LEN + 1> callback_msg;
|
||||
bool skip_at_check;
|
||||
INSERT_PADDING_BYTES(0xAB);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -71,6 +195,8 @@ public:
|
|||
void Finalize();
|
||||
|
||||
private:
|
||||
Frontend::KeyboardConfig ToFrontendConfig(const SoftwareKeyboardConfig& config) const;
|
||||
|
||||
/// This SharedMemory will be created when we receive the LibAppJustStarted message.
|
||||
/// It holds the framebuffer info retrieved by the application with
|
||||
/// GSPGPU::ImportDisplayCaptureInfo
|
||||
|
@ -81,6 +207,8 @@ private:
|
|||
|
||||
/// Configuration of this instance of the SoftwareKeyboard, as received from the application
|
||||
SoftwareKeyboardConfig config;
|
||||
|
||||
std::shared_ptr<Frontend::SoftwareKeyboard> frontend_applet;
|
||||
};
|
||||
} // namespace Applets
|
||||
} // namespace HLE
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue