SDL  2.0
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_SYS_GetInstanceIdOfDeviceIndex()

SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex ( int  device_index)

Definition at line 347 of file SDL_sysjoystick.m.

References GetDeviceForIndex(), and recDevice::instance_id.

Referenced by SDL_GameControllerOpen(), and SDL_JoystickOpen().

348 {
349  SDL_JoystickDeviceItem *device = GetDeviceForIndex(device_index);
350  return device ? device->instance_id : 0;
351 }
static SDL_JoystickDeviceItem * GetDeviceForIndex(int device_index)

◆ SDL_SYS_JoystickAttached()

SDL_bool SDL_SYS_JoystickAttached ( SDL_Joystick *  joystick)

Definition at line 404 of file SDL_sysjoystick.m.

References NULL.

Referenced by SDL_JoystickGetAttached().

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

◆ SDL_SYS_JoystickClose()

void SDL_SYS_JoystickClose ( SDL_Joystick *  joystick)

Definition at line 639 of file SDL_sysjoystick.m.

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

Referenced by SDL_JoystickClose().

640 {
641  SDL_JoystickDeviceItem *device = joystick->hwdata;
642 
643  if (device == NULL) {
644  return;
645  }
646 
647  device->joystick = NULL;
648 
649  @autoreleasepool {
650  if (device->accelerometer) {
651 #if !TARGET_OS_TV
652  [motionManager stopAccelerometerUpdates];
653 #endif /* !TARGET_OS_TV */
654  } else if (device->controller) {
655 #ifdef SDL_JOYSTICK_MFI
656  GCController *controller = device->controller;
657  controller.controllerPausedHandler = nil;
658  controller.playerIndex = -1;
659 #endif
660  }
661  }
662 }
SDL_Joystick * joystick
#define NULL
Definition: begin_code.h:143
GCController __unsafe_unretained * controller
static CMMotionManager * motionManager

◆ SDL_SYS_JoystickDetect()

void SDL_SYS_JoystickDetect ( )

Definition at line 334 of file SDL_sysjoystick.m.

Referenced by SDL_JoystickUpdate().

335 {
336 }

◆ SDL_SYS_JoystickGetDeviceGUID()

SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID ( int  device_index)

Definition at line 701 of file SDL_sysjoystick.m.

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

Referenced by SDL_JoystickGetDeviceGUID().

702 {
703  SDL_JoystickDeviceItem *device = GetDeviceForIndex(device_index);
704  SDL_JoystickGUID guid;
705  if (device) {
706  guid = device->guid;
707  } else {
708  SDL_zero(guid);
709  }
710  return guid;
711 }
SDL_JoystickGUID guid
static SDL_JoystickDeviceItem * GetDeviceForIndex(int device_index)
#define SDL_zero(x)
Definition: SDL_stdinc.h:361

◆ SDL_SYS_JoystickGetGUID()

SDL_JoystickGUID SDL_SYS_JoystickGetGUID ( SDL_Joystick *  joystick)

Definition at line 714 of file SDL_sysjoystick.m.

References recDevice::guid, and SDL_zero.

Referenced by SDL_JoystickGetGUID().

715 {
716  SDL_JoystickGUID guid;
717  if (joystick->hwdata) {
718  guid = joystick->hwdata->guid;
719  } else {
720  SDL_zero(guid);
721  }
722  return guid;
723 }
#define SDL_zero(x)
Definition: SDL_stdinc.h:361

◆ SDL_SYS_JoystickInit()

int SDL_SYS_JoystickInit ( void  )

Definition at line 274 of file SDL_sysjoystick.m.

References recDevice::controller, sort_controllers::controllers, NULL, numjoysticks, SDL_AddHintCallback, SDL_FALSE, SDL_GetHintBoolean, SDL_HINT_ACCELEROMETER_AS_JOYSTICK, SDL_HINT_APPLE_TV_REMOTE_ALLOW_ROTATION, SDL_SYS_AddJoystickDevice(), and SDL_TRUE.

Referenced by SDL_JoystickInit().

275 {
276  @autoreleasepool {
277  NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
278 
279 #if !TARGET_OS_TV
281  /* Default behavior, accelerometer as joystick */
283  }
284 #endif /* !TARGET_OS_TV */
285 
286 #ifdef SDL_JOYSTICK_MFI
287  /* GameController.framework was added in iOS 7. */
288  if (![GCController class]) {
289  return numjoysticks;
290  }
291 
292  for (GCController *controller in [GCController controllers]) {
294  }
295 
296 #if TARGET_OS_TV
298  SDL_AppleTVRemoteRotationHintChanged, NULL);
299 #endif /* TARGET_OS_TV */
300 
301  connectObserver = [center addObserverForName:GCControllerDidConnectNotification
302  object:nil
303  queue:nil
304  usingBlock:^(NSNotification *note) {
305  GCController *controller = note.object;
307  }];
308 
309  disconnectObserver = [center addObserverForName:GCControllerDidDisconnectNotification
310  object:nil
311  queue:nil
312  usingBlock:^(NSNotification *note) {
313  GCController *controller = note.object;
315  while (device != NULL) {
316  if (device->controller == controller) {
318  break;
319  }
320  device = device->next;
321  }
322  }];
323 #endif /* SDL_JOYSTICK_MFI */
324  }
325 
326  return numjoysticks;
327 }
static SDL_JoystickDeviceItem * deviceList
#define SDL_HINT_APPLE_TV_REMOTE_ALLOW_ROTATION
A variable controlling whether the Apple TV remote's joystick axes will automatically match the rotat...
Definition: SDL_hints.h:317
struct joystick_hwdata * next
#define SDL_GetHintBoolean
#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:328
#define NULL
Definition: begin_code.h:143
#define SDL_AddHintCallback
static SDL_JoystickDeviceItem * SDL_SYS_RemoveJoystickDevice(SDL_JoystickDeviceItem *device)
static int numjoysticks
GLuint in
static void SDL_SYS_AddJoystickDevice(GCController *controller, SDL_bool accelerometer)
GCController __unsafe_unretained * controller
GLuint object

◆ SDL_SYS_JoystickNameForDeviceIndex()

const char* SDL_SYS_JoystickNameForDeviceIndex ( int  device_index)

Definition at line 340 of file SDL_sysjoystick.m.

References GetDeviceForIndex(), and recDevice::name.

Referenced by SDL_JoystickNameForIndex(), and SDL_JoystickOpen().

341 {
342  SDL_JoystickDeviceItem *device = GetDeviceForIndex(device_index);
343  return device ? device->name : "Unknown";
344 }
static SDL_JoystickDeviceItem * GetDeviceForIndex(int device_index)

◆ SDL_SYS_JoystickOpen()

int SDL_SYS_JoystickOpen ( SDL_Joystick *  joystick,
int  device_index 
)

Definition at line 359 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().

360 {
361  SDL_JoystickDeviceItem *device = GetDeviceForIndex(device_index);
362  if (device == NULL) {
363  return SDL_SetError("Could not open Joystick: no hardware device for the specified index");
364  }
365 
366  joystick->hwdata = device;
367  joystick->instance_id = device->instance_id;
368 
369  joystick->naxes = device->naxes;
370  joystick->nhats = device->nhats;
371  joystick->nbuttons = device->nbuttons;
372  joystick->nballs = 0;
373 
374  device->joystick = joystick;
375 
376  @autoreleasepool {
377  if (device->accelerometer) {
378 #if !TARGET_OS_TV
379  if (motionManager == nil) {
380  motionManager = [[CMMotionManager alloc] init];
381  }
382 
383  /* Shorter times between updates can significantly increase CPU usage. */
384  motionManager.accelerometerUpdateInterval = 0.1;
385  [motionManager startAccelerometerUpdates];
386 #endif /* !TARGET_OS_TV */
387  } else {
388 #ifdef SDL_JOYSTICK_MFI
389  GCController *controller = device->controller;
390  controller.controllerPausedHandler = ^(GCController *c) {
391  if (joystick->hwdata) {
392  ++joystick->hwdata->num_pause_presses;
393  }
394  };
395 #endif /* SDL_JOYSTICK_MFI */
396  }
397  }
398 
399  return 0;
400 }
SDL_Joystick * joystick
static SDL_JoystickDeviceItem * GetDeviceForIndex(int device_index)
const GLubyte * c
#define NULL
Definition: begin_code.h:143
#define SDL_SetError
GCController __unsafe_unretained * controller
static CMMotionManager * motionManager

◆ SDL_SYS_JoystickQuit()

void SDL_SYS_JoystickQuit ( void  )

Definition at line 666 of file SDL_sysjoystick.m.

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

Referenced by SDL_JoystickQuit().

667 {
668  @autoreleasepool {
669 #ifdef SDL_JOYSTICK_MFI
670  NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
671 
672  if (connectObserver) {
673  [center removeObserver:connectObserver name:GCControllerDidConnectNotification object:nil];
674  connectObserver = nil;
675  }
676 
677  if (disconnectObserver) {
678  [center removeObserver:disconnectObserver name:GCControllerDidDisconnectNotification object:nil];
679  disconnectObserver = nil;
680  }
681 
682 #if TARGET_OS_TV
684  SDL_AppleTVRemoteRotationHintChanged, NULL);
685 #endif /* TARGET_OS_TV */
686 #endif /* SDL_JOYSTICK_MFI */
687 
688  while (deviceList != NULL) {
690  }
691 
692 #if !TARGET_OS_TV
693  motionManager = nil;
694 #endif /* !TARGET_OS_TV */
695  }
696 
697  numjoysticks = 0;
698 }
static SDL_JoystickDeviceItem * deviceList
#define SDL_HINT_APPLE_TV_REMOTE_ALLOW_ROTATION
A variable controlling whether the Apple TV remote's joystick axes will automatically match the rotat...
Definition: SDL_hints.h:317
GLuint const GLchar * name
#define NULL
Definition: begin_code.h:143
#define SDL_DelHintCallback
static SDL_JoystickDeviceItem * SDL_SYS_RemoveJoystickDevice(SDL_JoystickDeviceItem *device)
static int numjoysticks
GLuint object
static CMMotionManager * motionManager

◆ SDL_SYS_JoystickUpdate()

void SDL_SYS_JoystickUpdate ( SDL_Joystick *  joystick)

Definition at line 622 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().

623 {
624  SDL_JoystickDeviceItem *device = joystick->hwdata;
625 
626  if (device == NULL) {
627  return;
628  }
629 
630  if (device->accelerometer) {
631  SDL_SYS_AccelerometerUpdate(joystick);
632  } else if (device->controller) {
633  SDL_SYS_MFIJoystickUpdate(joystick);
634  }
635 }
static void SDL_SYS_MFIJoystickUpdate(SDL_Joystick *joystick)
#define NULL
Definition: begin_code.h:143
static void SDL_SYS_AccelerometerUpdate(SDL_Joystick *joystick)
GCController __unsafe_unretained * controller

◆ SDL_SYS_NumJoysticks()

int SDL_SYS_NumJoysticks ( )

Definition at line 329 of file SDL_sysjoystick.m.

References numjoysticks.

Referenced by SDL_NumJoysticks().

330 {
331  return numjoysticks;
332 }
static int numjoysticks