Skip to content

Commit

Permalink
Merge pull request #19254 from hrydgard/ios-fix-controller-home-button
Browse files Browse the repository at this point in the history
iOS: Fix "Home" button on controllers (like the PS logo button on a PS4 controller)
  • Loading branch information
hrydgard authored Jun 5, 2024
2 parents 247a06e + 338758f commit 3444c32
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Core/KeyMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,9 @@ static const KeyMap_IntStrPair key_names[] = {
{NKCODE_START_QUESTION, "¿"},
{NKCODE_LEFTBRACE, "{"},
{NKCODE_RIGHTBRACE, "}"},

{NKCODE_GUIDE, "Guide"},
{NKCODE_INFO, "Info"},
};

static const KeyMap_IntStrPair axis_names[] = {
Expand Down
3 changes: 2 additions & 1 deletion ios/Controls.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
// Code extracted from ViewController.mm, in order to modularize
// and share it between multiple view controllers.

bool SetupController(GCController *controller);
bool InitController(GCController *controller);
void ShutdownController(GCController *controller);

struct TouchTracker {
public:
Expand Down
18 changes: 16 additions & 2 deletions ios/Controls.mm
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,18 @@ static void analogTriggerPressed(InputAxis axis, float value) {
NativeAxis(&axisInput, 1);
}

bool SetupController(GCController *controller) {
bool InitController(GCController *controller) {
GCExtendedGamepad *extendedProfile = controller.extendedGamepad;
if (extendedProfile == nil) {
return false;
}

if (@available(iOS 14.0, tvOS 14.0, *)) {
for (GCControllerElement* element in controller.physicalInputProfile.allElements) {
element.preferredSystemGestureState = GCSystemGestureStateDisabled;
}
}

extendedProfile.buttonA.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) {
controllerButtonPressed(pressed, NKCODE_BUTTON_2); // Cross
};
Expand Down Expand Up @@ -106,7 +112,7 @@ bool SetupController(GCController *controller) {
#if defined(__IPHONE_14_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_14_0
if ([extendedProfile respondsToSelector:@selector(buttonHome)] && extendedProfile.buttonHome != nil) {
extendedProfile.buttonHome.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) {
controllerButtonPressed(pressed, NKCODE_BUTTON_15);
controllerButtonPressed(pressed, NKCODE_HOME);
};
}
#endif
Expand Down Expand Up @@ -148,6 +154,14 @@ bool SetupController(GCController *controller) {
return true;
}

void ShutdownController(GCController *controller) {
if (@available(iOS 14.0, tvOS 14.0, *)) {
for (GCControllerElement* element in controller.physicalInputProfile.allElements) {
element.preferredSystemGestureState = GCSystemGestureStateEnabled;
}
}
}

void TouchTracker::SendTouchEvent(float x, float y, int code, int pointerId) {
float scale = [UIScreen mainScreen].scale;
if ([[UIScreen mainScreen] respondsToSelector:@selector(nativeScale)]) {
Expand Down
2 changes: 2 additions & 0 deletions ios/PPSSPP-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
<false/>
<key>UIRequiresFullScreen</key>
<true/>
<key>NSLocalNetworkUsageDescription</key>
<string>PPSSPP needs some local network access for network multiplayer support.</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>arm64</string>
Expand Down
2 changes: 1 addition & 1 deletion ios/ViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ - (UIView *)getView {
- (void)setupController:(GCController *)controller
{
self.gameController = controller;
if (!SetupController(controller)) {
if (!InitController(controller)) {
self.gameController = nil;
}
}
Expand Down
2 changes: 1 addition & 1 deletion ios/ViewControllerMetal.mm
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ - (void)controllerDidDisconnect:(NSNotification *)note
- (void)setupController:(GCController *)controller
{
self.gameController = controller;
if (!SetupController(controller)) {
if (!InitController(controller)) {
self.gameController = nil;
}
}
Expand Down

0 comments on commit 3444c32

Please sign in to comment.