From a7215af23c89a9d99339b40ae77dc6cc0a2e4a21 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Tue, 6 Feb 2024 22:38:15 +0100 Subject: [PATCH] (Android) Added a small input blocking delay when entering the foreground to prevent unintended button presses --- es-app/src/main.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/es-app/src/main.cpp b/es-app/src/main.cpp index 50ebefdfb..7713fedab 100644 --- a/es-app/src/main.cpp +++ b/es-app/src/main.cpp @@ -62,6 +62,11 @@ namespace Window* window {nullptr}; int lastTime {0}; +#if defined(__ANDROID__) + int inputBlockTime {0}; + bool blockInput {false}; +#endif + #if defined(APPLICATION_UPDATER) bool noUpdateCheck {false}; #endif @@ -496,6 +501,15 @@ void applicationLoop() #endif if (SDL_PollEvent(&event)) { do { +#if defined(__ANDROID__) + // Prevent that button presses get registered immediately when entering the + // foreground (which most commonly mean we're returning from a game). + if (event.type == SDL_APP_WILLENTERFOREGROUND) { + blockInput = true; + inputBlockTime = 0; + window->setBlockInput(true); + } +#endif InputManager::getInstance().parseEvent(event); if (event.type == SDL_QUIT) @@ -515,6 +529,16 @@ void applicationLoop() if (deltaTime < 0) deltaTime = 1000; +#if defined(__ANDROID__) + if (blockInput) { + inputBlockTime += deltaTime; + if (inputBlockTime > 300) { + inputBlockTime = 0; + blockInput = false; + window->setBlockInput(false); + } + } +#endif window->update(deltaTime); window->render();