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_JoystickAxisInfo
 
struct  SDL_Joystick
 
struct  SDL_Joystick::balldelta
 

Macros

#define MAKE_VIDPID(VID, PID)   (((Uint32)(VID))<<16|(PID))
 

Functions

int SDL_SYS_JoystickInit (void)
 
int SDL_SYS_NumJoysticks (void)
 
void SDL_SYS_JoystickDetect (void)
 
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)
 

Macro Definition Documentation

◆ MAKE_VIDPID

Function Documentation

◆ SDL_SYS_GetInstanceIdOfDeviceIndex()

SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex ( int  device_index)

Definition at line 400 of file SDL_sysjoystick.m.

References device, GetDeviceForIndex(), and recDevice::instance_id.

Referenced by SDL_GameControllerOpen(), and SDL_JoystickGetDeviceInstanceID().

401 {
403  return device ? device->instance_id : 0;
404 }
static SDL_JoystickDeviceItem * GetDeviceForIndex(int device_index)
static SDL_AudioDeviceID device
Definition: loopwave.c:37

◆ SDL_SYS_JoystickAttached()

SDL_bool SDL_SYS_JoystickAttached ( SDL_Joystick *  joystick)

Definition at line 457 of file SDL_sysjoystick.m.

References NULL.

Referenced by SDL_JoystickGetAttached().

458 {
459  return joystick->hwdata != NULL;
460 }
#define NULL
Definition: begin_code.h:164

◆ SDL_SYS_JoystickClose()

void SDL_SYS_JoystickClose ( SDL_Joystick *  joystick)

Definition at line 697 of file SDL_sysjoystick.m.

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

Referenced by SDL_JoystickClose().

698 {
699  SDL_JoystickDeviceItem *device = joystick->hwdata;
700 
701  if (device == NULL) {
702  return;
703  }
704 
705  device->joystick = NULL;
706 
707  @autoreleasepool {
708  if (device->accelerometer) {
709 #if !TARGET_OS_TV
710  [motionManager stopAccelerometerUpdates];
711 #endif /* !TARGET_OS_TV */
712  } else if (device->controller) {
713 #ifdef SDL_JOYSTICK_MFI
714  GCController *controller = device->controller;
715  controller.controllerPausedHandler = nil;
716  controller.playerIndex = -1;
717 #endif
718  }
719  }
720 }
SDL_Joystick * joystick
static SDL_AudioDeviceID device
Definition: loopwave.c:37
#define NULL
Definition: begin_code.h:164
GCController __unsafe_unretained * controller
static CMMotionManager * motionManager

◆ SDL_SYS_JoystickDetect()

void SDL_SYS_JoystickDetect ( void  )

Definition at line 386 of file SDL_sysjoystick.m.

References SDL_UpdateSteamControllers().

Referenced by SDL_JoystickUpdate().

387 {
389 }
void SDL_UpdateSteamControllers(void)

◆ SDL_SYS_JoystickGetDeviceGUID()

SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID ( int  device_index)

Definition at line 761 of file SDL_sysjoystick.m.

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

Referenced by SDL_JoystickGetDeviceGUID().

762 {
764  SDL_JoystickGUID guid;
765  if (device) {
766  guid = device->guid;
767  } else {
768  SDL_zero(guid);
769  }
770  return guid;
771 }
SDL_JoystickGUID guid
static SDL_JoystickDeviceItem * GetDeviceForIndex(int device_index)
static SDL_AudioDeviceID device
Definition: loopwave.c:37
#define SDL_zero(x)
Definition: SDL_stdinc.h:416

◆ SDL_SYS_JoystickGetGUID()

SDL_JoystickGUID SDL_SYS_JoystickGetGUID ( SDL_Joystick *  joystick)

Definition at line 774 of file SDL_sysjoystick.m.

References recDevice::guid, and SDL_zero.

Referenced by SDL_JoystickGetGUID().

775 {
776  SDL_JoystickGUID guid;
777  if (joystick->hwdata) {
778  guid = joystick->hwdata->guid;
779  } else {
780  SDL_zero(guid);
781  }
782  return guid;
783 }
#define SDL_zero(x)
Definition: SDL_stdinc.h:416

◆ SDL_SYS_JoystickInit()

int SDL_SYS_JoystickInit ( void  )

Definition at line 321 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_InitSteamControllers(), SDL_SYS_AddJoystickDevice(), SDL_TRUE, SteamControllerConnectedCallback(), and SteamControllerDisconnectedCallback().

Referenced by SDL_JoystickInit().

322 {
323  @autoreleasepool {
324  NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
325 
328 
329 #if !TARGET_OS_TV
331  /* Default behavior, accelerometer as joystick */
333  }
334 #endif /* !TARGET_OS_TV */
335 
336 #ifdef SDL_JOYSTICK_MFI
337  /* GameController.framework was added in iOS 7. */
338  if (![GCController class]) {
339  return numjoysticks;
340  }
341 
342  for (GCController *controller in [GCController controllers]) {
344  }
345 
346 #if TARGET_OS_TV
348  SDL_AppleTVRemoteRotationHintChanged, NULL);
349 #endif /* TARGET_OS_TV */
350 
351  connectObserver = [center addObserverForName:GCControllerDidConnectNotification
352  object:nil
353  queue:nil
354  usingBlock:^(NSNotification *note) {
355  GCController *controller = note.object;
357  }];
358 
359  disconnectObserver = [center addObserverForName:GCControllerDidDisconnectNotification
360  object:nil
361  queue:nil
362  usingBlock:^(NSNotification *note) {
363  GCController *controller = note.object;
365  while (device != NULL) {
366  if (device->controller == controller) {
368  break;
369  }
370  device = device->next;
371  }
372  }];
373 #endif /* SDL_JOYSTICK_MFI */
374  }
375 
376  return numjoysticks;
377 }
void SDL_InitSteamControllers(SteamControllerConnectedCallback_t connectedCallback, SteamControllerDisconnectedCallback_t disconnectedCallback)
static void SteamControllerDisconnectedCallback(int device_instance)
static SDL_JoystickDeviceItem * deviceList
#define SDL_HINT_APPLE_TV_REMOTE_ALLOW_ROTATION
A variable controlling whether the Apple TV remote&#39;s joystick axes will automatically match the rotat...
Definition: SDL_hints.h:355
struct joystick_hwdata * next
#define SDL_GetHintBoolean
static SDL_AudioDeviceID device
Definition: loopwave.c:37
#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:366
static SDL_bool SteamControllerConnectedCallback(const char *name, SDL_JoystickGUID guid, int *device_instance)
#define NULL
Definition: begin_code.h:164
#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 393 of file SDL_sysjoystick.m.

References device, GetDeviceForIndex(), and recDevice::name.

Referenced by SDL_JoystickNameForIndex(), and SDL_JoystickOpen().

394 {
396  return device ? device->name : "Unknown";
397 }
static SDL_JoystickDeviceItem * GetDeviceForIndex(int device_index)
static SDL_AudioDeviceID device
Definition: loopwave.c:37

◆ SDL_SYS_JoystickOpen()

int SDL_SYS_JoystickOpen ( SDL_Joystick *  joystick,
int  device_index 
)

Definition at line 412 of file SDL_sysjoystick.m.

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

Referenced by SDL_JoystickOpen().

413 {
415  if (device == NULL) {
416  return SDL_SetError("Could not open Joystick: no hardware device for the specified index");
417  }
418 
419  joystick->hwdata = device;
420  joystick->instance_id = device->instance_id;
421 
422  joystick->naxes = device->naxes;
423  joystick->nhats = device->nhats;
424  joystick->nbuttons = device->nbuttons;
425  joystick->nballs = 0;
426 
427  device->joystick = joystick;
428 
429  @autoreleasepool {
430  if (device->accelerometer) {
431 #if !TARGET_OS_TV
432  if (motionManager == nil) {
433  motionManager = [[CMMotionManager alloc] init];
434  }
435 
436  /* Shorter times between updates can significantly increase CPU usage. */
437  motionManager.accelerometerUpdateInterval = 0.1;
438  [motionManager startAccelerometerUpdates];
439 #endif /* !TARGET_OS_TV */
440  } else {
441 #ifdef SDL_JOYSTICK_MFI
442  GCController *controller = device->controller;
443  controller.controllerPausedHandler = ^(GCController *c) {
444  if (joystick->hwdata) {
445  ++joystick->hwdata->num_pause_presses;
446  }
447  };
448 #endif /* SDL_JOYSTICK_MFI */
449  }
450  }
451 
452  return 0;
453 }
SDL_Joystick * joystick
static SDL_JoystickDeviceItem * GetDeviceForIndex(int device_index)
static SDL_AudioDeviceID device
Definition: loopwave.c:37
const GLubyte * c
#define NULL
Definition: begin_code.h:164
#define SDL_SetError
GCController __unsafe_unretained * controller
static CMMotionManager * motionManager

◆ SDL_SYS_JoystickQuit()

void SDL_SYS_JoystickQuit ( void  )

Definition at line 724 of file SDL_sysjoystick.m.

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

Referenced by SDL_JoystickQuit().

725 {
726  @autoreleasepool {
727 #ifdef SDL_JOYSTICK_MFI
728  NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
729 
730  if (connectObserver) {
731  [center removeObserver:connectObserver name:GCControllerDidConnectNotification object:nil];
732  connectObserver = nil;
733  }
734 
735  if (disconnectObserver) {
736  [center removeObserver:disconnectObserver name:GCControllerDidDisconnectNotification object:nil];
737  disconnectObserver = nil;
738  }
739 
740 #if TARGET_OS_TV
742  SDL_AppleTVRemoteRotationHintChanged, NULL);
743 #endif /* TARGET_OS_TV */
744 #endif /* SDL_JOYSTICK_MFI */
745 
746  while (deviceList != NULL) {
748  }
749 
750 #if !TARGET_OS_TV
751  motionManager = nil;
752 #endif /* !TARGET_OS_TV */
753  }
754 
756 
757  numjoysticks = 0;
758 }
void SDL_QuitSteamControllers(void)
static SDL_JoystickDeviceItem * deviceList
#define SDL_HINT_APPLE_TV_REMOTE_ALLOW_ROTATION
A variable controlling whether the Apple TV remote&#39;s joystick axes will automatically match the rotat...
Definition: SDL_hints.h:355
GLuint const GLchar * name
#define NULL
Definition: begin_code.h:164
#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 675 of file SDL_sysjoystick.m.

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

Referenced by SDL_JoystickOpen(), and SDL_JoystickUpdate().

676 {
677  SDL_JoystickDeviceItem *device = joystick->hwdata;
678 
679  if (device == NULL) {
680  return;
681  }
682 
683  if (device->m_bSteamController) {
684  SDL_UpdateSteamController(joystick);
685  return;
686  }
687 
688  if (device->accelerometer) {
689  SDL_SYS_AccelerometerUpdate(joystick);
690  } else if (device->controller) {
691  SDL_SYS_MFIJoystickUpdate(joystick);
692  }
693 }
static void SDL_SYS_MFIJoystickUpdate(SDL_Joystick *joystick)
static SDL_AudioDeviceID device
Definition: loopwave.c:37
#define NULL
Definition: begin_code.h:164
void SDL_UpdateSteamController(SDL_Joystick *joystick)
SDL_bool m_bSteamController
static void SDL_SYS_AccelerometerUpdate(SDL_Joystick *joystick)
GCController __unsafe_unretained * controller

◆ SDL_SYS_NumJoysticks()

int SDL_SYS_NumJoysticks ( void  )

Definition at line 380 of file SDL_sysjoystick.m.

References numjoysticks.

Referenced by SDL_NumJoysticks().

381 {
382  return numjoysticks;
383 }
static int numjoysticks