Skip to content

Commit fd04b15

Browse files
authored
Merge pull request #554 from psyke83/ps3_triggerfilter
Implement filterTrigger for PS3 controllers
2 parents 91d0b6c + 03341f2 commit fd04b15

4 files changed

Lines changed: 34 additions & 0 deletions

File tree

es-core/src/InputManager.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,12 @@ void InputManager::deinit()
172172
}
173173

174174
int InputManager::getNumJoysticks() { return (int)mJoysticks.size(); }
175+
176+
int InputManager::getAxisCountByDevice(SDL_JoystickID id)
177+
{
178+
return SDL_JoystickNumAxes(mJoysticks[id]);
179+
}
180+
175181
int InputManager::getButtonCountByDevice(SDL_JoystickID id)
176182
{
177183
if(id == DEVICE_KEYBOARD)

es-core/src/InputManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class InputManager
4848
void deinit();
4949

5050
int getNumJoysticks();
51+
int getAxisCountByDevice(int deviceId);
5152
int getButtonCountByDevice(int deviceId);
5253
int getNumConfiguredDevices();
5354

es-core/src/guis/GuiInputConfig.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ GuiInputConfig::GuiInputConfig(Window* window, InputConfig* target, bool reconfi
133133
return false;
134134
}
135135

136+
137+
// filter for input quirks specific to Sony DualShock 3
138+
if(filterTrigger(input, config))
139+
return false;
140+
136141
// we are configuring
137142
if(input.value != 0)
138143
{
@@ -331,3 +336,24 @@ void GuiInputConfig::clearAssignment(int inputId)
331336
{
332337
mTargetConfig->unmapInput(GUI_INPUT_CONFIG_LIST[inputId].name);
333338
}
339+
340+
bool GuiInputConfig::filterTrigger(Input input, InputConfig* config)
341+
{
342+
#if defined(__linux__)
343+
// match PlayStation joystick with 6 axes only
344+
if((strstr(config->getDeviceName().c_str(), "PLAYSTATION") != NULL \
345+
|| strstr(config->getDeviceName().c_str(), "PS3 Game") != NULL \
346+
|| strstr(config->getDeviceName().c_str(), "PS(R) Game") != NULL) \
347+
&& InputManager::getInstance()->getAxisCountByDevice(config->getDeviceId()) == 6)
348+
{
349+
// digital triggers are unwanted
350+
if (input.type == TYPE_BUTTON && (input.id == 6 || input.id == 7))
351+
return true;
352+
// ignore analog values < 0
353+
if (input.type == TYPE_AXIS && (input.id == 2 || input.id == 5) && input.value < 0)
354+
return true;
355+
}
356+
#endif
357+
358+
return false;
359+
}

es-core/src/guis/GuiInputConfig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class GuiInputConfig : public GuiComponent
2828

2929
bool assign(Input input, int inputId);
3030
void clearAssignment(int inputId);
31+
bool filterTrigger(Input input, InputConfig* config);
3132

3233
void rowDone();
3334

0 commit comments

Comments
 (0)