Enable option to rumble iOS device instead of controller (#14734).

This commit is contained in:
Eric Warmenhoven 2023-06-30 16:05:11 -04:00 committed by LibretroAdmin
parent b98bf2ccf0
commit ce49bd6dcc
3 changed files with 40 additions and 1 deletions

View File

@ -282,10 +282,18 @@ static void frontend_darwin_get_os(char *s, size_t len, int *major, int *minor)
{
#if defined(IOS)
get_ios_version(major, minor);
#if TARGET_OS_TV
s[0] = 't';
s[1] = 'v';
s[2] = 'O';
s[3] = 'S';
s[4] = '\0';
#else
s[0] = 'i';
s[1] = 'O';
s[2] = 'S';
s[3] = '\0';
#endif
#elif defined(OSX)
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 101300 // MAC_OS_X_VERSION_10_13

View File

@ -31,6 +31,11 @@
#define MAX_MFI_CONTROLLERS 4
#endif
#if TARGET_OS_IOS
#include "../../configuration.h"
static UIImpactFeedbackGenerator *deviceFeedbackGenerator;
#endif
enum
{
GCCONTROLLER_PLAYER_INDEX_UNSET = -1,
@ -487,6 +492,13 @@ void *apple_gamecontroller_joypad_init(void *data)
{
if (mfi_inited)
return (void*)-1;
#if TARGET_OS_IOS
if (!deviceFeedbackGenerator)
deviceFeedbackGenerator = [[UIImpactFeedbackGenerator alloc] init];
[deviceFeedbackGenerator prepare];
#endif
if (!apple_gamecontroller_available())
return NULL;
mfiControllers = [[NSMutableArray alloc] initWithCapacity:MAX_MFI_CONTROLLERS];
@ -588,6 +600,17 @@ static int16_t apple_gamecontroller_joypad_state(
static bool apple_gamecontroller_joypad_set_rumble(unsigned pad,
enum retro_rumble_effect type, uint16_t strength)
{
#if TARGET_OS_IOS
settings_t *settings = config_get_ptr();
bool enable_device_vibration = settings->bools.enable_device_vibration;
if (enable_device_vibration && pad == 0)
{
[deviceFeedbackGenerator impactOccurredWithIntensity:((float)strength)/65535.0f];
[deviceFeedbackGenerator prepare];
}
#endif
if (pad < MAX_MFI_CONTROLLERS)
{
if (@available(iOS 14, tvOS 14, macOS 11, *))

View File

@ -6742,6 +6742,13 @@ unsigned menu_displaylist_build_list(
{
input_driver_t *current_input =
input_state_get_ptr()->current_driver;
const frontend_ctx_driver_t *frontend =
frontend_get_ptr();
char os_ver[64] = {0};
int major, minor;
if (frontend && frontend->get_os)
frontend->get_os(os_ver, sizeof(os_ver), &major, &minor);
if (current_input->keypress_vibrate)
if (MENU_DISPLAYLIST_PARSE_SETTINGS_ENUM(list,
@ -6749,7 +6756,8 @@ unsigned menu_displaylist_build_list(
PARSE_ONLY_BOOL, false) == 0)
count++;
if (string_is_equal(current_input->ident, "android"))
if (string_is_equal(current_input->ident, "android") ||
(string_is_equal(current_input->ident, "cocoa") && string_is_equal(os_ver, "iOS")))
if (MENU_DISPLAYLIST_PARSE_SETTINGS_ENUM(list,
MENU_ENUM_LABEL_ENABLE_DEVICE_VIBRATION,
PARSE_ONLY_BOOL, false) == 0)