We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 5272

Summary: [PATCH] Windows: Switching left/right mouse buttons doesn't work in raw input mode
Product: SDL Reporter: Cameron Gutman <cameron.gutman>
Component: videoAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: sezeroz
Version: HG 2.0   
Hardware: x86   
OS: Windows 10   
Attachments: Patch

Description Cameron Gutman 2020-08-26 04:23:41 UTC
When I switch my left and right mouse buttons to use a left-handed mouse, SDL doesn't consistently report the swapped buttons correctly. SDL_GetGlobalMouseState() returns the physical button state without applying the swap. When in relative mouse mode, the buttons events are also not swapped. However, when not in relative mode, the buttons *are* swapped as expected.

GetAsyncKeyState() and GetRawInputData() report the state of the physical
buttons without applying the user's primary/secondary mouse button swap
preference. This behavior is documented on https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getasynckeystate

To match the behavior of other platforms and expose a consistent view of the buttons to SDL callers in raw vs. non raw mode, swap the buttons in the cases where the OS doesn't.
Comment 1 Cameron Gutman 2020-08-26 04:24:43 UTC
Created attachment 4449 [details]
Patch
Comment 2 Cameron Gutman 2020-11-12 00:40:50 UTC
Bump. Looks like this patch still applies on Hg.

It would be nice to get this upstream for 2.0.14 so I can stop carrying it in my local tree.
Comment 3 Sam Lantinga 2020-11-12 03:00:36 UTC
Patch added, thanks!
https://hg.libsdl.org/SDL/rev/1ce0cf1fea15

I assume you've checked the performance of GetSystemMetrics() so we can call this on every mouse event?
Comment 4 Cameron Gutman 2020-11-12 04:43:25 UTC
The value of SM_SWAPBUTTON is stored in an array inside user32, so looking it up is pretty cheap.

We also only call GetSystemMetrics(SM_SWAPBUTTON) when the mouse buttons change, so we don't end up calling it all that often anyway.