From: <mth...@us...> - 2011-06-22 12:49:02
|
Revision: 12193 http://openmsx.svn.sourceforge.net/openmsx/?rev=12193&view=rev Author: mthuurne Date: 2011-06-22 12:48:56 +0000 (Wed, 22 Jun 2011) Log Message: ----------- Reject 0-button joystick-like devices as joysticks. This avoids autoplugging an accelerometer if it is accidentally reported as a joystick by SDL. Modified Paths: -------------- openmsx/trunk/src/input/Joystick.cc openmsx/trunk/src/input/Joystick.hh Modified: openmsx/trunk/src/input/Joystick.cc =================================================================== --- openmsx/trunk/src/input/Joystick.cc 2011-06-22 10:01:01 UTC (rev 12192) +++ openmsx/trunk/src/input/Joystick.cc 2011-06-22 12:48:56 UTC (rev 12193) @@ -34,8 +34,19 @@ unsigned numJoysticks = SDL_NumJoysticks(); for (unsigned i = 0; i < numJoysticks; i++) { - controller.registerPluggable(new Joystick( - eventDistributor, stateChangeDistributor, i)); + SDL_Joystick* joystick = SDL_JoystickOpen(i); + if (joystick) { + // Avoid devices that have axes but no buttons, like accelerometers. + // SDL 1.2.14 in Linux has an issue where it rejects a device from + // /dev/input/event* if it has no buttons but does not reject a + // device from /dev/input/js* if it has no buttons, while + // accelerometers do end up being symlinked as a joystick in + // practice. + if (SDL_JoystickNumButtons(joystick) != 0) { + controller.registerPluggable(new Joystick( + eventDistributor, stateChangeDistributor, joystick)); + } + } } #endif } @@ -76,13 +87,13 @@ // the open/close calls. Joystick::Joystick(MSXEventDistributor& eventDistributor_, StateChangeDistributor& stateChangeDistributor_, - unsigned joyNum_) + SDL_Joystick* joystick_) : eventDistributor(eventDistributor_) , stateChangeDistributor(stateChangeDistributor_) + , joystick(joystick_) + , joyNum(SDL_JoystickIndex(joystick_)) , name("joystickX") // 'X' is filled in below - , desc(string(SDL_JoystickName(joyNum_))) - , joystick(SDL_JoystickOpen(joyNum_)) - , joyNum(joyNum_) + , desc(string(SDL_JoystickName(joyNum))) { const_cast<string&>(name)[8] = char('1' + joyNum); } Modified: openmsx/trunk/src/input/Joystick.hh =================================================================== --- openmsx/trunk/src/input/Joystick.hh 2011-06-22 10:01:01 UTC (rev 12192) +++ openmsx/trunk/src/input/Joystick.hh 2011-06-22 12:48:56 UTC (rev 12193) @@ -52,7 +52,7 @@ private: Joystick(MSXEventDistributor& eventDistributor, StateChangeDistributor& stateChangeDistributor, - unsigned joyNum); + SDL_Joystick* joystick); void plugHelper2(); byte calcInitialState(); @@ -69,10 +69,10 @@ MSXEventDistributor& eventDistributor; StateChangeDistributor& stateChangeDistributor; + SDL_Joystick* const joystick; + const unsigned joyNum; const std::string name; const std::string desc; - SDL_Joystick* const joystick; - const unsigned joyNum; byte status; #endif // SDL_JOYSTICK_DISABLED This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |