From 45bcfa91798863e36cc6843aae1ac66ea2353b53 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Thu, 1 Feb 2024 23:25:43 +0100 Subject: [PATCH] (Android) Enabled the use of the OS-supplied virtual keyboard if the ES-DE virtual keyboard setting has been disabled --- es-app/src/guis/GuiMenu.cpp | 6 ++++++ es-app/src/main.cpp | 7 ++++++- es-core/src/components/TextEditComponent.cpp | 4 ++++ es-core/src/guis/GuiTextEditPopup.cpp | 11 +++++++++++ 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/es-app/src/guis/GuiMenu.cpp b/es-app/src/guis/GuiMenu.cpp index 6319081a3..4ffcbd49a 100644 --- a/es-app/src/guis/GuiMenu.cpp +++ b/es-app/src/guis/GuiMenu.cpp @@ -888,6 +888,12 @@ void GuiMenu::openUIOptions() Settings::getInstance()->setBool("VirtualKeyboard", virtualKeyboard->getState()); s->setNeedsSaving(); s->setInvalidateCachedBackground(); +#if defined(__ANDROID__) + if (Settings::getInstance()->getBool("VirtualKeyboard")) + SDL_SetHint(SDL_HINT_ENABLE_SCREEN_KEYBOARD, "0"); + else + SDL_SetHint(SDL_HINT_ENABLE_SCREEN_KEYBOARD, "1"); +#endif } }); diff --git a/es-app/src/main.cpp b/es-app/src/main.cpp index a46a1568a..e2b0ae1ce 100644 --- a/es-app/src/main.cpp +++ b/es-app/src/main.cpp @@ -988,7 +988,12 @@ int main(int argc, char* argv[]) LOG(LogInfo) << "SDL version: " << std::to_string(version.major) << "." << std::to_string(version.minor) << "." << std::to_string(version.patch); -#if !defined(__ANDROID__) +#if defined(__ANDROID__) + if (Settings::getInstance()->getBool("VirtualKeyboard")) + SDL_SetHint(SDL_HINT_ENABLE_SCREEN_KEYBOARD, "0"); + else + SDL_SetHint(SDL_HINT_ENABLE_SCREEN_KEYBOARD, "1"); +#else if (version.major > 2 || (version.major == 2 && version.minor >= 28)) { // This will prevent the popup virtual keyboard of any handheld device from being // automatically displayed on top of the ES-DE virtual keyboard. diff --git a/es-core/src/components/TextEditComponent.cpp b/es-core/src/components/TextEditComponent.cpp index d58ee8499..1bf67ad1b 100644 --- a/es-core/src/components/TextEditComponent.cpp +++ b/es-core/src/components/TextEditComponent.cpp @@ -79,8 +79,10 @@ void TextEditComponent::setValue(const std::string& val) void TextEditComponent::textInput(const std::string& text, const bool pasting) { +#if !defined(__ANDROID__) if (mMaskInput && !pasting) return; +#endif // Allow pasting up to a reasonable max clipboard size. if (pasting && text.length() > (isMultiline() ? 16384 : 300)) @@ -197,11 +199,13 @@ bool TextEditComponent::input(InputConfig* config, Input input) } return true; } +#if !defined(__ANDROID__) else if (input.id == SDLK_BACKSPACE) { mMaskInput = false; textInput("\b"); return true; } +#endif } if (cursorLeft || cursorRight) { diff --git a/es-core/src/guis/GuiTextEditPopup.cpp b/es-core/src/guis/GuiTextEditPopup.cpp index 7f975f3c9..b86dc858f 100644 --- a/es-core/src/guis/GuiTextEditPopup.cpp +++ b/es-core/src/guis/GuiTextEditPopup.cpp @@ -115,16 +115,27 @@ GuiTextEditPopup::GuiTextEditPopup(const HelpStyle& helpstyle, setSize(windowWidth, mTitle->getFont()->getHeight() + textHeight + mButtonGrid->getSize().y + mButtonGrid->getSize().y * 1.85f); +#if defined(__ANDROID__) + setPosition((Renderer::getScreenWidth() - mSize.x) / 2.0f, + Font::get(FONT_SIZE_LARGE_FIXED)->getLetterHeight()); +#else setPosition((Renderer::getScreenWidth() - mSize.x) / 2.0f, (Renderer::getScreenHeight() - mSize.y) / 2.0f); +#endif } else { float width = glm::clamp(0.54f * aspectValue, 0.20f, 0.70f) * Renderer::getScreenWidth(); setSize(width, mTitle->getFont()->getHeight() + textHeight + mButtonGrid->getSize().y + mButtonGrid->getSize().y / 2.0f); + +#if defined(__ANDROID__) + setPosition((Renderer::getScreenWidth() - mSize.x) / 2.0f, + Font::get(FONT_SIZE_LARGE_FIXED)->getLetterHeight()); +#else setPosition((Renderer::getScreenWidth() - mSize.x) / 2.0f, (Renderer::getScreenHeight() - mSize.y) / 2.0f); +#endif } if (!multiLine)