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 1944

Summary: Linux events, joysticks having only hat are not read
Product: SDL Reporter: Nicolas Adenis-Lamarre <nicolas.adenis.lamarre>
Component: joystickAssignee: Ryan C. Gordon <icculus>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: gabomdq
Version: 2.0.0   
Hardware: x86   
OS: Linux   

Description Nicolas Adenis-Lamarre 2013-07-07 15:31:06 UTC
EV_IsJoystick(int fd) is too restritive :

In sdl 1.x
same problem as in SDL2 +

in the function static int EV_IsJoystick(int fd)
you do:
(test_bit(BTN_TRIGGER, keybit) || test_bit(BTN_A, keybit) || test_bit(BTN_1, keybit))
doesn't work for the wii guitar hero guitar driver i've wrotten for linux 3.11 because this guitar has no TRIGGER nor A nor 1 button.

In sdl 2.x
in the function static int EV_IsJoystick(int fd)
you do:

test_bit(ABS_X, absbit) && test_bit(ABS_Y, absbit)

but some joysticks have only hat.
so, it should be

(test_bit(ABS_X, absbit) && test_bit(ABS_Y, absbit))
||
test_bit(ABS_HAT0X, absbit) && test_bit(ABS_HAT0Y, absbit)
||
test_bit(ABS_HAT1X, absbit) && test_bit(ABS_HAT1Y, absbit)
||
test_bit(ABS_HAT2X, absbit) && test_bit(ABS_HAT2Y, absbit)
Comment 1 Nicolas Adenis-Lamarre 2013-07-07 16:09:49 UTC
some other devices not detected :  "Nintendo Wii Remote IR" and "Nintendo Wii Remote Acceleromete"
because they are just axes. (i can however understand that it's not joysticks, and in my own opinion, the 3 devices should be only 1 because it's physically only 1 )

name    : "Nintendo Wii Remote IR"
   bits ev : EV_SYN EV_ABS

name    : "Nintendo Wii Remote"
   bits ev : EV_SYN EV_KEY EV_FF

name    : "Nintendo Wii Remote Acceleromete"
   bits ev : EV_SYN EV_ABS
Comment 2 Nicolas Adenis-Lamarre 2013-07-12 06:19:29 UTC
the worst effect making this test less restrictive is to have some non joystick devices recognized as a joystick.
not really a keyboard, because a keyboard with axes could be considered as a joystick, but the question is more not detect a mouse as a joystick.
I could think this test has been added to difference a joystick and a mouse ; but in my humble opinion, the wiimote can be considered as a joystick and as mouse for the IR part at least.
At least having a hat, make your device a joystick, i think.

isn't it possible to add eventDevices including all of them and let the application choose what it needs to filter on ?
For example, for a game, i could have the need of only one axis to increase or decrease a value (speed for example).

what about an argument when initializing joysticks ?

struct joystickRequirements {
  // something which help to customize EV_IsJoystick() behavior
  // hasAxisX, hasAxisY, hasHATX, hasHATY, hasButton = true/false
  // minimum list of required button = A 1 TRIGGER
};

defaultJoystickRequirements { // default value when initializing joystick
 // something which define the default behavior
};
Comment 3 Gabriel Jacobo 2013-11-05 23:49:17 UTC
My two cents, with UDEV hotplugging in place, I think the IsJoystick test can be relaxed completely (if the device addition comes from UDEV).
Comment 4 Sam Lantinga 2013-11-06 05:34:32 UTC
Agreed, as long as udev actually identifies it as a joystick device. Gabriel, do you want to make that change?
Comment 5 Gabriel Jacobo 2013-11-06 12:49:33 UTC
Hopefully this fixes it: http://hg.libsdl.org/SDL/rev/4434ab25abf3