mirror of https://github.com/encounter/SDL.git
Send Apple TV remote input as key events unless it's opened as a joystick, to match Android behavior.
This commit is contained in:
parent
f59b9c8b13
commit
73c26c204c
|
@ -60,6 +60,7 @@ static SDL_JoystickDeviceItem *deviceList = NULL;
|
||||||
|
|
||||||
static int numjoysticks = 0;
|
static int numjoysticks = 0;
|
||||||
static SDL_JoystickID instancecounter = 0;
|
static SDL_JoystickID instancecounter = 0;
|
||||||
|
int SDL_AppleTVRemoteOpenedAsJoystick = 0;
|
||||||
|
|
||||||
static SDL_JoystickDeviceItem *
|
static SDL_JoystickDeviceItem *
|
||||||
GetDeviceForIndex(int device_index)
|
GetDeviceForIndex(int device_index)
|
||||||
|
@ -116,6 +117,7 @@ SDL_SYS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCController *contr
|
||||||
#if TARGET_OS_TV
|
#if TARGET_OS_TV
|
||||||
else if (controller.microGamepad) {
|
else if (controller.microGamepad) {
|
||||||
device->guid.data[10] = 3;
|
device->guid.data[10] = 3;
|
||||||
|
device->remote = SDL_TRUE;
|
||||||
}
|
}
|
||||||
#endif /* TARGET_OS_TV */
|
#endif /* TARGET_OS_TV */
|
||||||
|
|
||||||
|
@ -455,6 +457,9 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
|
||||||
#endif /* SDL_JOYSTICK_MFI */
|
#endif /* SDL_JOYSTICK_MFI */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (device->remote) {
|
||||||
|
++SDL_AppleTVRemoteOpenedAsJoystick;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -719,6 +724,9 @@ SDL_SYS_JoystickClose(SDL_Joystick * joystick)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (device->remote) {
|
||||||
|
--SDL_AppleTVRemoteOpenedAsJoystick;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Function to perform any system-specific joystick related cleanup */
|
/* Function to perform any system-specific joystick related cleanup */
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
typedef struct joystick_hwdata
|
typedef struct joystick_hwdata
|
||||||
{
|
{
|
||||||
SDL_bool accelerometer;
|
SDL_bool accelerometer;
|
||||||
|
SDL_bool remote;
|
||||||
|
|
||||||
GCController __unsafe_unretained *controller;
|
GCController __unsafe_unretained *controller;
|
||||||
int num_pause_presses;
|
int num_pause_presses;
|
||||||
|
|
|
@ -33,6 +33,9 @@
|
||||||
#import "SDL_uikitmodes.h"
|
#import "SDL_uikitmodes.h"
|
||||||
#import "SDL_uikitwindow.h"
|
#import "SDL_uikitwindow.h"
|
||||||
|
|
||||||
|
/* This is defined in SDL_sysjoystick.m */
|
||||||
|
extern int SDL_AppleTVRemoteOpenedAsJoystick;
|
||||||
|
|
||||||
@implementation SDL_uikitview {
|
@implementation SDL_uikitview {
|
||||||
SDL_Window *sdlwindow;
|
SDL_Window *sdlwindow;
|
||||||
|
|
||||||
|
@ -44,24 +47,22 @@
|
||||||
{
|
{
|
||||||
if ((self = [super initWithFrame:frame])) {
|
if ((self = [super initWithFrame:frame])) {
|
||||||
#if TARGET_OS_TV
|
#if TARGET_OS_TV
|
||||||
if (!SDL_GetHintBoolean(SDL_HINT_TV_REMOTE_AS_JOYSTICK, SDL_TRUE)) {
|
/* Apple TV Remote touchpad swipe gestures. */
|
||||||
/* Apple TV Remote touchpad swipe gestures. */
|
UISwipeGestureRecognizer *swipeUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
|
||||||
UISwipeGestureRecognizer *swipeUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
|
swipeUp.direction = UISwipeGestureRecognizerDirectionUp;
|
||||||
swipeUp.direction = UISwipeGestureRecognizerDirectionUp;
|
[self addGestureRecognizer:swipeUp];
|
||||||
[self addGestureRecognizer:swipeUp];
|
|
||||||
|
|
||||||
UISwipeGestureRecognizer *swipeDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
|
UISwipeGestureRecognizer *swipeDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
|
||||||
swipeDown.direction = UISwipeGestureRecognizerDirectionDown;
|
swipeDown.direction = UISwipeGestureRecognizerDirectionDown;
|
||||||
[self addGestureRecognizer:swipeDown];
|
[self addGestureRecognizer:swipeDown];
|
||||||
|
|
||||||
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
|
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
|
||||||
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
|
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
|
||||||
[self addGestureRecognizer:swipeLeft];
|
[self addGestureRecognizer:swipeLeft];
|
||||||
|
|
||||||
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
|
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
|
||||||
swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
|
swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
|
||||||
[self addGestureRecognizer:swipeRight];
|
[self addGestureRecognizer:swipeRight];
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
||||||
|
@ -251,7 +252,7 @@
|
||||||
|
|
||||||
- (void)pressesBegan:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event
|
- (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) {
|
for (UIPress *press in presses) {
|
||||||
SDL_Scancode scancode = [self scancodeFromPressType:press.type];
|
SDL_Scancode scancode = [self scancodeFromPressType:press.type];
|
||||||
SDL_SendKeyboardKey(SDL_PRESSED, scancode);
|
SDL_SendKeyboardKey(SDL_PRESSED, scancode);
|
||||||
|
@ -262,7 +263,7 @@
|
||||||
|
|
||||||
- (void)pressesEnded:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event
|
- (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) {
|
for (UIPress *press in presses) {
|
||||||
SDL_Scancode scancode = [self scancodeFromPressType:press.type];
|
SDL_Scancode scancode = [self scancodeFromPressType:press.type];
|
||||||
SDL_SendKeyboardKey(SDL_RELEASED, scancode);
|
SDL_SendKeyboardKey(SDL_RELEASED, scancode);
|
||||||
|
@ -273,7 +274,7 @@
|
||||||
|
|
||||||
- (void)pressesCancelled:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event
|
- (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) {
|
for (UIPress *press in presses) {
|
||||||
SDL_Scancode scancode = [self scancodeFromPressType:press.type];
|
SDL_Scancode scancode = [self scancodeFromPressType:press.type];
|
||||||
SDL_SendKeyboardKey(SDL_RELEASED, scancode);
|
SDL_SendKeyboardKey(SDL_RELEASED, scancode);
|
||||||
|
@ -294,25 +295,27 @@
|
||||||
{
|
{
|
||||||
/* Swipe gestures don't trigger begin states. */
|
/* Swipe gestures don't trigger begin states. */
|
||||||
if (gesture.state == UIGestureRecognizerStateEnded) {
|
if (gesture.state == UIGestureRecognizerStateEnded) {
|
||||||
/* Send arrow key presses for now, as we don't have an external API
|
if (!SDL_AppleTVRemoteOpenedAsJoystick) {
|
||||||
* which better maps to swipe gestures. */
|
/* Send arrow key presses for now, as we don't have an external API
|
||||||
switch (gesture.direction) {
|
* which better maps to swipe gestures. */
|
||||||
case UISwipeGestureRecognizerDirectionUp:
|
switch (gesture.direction) {
|
||||||
SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_UP);
|
case UISwipeGestureRecognizerDirectionUp:
|
||||||
SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_UP);
|
SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_UP);
|
||||||
break;
|
SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_UP);
|
||||||
case UISwipeGestureRecognizerDirectionDown:
|
break;
|
||||||
SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_DOWN);
|
case UISwipeGestureRecognizerDirectionDown:
|
||||||
SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_DOWN);
|
SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_DOWN);
|
||||||
break;
|
SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_DOWN);
|
||||||
case UISwipeGestureRecognizerDirectionLeft:
|
break;
|
||||||
SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_LEFT);
|
case UISwipeGestureRecognizerDirectionLeft:
|
||||||
SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_LEFT);
|
SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_LEFT);
|
||||||
break;
|
SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_LEFT);
|
||||||
case UISwipeGestureRecognizerDirectionRight:
|
break;
|
||||||
SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_RIGHT);
|
case UISwipeGestureRecognizerDirectionRight:
|
||||||
SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_RIGHT);
|
SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_RIGHT);
|
||||||
break;
|
SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_RIGHT);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue