|
127 | 127 | } |
128 | 128 | #if TARGET_OS_TV |
129 | 129 | else if (controller.microGamepad) { |
| 130 | + const char *hint = SDL_GetHint(SDL_HINT_APPLE_TV_REMOTE_ALLOW_ROTATION); |
| 131 | + |
130 | 132 | device->naxes = 2; /* treat the touch surface as two axes */ |
131 | 133 | device->nhats = 0; /* apparently the touch surface-as-dpad is buggy */ |
132 | 134 | device->nbuttons = 3; /* AX, pause button */ |
| 135 | + |
| 136 | + controller.microGamepad.allowsRotation = (hint != NULL && *hint != '0'); |
133 | 137 | } |
134 | 138 | #endif /* TARGET_OS_TV */ |
135 | 139 |
|
|
248 | 252 | return next; |
249 | 253 | } |
250 | 254 |
|
| 255 | +#if TARGET_OS_TV |
| 256 | +static void |
| 257 | +SDL_AppleTVRemoteRotationHintChanged(void *udata, const char *name, const char *oldValue, const char *newValue) |
| 258 | +{ |
| 259 | + BOOL allowRotation = newValue != NULL && *newValue != '0'; |
| 260 | + |
| 261 | + @autoreleasepool { |
| 262 | + for (GCController *controller in [GCController controllers]) { |
| 263 | + if (controller.microGamepad) { |
| 264 | + controller.microGamepad.allowsRotation = allowRotation; |
| 265 | + } |
| 266 | + } |
| 267 | + } |
| 268 | +} |
| 269 | +#endif /* TARGET_OS_TV */ |
| 270 | + |
251 | 271 | /* Function to scan the system for joysticks. |
252 | 272 | * Joystick 0 should be the system default joystick. |
253 | 273 | * It should return 0, or -1 on an unrecoverable fatal error. |
|
276 | 296 | SDL_SYS_AddJoystickDevice(controller, SDL_FALSE); |
277 | 297 | } |
278 | 298 |
|
| 299 | +#if TARGET_OS_TV |
| 300 | + SDL_AddHintCallback(SDL_HINT_APPLE_TV_REMOTE_ALLOW_ROTATION, |
| 301 | + SDL_AppleTVRemoteRotationHintChanged, NULL); |
| 302 | +#endif /* TARGET_OS_TV */ |
| 303 | + |
279 | 304 | connectObserver = [center addObserverForName:GCControllerDidConnectNotification |
280 | 305 | object:nil |
281 | 306 | queue:nil |
@@ -656,6 +681,11 @@ SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index) |
656 | 681 | [center removeObserver:disconnectObserver name:GCControllerDidDisconnectNotification object:nil]; |
657 | 682 | disconnectObserver = nil; |
658 | 683 | } |
| 684 | + |
| 685 | +#if TARGET_OS_TV |
| 686 | + SDL_DelHintCallback(SDL_HINT_APPLE_TV_REMOTE_ALLOW_ROTATION, |
| 687 | + SDL_AppleTVRemoteRotationHintChanged, NULL); |
| 688 | +#endif /* TARGET_OS_TV */ |
659 | 689 | #endif /* SDL_JOYSTICK_MFI */ |
660 | 690 |
|
661 | 691 | while (deviceList != NULL) { |
|
0 commit comments