src/joystick/windows/SDL_windowsjoystick.c
changeset 12088 399cc39583cc
parent 11811 5d94cb6b24d3
child 12090 c3209fca27b2
     1.1 --- a/src/joystick/windows/SDL_windowsjoystick.c	Wed Aug 08 15:39:20 2018 -0400
     1.2 +++ b/src/joystick/windows/SDL_windowsjoystick.c	Thu Aug 09 16:00:17 2018 -0700
     1.3 @@ -61,7 +61,6 @@
     1.4  /* local variables */
     1.5  static SDL_bool s_bDeviceAdded = SDL_FALSE;
     1.6  static SDL_bool s_bDeviceRemoved = SDL_FALSE;
     1.7 -static SDL_JoystickID s_nInstanceID = -1;
     1.8  static SDL_cond *s_condJoystickThread = NULL;
     1.9  static SDL_mutex *s_mutexJoyStickEnum = NULL;
    1.10  static SDL_Thread *s_threadJoystick = NULL;
    1.11 @@ -271,30 +270,33 @@
    1.12      return 1;
    1.13  }
    1.14  
    1.15 -void SDL_SYS_AddJoystickDevice(JoyStick_DeviceData *device)
    1.16 +void WINDOWS_AddJoystickDevice(JoyStick_DeviceData *device)
    1.17  {
    1.18      device->send_add_event = SDL_TRUE;
    1.19 -    device->nInstanceID = ++s_nInstanceID;
    1.20 +    device->nInstanceID = SDL_GetNextJoystickInstanceID();
    1.21      device->pNext = SYS_Joystick;
    1.22      SYS_Joystick = device;
    1.23  
    1.24      s_bDeviceAdded = SDL_TRUE;
    1.25  }
    1.26  
    1.27 +static void WINDOWS_JoystickDetect(void);
    1.28 +static void WINDOWS_JoystickQuit(void);
    1.29 +
    1.30  /* Function to scan the system for joysticks.
    1.31   * Joystick 0 should be the system default joystick.
    1.32   * It should return 0, or -1 on an unrecoverable fatal error.
    1.33   */
    1.34 -int
    1.35 -SDL_SYS_JoystickInit(void)
    1.36 +static int
    1.37 +WINDOWS_JoystickInit(void)
    1.38  {
    1.39      if (SDL_DINPUT_JoystickInit() < 0) {
    1.40 -        SDL_SYS_JoystickQuit();
    1.41 +        WINDOWS_JoystickQuit();
    1.42          return -1;
    1.43      }
    1.44  
    1.45      if (SDL_XINPUT_JoystickInit() < 0) {
    1.46 -        SDL_SYS_JoystickQuit();
    1.47 +        WINDOWS_JoystickQuit();
    1.48          return -1;
    1.49      }
    1.50  
    1.51 @@ -302,19 +304,19 @@
    1.52      s_condJoystickThread = SDL_CreateCond();
    1.53      s_bDeviceAdded = SDL_TRUE; /* force a scan of the system for joysticks this first time */
    1.54  
    1.55 -    SDL_SYS_JoystickDetect();
    1.56 +    WINDOWS_JoystickDetect();
    1.57  
    1.58      if (!s_threadJoystick) {
    1.59          /* spin up the thread to detect hotplug of devices */
    1.60          s_bJoystickThreadQuit = SDL_FALSE;
    1.61          s_threadJoystick = SDL_CreateThreadInternal(SDL_JoystickThread, "SDL_joystick", 64 * 1024, NULL);
    1.62      }
    1.63 -    return SDL_SYS_NumJoysticks();
    1.64 +    return 0;
    1.65  }
    1.66  
    1.67  /* return the number of joysticks that are connected right now */
    1.68 -int
    1.69 -SDL_SYS_NumJoysticks(void)
    1.70 +static int
    1.71 +WINDOWS_JoystickGetCount(void)
    1.72  {
    1.73      int nJoysticks = 0;
    1.74      JoyStick_DeviceData *device = SYS_Joystick;
    1.75 @@ -327,8 +329,8 @@
    1.76  }
    1.77  
    1.78  /* detect any new joysticks being inserted into the system */
    1.79 -void
    1.80 -SDL_SYS_JoystickDetect(void)
    1.81 +static void
    1.82 +WINDOWS_JoystickDetect(void)
    1.83  {
    1.84      JoyStick_DeviceData *pCurList = NULL;
    1.85  
    1.86 @@ -383,7 +385,7 @@
    1.87                      SDL_DINPUT_MaybeAddDevice(&pNewJoystick->dxdevice);
    1.88                  }
    1.89  
    1.90 -                SDL_PrivateJoystickAdded(device_index);
    1.91 +                SDL_PrivateJoystickAdded(pNewJoystick->nInstanceID);
    1.92  
    1.93                  pNewJoystick->send_add_event = SDL_FALSE;
    1.94              }
    1.95 @@ -394,8 +396,8 @@
    1.96  }
    1.97  
    1.98  /* Function to get the device-dependent name of a joystick */
    1.99 -const char *
   1.100 -SDL_SYS_JoystickNameForDeviceIndex(int device_index)
   1.101 +static const char *
   1.102 +WINDOWS_JoystickGetDeviceName(int device_index)
   1.103  {
   1.104      JoyStick_DeviceData *device = SYS_Joystick;
   1.105  
   1.106 @@ -405,9 +407,22 @@
   1.107      return device->joystickname;
   1.108  }
   1.109  
   1.110 +/* return the stable device guid for this device index */
   1.111 +static SDL_JoystickGUID
   1.112 +WINDOWS_JoystickGetDeviceGUID(int device_index)
   1.113 +{
   1.114 +    JoyStick_DeviceData *device = SYS_Joystick;
   1.115 +    int index;
   1.116 +
   1.117 +    for (index = device_index; index > 0; index--)
   1.118 +        device = device->pNext;
   1.119 +
   1.120 +    return device->guid;
   1.121 +}
   1.122 +
   1.123  /* Function to perform the mapping between current device instance and this joysticks instance id */
   1.124 -SDL_JoystickID
   1.125 -SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
   1.126 +static SDL_JoystickID
   1.127 +WINDOWS_JoystickGetDeviceInstanceID(int device_index)
   1.128  {
   1.129      JoyStick_DeviceData *device = SYS_Joystick;
   1.130      int index;
   1.131 @@ -423,8 +438,8 @@
   1.132     This should fill the nbuttons and naxes fields of the joystick structure.
   1.133     It returns 0, or -1 if there is an error.
   1.134   */
   1.135 -int
   1.136 -SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
   1.137 +static int
   1.138 +WINDOWS_JoystickOpen(SDL_Joystick * joystick, int device_index)
   1.139  {
   1.140      JoyStick_DeviceData *joystickdevice = SYS_Joystick;
   1.141  
   1.142 @@ -449,14 +464,24 @@
   1.143  }
   1.144  
   1.145  /* return true if this joystick is plugged in right now */
   1.146 -SDL_bool 
   1.147 -SDL_SYS_JoystickAttached(SDL_Joystick * joystick)
   1.148 +static SDL_bool 
   1.149 +WINDOWS_JoystickIsAttached(SDL_Joystick * joystick)
   1.150  {
   1.151      return joystick->hwdata && !joystick->hwdata->removed;
   1.152  }
   1.153  
   1.154 -void
   1.155 -SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
   1.156 +static int
   1.157 +WINDOWS_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms)
   1.158 +{
   1.159 +    if (joystick->hwdata->bXInputDevice) {
   1.160 +        return SDL_XINPUT_JoystickRumble(joystick, low_frequency_rumble, high_frequency_rumble, duration_ms);
   1.161 +    } else {
   1.162 +        return SDL_DINPUT_JoystickRumble(joystick, low_frequency_rumble, high_frequency_rumble, duration_ms);
   1.163 +    }
   1.164 +}
   1.165 +
   1.166 +static void
   1.167 +WINDOWS_JoystickUpdate(SDL_Joystick * joystick)
   1.168  {
   1.169      if (!joystick->hwdata || joystick->hwdata->removed) {
   1.170          return;
   1.171 @@ -474,8 +499,8 @@
   1.172  }
   1.173  
   1.174  /* Function to close a joystick after use */
   1.175 -void
   1.176 -SDL_SYS_JoystickClose(SDL_Joystick * joystick)
   1.177 +static void
   1.178 +WINDOWS_JoystickClose(SDL_Joystick * joystick)
   1.179  {
   1.180      if (joystick->hwdata->bXInputDevice) {
   1.181          SDL_XINPUT_JoystickClose(joystick);
   1.182 @@ -487,8 +512,8 @@
   1.183  }
   1.184  
   1.185  /* Function to perform any system-specific joystick related cleanup */
   1.186 -void
   1.187 -SDL_SYS_JoystickQuit(void)
   1.188 +static void
   1.189 +WINDOWS_JoystickQuit(void)
   1.190  {
   1.191      JoyStick_DeviceData *device = SYS_Joystick;
   1.192  
   1.193 @@ -524,24 +549,21 @@
   1.194      s_bDeviceRemoved = SDL_FALSE;
   1.195  }
   1.196  
   1.197 -/* return the stable device guid for this device index */
   1.198 -SDL_JoystickGUID
   1.199 -SDL_SYS_JoystickGetDeviceGUID(int device_index)
   1.200 +SDL_JoystickDriver SDL_WINDOWS_JoystickDriver =
   1.201  {
   1.202 -    JoyStick_DeviceData *device = SYS_Joystick;
   1.203 -    int index;
   1.204 -
   1.205 -    for (index = device_index; index > 0; index--)
   1.206 -        device = device->pNext;
   1.207 -
   1.208 -    return device->guid;
   1.209 -}
   1.210 -
   1.211 -SDL_JoystickGUID
   1.212 -SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
   1.213 -{
   1.214 -    return joystick->hwdata->guid;
   1.215 -}
   1.216 +    WINDOWS_JoystickInit,
   1.217 +    WINDOWS_JoystickGetCount,
   1.218 +    WINDOWS_JoystickDetect,
   1.219 +    WINDOWS_JoystickGetDeviceName,
   1.220 +    WINDOWS_JoystickGetDeviceGUID,
   1.221 +    WINDOWS_JoystickGetDeviceInstanceID,
   1.222 +    WINDOWS_JoystickOpen,
   1.223 +    WINDOWS_JoystickIsAttached,
   1.224 +    WINDOWS_JoystickRumble,
   1.225 +    WINDOWS_JoystickUpdate,
   1.226 +    WINDOWS_JoystickClose,
   1.227 +    WINDOWS_JoystickQuit,
   1.228 +};
   1.229  
   1.230  #endif /* SDL_JOYSTICK_DINPUT || SDL_JOYSTICK_XINPUT */
   1.231