iOS now respects SDL_HINT_ACCELEROMETER_AS_JOYSTICK.
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
diff --git a/include/SDL_hints.h b/include/SDL_hints.h
index e0fce66..1c46515 100644
--- a/include/SDL_hints.h
+++ b/include/SDL_hints.h
@@ -261,8 +261,9 @@ extern "C" {
#define SDL_HINT_ORIENTATIONS "SDL_IOS_ORIENTATIONS"
/**
- * \brief A variable controlling whether an Android built-in accelerometer should be
- * listed as a joystick device, rather than listing actual joysticks only.
+ * \brief A variable controlling whether the Android / iOS built-in
+ * accelerometer should be listed as a joystick device, rather than listing
+ * actual joysticks only.
*
* This variable can be set to the following values:
* "0" - List only real joysticks and accept input from them
diff --git a/src/joystick/iphoneos/SDL_sysjoystick.m b/src/joystick/iphoneos/SDL_sysjoystick.m
index a402759..1f37af4 100644
--- a/src/joystick/iphoneos/SDL_sysjoystick.m
+++ b/src/joystick/iphoneos/SDL_sysjoystick.m
@@ -23,6 +23,7 @@
/* This is the iOS implementation of the SDL joystick API */
#include "SDL_joystick.h"
+#include "SDL_hints.h"
#include "SDL_stdinc.h"
#include "../SDL_sysjoystick.h"
#include "../SDL_joystick_c.h"
@@ -32,9 +33,10 @@
/* needed for SDL_IPHONE_MAX_GFORCE macro */
#import "SDL_config_iphoneos.h"
-const char *accelerometerName = "iOS accelerometer";
+const char *accelerometerName = "iOS Accelerometer";
static CMMotionManager *motionManager = nil;
+static int numjoysticks = 0;
/* Function to scan the system for joysticks.
* This function should set SDL_numjoysticks to the number of available
@@ -44,12 +46,18 @@ static CMMotionManager *motionManager = nil;
int
SDL_SYS_JoystickInit(void)
{
- return (1);
+ const char *hint = SDL_GetHint(SDL_HINT_ACCELEROMETER_AS_JOYSTICK);
+ if (!hint || SDL_atoi(hint)) {
+ /* Default behavior, accelerometer as joystick */
+ numjoysticks++;
+ }
+
+ return numjoysticks;
}
int SDL_SYS_NumJoysticks()
{
- return 1;
+ return numjoysticks;
}
void SDL_SYS_JoystickDetect()
@@ -165,6 +173,8 @@ SDL_SYS_JoystickQuit(void)
[motionManager release];
motionManager = nil;
}
+
+ numjoysticks = 0;
}
SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )