Skip to content

pen: fix buttons incorrectly mapped on linux backends#15556

Open
LordCarve wants to merge 2 commits into
libsdl-org:mainfrom
LordCarve:14778-per-backend-pen-to-mouse-button
Open

pen: fix buttons incorrectly mapped on linux backends#15556
LordCarve wants to merge 2 commits into
libsdl-org:mainfrom
LordCarve:14778-per-backend-pen-to-mouse-button

Conversation

@LordCarve
Copy link
Copy Markdown

  • I confirm that I am the author of this code and release it to the SDL project under the Zlib license. This contribution does not contain code from other sources, including code generated by a Large Language Model ("AI").

Description

On linux backends (both X11 and Wayland) the pen-to-mouse remapping applied in SDL_pen.c confused RMB with MMB by hardcoding RMB to button 2 and MMB to button 3 (windows-canon).
Erroneous flows:

  • Button 2 (unix MMB) passed as pen button 1 mapped to SDL_BUTTON_RIGHT = 3 (unix RMB).
  • Button 3 (unix RMB) passed pen button 2 mapped to SDL_BUTTON_MIDDLE = 2 (unix MMB).

Since which pen button corresponds to which mouse button is backend-dependent, this information should be passed from backend into SDL_SendPenButton() and so its signature has been extended with Uint8 mouse_button (with button renamed to pen_button for clarity).

Now in pen-as-mouse scenarios backend has full control over which mouse button is used in mouse events, and it leverages that to pass the correct per-backend mouse buttons.

As a result, the bug of RMB<->MMB being mixed-up on linux backends is resolved.

For other backends I maintained the exact pen-to-mouse button mappings as they were before (including the edge-case of android's pen button 5 sending a pen event but explicitly not sending a mouse event). This is to avoid regression because I can't test any other backends.

I tested X11 and Wayland, and this addresses the underlying issue.

Existing Issue(s)

Fixes #14788

@Kontrabant Kontrabant requested a review from icculus May 11, 2026 16:40
@slouken slouken modified the milestones: 3.4.10, 3.6.0 May 11, 2026
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.

SDL3:Pen:Linux: RMB and MMB are confused

2 participants