iOS: Fix "Home" button on controllers (like the PS logo button on a PS4 controller)

This commit is contained in:
Henrik Rydgård 2024-06-05 15:01:02 +02:00
parent dca67bb5ce
commit 338758f430
5 changed files with 23 additions and 5 deletions

View File

@ -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[] = {

View File

@ -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:

View File

@ -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
};
@ -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
@ -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)]) {

View File

@ -466,7 +466,7 @@ void GLRenderLoop(IOSGLESContext *graphicsContext) {
- (void)setupController:(GCController *)controller
{
self.gameController = controller;
if (!SetupController(controller)) {
if (!InitController(controller)) {
self.gameController = nil;
}
}

View File

@ -595,7 +595,7 @@ extern float g_safeInsetBottom;
- (void)setupController:(GCController *)controller
{
self.gameController = controller;
if (!SetupController(controller)) {
if (!InitController(controller)) {
self.gameController = nil;
}
}