Skip to content

Commit

Permalink
Enable option to rumble iOS device instead of controller (#14734).
Browse files Browse the repository at this point in the history
  • Loading branch information
warmenhoven authored and LibretroAdmin committed Jul 1, 2023
1 parent b98bf2c commit ce49bd6
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
8 changes: 8 additions & 0 deletions frontend/drivers/platform_darwin.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions input/drivers_joypad/mfi_joypad.m
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -487,6 +492,13 @@ static void apple_gamecontroller_joypad_disconnect(GCController* controller)
{
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];
Expand Down Expand Up @@ -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, *))
Expand Down
10 changes: 9 additions & 1 deletion menu/menu_displaylist.c
Original file line number Diff line number Diff line change
Expand Up @@ -6742,14 +6742,22 @@ 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,
MENU_ENUM_LABEL_VIBRATE_ON_KEYPRESS,
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)
Expand Down

0 comments on commit ce49bd6

Please sign in to comment.