Skip to content

Feature: Native 1:1 PS4 Touchpad Mapping for DS Touchscreen#2682

Open
Appltron wants to merge 4 commits into
melonDS-emu:masterfrom
Appltron:master
Open

Feature: Native 1:1 PS4 Touchpad Mapping for DS Touchscreen#2682
Appltron wants to merge 4 commits into
melonDS-emu:masterfrom
Appltron:master

Conversation

@Appltron

@Appltron Appltron commented Jun 5, 2026

Copy link
Copy Markdown

The Concept
Playing touch-heavy games on a monitor can feel clunky when using a mouse to mimic quick stylus taps. This PR introduces native, absolute 1:1 coordinate mapping using a DualShock 4 controller's built-in touchpad via Bluetooth.

This implementation takes heavy inspiration from 3DS emulation fork Azahar, which has proven how seamless and natural absolute touchpad integration feels for dual-screen emulation.

Implementation Details
Instead of building a complex event loop, this leverages SDL2's internal state tracker directly within the EmuThread.cpp loop, right before emuInstance->isTouching is evaluated:

Uses SDL_GameControllerGetTouchpadFinger() to instantly query the absolute position of the primary finger.

Converts SDL's normalized decimal coordinates (0.0 to 1.0) into the rigid 256x192 pixel space of the DS bottom screen using standard aspect compression.

Automatically clamps boundaries to prevent out-of-bounds emulator crashes.

Seamlessly hands control back to the mouse upon finger lift (padWasTouching flag) so users can switch between mouse and touchpad dynamically.

Testing Environment

OS: Windows 11

Hardware: HP ProBook 445 G8 (Ryzen 5 5600U, 16GB RAM)

Controller: Original DualShock 4 via Bluetooth

Build Toolchain: MSYS2 / MinGW-w64 (Compiled via CMake + Ninja)

A Note on Development
Transparency note: I am not a career C++ software engineer, so I utilized an AI assistant to help draft the precise SDL2 API calls and coordinate math. However, I have fully compiled the source code from scratch, resolved the MSYS2 toolchain dependencies, and extensively tested the compiled .exe on hardware to verify the touch inputs register flawlessly without performance dips.

Comment thread src/frontend/qt_sdl/main.cpp Outdated
{
printf("SDL couldn't init rumble\n");
}
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS4, "1");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is redundant. The default is the value of [SDL_HINT_JOYSTICK_HIDAPI](https://wiki.libsdl.org/SDL2/SDL_HINT_JOYSTICK_HIDAPI) => "1": HIDAPI drivers are used (the default).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for pointing this out. I was unaware it was the default behavior. I have removed the redundant line in the latest commit.

Comment thread src/frontend/qt_sdl/EmuThread.cpp Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants