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 409 of file SDL_sysjoystick.m.

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

Referenced by SDL_GameControllerOpen(), and SDL_JoystickGetDeviceInstanceID().

410 {
412  return device ? device->instance_id : 0;
413 }
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 469 of file SDL_sysjoystick.m.

References NULL.

Referenced by SDL_JoystickGetAttached().

470 {
471  return joystick->hwdata != NULL;
472 }
#define NULL
Definition: begin_code.h:164

◆ SDL_SYS_JoystickClose()

void SDL_SYS_JoystickClose ( SDL_Joystick *  joystick)

Definition at line 704 of file SDL_sysjoystick.m.

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

Referenced by SDL_JoystickClose().

705 {
706  SDL_JoystickDeviceItem *device = joystick->hwdata;
707 
708  if (device == NULL) {
709  return;
710  }
711 
712  device->joystick = NULL;
713 
714  @autoreleasepool {
715  if (device->accelerometer) {
716 #if !TARGET_OS_TV
717  [motionManager stopAccelerometerUpdates];
718 #endif /* !TARGET_OS_TV */
719  } else if (device->controller) {
720 #ifdef SDL_JOYSTICK_MFI
721  GCController *controller = device->controller;
722  controller.controllerPausedHandler = nil;
723  controller.playerIndex = -1;
724 #endif
725  }
726  }
727  if (device->remote) {
729  }
730 }
SDL_Joystick * joystick
static SDL_AudioDeviceID device
Definition: loopwave.c:37
#define NULL
Definition: begin_code.h:164
int SDL_AppleTVRemoteOpenedAsJoystick
GCController __unsafe_unretained * controller
static CMMotionManager * motionManager

◆ SDL_SYS_JoystickDetect()

void SDL_SYS_JoystickDetect ( void  )

Definition at line 395 of file SDL_sysjoystick.m.

References SDL_UpdateSteamControllers().

Referenced by SDL_JoystickUpdate().

396 {
398 }
void SDL_UpdateSteamControllers(void)

◆ SDL_SYS_JoystickGetDeviceGUID()

SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID ( int  device_index)

Definition at line 771 of file SDL_sysjoystick.m.

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

Referenced by SDL_JoystickGetDeviceGUID().

772 {
774  SDL_JoystickGUID guid;
775  if (device) {
776  guid = device->guid;
777  } else {
778  SDL_zero(guid);
779  }
780  return guid;
781 }
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 784 of file SDL_sysjoystick.m.

References recDevice::guid, and SDL_zero.

Referenced by SDL_JoystickGetGUID().

785 {
786  SDL_JoystickGUID guid;
787  if (joystick->hwdata) {
788  guid = joystick->hwdata->guid;
789  } else {
790  SDL_zero(guid);
791  }
792  return guid;
793 }
#define SDL_zero(x)
Definition: SDL_stdinc.h:416

◆ SDL_SYS_JoystickInit()

int SDL_SYS_JoystickInit ( void  )

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

331 {
332  @autoreleasepool {
333  NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
334 
337 
338 #if !TARGET_OS_TV
340  /* Default behavior, accelerometer as joystick */
342  }
343 #endif /* !TARGET_OS_TV */
344 
345 #ifdef SDL_JOYSTICK_MFI
346  /* GameController.framework was added in iOS 7. */
347  if (![GCController class]) {
348  return numjoysticks;
349  }
350 
351  for (GCController *controller in [GCController controllers]) {
353  }
354 
355 #if TARGET_OS_TV
357  SDL_AppleTVRemoteRotationHintChanged, NULL);
358 #endif /* TARGET_OS_TV */
359 
360  connectObserver = [center addObserverForName:GCControllerDidConnectNotification
361  object:nil
362  queue:nil
363  usingBlock:^(NSNotification *note) {
364  GCController *controller = note.object;
366  }];
367 
368  disconnectObserver = [center addObserverForName:GCControllerDidDisconnectNotification
369  object:nil
370  queue:nil
371  usingBlock:^(NSNotification *note) {
372  GCController *controller = note.object;
374  while (device != NULL) {
375  if (device->controller == controller) {
377  break;
378  }
379  device = device->next;
380  }
381  }];
382 #endif /* SDL_JOYSTICK_MFI */
383  }
384 
385  return numjoysticks;
386 }
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:368
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:389
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 402 of file SDL_sysjoystick.m.

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

Referenced by SDL_JoystickNameForIndex(), and SDL_JoystickOpen().

403 {
405  return device ? device->name : "Unknown";
406 }
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 421 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, recDevice::remote, SDL_AppleTVRemoteOpenedAsJoystick, and SDL_SetError.

Referenced by SDL_JoystickOpen().

422 {
424  if (device == NULL) {
425  return SDL_SetError("Could not open Joystick: no hardware device for the specified index");
426  }
427 
428  joystick->hwdata = device;
429  joystick->instance_id = device->instance_id;
430 
431  joystick->naxes = device->naxes;
432  joystick->nhats = device->nhats;
433  joystick->nbuttons = device->nbuttons;
434  joystick->nballs = 0;
435 
436  device->joystick = joystick;
437 
438  @autoreleasepool {
439  if (device->accelerometer) {
440 #if !TARGET_OS_TV
441  if (motionManager == nil) {
442  motionManager = [[CMMotionManager alloc] init];
443  }
444 
445  /* Shorter times between updates can significantly increase CPU usage. */
446  motionManager.accelerometerUpdateInterval = 0.1;
447  [motionManager startAccelerometerUpdates];
448 #endif /* !TARGET_OS_TV */
449  } else {
450 #ifdef SDL_JOYSTICK_MFI
451  GCController *controller = device->controller;
452  controller.controllerPausedHandler = ^(GCController *c) {
453  if (joystick->hwdata) {
454  ++joystick->hwdata->num_pause_presses;
455  }
456  };
457 #endif /* SDL_JOYSTICK_MFI */
458  }
459  }
460  if (device->remote) {
462  }
463 
464  return 0;
465 }
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
int SDL_AppleTVRemoteOpenedAsJoystick
GCController __unsafe_unretained * controller
static CMMotionManager * motionManager

◆ SDL_SYS_JoystickQuit()

void SDL_SYS_JoystickQuit ( void  )

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

735 {
736  @autoreleasepool {
737 #ifdef SDL_JOYSTICK_MFI
738  NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
739 
740  if (connectObserver) {
741  [center removeObserver:connectObserver name:GCControllerDidConnectNotification object:nil];
742  connectObserver = nil;
743  }
744 
745  if (disconnectObserver) {
746  [center removeObserver:disconnectObserver name:GCControllerDidDisconnectNotification object:nil];
747  disconnectObserver = nil;
748  }
749 
750 #if TARGET_OS_TV
752  SDL_AppleTVRemoteRotationHintChanged, NULL);
753 #endif /* TARGET_OS_TV */
754 #endif /* SDL_JOYSTICK_MFI */
755 
756  while (deviceList != NULL) {
758  }
759 
760 #if !TARGET_OS_TV
761  motionManager = nil;
762 #endif /* !TARGET_OS_TV */
763  }
764 
766 
767  numjoysticks = 0;
768 }
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:368
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 682 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().

683 {
684  SDL_JoystickDeviceItem *device = joystick->hwdata;
685 
686  if (device == NULL) {
687  return;
688  }
689 
690  if (device->m_bSteamController) {
691  SDL_UpdateSteamController(joystick);
692  return;
693  }
694 
695  if (device->accelerometer) {
696  SDL_SYS_AccelerometerUpdate(joystick);
697  } else if (device->controller) {
698  SDL_SYS_MFIJoystickUpdate(joystick);
699  }
700 }
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 389 of file SDL_sysjoystick.m.

References numjoysticks.

Referenced by SDL_NumJoysticks().

390 {
391  return numjoysticks;
392 }
static int numjoysticks