Skip to content

Commit 22f533d

Browse files
committed
Libretro: Add support for cursor auto-hide
1 parent 7a88ba9 commit 22f533d

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/libretro_core.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <stdexcept>
22
#include <cstdio>
33
#include <regex>
4+
#include <chrono>
45

56
#include <libretro.h>
67

@@ -20,6 +21,10 @@ static std::filesystem::path savePath;
2021
static std::string touchScreenMode;
2122
static bool renderTouchScreen;
2223

24+
static auto cursorTimeout = 0;
25+
static auto cursorMovedAt = std::chrono::steady_clock::now();
26+
static bool cursorVisible = false;
27+
2328
static bool screenTouched;
2429
static int lastMouseX;
2530
static int lastMouseY;
@@ -209,6 +214,7 @@ static void configInit() {
209214
{"panda3ds_use_charger", "Charger plugged; enabled|disabled"},
210215
{"panda3ds_touchscreen_mode", "Touchscreen touch mode; Auto|Pointer|Joystick|None"},
211216
{"panda3ds_render_touchscreen", "Render touchscreen pointer; disabled|enabled"},
217+
{"panda3ds_hide_cursor_timeout", "Hide touchScreen pointer timeout; 3 Seconds|5 Seconds|10 Seconds|15 Seconds|20 Seconds|Never Hide"},
212218
{nullptr, nullptr},
213219
};
214220

@@ -241,6 +247,7 @@ static void configUpdate() {
241247

242248
touchScreenMode = fetchVariable("panda3ds_touchscreen_mode", "Auto");
243249
renderTouchScreen = fetchVariableBool("panda3ds_render_touchscreen", false);
250+
cursorTimeout = fetchVariableInt("panda3ds_hide_cursor_timeout", 3);
244251

245252
// Handle any settings that might need the emulator core to be notified when they're changed, and save the config.
246253
emulator->setAudioEnabled(config.audioEnabled);
@@ -257,6 +264,21 @@ static void configCheckVariables() {
257264
}
258265
}
259266

267+
static void updateCursorVisibility() {
268+
if (renderTouchScreen && cursorTimeout) {
269+
if (cursorVisible) {
270+
auto current = std::chrono::steady_clock::now();
271+
auto elapsed = std::chrono::duration_cast<std::chrono::seconds>(current - cursorMovedAt).count();
272+
273+
if (elapsed >= cursorTimeout) {
274+
cursorVisible = false;
275+
}
276+
}
277+
} else {
278+
cursorVisible = true;
279+
}
280+
}
281+
260282
void CursorRenderer::init() {
261283
#ifdef USING_GLES
262284
static const std::string version = R"(
@@ -425,6 +447,7 @@ void retro_reset() {
425447

426448
void retro_run() {
427449
configCheckVariables();
450+
updateCursorVisibility();
428451

429452
renderer->setFBO(hwRender.get_current_framebuffer());
430453
renderer->resetStateManager();
@@ -500,6 +523,11 @@ void retro_run() {
500523
}
501524
}
502525

526+
if (cursorTimeout && (pointerX != touchX || pointerY != touchY)) {
527+
cursorVisible = true;
528+
cursorMovedAt = std::chrono::steady_clock::now();
529+
}
530+
503531
touchX = std::clamp(pointerX, 0, (int)(emulator->width - (offsetX * 2)));
504532
touchY = std::clamp(pointerY, 0, (int)(emulator->height - offsetY));
505533

0 commit comments

Comments
 (0)