diff --git a/src/libretro_core.cpp b/src/libretro_core.cpp index 460b6bb03..5fab1be6a 100644 --- a/src/libretro_core.cpp +++ b/src/libretro_core.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include @@ -20,6 +21,10 @@ static std::filesystem::path savePath; static std::string touchScreenMode; static bool renderTouchScreen; +static auto cursorTimeout = 0; +static auto cursorMovedAt = std::chrono::steady_clock::now(); +static bool cursorVisible = false; + static bool screenTouched; static int lastMouseX; static int lastMouseY; @@ -204,6 +209,7 @@ static void configInit() { {"panda3ds_ubershader_lighting_override_threshold", "Light threshold for forcing shadergen; 1|2|3|4|5|6|7|8"}, {"panda3ds_touchscreen_mode", "Touchscreen touch mode; Auto|Pointer|Joystick|None"}, {"panda3ds_render_touchscreen", "Render touchscreen pointer; disabled|enabled"}, + {"panda3ds_hide_cursor_timeout", "Hide touchScreen pointer timeout; 3 Seconds|5 Seconds|10 Seconds|15 Seconds|20 Seconds|Never Hide"}, {nullptr, nullptr}, }; @@ -230,6 +236,7 @@ static void configUpdate() { touchScreenMode = fetchVariable("panda3ds_touchscreen_mode", "Auto"); renderTouchScreen = fetchVariableBool("panda3ds_render_touchscreen", false); + cursorTimeout = fetchVariableInt("panda3ds_hide_cursor_timeout", 3); config.save(); } @@ -243,6 +250,21 @@ static void configCheckVariables() { } } +static void updateCursorVisibility() { + if (renderTouchScreen && cursorTimeout) { + if (cursorVisible) { + auto current = std::chrono::steady_clock::now(); + auto elapsed = std::chrono::duration_cast(current - cursorMovedAt).count(); + + if (elapsed >= cursorTimeout) { + cursorVisible = false; + } + } + } else { + cursorVisible = true; + } +} + void CursorRenderer::init() { #ifdef USING_GLES static const std::string version = R"( @@ -411,6 +433,7 @@ void retro_reset() { void retro_run() { configCheckVariables(); + updateCursorVisibility(); renderer->setFBO(hwRender.get_current_framebuffer()); renderer->resetStateManager(); @@ -486,6 +509,11 @@ void retro_run() { } } + if (cursorTimeout && (pointerX != touchX || pointerY != touchY)) { + cursorVisible = true; + cursorMovedAt = std::chrono::steady_clock::now(); + } + touchX = std::clamp(pointerX, 0, (int)(emulator->width - (offsetX * 2))); touchY = std::clamp(pointerY, 0, (int)(emulator->height - offsetY));