Mouse buttons settings not respected when cursor grabbed and not shown on Linux

Hi, I have a problem with SDL-using programs not respecting that I
have swapped the mouse buttons for left handed use. I use Xubuntu and
have tried swapping the mouse buttons with both the graphical utility
in xfce and xmodmap. The programs (Dosbox, Spacechem, Darwinia and
Dungeons of Dredmor) do not have this problem when run in Windows.

The attached code is for testing the two primary mouse buttons with
variations on grabbing and showing the cursor (mode is changed with
middle button). It reproduces the error if the mouse cursor is grabbed
and not shown but not otherwise. For example, if I run it and just
alternate clicking the right and the middle button I get this output:

Show cursor: 1 ; Grab input: 0
SDL_BUTTON_LEFT
Show cursor: 0 ; Grab input: 1
SDL_BUTTON_RIGHT
Show cursor: 0 ; Grab input: 0
SDL_BUTTON_LEFT
Show cursor: 1 ; Grab input: 1
SDL_BUTTON_LEFT

Notice that when the cursor is grabbed and not shown the right mouse
button is interpreted as a right click and not a left click as it
should be when the buttons have been swapped for left handed use. It
is also inconsistent with the other modes for showing or grabbing the
cursor. When the buttons are set for right handed use, there is no
inconsistency or incorrect interpretation of the buttons.
-------------- next part --------------
A non-text attachment was scrubbed…
Name: buttontest.c
Type: text/x-csrc
Size: 1469 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20120411/900eefeb/attachment.c