src/joystick/iphoneos/SDL_sysjoystick.m
changeset 10351 12f90eb6b52b
parent 10341 75ac5b0ed013
child 10499 363c1c7e7a41
     1.1 --- a/src/joystick/iphoneos/SDL_sysjoystick.m	Thu Sep 15 21:49:29 2016 -0300
     1.2 +++ b/src/joystick/iphoneos/SDL_sysjoystick.m	Sat Sep 17 01:31:07 2016 -0300
     1.3 @@ -127,9 +127,13 @@
     1.4      }
     1.5  #if TARGET_OS_TV
     1.6      else if (controller.microGamepad) {
     1.7 +        const char *hint = SDL_GetHint(SDL_HINT_APPLE_TV_REMOTE_ALLOW_ROTATION);
     1.8 +
     1.9          device->naxes = 2; /* treat the touch surface as two axes */
    1.10          device->nhats = 0; /* apparently the touch surface-as-dpad is buggy */
    1.11          device->nbuttons = 3; /* AX, pause button */
    1.12 +
    1.13 +        controller.microGamepad.allowsRotation = (hint != NULL && *hint != '0');
    1.14      }
    1.15  #endif /* TARGET_OS_TV */
    1.16  
    1.17 @@ -248,6 +252,22 @@
    1.18      return next;
    1.19  }
    1.20  
    1.21 +#if TARGET_OS_TV
    1.22 +static void
    1.23 +SDL_AppleTVRemoteRotationHintChanged(void *udata, const char *name, const char *oldValue, const char *newValue)
    1.24 +{
    1.25 +    BOOL allowRotation = newValue != NULL && *newValue != '0';
    1.26 +
    1.27 +    @autoreleasepool {
    1.28 +        for (GCController *controller in [GCController controllers]) {
    1.29 +            if (controller.microGamepad) {
    1.30 +                controller.microGamepad.allowsRotation = allowRotation;
    1.31 +            }
    1.32 +        }
    1.33 +    }
    1.34 +}
    1.35 +#endif /* TARGET_OS_TV */
    1.36 +
    1.37  /* Function to scan the system for joysticks.
    1.38   * Joystick 0 should be the system default joystick.
    1.39   * It should return 0, or -1 on an unrecoverable fatal error.
    1.40 @@ -276,6 +296,11 @@
    1.41              SDL_SYS_AddJoystickDevice(controller, SDL_FALSE);
    1.42          }
    1.43  
    1.44 +#if TARGET_OS_TV
    1.45 +        SDL_AddHintCallback(SDL_HINT_APPLE_TV_REMOTE_ALLOW_ROTATION,
    1.46 +                            SDL_AppleTVRemoteRotationHintChanged, NULL);
    1.47 +#endif /* TARGET_OS_TV */
    1.48 +
    1.49          connectObserver = [center addObserverForName:GCControllerDidConnectNotification
    1.50                                                object:nil
    1.51                                                 queue:nil
    1.52 @@ -656,6 +681,11 @@
    1.53              [center removeObserver:disconnectObserver name:GCControllerDidDisconnectNotification object:nil];
    1.54              disconnectObserver = nil;
    1.55          }
    1.56 +
    1.57 +#if TARGET_OS_TV
    1.58 +        SDL_DelHintCallback(SDL_HINT_APPLE_TV_REMOTE_ALLOW_ROTATION,
    1.59 +                            SDL_AppleTVRemoteRotationHintChanged, NULL);
    1.60 +#endif /* TARGET_OS_TV */
    1.61  #endif /* SDL_JOYSTICK_MFI */
    1.62  
    1.63          while (deviceList != NULL) {