Skip to content

Expose Steam Controller touchpads in Gamepad API#15378

Draft
Kuratius wants to merge 1 commit intolibsdl-org:mainfrom
Kuratius:wip-steamcontroller
Draft

Expose Steam Controller touchpads in Gamepad API#15378
Kuratius wants to merge 1 commit intolibsdl-org:mainfrom
Kuratius:wip-steamcontroller

Conversation

@Kuratius
Copy link
Copy Markdown

@Kuratius Kuratius commented Apr 13, 2026

Description

Adds the touchpads to the joystick object associated with the steam controller, and updates them when possible.

Existing Issue(s)

Fixes #15359

Should be checked by someone with more experience with the hardware who knows whether the pads are properly centered at (0,0) to decide whether it should be ~ or - for reporting the y-coordinate. The kernel driver does this differently from SDL, so there are two different implementations out there. Overflow is not a problem here.

The cast I added a comment to should probably be changed in the future, but that might be better as its own issue to discuss it. I do not believe it is safe to keep it as is because struct padding is platform dependent.

I copied the syntax for converting from int to sdl's float format from the steam deck code, though I'm not sure this is optimal. Probably depends on whether sdl can be used on soft-float devices. It should be reasonably trivial to keep it mostly as int or fixed point except for the last step when converting to float, even provided that you want the same rounding behavior.

@Kuratius
Copy link
Copy Markdown
Author

Kuratius commented Apr 13, 2026

Also something I noticed when comparing this to the kernel driver:
The data read via sdl has a noticeable jitter on it, the kernel driver does not. The input from /dev/input feels much cleaner to me. I don't know what causes this.

@Kuratius
Copy link
Copy Markdown
Author

Kuratius commented Apr 13, 2026

I made two videos with a green pixel showing the touchpad positions to show the jitter.

Kernel-Driver.mp4
SDL-Driver.mp4

The code I'm using to read the kernel driver is fairly simple.
During init

    int fd=-1;
    const char *device = "/dev/input/event26";
    fd = open(device, O_RDONLY | O_NONBLOCK);

    if (fd < 0)
    {
        printf("failed to open device %s\n", device);
        return 1;
    }

and then in the main loop:

#if USE_SDL
        bool isdown=0;
        if (SDL_GetGamepadTouchpadFinger(steamController, 
                                        0, 0, 
                                        &isdown, 
                                        &leftX, &leftY, &pressure))
        {
            if (isdown)
                drawControllerDot(xToWindow((leftX-0.5f)*(1<<16)),yToWindow((leftY-0.5f)*(1<<16)));

        }
        isdown=0;
        if (SDL_GetGamepadTouchpadFinger(steamController, 
                                        1, 0, 
                                        &isdown, 
                                        &rightX, &rightY, &pressure))
        {
            if (isdown)
                drawControllerDot(xToWindow((rightX-0.5f)*(1<<16))+(1280/2),yToWindow((rightY-0.5f)*(1<<16)));
        }
#else
        ssize_t n=-1;
        do
        {
            n = read(fd, &ev, sizeof(ev));
            if (n < (ssize_t)sizeof(ev))
            {
               break;
            }
            if (ev.type == EV_ABS)
            {
                switch (ev.code)
                {
                    case ABS_HAT0X:
                        leftX=ev.value;
                        break;
                    case ABS_HAT0Y:
                        leftY=ev.value;
                        break;
                    case ABS_RX:
                        rightX=ev.value;
                        break;
                    case ABS_RY:
                        rightY=ev.value;
                        break;
                }
            }
        } while(1);
        drawControllerDot(xToWindow(leftX),yToWindow(leftY));
        drawControllerDot(xToWindow(rightX)+(1280/2),yToWindow(rightY));

Note that you need avoid setting SDL_INIT_GAMEPAD, otherwise sdl blocks the /dev/input device.

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.

Expose Steam Controller touchpads

1 participant