mirror of https://github.com/encounter/SDL.git
Added controller mapping for Android TV remotes
Also fixed the back button on the remote exiting the application
This commit is contained in:
parent
4478707b0a
commit
a90be440e8
|
@ -88,6 +88,8 @@ public class SDLControllerManager
|
|||
}
|
||||
int sources = device.getSources();
|
||||
|
||||
/* This is called for every button press, so let's not spam the logs */
|
||||
/**
|
||||
if ((sources & InputDevice.SOURCE_CLASS_JOYSTICK) == InputDevice.SOURCE_CLASS_JOYSTICK) {
|
||||
Log.v(TAG, "Input device " + device.getName() + " is a joystick.");
|
||||
}
|
||||
|
@ -97,6 +99,7 @@ public class SDLControllerManager
|
|||
if ((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) {
|
||||
Log.v(TAG, "Input device " + device.getName() + " is a gamepad.");
|
||||
}
|
||||
**/
|
||||
|
||||
return (((sources & InputDevice.SOURCE_CLASS_JOYSTICK) == InputDevice.SOURCE_CLASS_JOYSTICK) ||
|
||||
((sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD) ||
|
||||
|
|
|
@ -919,6 +919,15 @@ static ControllerMapping_t *SDL_PrivateGetControllerMapping(int device_index)
|
|||
mapping = s_pXInputMapping;
|
||||
}
|
||||
#endif
|
||||
#if defined(__ANDROID__)
|
||||
if (!mapping && SDL_SYS_IsDPAD_DeviceIndex(device_index)) {
|
||||
SDL_bool existing;
|
||||
char mapping_string[1024];
|
||||
SDL_snprintf(mapping_string, sizeof(mapping_string), "none,%s,a:b0,b:b1,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,", name);
|
||||
mapping = SDL_PrivateAddMappingForGUID(guid, mapping_string,
|
||||
&existing, SDL_CONTROLLER_MAPPING_PRIORITY_DEFAULT);
|
||||
#endif /* __ANDROID__ */
|
||||
}
|
||||
SDL_UnlockJoysticks();
|
||||
return mapping;
|
||||
}
|
||||
|
|
|
@ -126,6 +126,11 @@ extern SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick);
|
|||
extern SDL_bool SDL_SYS_IsXInputGamepad_DeviceIndex(int device_index);
|
||||
#endif
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
/* Function returns SDL_TRUE if this device is a DPAD (maybe a TV remote) */
|
||||
extern SDL_bool SDL_SYS_IsDPAD_DeviceIndex(int device_index);
|
||||
#endif
|
||||
|
||||
#endif /* SDL_sysjoystick_h_ */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
@ -143,7 +143,13 @@ keycode_to_SDL(int keycode)
|
|||
button = SDL_CONTROLLER_BUTTON_DPAD_RIGHT;
|
||||
break;
|
||||
case AKEYCODE_DPAD_CENTER:
|
||||
button = SDL_CONTROLLER_BUTTON_MAX+4; /* Not supported by GameController */
|
||||
/* This is handled better by applications as the A button */
|
||||
/*button = SDL_CONTROLLER_BUTTON_MAX+4; /* Not supported by GameController */
|
||||
button = SDL_CONTROLLER_BUTTON_A;
|
||||
break;
|
||||
|
||||
case AKEYCODE_BACK:
|
||||
button = SDL_CONTROLLER_BUTTON_B;
|
||||
break;
|
||||
|
||||
/* More gamepad buttons (API 12), these get mapped to 20...35*/
|
||||
|
@ -640,6 +646,11 @@ SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
|
|||
return guid;
|
||||
}
|
||||
|
||||
SDL_bool SDL_SYS_IsDPAD_DeviceIndex(int device_index)
|
||||
{
|
||||
return JoystickByDevIndex(device_index)->naxes == 0;
|
||||
}
|
||||
|
||||
#endif /* SDL_JOYSTICK_ANDROID */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
Loading…
Reference in New Issue