Send Apple TV remote input as key events unless it's opened as a joystick, to match Android behavior.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
diff --git a/src/joystick/iphoneos/SDL_sysjoystick.m b/src/joystick/iphoneos/SDL_sysjoystick.m
index e1602e5..d601498 100644
--- a/src/joystick/iphoneos/SDL_sysjoystick.m
+++ b/src/joystick/iphoneos/SDL_sysjoystick.m
@@ -60,6 +60,7 @@ static SDL_JoystickDeviceItem *deviceList = NULL;
static int numjoysticks = 0;
static SDL_JoystickID instancecounter = 0;
+int SDL_AppleTVRemoteOpenedAsJoystick = 0;
static SDL_JoystickDeviceItem *
GetDeviceForIndex(int device_index)
@@ -116,6 +117,7 @@ SDL_SYS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCController *contr
#if TARGET_OS_TV
else if (controller.microGamepad) {
device->guid.data[10] = 3;
+ device->remote = SDL_TRUE;
}
#endif /* TARGET_OS_TV */
@@ -455,6 +457,9 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
#endif /* SDL_JOYSTICK_MFI */
}
}
+ if (device->remote) {
+ ++SDL_AppleTVRemoteOpenedAsJoystick;
+ }
return 0;
}
@@ -719,6 +724,9 @@ SDL_SYS_JoystickClose(SDL_Joystick * joystick)
#endif
}
}
+ if (device->remote) {
+ --SDL_AppleTVRemoteOpenedAsJoystick;
+ }
}
/* Function to perform any system-specific joystick related cleanup */
diff --git a/src/joystick/iphoneos/SDL_sysjoystick_c.h b/src/joystick/iphoneos/SDL_sysjoystick_c.h
index d99e5d4..7be5b04 100644
--- a/src/joystick/iphoneos/SDL_sysjoystick_c.h
+++ b/src/joystick/iphoneos/SDL_sysjoystick_c.h
@@ -31,6 +31,7 @@
typedef struct joystick_hwdata
{
SDL_bool accelerometer;
+ SDL_bool remote;
GCController __unsafe_unretained *controller;
int num_pause_presses;
diff --git a/src/video/uikit/SDL_uikitview.m b/src/video/uikit/SDL_uikitview.m
index b4f0f33..bd60c55 100644
--- a/src/video/uikit/SDL_uikitview.m
+++ b/src/video/uikit/SDL_uikitview.m
@@ -33,6 +33,9 @@
#import "SDL_uikitmodes.h"
#import "SDL_uikitwindow.h"
+/* This is defined in SDL_sysjoystick.m */
+extern int SDL_AppleTVRemoteOpenedAsJoystick;
+
@implementation SDL_uikitview {
SDL_Window *sdlwindow;
@@ -44,24 +47,22 @@
{
if ((self = [super initWithFrame:frame])) {
#if TARGET_OS_TV
- if (!SDL_GetHintBoolean(SDL_HINT_TV_REMOTE_AS_JOYSTICK, SDL_TRUE)) {
- /* Apple TV Remote touchpad swipe gestures. */
- UISwipeGestureRecognizer *swipeUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
- swipeUp.direction = UISwipeGestureRecognizerDirectionUp;
- [self addGestureRecognizer:swipeUp];
-
- UISwipeGestureRecognizer *swipeDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
- swipeDown.direction = UISwipeGestureRecognizerDirectionDown;
- [self addGestureRecognizer:swipeDown];
-
- UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
- swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
- [self addGestureRecognizer:swipeLeft];
-
- UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
- swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
- [self addGestureRecognizer:swipeRight];
- }
+ /* Apple TV Remote touchpad swipe gestures. */
+ UISwipeGestureRecognizer *swipeUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
+ swipeUp.direction = UISwipeGestureRecognizerDirectionUp;
+ [self addGestureRecognizer:swipeUp];
+
+ UISwipeGestureRecognizer *swipeDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
+ swipeDown.direction = UISwipeGestureRecognizerDirectionDown;
+ [self addGestureRecognizer:swipeDown];
+
+ UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
+ swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
+ [self addGestureRecognizer:swipeLeft];
+
+ UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
+ swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
+ [self addGestureRecognizer:swipeRight];
#endif
self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
@@ -251,7 +252,7 @@
- (void)pressesBegan:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event
{
- if (!SDL_GetHintBoolean(SDL_HINT_TV_REMOTE_AS_JOYSTICK, SDL_TRUE)) {
+ if (!SDL_AppleTVRemoteOpenedAsJoystick) {
for (UIPress *press in presses) {
SDL_Scancode scancode = [self scancodeFromPressType:press.type];
SDL_SendKeyboardKey(SDL_PRESSED, scancode);
@@ -262,7 +263,7 @@
- (void)pressesEnded:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event
{
- if (!SDL_GetHintBoolean(SDL_HINT_TV_REMOTE_AS_JOYSTICK, SDL_TRUE)) {
+ if (!SDL_AppleTVRemoteOpenedAsJoystick) {
for (UIPress *press in presses) {
SDL_Scancode scancode = [self scancodeFromPressType:press.type];
SDL_SendKeyboardKey(SDL_RELEASED, scancode);
@@ -273,7 +274,7 @@
- (void)pressesCancelled:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event
{
- if (!SDL_GetHintBoolean(SDL_HINT_TV_REMOTE_AS_JOYSTICK, SDL_TRUE)) {
+ if (!SDL_AppleTVRemoteOpenedAsJoystick) {
for (UIPress *press in presses) {
SDL_Scancode scancode = [self scancodeFromPressType:press.type];
SDL_SendKeyboardKey(SDL_RELEASED, scancode);
@@ -294,25 +295,27 @@
{
/* Swipe gestures don't trigger begin states. */
if (gesture.state == UIGestureRecognizerStateEnded) {
- /* Send arrow key presses for now, as we don't have an external API
- * which better maps to swipe gestures. */
- switch (gesture.direction) {
- case UISwipeGestureRecognizerDirectionUp:
- SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_UP);
- SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_UP);
- break;
- case UISwipeGestureRecognizerDirectionDown:
- SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_DOWN);
- SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_DOWN);
- break;
- case UISwipeGestureRecognizerDirectionLeft:
- SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_LEFT);
- SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_LEFT);
- break;
- case UISwipeGestureRecognizerDirectionRight:
- SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_RIGHT);
- SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_RIGHT);
- break;
+ if (!SDL_AppleTVRemoteOpenedAsJoystick) {
+ /* Send arrow key presses for now, as we don't have an external API
+ * which better maps to swipe gestures. */
+ switch (gesture.direction) {
+ case UISwipeGestureRecognizerDirectionUp:
+ SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_UP);
+ SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_UP);
+ break;
+ case UISwipeGestureRecognizerDirectionDown:
+ SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_DOWN);
+ SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_DOWN);
+ break;
+ case UISwipeGestureRecognizerDirectionLeft:
+ SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_LEFT);
+ SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_LEFT);
+ break;
+ case UISwipeGestureRecognizerDirectionRight:
+ SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_RIGHT);
+ SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_RIGHT);
+ break;
+ }
}
}
}