SDL_sysjoystick.h File Reference
`#include "../SDL_internal.h"`
`#include "SDL_joystick.h"`
`#include "SDL_joystick_c.h"`
Include dependency graph for SDL_sysjoystick.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Data Structures

struct | SDL_Joystick
struct | SDL_Joystick::balldelta

## Functions

int | SDL_SYS_JoystickInit (void)
int | SDL_SYS_NumJoysticks ()
void | SDL_SYS_JoystickDetect ()
const char * | SDL_SYS_JoystickNameForDeviceIndex (int device_index)
SDL_JoystickID | SDL_SYS_GetInstanceIdOfDeviceIndex (int device_index)
int | SDL_SYS_JoystickOpen (SDL_Joystick *joystick, int device_index)
SDL_bool | SDL_SYS_JoystickAttached (SDL_Joystick *joystick)
void | SDL_SYS_JoystickUpdate (SDL_Joystick *joystick)
void | SDL_SYS_JoystickClose (SDL_Joystick *joystick)
void | SDL_SYS_JoystickQuit (void)
SDL_JoystickGUID | SDL_SYS_JoystickGetDeviceGUID (int device_index)
SDL_JoystickGUID | SDL_SYS_JoystickGetGUID (SDL_Joystick *joystick)

## Function Documentation

SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex | ( | int | device_index | ) |

Definition at line 327 of file SDL_sysjoystick.m.

References GetDeviceForIndex(), and recDevice::instance_id.

Referenced by SDL_GameControllerOpen(), and SDL_JoystickOpen().

{
SDL_JoystickDeviceItem *device = GetDeviceForIndex(device_index);
return device ? device->instance_id : 0;
}
GetDeviceForIndex
static SDL_JoystickDeviceItem * GetDeviceForIndex(int device_index)
Definition: SDL_sysjoystick.m:57
joystick_hwdata
Definition: SDL_sysjoystick_c.h:44
joystick_hwdata::instance_id
int instance_id
Definition: SDL_sysjoystick_c.h:64

SDL_bool SDL_SYS_JoystickAttached | ( | SDL_Joystick * | joystick | ) |

Definition at line 382 of file SDL_sysjoystick.m.

References NULL.

Referenced by SDL_JoystickGetAttached().

{
return joystick->hwdata != NULL;
}
NULL
#define NULL
Definition: begin_code.h:143

void SDL_SYS_JoystickClose | ( | SDL_Joystick * | joystick | ) |

Definition at line 586 of file SDL_sysjoystick.m.

References recDevice::accelerometer, recDevice::controller, recDevice::joystick, and NULL.

Referenced by SDL_JoystickClose().

{
SDL_JoystickDeviceItem *device = joystick->hwdata;
if (device == NULL) {
return;
}
device->joystick = NULL;
@autoreleasepool {
if (device->accelerometer) {
[motionManager stopAccelerometerUpdates];
} else if (device->controller) {
#ifdef SDL_JOYSTICK_MFI
GCController *controller = device->controller;
controller.controllerPausedHandler = nil;
controller.playerIndex = -1;
#endif
}
}
}
joystick_hwdata::joystick
SDL_Joystick * joystick
Definition: SDL_sysjoystick_c.h:39
joystick_hwdata
Definition: SDL_sysjoystick_c.h:44
joystick_hwdata::accelerometer
SDL_bool accelerometer
Definition: SDL_sysjoystick_c.h:33
NULL
#define NULL
Definition: begin_code.h:143
joystick_hwdata::controller
GCController __unsafe_unretained * controller
Definition: SDL_sysjoystick_c.h:35
motionManager
static CMMotionManager * motionManager
Definition: SDL_sysjoystick.m:49

void SDL_SYS_JoystickDetect | ( |  | ) |

Definition at line 314 of file SDL_sysjoystick.m.

Referenced by SDL_JoystickUpdate().

{
}

SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID | ( | int | device_index | ) |

Definition at line 639 of file SDL_sysjoystick.m.

References GetDeviceForIndex(), recDevice::guid, and SDL_zero.

Referenced by SDL_JoystickGetDeviceGUID().

{
SDL_JoystickDeviceItem *device = GetDeviceForIndex(device_index);
SDL_JoystickGUID guid;
if (device) {
guid = device->guid;
} else {
SDL_zero(guid);
}
return guid;
}
joystick_hwdata::guid
SDL_JoystickGUID guid
Definition: SDL_sysjoystick_c.h:65
GetDeviceForIndex
static SDL_JoystickDeviceItem * GetDeviceForIndex(int device_index)
Definition: SDL_sysjoystick.m:57
joystick_hwdata
Definition: SDL_sysjoystick_c.h:44
SDL_zero
#define SDL_zero(x)
Definition: SDL_stdinc.h:355
SDL_JoystickGUID
Definition: SDL_joystick.h:68

SDL_JoystickGUID SDL_SYS_JoystickGetGUID | ( | SDL_Joystick * | joystick | ) |

Definition at line 652 of file SDL_sysjoystick.m.

References recDevice::guid, and SDL_zero.

Referenced by SDL_JoystickGetGUID().

{
SDL_JoystickGUID guid;
if (joystick->hwdata) {
guid = joystick->hwdata->guid;
} else {
SDL_zero(guid);
}
return guid;
}
SDL_zero
#define SDL_zero(x)
Definition: SDL_stdinc.h:355
SDL_JoystickGUID
Definition: SDL_joystick.h:68

int SDL_SYS_JoystickInit | ( | void |  | ) |

Definition at line 260 of file SDL_sysjoystick.m.

References recDevice::controller, sort_controllers::controllers, numjoysticks, SDL_atoi, SDL_FALSE, SDL_GetHint, SDL_HINT_ACCELEROMETER_AS_JOYSTICK, SDL_SYS_AddJoystickDevice(), and SDL_TRUE.

Referenced by SDL_JoystickInit().

{
@autoreleasepool {
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
const char *hint = SDL_GetHint(SDL_HINT_ACCELEROMETER_AS_JOYSTICK);
if (!hint || SDL_atoi(hint)) {
/* Default behavior, accelerometer as joystick */
SDL_SYS_AddJoystickDevice(nil, SDL_TRUE);
}
#ifdef SDL_JOYSTICK_MFI
/* GameController.framework was added in iOS 7. */
if (![GCController class]) {
return numjoysticks;
}
for (GCController *controller in [GCController controllers]) {
SDL_SYS_AddJoystickDevice(controller, SDL_FALSE);
}
connectObserver = [center addObserverForName:GCControllerDidConnectNotification
object:nil
queue:nil
usingBlock:^(NSNotification *note) {
GCController *controller = note.object;
SDL_SYS_AddJoystickDevice(controller, SDL_FALSE);
}];
disconnectObserver = [center addObserverForName:GCControllerDidDisconnectNotification
object:nil
queue:nil
usingBlock:^(NSNotification *note) {
GCController *controller = note.object;
SDL_JoystickDeviceItem *device = deviceList;
while (device != NULL) {
if (device->controller == controller) {
SDL_SYS_RemoveJoystickDevice(device);
break;
}
device = device->next;
}
}];
#endif /* SDL_JOYSTICK_MFI */
}
return numjoysticks;
}
deviceList
static SDL_JoystickDeviceItem * deviceList
Definition: SDL_sysjoystick.m:51
SDL_GetHint
#define SDL_GetHint
Definition: SDL_dynapi_overrides.h:197
joystick_hwdata::next
struct joystick_hwdata * next
Definition: SDL_sysjoystick_c.h:47
joystick_hwdata
Definition: SDL_sysjoystick_c.h:44
SDL_HINT_ACCELEROMETER_AS_JOYSTICK
#define SDL_HINT_ACCELEROMETER_AS_JOYSTICK
A variable controlling whether the Android / iOS built-in accelerometer should be listed as a joystic...
Definition: SDL_hints.h:289
sort_controllers.controllers
list controllers
Definition: sort_controllers.py:12
SDL_TRUE
Definition: SDL_stdinc.h:129
SDL_atoi
#define SDL_atoi
Definition: SDL_dynapi_overrides.h:416
NULL
#define NULL
Definition: begin_code.h:143
SDL_FALSE
Definition: SDL_stdinc.h:128
SDL_SYS_RemoveJoystickDevice
static SDL_JoystickDeviceItem * SDL_SYS_RemoveJoystickDevice(SDL_JoystickDeviceItem *device)
Definition: SDL_sysjoystick.m:189
numjoysticks
static int numjoysticks
Definition: SDL_sysjoystick.m:53
in
GLuint in
Definition: SDL_opengl_glext.h:7940
SDL_SYS_AddJoystickDevice
static void SDL_SYS_AddJoystickDevice(GCController *controller, SDL_bool accelerometer)
Definition: SDL_sysjoystick.m:127
joystick_hwdata::controller
GCController __unsafe_unretained * controller
Definition: SDL_sysjoystick_c.h:35

const char* SDL_SYS_JoystickNameForDeviceIndex | ( | int | device_index | ) |

Definition at line 320 of file SDL_sysjoystick.m.

References GetDeviceForIndex(), and recDevice::name.

Referenced by SDL_JoystickNameForIndex(), and SDL_JoystickOpen().

{
SDL_JoystickDeviceItem *device = GetDeviceForIndex(device_index);
return device ? device->name : "Unknown";
}
GetDeviceForIndex
static SDL_JoystickDeviceItem * GetDeviceForIndex(int device_index)
Definition: SDL_sysjoystick.m:57
joystick_hwdata
Definition: SDL_sysjoystick_c.h:44
joystick_hwdata::name
char * name
Definition: SDL_sysjoystick_c.h:38

int SDL_SYS_JoystickOpen | ( | SDL_Joystick * | joystick,
|  | int | device_index
| ) |  |

Definition at line 339 of file SDL_sysjoystick.m.

References recDevice::accelerometer, recDevice::controller, GetDeviceForIndex(), recDevice::instance_id, recDevice::joystick, motionManager, recDevice::naxes, recDevice::nbuttons, recDevice::nhats, NULL, and SDL_SetError.

Referenced by SDL_JoystickOpen().

{
SDL_JoystickDeviceItem *device = GetDeviceForIndex(device_index);
if (device == NULL) {
return SDL_SetError("Could not open Joystick: no hardware device for the specified index");
}
joystick->hwdata = device;
joystick->instance_id = device->instance_id;
joystick->naxes = device->naxes;
joystick->nhats = device->nhats;
joystick->nbuttons = device->nbuttons;
joystick->nballs = 0;
device->joystick = joystick;
@autoreleasepool {
if (device->accelerometer) {
if (motionManager == nil) {
motionManager = [[CMMotionManager alloc] init];
}
/* Shorter times between updates can significantly increase CPU usage. */
motionManager.accelerometerUpdateInterval = 0.1;
[motionManager startAccelerometerUpdates];
} else {
#ifdef SDL_JOYSTICK_MFI
GCController *controller = device->controller;
controller.controllerPausedHandler = ^(GCController *c) {
if (joystick->hwdata) {
++joystick->hwdata->num_pause_presses;
}
};
#endif /* SDL_JOYSTICK_MFI */
}
}
return 0;
}
joystick_hwdata::nbuttons
int nbuttons
Definition: SDL_sysjoystick_c.h:44
joystick_hwdata::joystick
SDL_Joystick * joystick
Definition: SDL_sysjoystick_c.h:39
GetDeviceForIndex
static SDL_JoystickDeviceItem * GetDeviceForIndex(int device_index)
Definition: SDL_sysjoystick.m:57
joystick_hwdata::naxes
int naxes
Definition: SDL_sysjoystick_c.h:43
joystick_hwdata
Definition: SDL_sysjoystick_c.h:44
joystick_hwdata::accelerometer
SDL_bool accelerometer
Definition: SDL_sysjoystick_c.h:33
joystick_hwdata::instance_id
int instance_id
Definition: SDL_sysjoystick_c.h:64
c
const GLubyte * c
Definition: SDL_opengl_glext.h:11093
NULL
#define NULL
Definition: begin_code.h:143
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:36
joystick_hwdata::nhats
int nhats
Definition: SDL_sysjoystick_c.h:45
joystick_hwdata::controller
GCController __unsafe_unretained * controller
Definition: SDL_sysjoystick_c.h:35
motionManager
static CMMotionManager * motionManager
Definition: SDL_sysjoystick.m:49

void SDL_SYS_JoystickQuit | ( | void |  | ) |

Definition at line 611 of file SDL_sysjoystick.m.

References motionManager, NULL, numjoysticks, and SDL_SYS_RemoveJoystickDevice().

Referenced by SDL_JoystickQuit().

{
@autoreleasepool {
#ifdef SDL_JOYSTICK_MFI
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
if (connectObserver) {
[center removeObserver:connectObserver name:GCControllerDidConnectNotification object:nil];
connectObserver = nil;
}
if (disconnectObserver) {
[center removeObserver:disconnectObserver name:GCControllerDidDisconnectNotification object:nil];
disconnectObserver = nil;
}
#endif /* SDL_JOYSTICK_MFI */
while (deviceList != NULL) {
SDL_SYS_RemoveJoystickDevice(deviceList);
}
motionManager = nil;
}
numjoysticks = 0;
}
deviceList
static SDL_JoystickDeviceItem * deviceList
Definition: SDL_sysjoystick.m:51
name
GLuint const GLchar * name
Definition: SDL_opengl_glext.h:660
NULL
#define NULL
Definition: begin_code.h:143
SDL_SYS_RemoveJoystickDevice
static SDL_JoystickDeviceItem * SDL_SYS_RemoveJoystickDevice(SDL_JoystickDeviceItem *device)
Definition: SDL_sysjoystick.m:189
numjoysticks
static int numjoysticks
Definition: SDL_sysjoystick.m:53
motionManager
static CMMotionManager * motionManager
Definition: SDL_sysjoystick.m:49

void SDL_SYS_JoystickUpdate | ( | SDL_Joystick * | joystick | ) |

Definition at line 569 of file SDL_sysjoystick.m.

References recDevice::accelerometer, recDevice::controller, NULL, SDL_SYS_AccelerometerUpdate(), and SDL_SYS_MFIJoystickUpdate().

Referenced by SDL_GameControllerOpen(), SDL_JoystickOpen(), and SDL_JoystickUpdate().

{
SDL_JoystickDeviceItem *device = joystick->hwdata;
if (device == NULL) {
return;
}
if (device->accelerometer) {
SDL_SYS_AccelerometerUpdate(joystick);
} else if (device->controller) {
SDL_SYS_MFIJoystickUpdate(joystick);
}
}
SDL_SYS_MFIJoystickUpdate
static void SDL_SYS_MFIJoystickUpdate(SDL_Joystick *joystick)
Definition: SDL_sysjoystick.m:456
joystick_hwdata
Definition: SDL_sysjoystick_c.h:44
joystick_hwdata::accelerometer
SDL_bool accelerometer
Definition: SDL_sysjoystick_c.h:33
NULL
#define NULL
Definition: begin_code.h:143
SDL_SYS_AccelerometerUpdate
static void SDL_SYS_AccelerometerUpdate(SDL_Joystick *joystick)
Definition: SDL_sysjoystick.m:388
joystick_hwdata::controller
GCController __unsafe_unretained * controller
Definition: SDL_sysjoystick_c.h:35

int SDL_SYS_NumJoysticks | ( |  | ) |

Definition at line 309 of file SDL_sysjoystick.m.

References numjoysticks.

Referenced by SDL_NumJoysticks().

{
return numjoysticks;
}
numjoysticks
static int numjoysticks
Definition: SDL_sysjoystick.m:53