Show the on-screen keyboard only while an edit line has focus

SDL_StartTextInput was called once for the whole session, which keeps the
Android soft keyboard over the game. Where SDL reports on-screen keyboard
support, the frame loop now starts/stops text input with the original
EditLine focus (ime.EnableCaptureInput/DisableCaptureInput in ui.py), the
in-game chat and the dev login view. Desktop keeps text input always on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-10-12 18:55:51 +09:00
co-authored by Claude Opus 5.5
parent b0044c9097
commit 4b8425c64b
+14 -1
View File
@@ -386,7 +386,10 @@ int main(int argc, char** argv) {
SDL_SetRenderLogicalPresentation(renderer.get(), screen_width, screen_height, SDL_LOGICAL_PRESENTATION_LETTERBOX);
// One pacing source: software caps must not also wait on the display refresh.
SDL_SetRenderVSync(renderer.get(), fps_cap > 0 ? 0 : 1);
SDL_StartTextInput(window.get());
// Desktop: text input stays on for the whole session, as on Windows. Phones would keep the
// on-screen keyboard covering the game, so the frame loop toggles it with edit focus instead.
[[maybe_unused]] const bool screen_keyboard = SDL_HasScreenKeyboardSupport();
if (!screen_keyboard) SDL_StartTextInput(window.get());
float dpi_scale = SDL_GetWindowPixelDensity(window.get());
SDL_Log("AVA2 host started: platform=%s GPU=%s Retina_DPI=%.2fx FPS_Cap=%d RenderScale=%.2f",
SDL_GetPlatform(), SDL_GetGPUDeviceDriver(gpu.get()), dpi_scale, fps_cap, render_scale);
@@ -1211,6 +1214,16 @@ const auto profileActiveStart = std::chrono::steady_clock::now();
active_map_objects = ava2::CPythonBackground::Instance().GetMapObjects();
}
}
#endif
#ifdef AVA2_HAS_PYTHON
// On-screen keyboards appear only while an edit line captures text (ime.EnableCaptureInput
// from the original ui.py), the in-game chat is open or the dev login view is editing.
if (screen_keyboard) {
const bool want = ava2::IME_IsCaptureInput() || chat_input_active
|| (!view_script.empty() && snapshot.phase == "login");
if (want != SDL_TextInputActive(window.get()))
want ? SDL_StartTextInput(window.get()) : SDL_StopTextInput(window.get());
}
#endif
SDL_Event event;
while (SDL_PollEvent(&event)) {