src/joystick/windows/SDL_dxjoystick.c
author Ryan C. Gordon <icculus@icculus.org>
Wed, 28 Aug 2013 22:09:17 -0400
changeset 7712 66b5b8446275
parent 7711 db9e27a52d77
child 7719 31b5f9ff36ca
permissions -rw-r--r--
Change order we enumerate Windows joysticks. Make it so XInput devices are listed before DirectInput devices, and that the XInput devices are sorted by userid in ascending numeric order (so device 0 comes first).
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     1
/*
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     2
  Simple DirectMedia Layer
6885
700f1b25f77f Happy New Year!
Sam Lantinga <slouken@libsdl.org>
parents: 6782
diff changeset
     3
  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     4
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     5
  This software is provided 'as-is', without any express or implied
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     7
  arising from the use of this software.
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     8
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    11
  freely, subject to the following restrictions:
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    14
     claim that you wrote the original software. If you use this software
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    16
     appreciated but is not required.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    18
     misrepresented as being the original software.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
*/
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    21
#include "SDL_config.h"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    22
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    23
#ifdef SDL_JOYSTICK_DINPUT
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    24
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    25
/* DirectInput joystick driver; written by Glenn Maynard, based on Andrei de
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
    26
 * A. Formiga's WINMM driver.
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    27
 *
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    28
 * Hats and sliders are completely untested; the app I'm writing this for mostly
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
    29
 * doesn't use them and I don't own any joysticks with them.
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    30
 *
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    31
 * We don't bother to use event notification here.  It doesn't seem to work
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
    32
 * with polled devices, and it's fine to call IDirectInputDevice8_GetDeviceData and
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    33
 * let it return 0 events. */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    34
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    35
#include "SDL_error.h"
6993
33f1e384ed56 Patched to compile on Visual Studio.
Ryan C. Gordon <icculus@icculus.org>
parents: 6991
diff changeset
    36
#include "SDL_assert.h"
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    37
#include "SDL_events.h"
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
    38
#include "SDL_thread.h"
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
    39
#include "SDL_timer.h"
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
    40
#include "SDL_mutex.h"
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
    41
#include "SDL_events.h"
6971
5ded971ee761 Fixed compile errors on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 6965
diff changeset
    42
#include "SDL_hints.h"
7260
7601833a69ee Gyrations to get the code to compile with the latest version of mingw-w64 as well as Visual Studio.
Sam Lantinga <slouken@libsdl.org>
parents: 7230
diff changeset
    43
#include "SDL_joystick.h"
7601833a69ee Gyrations to get the code to compile with the latest version of mingw-w64 as well as Visual Studio.
Sam Lantinga <slouken@libsdl.org>
parents: 7230
diff changeset
    44
#include "../SDL_sysjoystick.h"
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
    45
#if !SDL_EVENTS_DISABLED
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
    46
#include "../../events/SDL_events_c.h"
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
    47
#endif
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    48
7260
7601833a69ee Gyrations to get the code to compile with the latest version of mingw-w64 as well as Visual Studio.
Sam Lantinga <slouken@libsdl.org>
parents: 7230
diff changeset
    49
#define INITGUID /* Only set here, if set twice will cause mingw32 to break. */
7601833a69ee Gyrations to get the code to compile with the latest version of mingw-w64 as well as Visual Studio.
Sam Lantinga <slouken@libsdl.org>
parents: 7230
diff changeset
    50
#include "SDL_dxjoystick_c.h"
7601833a69ee Gyrations to get the code to compile with the latest version of mingw-w64 as well as Visual Studio.
Sam Lantinga <slouken@libsdl.org>
parents: 7230
diff changeset
    51
2761
0c544c2eff77 Almost got this compiling on Cygwin32, just needs DirectInput 7
Sam Lantinga <slouken@libsdl.org>
parents: 2760
diff changeset
    52
#ifndef DIDFT_OPTIONAL
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
    53
#define DIDFT_OPTIONAL      0x80000000
2761
0c544c2eff77 Almost got this compiling on Cygwin32, just needs DirectInput 7
Sam Lantinga <slouken@libsdl.org>
parents: 2760
diff changeset
    54
#endif
0c544c2eff77 Almost got this compiling on Cygwin32, just needs DirectInput 7
Sam Lantinga <slouken@libsdl.org>
parents: 2760
diff changeset
    55
0c544c2eff77 Almost got this compiling on Cygwin32, just needs DirectInput 7
Sam Lantinga <slouken@libsdl.org>
parents: 2760
diff changeset
    56
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
    57
#define INPUT_QSIZE 32      /* Buffer up to 32 input messages */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
    58
#define AXIS_MIN    -32768  /* minimum value for axis coordinate */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
    59
#define AXIS_MAX    32767   /* maximum value for axis coordinate */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
    60
#define JOY_AXIS_THRESHOLD  (((AXIS_MAX)-(AXIS_MIN))/100)   /* 1% motion */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    61
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    62
/* external variables referenced. */
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2198
diff changeset
    63
extern HWND SDL_HelperWindow;
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    64
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    65
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    66
/* local variables */
5591
17beb16fa838 Cleaned up CoInitialize() politics on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
    67
static SDL_bool coinitialized = SDL_FALSE;
6716
1616f6b3738c Move all DirectInput code from DI2 to DI8.
Ryan C. Gordon <icculus@icculus.org>
parents: 6712
diff changeset
    68
static LPDIRECTINPUT8 dinput = NULL;
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
    69
static SDL_bool s_bDeviceAdded = SDL_FALSE;
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
    70
static SDL_bool s_bDeviceRemoved = SDL_FALSE;
6974
11a03a79dfe8 The joystick events contain a joystick instance ID, which is a signed value, with -1 being invalid.
Sam Lantinga <slouken@libsdl.org>
parents: 6971
diff changeset
    71
static SDL_JoystickID s_nInstanceID = -1;
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
    72
static SDL_cond *s_condJoystickThread = NULL;
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
    73
static SDL_mutex *s_mutexJoyStickEnum = NULL;
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
    74
static SDL_Thread *s_threadJoystick = NULL;
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
    75
static SDL_bool s_bJoystickThreadQuit = SDL_FALSE;
6965
ab4bb4e99961 add hint to allow disabling the use of Xinput.
Edward Rudd <urkle@outoforder.cc>
parents: 6885
diff changeset
    76
static SDL_bool s_bXInputEnabled = SDL_TRUE;
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
    77
6991
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
    78
XInputGetState_t SDL_XInputGetState = NULL;
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
    79
XInputSetState_t SDL_XInputSetState = NULL;
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
    80
XInputGetCapabilities_t SDL_XInputGetCapabilities = NULL;
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
    81
DWORD SDL_XInputVersion = 0;
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
    82
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
    83
static HANDLE s_pXInputDLL = 0;
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
    84
static int s_XInputDLLRefCount = 0;
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
    85
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
    86
int
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
    87
WIN_LoadXInputDLL(void)
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
    88
{
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
    89
    DWORD version = 0;
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
    90
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
    91
    if (s_pXInputDLL) {
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
    92
        SDL_assert(s_XInputDLLRefCount > 0);
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
    93
        s_XInputDLLRefCount++;
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
    94
        return 0;  /* already loaded */
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
    95
    }
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
    96
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
    97
    version = (1 << 16) | 4;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
    98
    s_pXInputDLL = LoadLibrary( L"XInput1_4.dll" );  /* 1.4 Ships with Windows 8. */
6991
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
    99
    if (!s_pXInputDLL) {
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
   100
        version = (1 << 16) | 3;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   101
        s_pXInputDLL = LoadLibrary( L"XInput1_3.dll" );  /* 1.3 Ships with Vista and Win7, can be installed as a redistributable component. */
6991
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
   102
    }
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
   103
    if (!s_pXInputDLL) {
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
   104
        s_pXInputDLL = LoadLibrary( L"bin\\XInput1_3.dll" );
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
   105
    }
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
   106
    if (!s_pXInputDLL) {
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
   107
        return -1;
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
   108
    }
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
   109
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
   110
    SDL_assert(s_XInputDLLRefCount == 0);
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
   111
    SDL_XInputVersion = version;
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
   112
    s_XInputDLLRefCount = 1;
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
   113
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
   114
    /* 100 is the ordinal for _XInputGetStateEx, which returns the same struct as XinputGetState, but with extra data in wButtons for the guide button, we think... */
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
   115
    SDL_XInputGetState = (XInputGetState_t)GetProcAddress( (HMODULE)s_pXInputDLL, (LPCSTR)100 );
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
   116
    SDL_XInputSetState = (XInputSetState_t)GetProcAddress( (HMODULE)s_pXInputDLL, "XInputSetState" );
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
   117
    SDL_XInputGetCapabilities = (XInputGetCapabilities_t)GetProcAddress( (HMODULE)s_pXInputDLL, "XInputGetCapabilities" );
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
   118
    if ( !SDL_XInputGetState || !SDL_XInputSetState || !SDL_XInputGetCapabilities ) {
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
   119
        WIN_UnloadXInputDLL();
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
   120
        return -1;
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
   121
    }
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
   122
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
   123
    return 0;
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
   124
}
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
   125
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
   126
void
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
   127
WIN_UnloadXInputDLL(void)
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
   128
{
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
   129
    if ( s_pXInputDLL ) {
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
   130
        SDL_assert(s_XInputDLLRefCount > 0);
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
   131
        if (--s_XInputDLLRefCount == 0) {
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
   132
            FreeLibrary( s_pXInputDLL );
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
   133
            s_pXInputDLL = NULL;
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
   134
        }
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
   135
    } else {
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
   136
        SDL_assert(s_XInputDLLRefCount == 0);
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
   137
    }
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
   138
}
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
   139
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
   140
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   141
extern HRESULT(WINAPI * DInputCreate) (HINSTANCE hinst, DWORD dwVersion,
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   142
                                       LPDIRECTINPUT * ppDI,
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   143
                                       LPUNKNOWN punkOuter);
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   144
struct JoyStick_DeviceData_
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   145
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   146
    SDL_JoystickGUID guid;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   147
    DIDEVICEINSTANCE dxdevice;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   148
    char *joystickname;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   149
    Uint8 send_add_event;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   150
    SDL_JoystickID nInstanceID;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   151
    SDL_bool bXInputDevice;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   152
    Uint8 XInputUserId;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   153
    struct JoyStick_DeviceData_ *pNext;
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   154
};
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   155
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   156
typedef struct JoyStick_DeviceData_ JoyStick_DeviceData;
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   157
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   158
static JoyStick_DeviceData *SYS_Joystick;    /* array to hold joystick ID values */
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   159
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   160
/* local prototypes */
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6993
diff changeset
   161
static int SetDIerror(const char *function, HRESULT code);
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   162
static BOOL CALLBACK EnumJoysticksCallback(const DIDEVICEINSTANCE *
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   163
                                           pdidInstance, VOID * pContext);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   164
static BOOL CALLBACK EnumDevObjectsCallback(LPCDIDEVICEOBJECTINSTANCE dev,
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   165
                                            LPVOID pvRef);
6220
c36934808194 Fixed bug 1371 - DX joystick axis ordering fix
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   166
static void SortDevObjects(SDL_Joystick *joystick);
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   167
static Uint8 TranslatePOV(DWORD value);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   168
static int SDL_PrivateJoystickAxis_Int(SDL_Joystick * joystick, Uint8 axis,
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   169
                                       Sint16 value);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   170
static int SDL_PrivateJoystickHat_Int(SDL_Joystick * joystick, Uint8 hat,
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   171
                                      Uint8 value);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   172
static int SDL_PrivateJoystickButton_Int(SDL_Joystick * joystick,
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   173
                                         Uint8 button, Uint8 state);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   174
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   175
/* Taken from Wine - Thanks! */
2760
02aa80d7905f Updated Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 2717
diff changeset
   176
DIOBJECTDATAFORMAT dfDIJoystick2[] = {
3013
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   177
  { &GUID_XAxis,DIJOFS_X,DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   178
  { &GUID_YAxis,DIJOFS_Y,DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   179
  { &GUID_ZAxis,DIJOFS_Z,DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   180
  { &GUID_RxAxis,DIJOFS_RX,DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   181
  { &GUID_RyAxis,DIJOFS_RY,DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   182
  { &GUID_RzAxis,DIJOFS_RZ,DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   183
  { &GUID_Slider,DIJOFS_SLIDER(0),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   184
  { &GUID_Slider,DIJOFS_SLIDER(1),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   185
  { &GUID_POV,DIJOFS_POV(0),DIDFT_OPTIONAL|DIDFT_POV|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   186
  { &GUID_POV,DIJOFS_POV(1),DIDFT_OPTIONAL|DIDFT_POV|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   187
  { &GUID_POV,DIJOFS_POV(2),DIDFT_OPTIONAL|DIDFT_POV|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   188
  { &GUID_POV,DIJOFS_POV(3),DIDFT_OPTIONAL|DIDFT_POV|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   189
  { NULL,DIJOFS_BUTTON(0),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   190
  { NULL,DIJOFS_BUTTON(1),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   191
  { NULL,DIJOFS_BUTTON(2),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   192
  { NULL,DIJOFS_BUTTON(3),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   193
  { NULL,DIJOFS_BUTTON(4),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   194
  { NULL,DIJOFS_BUTTON(5),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   195
  { NULL,DIJOFS_BUTTON(6),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   196
  { NULL,DIJOFS_BUTTON(7),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   197
  { NULL,DIJOFS_BUTTON(8),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   198
  { NULL,DIJOFS_BUTTON(9),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   199
  { NULL,DIJOFS_BUTTON(10),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   200
  { NULL,DIJOFS_BUTTON(11),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   201
  { NULL,DIJOFS_BUTTON(12),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   202
  { NULL,DIJOFS_BUTTON(13),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   203
  { NULL,DIJOFS_BUTTON(14),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   204
  { NULL,DIJOFS_BUTTON(15),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   205
  { NULL,DIJOFS_BUTTON(16),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   206
  { NULL,DIJOFS_BUTTON(17),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   207
  { NULL,DIJOFS_BUTTON(18),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   208
  { NULL,DIJOFS_BUTTON(19),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   209
  { NULL,DIJOFS_BUTTON(20),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   210
  { NULL,DIJOFS_BUTTON(21),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   211
  { NULL,DIJOFS_BUTTON(22),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   212
  { NULL,DIJOFS_BUTTON(23),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   213
  { NULL,DIJOFS_BUTTON(24),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   214
  { NULL,DIJOFS_BUTTON(25),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   215
  { NULL,DIJOFS_BUTTON(26),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   216
  { NULL,DIJOFS_BUTTON(27),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   217
  { NULL,DIJOFS_BUTTON(28),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   218
  { NULL,DIJOFS_BUTTON(29),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   219
  { NULL,DIJOFS_BUTTON(30),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   220
  { NULL,DIJOFS_BUTTON(31),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   221
  { NULL,DIJOFS_BUTTON(32),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   222
  { NULL,DIJOFS_BUTTON(33),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   223
  { NULL,DIJOFS_BUTTON(34),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   224
  { NULL,DIJOFS_BUTTON(35),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   225
  { NULL,DIJOFS_BUTTON(36),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   226
  { NULL,DIJOFS_BUTTON(37),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   227
  { NULL,DIJOFS_BUTTON(38),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   228
  { NULL,DIJOFS_BUTTON(39),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   229
  { NULL,DIJOFS_BUTTON(40),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   230
  { NULL,DIJOFS_BUTTON(41),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   231
  { NULL,DIJOFS_BUTTON(42),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   232
  { NULL,DIJOFS_BUTTON(43),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   233
  { NULL,DIJOFS_BUTTON(44),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   234
  { NULL,DIJOFS_BUTTON(45),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   235
  { NULL,DIJOFS_BUTTON(46),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   236
  { NULL,DIJOFS_BUTTON(47),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   237
  { NULL,DIJOFS_BUTTON(48),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   238
  { NULL,DIJOFS_BUTTON(49),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   239
  { NULL,DIJOFS_BUTTON(50),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   240
  { NULL,DIJOFS_BUTTON(51),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   241
  { NULL,DIJOFS_BUTTON(52),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   242
  { NULL,DIJOFS_BUTTON(53),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   243
  { NULL,DIJOFS_BUTTON(54),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   244
  { NULL,DIJOFS_BUTTON(55),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   245
  { NULL,DIJOFS_BUTTON(56),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   246
  { NULL,DIJOFS_BUTTON(57),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   247
  { NULL,DIJOFS_BUTTON(58),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   248
  { NULL,DIJOFS_BUTTON(59),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   249
  { NULL,DIJOFS_BUTTON(60),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   250
  { NULL,DIJOFS_BUTTON(61),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   251
  { NULL,DIJOFS_BUTTON(62),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   252
  { NULL,DIJOFS_BUTTON(63),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   253
  { NULL,DIJOFS_BUTTON(64),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   254
  { NULL,DIJOFS_BUTTON(65),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   255
  { NULL,DIJOFS_BUTTON(66),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   256
  { NULL,DIJOFS_BUTTON(67),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   257
  { NULL,DIJOFS_BUTTON(68),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   258
  { NULL,DIJOFS_BUTTON(69),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   259
  { NULL,DIJOFS_BUTTON(70),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   260
  { NULL,DIJOFS_BUTTON(71),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   261
  { NULL,DIJOFS_BUTTON(72),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   262
  { NULL,DIJOFS_BUTTON(73),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   263
  { NULL,DIJOFS_BUTTON(74),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   264
  { NULL,DIJOFS_BUTTON(75),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   265
  { NULL,DIJOFS_BUTTON(76),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   266
  { NULL,DIJOFS_BUTTON(77),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   267
  { NULL,DIJOFS_BUTTON(78),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   268
  { NULL,DIJOFS_BUTTON(79),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   269
  { NULL,DIJOFS_BUTTON(80),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   270
  { NULL,DIJOFS_BUTTON(81),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   271
  { NULL,DIJOFS_BUTTON(82),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   272
  { NULL,DIJOFS_BUTTON(83),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   273
  { NULL,DIJOFS_BUTTON(84),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   274
  { NULL,DIJOFS_BUTTON(85),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   275
  { NULL,DIJOFS_BUTTON(86),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   276
  { NULL,DIJOFS_BUTTON(87),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   277
  { NULL,DIJOFS_BUTTON(88),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   278
  { NULL,DIJOFS_BUTTON(89),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   279
  { NULL,DIJOFS_BUTTON(90),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   280
  { NULL,DIJOFS_BUTTON(91),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   281
  { NULL,DIJOFS_BUTTON(92),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   282
  { NULL,DIJOFS_BUTTON(93),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   283
  { NULL,DIJOFS_BUTTON(94),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   284
  { NULL,DIJOFS_BUTTON(95),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   285
  { NULL,DIJOFS_BUTTON(96),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   286
  { NULL,DIJOFS_BUTTON(97),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   287
  { NULL,DIJOFS_BUTTON(98),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   288
  { NULL,DIJOFS_BUTTON(99),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   289
  { NULL,DIJOFS_BUTTON(100),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   290
  { NULL,DIJOFS_BUTTON(101),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   291
  { NULL,DIJOFS_BUTTON(102),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   292
  { NULL,DIJOFS_BUTTON(103),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   293
  { NULL,DIJOFS_BUTTON(104),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   294
  { NULL,DIJOFS_BUTTON(105),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   295
  { NULL,DIJOFS_BUTTON(106),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   296
  { NULL,DIJOFS_BUTTON(107),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   297
  { NULL,DIJOFS_BUTTON(108),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   298
  { NULL,DIJOFS_BUTTON(109),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   299
  { NULL,DIJOFS_BUTTON(110),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   300
  { NULL,DIJOFS_BUTTON(111),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   301
  { NULL,DIJOFS_BUTTON(112),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   302
  { NULL,DIJOFS_BUTTON(113),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   303
  { NULL,DIJOFS_BUTTON(114),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   304
  { NULL,DIJOFS_BUTTON(115),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   305
  { NULL,DIJOFS_BUTTON(116),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   306
  { NULL,DIJOFS_BUTTON(117),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   307
  { NULL,DIJOFS_BUTTON(118),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   308
  { NULL,DIJOFS_BUTTON(119),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   309
  { NULL,DIJOFS_BUTTON(120),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   310
  { NULL,DIJOFS_BUTTON(121),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   311
  { NULL,DIJOFS_BUTTON(122),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   312
  { NULL,DIJOFS_BUTTON(123),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   313
  { NULL,DIJOFS_BUTTON(124),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   314
  { NULL,DIJOFS_BUTTON(125),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   315
  { NULL,DIJOFS_BUTTON(126),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   316
  { NULL,DIJOFS_BUTTON(127),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   317
  { &GUID_XAxis,FIELD_OFFSET(DIJOYSTATE2,lVX),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   318
  { &GUID_YAxis,FIELD_OFFSET(DIJOYSTATE2,lVY),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   319
  { &GUID_ZAxis,FIELD_OFFSET(DIJOYSTATE2,lVZ),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   320
  { &GUID_RxAxis,FIELD_OFFSET(DIJOYSTATE2,lVRx),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   321
  { &GUID_RyAxis,FIELD_OFFSET(DIJOYSTATE2,lVRy),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   322
  { &GUID_RzAxis,FIELD_OFFSET(DIJOYSTATE2,lVRz),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   323
  { &GUID_Slider,FIELD_OFFSET(DIJOYSTATE2,rglVSlider[0]),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   324
  { &GUID_Slider,FIELD_OFFSET(DIJOYSTATE2,rglVSlider[1]),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   325
  { &GUID_XAxis,FIELD_OFFSET(DIJOYSTATE2,lAX),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   326
  { &GUID_YAxis,FIELD_OFFSET(DIJOYSTATE2,lAY),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   327
  { &GUID_ZAxis,FIELD_OFFSET(DIJOYSTATE2,lAZ),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   328
  { &GUID_RxAxis,FIELD_OFFSET(DIJOYSTATE2,lARx),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   329
  { &GUID_RyAxis,FIELD_OFFSET(DIJOYSTATE2,lARy),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   330
  { &GUID_RzAxis,FIELD_OFFSET(DIJOYSTATE2,lARz),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   331
  { &GUID_Slider,FIELD_OFFSET(DIJOYSTATE2,rglASlider[0]),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   332
  { &GUID_Slider,FIELD_OFFSET(DIJOYSTATE2,rglASlider[1]),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   333
  { &GUID_XAxis,FIELD_OFFSET(DIJOYSTATE2,lFX),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   334
  { &GUID_YAxis,FIELD_OFFSET(DIJOYSTATE2,lFY),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   335
  { &GUID_ZAxis,FIELD_OFFSET(DIJOYSTATE2,lFZ),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   336
  { &GUID_RxAxis,FIELD_OFFSET(DIJOYSTATE2,lFRx),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   337
  { &GUID_RyAxis,FIELD_OFFSET(DIJOYSTATE2,lFRy),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   338
  { &GUID_RzAxis,FIELD_OFFSET(DIJOYSTATE2,lFRz),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   339
  { &GUID_Slider,FIELD_OFFSET(DIJOYSTATE2,rglFSlider[0]),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   340
  { &GUID_Slider,FIELD_OFFSET(DIJOYSTATE2,rglFSlider[1]),DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
2760
02aa80d7905f Updated Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 2717
diff changeset
   341
};
02aa80d7905f Updated Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 2717
diff changeset
   342
02aa80d7905f Updated Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 2717
diff changeset
   343
const DIDATAFORMAT c_dfDIJoystick2 = {
02aa80d7905f Updated Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 2717
diff changeset
   344
    sizeof(DIDATAFORMAT),
02aa80d7905f Updated Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 2717
diff changeset
   345
    sizeof(DIOBJECTDATAFORMAT),
02aa80d7905f Updated Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 2717
diff changeset
   346
    DIDF_ABSAXIS,
02aa80d7905f Updated Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 2717
diff changeset
   347
    sizeof(DIJOYSTATE2),
02aa80d7905f Updated Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 2717
diff changeset
   348
    SDL_arraysize(dfDIJoystick2),
02aa80d7905f Updated Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 2717
diff changeset
   349
    dfDIJoystick2
02aa80d7905f Updated Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 2717
diff changeset
   350
};
02aa80d7905f Updated Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 2717
diff changeset
   351
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   352
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   353
/* Convert a DirectInput return code to a text message */
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6993
diff changeset
   354
static int
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   355
SetDIerror(const char *function, HRESULT code)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   356
{
2760
02aa80d7905f Updated Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 2717
diff changeset
   357
    /*
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6993
diff changeset
   358
    return SDL_SetError("%s() [%s]: %s", function,
3013
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   359
                 DXGetErrorString9A(code), DXGetErrorDescription9A(code));
2760
02aa80d7905f Updated Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 2717
diff changeset
   360
     */
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6993
diff changeset
   361
    return SDL_SetError("%s() DirectX error %d", function, code);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   362
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   363
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   364
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   365
#define SAFE_RELEASE(p)                             \
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   366
{                                                   \
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   367
    if (p) {                                        \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   368
        (p)->lpVtbl->Release((p));                  \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   369
        (p) = 0;                                    \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   370
    }                                               \
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   371
}
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   372
7299
280e86365933 Check for well known XInput device GUIDs before enumerating the device list.
Sam Lantinga <slouken@libsdl.org>
parents: 7296
diff changeset
   373
DEFINE_GUID(IID_ValveStreamingGamepad,  MAKELONG( 0x28DE, 0x11FF ),0x0000,0x0000,0x00,0x00,0x50,0x49,0x44,0x56,0x49,0x44);
7706
8cc29a668223 Better XInput detection code for DirectInput device enumeration.
Ryan C. Gordon <icculus@icculus.org>
parents: 7685
diff changeset
   374
DEFINE_GUID(IID_X360WiredGamepad,  MAKELONG( 0x045E, 0x02A1 ),0x0000,0x0000,0x00,0x00,0x50,0x49,0x44,0x56,0x49,0x44);
8cc29a668223 Better XInput detection code for DirectInput device enumeration.
Ryan C. Gordon <icculus@icculus.org>
parents: 7685
diff changeset
   375
DEFINE_GUID(IID_X360WirelessGamepad,  MAKELONG( 0x045E, 0x028E ),0x0000,0x0000,0x00,0x00,0x50,0x49,0x44,0x56,0x49,0x44);
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   376
7706
8cc29a668223 Better XInput detection code for DirectInput device enumeration.
Ryan C. Gordon <icculus@icculus.org>
parents: 7685
diff changeset
   377
static PRAWINPUTDEVICELIST SDL_RawDevList = NULL;
8cc29a668223 Better XInput detection code for DirectInput device enumeration.
Ryan C. Gordon <icculus@icculus.org>
parents: 7685
diff changeset
   378
static UINT SDL_RawDevListCount = 0;
8cc29a668223 Better XInput detection code for DirectInput device enumeration.
Ryan C. Gordon <icculus@icculus.org>
parents: 7685
diff changeset
   379
8cc29a668223 Better XInput detection code for DirectInput device enumeration.
Ryan C. Gordon <icculus@icculus.org>
parents: 7685
diff changeset
   380
static SDL_bool
8cc29a668223 Better XInput detection code for DirectInput device enumeration.
Ryan C. Gordon <icculus@icculus.org>
parents: 7685
diff changeset
   381
SDL_IsXInputDevice( const GUID* pGuidProductFromDirectInput )
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   382
{
7299
280e86365933 Check for well known XInput device GUIDs before enumerating the device list.
Sam Lantinga <slouken@libsdl.org>
parents: 7296
diff changeset
   383
    static const GUID *s_XInputProductGUID[] = {
7706
8cc29a668223 Better XInput detection code for DirectInput device enumeration.
Ryan C. Gordon <icculus@icculus.org>
parents: 7685
diff changeset
   384
        &IID_ValveStreamingGamepad,
8cc29a668223 Better XInput detection code for DirectInput device enumeration.
Ryan C. Gordon <icculus@icculus.org>
parents: 7685
diff changeset
   385
        &IID_X360WiredGamepad,   /* Microsoft's wired X360 controller for Windows. */
8cc29a668223 Better XInput detection code for DirectInput device enumeration.
Ryan C. Gordon <icculus@icculus.org>
parents: 7685
diff changeset
   386
        &IID_X360WirelessGamepad /* Microsoft's wireless X360 controller for Windows. */
7299
280e86365933 Check for well known XInput device GUIDs before enumerating the device list.
Sam Lantinga <slouken@libsdl.org>
parents: 7296
diff changeset
   387
    };
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   388
7706
8cc29a668223 Better XInput detection code for DirectInput device enumeration.
Ryan C. Gordon <icculus@icculus.org>
parents: 7685
diff changeset
   389
    size_t iDevice;
8cc29a668223 Better XInput detection code for DirectInput device enumeration.
Ryan C. Gordon <icculus@icculus.org>
parents: 7685
diff changeset
   390
    SDL_bool retval = SDL_FALSE;
8cc29a668223 Better XInput detection code for DirectInput device enumeration.
Ryan C. Gordon <icculus@icculus.org>
parents: 7685
diff changeset
   391
    UINT i;
8cc29a668223 Better XInput detection code for DirectInput device enumeration.
Ryan C. Gordon <icculus@icculus.org>
parents: 7685
diff changeset
   392
8cc29a668223 Better XInput detection code for DirectInput device enumeration.
Ryan C. Gordon <icculus@icculus.org>
parents: 7685
diff changeset
   393
    if (!s_bXInputEnabled) {
6965
ab4bb4e99961 add hint to allow disabling the use of Xinput.
Edward Rudd <urkle@outoforder.cc>
parents: 6885
diff changeset
   394
        return SDL_FALSE;
ab4bb4e99961 add hint to allow disabling the use of Xinput.
Edward Rudd <urkle@outoforder.cc>
parents: 6885
diff changeset
   395
    }
ab4bb4e99961 add hint to allow disabling the use of Xinput.
Edward Rudd <urkle@outoforder.cc>
parents: 6885
diff changeset
   396
7663
53fe1b64eb2d More non C89 compliant comments
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7321
diff changeset
   397
    /* Check for well known XInput device GUIDs */
7706
8cc29a668223 Better XInput detection code for DirectInput device enumeration.
Ryan C. Gordon <icculus@icculus.org>
parents: 7685
diff changeset
   398
    /* This lets us skip RAWINPUT for popular devices. Also, we need to do this for the Valve Streaming Gamepad because it's virtualized and doesn't show up in the device list. */
7299
280e86365933 Check for well known XInput device GUIDs before enumerating the device list.
Sam Lantinga <slouken@libsdl.org>
parents: 7296
diff changeset
   399
    for ( iDevice = 0; iDevice < SDL_arraysize(s_XInputProductGUID); ++iDevice ) {
280e86365933 Check for well known XInput device GUIDs before enumerating the device list.
Sam Lantinga <slouken@libsdl.org>
parents: 7296
diff changeset
   400
        if (SDL_memcmp(pGuidProductFromDirectInput, s_XInputProductGUID[iDevice], sizeof(GUID)) == 0) {
280e86365933 Check for well known XInput device GUIDs before enumerating the device list.
Sam Lantinga <slouken@libsdl.org>
parents: 7296
diff changeset
   401
            return SDL_TRUE;
280e86365933 Check for well known XInput device GUIDs before enumerating the device list.
Sam Lantinga <slouken@libsdl.org>
parents: 7296
diff changeset
   402
        }
280e86365933 Check for well known XInput device GUIDs before enumerating the device list.
Sam Lantinga <slouken@libsdl.org>
parents: 7296
diff changeset
   403
    }
280e86365933 Check for well known XInput device GUIDs before enumerating the device list.
Sam Lantinga <slouken@libsdl.org>
parents: 7296
diff changeset
   404
7706
8cc29a668223 Better XInput detection code for DirectInput device enumeration.
Ryan C. Gordon <icculus@icculus.org>
parents: 7685
diff changeset
   405
    /* Go through RAWINPUT (WinXP and later) to find HID devices. */
8cc29a668223 Better XInput detection code for DirectInput device enumeration.
Ryan C. Gordon <icculus@icculus.org>
parents: 7685
diff changeset
   406
    /* Cache this if we end up using it. */
8cc29a668223 Better XInput detection code for DirectInput device enumeration.
Ryan C. Gordon <icculus@icculus.org>
parents: 7685
diff changeset
   407
    if (SDL_RawDevList == NULL) {
8cc29a668223 Better XInput detection code for DirectInput device enumeration.
Ryan C. Gordon <icculus@icculus.org>
parents: 7685
diff changeset
   408
        if ((GetRawInputDeviceList(NULL, &SDL_RawDevListCount, sizeof (RAWINPUTDEVICELIST)) == -1) || (!SDL_RawDevListCount)) {
8cc29a668223 Better XInput detection code for DirectInput device enumeration.
Ryan C. Gordon <icculus@icculus.org>
parents: 7685
diff changeset
   409
            return SDL_FALSE;  /* oh well. */
8cc29a668223 Better XInput detection code for DirectInput device enumeration.
Ryan C. Gordon <icculus@icculus.org>
parents: 7685
diff changeset
   410
        }
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   411
7706
8cc29a668223 Better XInput detection code for DirectInput device enumeration.
Ryan C. Gordon <icculus@icculus.org>
parents: 7685
diff changeset
   412
        SDL_RawDevList = (PRAWINPUTDEVICELIST) SDL_malloc(sizeof (RAWINPUTDEVICELIST) * SDL_RawDevListCount);
8cc29a668223 Better XInput detection code for DirectInput device enumeration.
Ryan C. Gordon <icculus@icculus.org>
parents: 7685
diff changeset
   413
        if (SDL_RawDevList == NULL) {
8cc29a668223 Better XInput detection code for DirectInput device enumeration.
Ryan C. Gordon <icculus@icculus.org>
parents: 7685
diff changeset
   414
            SDL_OutOfMemory();
8cc29a668223 Better XInput detection code for DirectInput device enumeration.
Ryan C. Gordon <icculus@icculus.org>
parents: 7685
diff changeset
   415
            return SDL_FALSE;
8cc29a668223 Better XInput detection code for DirectInput device enumeration.
Ryan C. Gordon <icculus@icculus.org>
parents: 7685
diff changeset
   416
        }
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   417
7706
8cc29a668223 Better XInput detection code for DirectInput device enumeration.
Ryan C. Gordon <icculus@icculus.org>
parents: 7685
diff changeset
   418
        if (GetRawInputDeviceList(SDL_RawDevList, &SDL_RawDevListCount, sizeof (RAWINPUTDEVICELIST)) == -1) {
8cc29a668223 Better XInput detection code for DirectInput device enumeration.
Ryan C. Gordon <icculus@icculus.org>
parents: 7685
diff changeset
   419
             SDL_free(SDL_RawDevList);
8cc29a668223 Better XInput detection code for DirectInput device enumeration.
Ryan C. Gordon <icculus@icculus.org>
parents: 7685
diff changeset
   420
             SDL_RawDevList = NULL;
8cc29a668223 Better XInput detection code for DirectInput device enumeration.
Ryan C. Gordon <icculus@icculus.org>
parents: 7685
diff changeset
   421
             return SDL_FALSE;  /* oh well. */
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   422
        }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   423
    }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   424
7706
8cc29a668223 Better XInput detection code for DirectInput device enumeration.
Ryan C. Gordon <icculus@icculus.org>
parents: 7685
diff changeset
   425
    for (i = 0; i < SDL_RawDevListCount; i++) {
8cc29a668223 Better XInput detection code for DirectInput device enumeration.
Ryan C. Gordon <icculus@icculus.org>
parents: 7685
diff changeset
   426
        RID_DEVICE_INFO rdi;
8cc29a668223 Better XInput detection code for DirectInput device enumeration.
Ryan C. Gordon <icculus@icculus.org>
parents: 7685
diff changeset
   427
        char devName[128];
8cc29a668223 Better XInput detection code for DirectInput device enumeration.
Ryan C. Gordon <icculus@icculus.org>
parents: 7685
diff changeset
   428
        UINT rdiSize = sizeof (rdi);
8cc29a668223 Better XInput detection code for DirectInput device enumeration.
Ryan C. Gordon <icculus@icculus.org>
parents: 7685
diff changeset
   429
        UINT nameSize = SDL_arraysize(devName);
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   430
7706
8cc29a668223 Better XInput detection code for DirectInput device enumeration.
Ryan C. Gordon <icculus@icculus.org>
parents: 7685
diff changeset
   431
        rdi.cbSize = sizeof (rdi);
8cc29a668223 Better XInput detection code for DirectInput device enumeration.
Ryan C. Gordon <icculus@icculus.org>
parents: 7685
diff changeset
   432
        if ( (SDL_RawDevList[i].dwType == RIM_TYPEHID) &&
8cc29a668223 Better XInput detection code for DirectInput device enumeration.
Ryan C. Gordon <icculus@icculus.org>
parents: 7685
diff changeset
   433
             (GetRawInputDeviceInfoA(SDL_RawDevList[i].hDevice, RIDI_DEVICEINFO, &rdi, &rdiSize) != ((UINT)-1)) &&
8cc29a668223 Better XInput detection code for DirectInput device enumeration.
Ryan C. Gordon <icculus@icculus.org>
parents: 7685
diff changeset
   434
             (MAKELONG(rdi.hid.dwVendorId, rdi.hid.dwProductId) == ((LONG)pGuidProductFromDirectInput->Data1)) &&
8cc29a668223 Better XInput detection code for DirectInput device enumeration.
Ryan C. Gordon <icculus@icculus.org>
parents: 7685
diff changeset
   435
             (GetRawInputDeviceInfoA(SDL_RawDevList[i].hDevice, RIDI_DEVICENAME, devName, &nameSize) != ((UINT)-1)) &&
8cc29a668223 Better XInput detection code for DirectInput device enumeration.
Ryan C. Gordon <icculus@icculus.org>
parents: 7685
diff changeset
   436
             (SDL_strstr(devName, "IG_") != NULL) ) {
8cc29a668223 Better XInput detection code for DirectInput device enumeration.
Ryan C. Gordon <icculus@icculus.org>
parents: 7685
diff changeset
   437
             return SDL_TRUE;
8cc29a668223 Better XInput detection code for DirectInput device enumeration.
Ryan C. Gordon <icculus@icculus.org>
parents: 7685
diff changeset
   438
        }
8cc29a668223 Better XInput detection code for DirectInput device enumeration.
Ryan C. Gordon <icculus@icculus.org>
parents: 7685
diff changeset
   439
    }
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   440
7706
8cc29a668223 Better XInput detection code for DirectInput device enumeration.
Ryan C. Gordon <icculus@icculus.org>
parents: 7685
diff changeset
   441
    return SDL_FALSE;
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   442
}
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   443
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   444
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   445
static SDL_bool s_bWindowsDeviceChanged = SDL_FALSE;
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   446
7133
87d4cb9bb66c Corrected spelling in C source files.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7037
diff changeset
   447
/* windowproc for our joystick detect thread message only window, to detect any USB device addition/removal
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   448
 */
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   449
LRESULT CALLBACK SDL_PrivateJoystickDetectProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)    {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   450
    switch (message)    {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   451
    case WM_DEVICECHANGE:
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   452
        switch (wParam) {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   453
        case DBT_DEVICEARRIVAL:
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   454
            if (((DEV_BROADCAST_HDR*)lParam)->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE)    {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   455
                s_bWindowsDeviceChanged = SDL_TRUE;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   456
            }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   457
            break;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   458
        case DBT_DEVICEREMOVECOMPLETE:
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   459
            if (((DEV_BROADCAST_HDR*)lParam)->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE)    {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   460
                s_bWindowsDeviceChanged = SDL_TRUE;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   461
            }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   462
            break;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   463
        }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   464
        return 0;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   465
    }
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   466
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   467
    return DefWindowProc (hwnd, message, wParam, lParam);
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   468
}
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   469
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   470
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   471
DEFINE_GUID(GUID_DEVINTERFACE_USB_DEVICE, 0xA5DCBF10L, 0x6530, 0x11D2, 0x90, 0x1F, 0x00, \
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   472
    0xC0, 0x4F, 0xB9, 0x51, 0xED);
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   473
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   474
/* Function/thread to scan the system for joysticks.
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   475
 */
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   476
static int
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   477
SDL_JoystickThread(void *_data)
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   478
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   479
    HWND messageWindow = 0;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   480
    HDEVNOTIFY hNotify = 0;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   481
    DEV_BROADCAST_DEVICEINTERFACE dbh;
7707
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   482
    SDL_bool bOpenedXInputDevices[SDL_XINPUT_MAX_DEVICES];
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   483
    WNDCLASSEX wincl;
6710
e650705e2c1d Alfred Reynolds - add scanning of XInput for controller connectedness so we can detect when the wireless controller turns on and off, the usb side doesn't change when the controller goes away
Sam Lantinga <slouken@libsdl.org>
parents: 6709
diff changeset
   484
7707
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   485
    SDL_zero(bOpenedXInputDevices);
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   486
7223
76fa20889de8 Fixed compile errors building with mingw64
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   487
    WIN_CoInitialize();
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   488
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   489
    SDL_memset( &wincl, 0x0, sizeof(wincl) );
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   490
    wincl.hInstance = GetModuleHandle( NULL );
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   491
    wincl.lpszClassName = L"Message";
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   492
    wincl.lpfnWndProc = SDL_PrivateJoystickDetectProc;      /* This function is called by windows */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   493
    wincl.cbSize = sizeof (WNDCLASSEX);
6712
05f046f5886b Fixed crashes in new joystick code
Sam Lantinga <slouken@libsdl.org>
parents: 6710
diff changeset
   494
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   495
    if (!RegisterClassEx (&wincl))
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   496
    {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   497
        return SDL_SetError("Failed to create register class for joystick autodetect.", GetLastError());
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   498
    }
6712
05f046f5886b Fixed crashes in new joystick code
Sam Lantinga <slouken@libsdl.org>
parents: 6710
diff changeset
   499
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   500
    messageWindow = (HWND)CreateWindowEx( 0,  L"Message", NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, NULL, NULL );
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   501
    if ( !messageWindow )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   502
    {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   503
        return SDL_SetError("Failed to create message window for joystick autodetect.", GetLastError());
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   504
    }
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   505
7707
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   506
    SDL_zero(dbh);
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   507
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   508
    dbh.dbcc_size = sizeof(dbh);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   509
    dbh.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   510
    dbh.dbcc_classguid = GUID_DEVINTERFACE_USB_DEVICE;
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   511
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   512
    hNotify = RegisterDeviceNotification( messageWindow, &dbh, DEVICE_NOTIFY_WINDOW_HANDLE );
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   513
    if ( !hNotify )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   514
    {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   515
        return SDL_SetError("Failed to create notify device for joystick autodetect.", GetLastError());
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   516
    }
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   517
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   518
    SDL_LockMutex( s_mutexJoyStickEnum );
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   519
    while ( s_bJoystickThreadQuit == SDL_FALSE )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   520
    {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   521
        MSG messages;
7707
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   522
        SDL_bool bXInputChanged = SDL_FALSE;
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   523
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   524
        SDL_CondWaitTimeout( s_condJoystickThread, s_mutexJoyStickEnum, 300 );
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   525
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   526
        while ( s_bJoystickThreadQuit == SDL_FALSE && PeekMessage(&messages, messageWindow, 0, 0, PM_NOREMOVE) )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   527
        {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   528
            if ( GetMessage(&messages, messageWindow, 0, 0) != 0 )  {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   529
                TranslateMessage(&messages);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   530
                DispatchMessage(&messages);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   531
            }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   532
        }
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   533
7707
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   534
        if ( s_bXInputEnabled && XINPUTGETCAPABILITIES ) {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   535
            /* scan for any change in XInput devices */
7707
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   536
            Uint8 userId;
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   537
            for (userId = 0; userId < SDL_XINPUT_MAX_DEVICES; userId++) {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   538
                XINPUT_CAPABILITIES capabilities;
7707
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   539
                const DWORD result = XINPUTGETCAPABILITIES( userId, XINPUT_FLAG_GAMEPAD, &capabilities );
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   540
                const SDL_bool available = (result == ERROR_SUCCESS);
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   541
                if (bOpenedXInputDevices[userId] != available) {
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   542
                    bXInputChanged = SDL_TRUE;
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   543
                    bOpenedXInputDevices[userId] = available;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   544
                }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   545
            }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   546
        }
6710
e650705e2c1d Alfred Reynolds - add scanning of XInput for controller connectedness so we can detect when the wireless controller turns on and off, the usb side doesn't change when the controller goes away
Sam Lantinga <slouken@libsdl.org>
parents: 6709
diff changeset
   547
7707
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   548
        if (s_bWindowsDeviceChanged || bXInputChanged) {
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   549
            SDL_UnlockMutex( s_mutexJoyStickEnum );  /* let main thread go while we SDL_Delay(). */
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   550
            SDL_Delay( 300 ); /* wait for direct input to find out about this device */
7707
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   551
            SDL_LockMutex( s_mutexJoyStickEnum );
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   552
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   553
            s_bDeviceRemoved = SDL_TRUE;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   554
            s_bDeviceAdded = SDL_TRUE;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   555
            s_bWindowsDeviceChanged = SDL_FALSE;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   556
        }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   557
    }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   558
    SDL_UnlockMutex( s_mutexJoyStickEnum );
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   559
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   560
    if ( hNotify )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   561
        UnregisterDeviceNotification( hNotify );
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   562
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   563
    if ( messageWindow )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   564
        DestroyWindow( messageWindow );
6712
05f046f5886b Fixed crashes in new joystick code
Sam Lantinga <slouken@libsdl.org>
parents: 6710
diff changeset
   565
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   566
    UnregisterClass( wincl.lpszClassName, wincl.hInstance );
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   567
    messageWindow = 0;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   568
    WIN_CoUninitialize();
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   569
    return 1;
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   570
}
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   571
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   572
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   573
/* Function to scan the system for joysticks.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   574
 * This function should set SDL_numjoysticks to the number of available
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   575
 * joysticks.  Joystick 0 should be the system default joystick.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   576
 * It should return 0, or -1 on an unrecoverable fatal error.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   577
 */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   578
int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   579
SDL_SYS_JoystickInit(void)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   580
{
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   581
    HRESULT result;
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2198
diff changeset
   582
    HINSTANCE instance;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   583
    const char *env = SDL_GetHint(SDL_HINT_XINPUT_ENABLED);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   584
    if (env && !SDL_atoi(env)) {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   585
        s_bXInputEnabled = SDL_FALSE;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   586
    }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   587
5591
17beb16fa838 Cleaned up CoInitialize() politics on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   588
    result = WIN_CoInitialize();
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   589
    if (FAILED(result)) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6993
diff changeset
   590
        return SetDIerror("CoInitialize", result);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   591
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   592
5591
17beb16fa838 Cleaned up CoInitialize() politics on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   593
    coinitialized = SDL_TRUE;
17beb16fa838 Cleaned up CoInitialize() politics on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   594
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   595
    result = CoCreateInstance(&CLSID_DirectInput8, NULL, CLSCTX_INPROC_SERVER,
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   596
                              &IID_IDirectInput8, (LPVOID)&dinput);
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   597
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   598
    if (FAILED(result)) {
5591
17beb16fa838 Cleaned up CoInitialize() politics on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   599
        SDL_SYS_JoystickQuit();
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6993
diff changeset
   600
        return SetDIerror("CoCreateInstance", result);
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   601
    }
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   602
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   603
    /* Because we used CoCreateInstance, we need to Initialize it, first. */
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2198
diff changeset
   604
    instance = GetModuleHandle(NULL);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2198
diff changeset
   605
    if (instance == NULL) {
5591
17beb16fa838 Cleaned up CoInitialize() politics on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   606
        SDL_SYS_JoystickQuit();
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6993
diff changeset
   607
        return SDL_SetError("GetModuleHandle() failed with error code %d.", GetLastError());
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2198
diff changeset
   608
    }
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   609
    result = IDirectInput8_Initialize(dinput, instance, DIRECTINPUT_VERSION);
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   610
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   611
    if (FAILED(result)) {
5591
17beb16fa838 Cleaned up CoInitialize() politics on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   612
        SDL_SYS_JoystickQuit();
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6993
diff changeset
   613
        return SetDIerror("IDirectInput::Initialize", result);
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   614
    }
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   615
7707
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   616
    if ((s_bXInputEnabled) && (WIN_LoadXInputDLL() == -1)) {
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   617
        s_bXInputEnabled = SDL_FALSE;  /* oh well. */
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   618
    }
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   619
6990
2514368c2aaf First shot at Windows XInput haptics.
Ryan C. Gordon <icculus@icculus.org>
parents: 6977
diff changeset
   620
    s_mutexJoyStickEnum = SDL_CreateMutex();
2514368c2aaf First shot at Windows XInput haptics.
Ryan C. Gordon <icculus@icculus.org>
parents: 6977
diff changeset
   621
    s_condJoystickThread = SDL_CreateCond();
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   622
    s_bDeviceAdded = SDL_TRUE; /* force a scan of the system for joysticks this first time */
7707
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   623
6990
2514368c2aaf First shot at Windows XInput haptics.
Ryan C. Gordon <icculus@icculus.org>
parents: 6977
diff changeset
   624
    SDL_SYS_JoystickDetect();
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   625
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   626
    if ( !s_threadJoystick )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   627
    {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   628
        s_bJoystickThreadQuit = SDL_FALSE;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   629
        /* spin up the thread to detect hotplug of devices */
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   630
#if defined(__WIN32__) && !defined(HAVE_LIBC)
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   631
#undef SDL_CreateThread
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   632
        s_threadJoystick= SDL_CreateThread( SDL_JoystickThread, "SDL_joystick", NULL, NULL, NULL );
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   633
#else
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   634
        s_threadJoystick = SDL_CreateThread( SDL_JoystickThread, "SDL_joystick", NULL );
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   635
#endif
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   636
    }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   637
        return SDL_SYS_NumJoysticks();
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   638
}
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   639
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   640
/* return the number of joysticks that are connected right now */
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   641
int SDL_SYS_NumJoysticks()
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   642
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   643
    int nJoysticks = 0;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   644
    JoyStick_DeviceData *device = SYS_Joystick;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   645
    while ( device )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   646
    {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   647
        nJoysticks++;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   648
        device = device->pNext;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   649
    }
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   650
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   651
    return nJoysticks;
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   652
}
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   653
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   654
/* helper function for direct input, gets called for each connected joystick */
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   655
static BOOL CALLBACK
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   656
    EnumJoysticksCallback(const DIDEVICEINSTANCE * pdidInstance, VOID * pContext)
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   657
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   658
    JoyStick_DeviceData *pNewJoystick;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   659
    JoyStick_DeviceData *pPrevJoystick = NULL;
7707
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   660
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   661
    if (SDL_IsXInputDevice( &pdidInstance->guidProduct )) {
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   662
        return DIENUM_CONTINUE;  /* ignore XInput devices here, keep going. */
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   663
    }
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   664
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   665
    pNewJoystick = *(JoyStick_DeviceData **)pContext;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   666
    while ( pNewJoystick )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   667
    {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   668
        if ( !SDL_memcmp( &pNewJoystick->dxdevice.guidInstance, &pdidInstance->guidInstance, sizeof(pNewJoystick->dxdevice.guidInstance) ) )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   669
        {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   670
            /* if we are replacing the front of the list then update it */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   671
            if ( pNewJoystick == *(JoyStick_DeviceData **)pContext )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   672
            {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   673
                *(JoyStick_DeviceData **)pContext = pNewJoystick->pNext;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   674
            }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   675
            else if ( pPrevJoystick )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   676
            {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   677
                pPrevJoystick->pNext = pNewJoystick->pNext;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   678
            }
6712
05f046f5886b Fixed crashes in new joystick code
Sam Lantinga <slouken@libsdl.org>
parents: 6710
diff changeset
   679
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   680
            pNewJoystick->pNext = SYS_Joystick;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   681
            SYS_Joystick = pNewJoystick;
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   682
7707
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   683
            return DIENUM_CONTINUE; /* already have this joystick loaded, just keep going */
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   684
        }
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   685
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   686
        pPrevJoystick = pNewJoystick;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   687
        pNewJoystick = pNewJoystick->pNext;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   688
    }
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   689
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   690
    pNewJoystick = (JoyStick_DeviceData *)SDL_malloc( sizeof(JoyStick_DeviceData) );
7707
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   691
    if (!pNewJoystick) {
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   692
        return DIENUM_CONTINUE; /* better luck next time? */
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   693
    }
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   694
7707
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   695
    SDL_zerop(pNewJoystick);
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   696
    pNewJoystick->joystickname = WIN_StringToUTF8(pdidInstance->tszProductName);
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   697
    if (!pNewJoystick->joystickname) {
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   698
        SDL_free(pNewJoystick);
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   699
        return DIENUM_CONTINUE; /* better luck next time? */
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   700
    }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   701
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   702
    SDL_memcpy(&(pNewJoystick->dxdevice), pdidInstance,
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   703
        sizeof(DIDEVICEINSTANCE));
6712
05f046f5886b Fixed crashes in new joystick code
Sam Lantinga <slouken@libsdl.org>
parents: 6710
diff changeset
   704
7707
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   705
    pNewJoystick->XInputUserId = INVALID_XINPUT_USERID;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   706
    pNewJoystick->send_add_event = 1;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   707
    pNewJoystick->nInstanceID = ++s_nInstanceID;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   708
    SDL_memcpy( &pNewJoystick->guid, &pdidInstance->guidProduct, sizeof(pNewJoystick->guid) );
7707
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   709
    pNewJoystick->pNext = SYS_Joystick;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   710
    SYS_Joystick = pNewJoystick;
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   711
7707
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   712
    s_bDeviceAdded = SDL_TRUE;
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   713
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   714
    return DIENUM_CONTINUE; /* get next device, please */
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   715
}
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   716
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   717
static void
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   718
AddXInputDevice(const Uint8 userid, JoyStick_DeviceData **pContext)
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   719
{
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   720
    char name[32];
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   721
    JoyStick_DeviceData *pPrevJoystick = NULL;
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   722
    JoyStick_DeviceData *pNewJoystick = *pContext;
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   723
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   724
    while (pNewJoystick) {
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   725
        if ((pNewJoystick->bXInputDevice) && (pNewJoystick->XInputUserId == userid)) {
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   726
            /* if we are replacing the front of the list then update it */
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   727
            if (pNewJoystick == *pContext) {
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   728
                *pContext = pNewJoystick->pNext;
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   729
            } else if (pPrevJoystick) {
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   730
                pPrevJoystick->pNext = pNewJoystick->pNext;
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   731
            }
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   732
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   733
            pNewJoystick->pNext = SYS_Joystick;
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   734
            SYS_Joystick = pNewJoystick;
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   735
        }
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   736
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   737
        pPrevJoystick = pNewJoystick;
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   738
        pNewJoystick = pNewJoystick->pNext;
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   739
        return;   /* already in the list. */
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   740
    }
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   741
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   742
    pNewJoystick = (JoyStick_DeviceData *) SDL_malloc(sizeof (JoyStick_DeviceData));
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   743
    if (!pNewJoystick) {
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   744
        return; /* better luck next time? */
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   745
    }
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   746
    SDL_zerop(pNewJoystick);
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   747
7709
edd2c14acf66 Make XInput joystick names match the numbers on the device.
Ryan C. Gordon <icculus@icculus.org>
parents: 7707
diff changeset
   748
    SDL_snprintf(name, sizeof (name), "XInput Controller #%u", ((unsigned int) userid) + 1);
7707
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   749
    pNewJoystick->joystickname = SDL_strdup(name);
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   750
    if (!pNewJoystick->joystickname) {
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   751
        SDL_free(pNewJoystick);
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   752
        return; /* better luck next time? */
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   753
    }
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   754
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   755
    pNewJoystick->bXInputDevice = SDL_TRUE;
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   756
    pNewJoystick->XInputUserId = userid;
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   757
    pNewJoystick->send_add_event = 1;
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   758
    pNewJoystick->nInstanceID = ++s_nInstanceID;
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   759
    pNewJoystick->pNext = SYS_Joystick;
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   760
    SYS_Joystick = pNewJoystick;
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   761
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   762
    s_bDeviceAdded = SDL_TRUE;
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   763
}
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   764
7707
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   765
static void
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   766
EnumXInputDevices(JoyStick_DeviceData **pContext)
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   767
{
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   768
    if (s_bXInputEnabled) {
7712
66b5b8446275 Change order we enumerate Windows joysticks.
Ryan C. Gordon <icculus@icculus.org>
parents: 7711
diff changeset
   769
        int iuserid;
66b5b8446275 Change order we enumerate Windows joysticks.
Ryan C. Gordon <icculus@icculus.org>
parents: 7711
diff changeset
   770
        /* iterate in reverse, so these are in the final list in ascending numeric order. */
66b5b8446275 Change order we enumerate Windows joysticks.
Ryan C. Gordon <icculus@icculus.org>
parents: 7711
diff changeset
   771
        for (iuserid = SDL_XINPUT_MAX_DEVICES-1; iuserid >= 0; iuserid--) {
66b5b8446275 Change order we enumerate Windows joysticks.
Ryan C. Gordon <icculus@icculus.org>
parents: 7711
diff changeset
   772
            const Uint8 userid = (Uint8) iuserid;
7707
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   773
            XINPUT_CAPABILITIES capabilities;
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   774
            if (XINPUTGETCAPABILITIES(userid, XINPUT_FLAG_GAMEPAD, &capabilities) == ERROR_SUCCESS) {
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   775
                /* Current version of XInput mistakenly returns 0 as the Type. Ignore it and ensure the subtype is a gamepad. */
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   776
                /* !!! FIXME: we might want to support steering wheels or guitars or whatever laster. */
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   777
                if (capabilities.SubType == XINPUT_DEVSUBTYPE_GAMEPAD) {
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   778
                    AddXInputDevice(userid, pContext);
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   779
                }
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   780
            }
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   781
        }
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   782
    }
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   783
}
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   784
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   785
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   786
/* detect any new joysticks being inserted into the system */
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   787
void SDL_SYS_JoystickDetect()
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   788
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   789
    JoyStick_DeviceData *pCurList = NULL;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   790
    /* only enum the devices if the joystick thread told us something changed */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   791
    if ( s_bDeviceAdded || s_bDeviceRemoved )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   792
    {
7707
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   793
        SDL_LockMutex( s_mutexJoyStickEnum );
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   794
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   795
        s_bDeviceAdded = SDL_FALSE;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   796
        s_bDeviceRemoved = SDL_FALSE;
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   797
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   798
        pCurList = SYS_Joystick;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   799
        SYS_Joystick = NULL;
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   800
7707
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   801
        /* Look for DirectInput joysticks, wheels, head trackers, gamepads, etc.. */
7223
76fa20889de8 Fixed compile errors building with mingw64
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   802
        IDirectInput8_EnumDevices(dinput,
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   803
            DI8DEVCLASS_GAMECTRL,
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   804
            EnumJoysticksCallback,
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   805
            &pCurList, DIEDFL_ATTACHEDONLY);
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   806
7707
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   807
        SDL_free(SDL_RawDevList);  /* in case we used this in DirectInput enumerator. */
7706
8cc29a668223 Better XInput detection code for DirectInput device enumeration.
Ryan C. Gordon <icculus@icculus.org>
parents: 7685
diff changeset
   808
        SDL_RawDevList = NULL;
7707
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   809
        SDL_RawDevListCount = 0;
7706
8cc29a668223 Better XInput detection code for DirectInput device enumeration.
Ryan C. Gordon <icculus@icculus.org>
parents: 7685
diff changeset
   810
7712
66b5b8446275 Change order we enumerate Windows joysticks.
Ryan C. Gordon <icculus@icculus.org>
parents: 7711
diff changeset
   811
        /* Look for XInput devices. Do this last, so they're first in the final list. */
66b5b8446275 Change order we enumerate Windows joysticks.
Ryan C. Gordon <icculus@icculus.org>
parents: 7711
diff changeset
   812
        EnumXInputDevices(&pCurList);
66b5b8446275 Change order we enumerate Windows joysticks.
Ryan C. Gordon <icculus@icculus.org>
parents: 7711
diff changeset
   813
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   814
        SDL_UnlockMutex( s_mutexJoyStickEnum );
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   815
    }
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   816
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   817
    if ( pCurList )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   818
    {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   819
        while ( pCurList )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   820
        {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   821
            JoyStick_DeviceData *pListNext = NULL;
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   822
#if !SDL_EVENTS_DISABLED
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   823
            SDL_Event event;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   824
            event.type = SDL_JOYDEVICEREMOVED;
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   825
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   826
            if (SDL_GetEventState(event.type) == SDL_ENABLE) {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   827
                event.jdevice.which = pCurList->nInstanceID;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   828
                if ((SDL_EventOK == NULL)
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   829
                    || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   830
                        SDL_PushEvent(&event);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   831
                }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   832
            }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   833
#endif /* !SDL_EVENTS_DISABLED */
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   834
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   835
            pListNext = pCurList->pNext;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   836
            SDL_free(pCurList->joystickname);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   837
            SDL_free( pCurList );
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   838
            pCurList = pListNext;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   839
        }
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   840
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   841
    }
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   842
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   843
    if ( s_bDeviceAdded )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   844
    {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   845
        JoyStick_DeviceData *pNewJoystick;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   846
        int device_index = 0;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   847
        s_bDeviceAdded = SDL_FALSE;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   848
        pNewJoystick = SYS_Joystick;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   849
        while ( pNewJoystick )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   850
        {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   851
            if ( pNewJoystick->send_add_event )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   852
            {
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   853
#if !SDL_EVENTS_DISABLED
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   854
                SDL_Event event;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   855
                event.type = SDL_JOYDEVICEADDED;
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   856
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   857
                if (SDL_GetEventState(event.type) == SDL_ENABLE) {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   858
                    event.jdevice.which = device_index;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   859
                    if ((SDL_EventOK == NULL)
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   860
                        || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   861
                            SDL_PushEvent(&event);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   862
                    }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   863
                }
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   864
#endif /* !SDL_EVENTS_DISABLED */
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   865
                pNewJoystick->send_add_event = 0;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   866
            }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   867
            device_index++;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   868
            pNewJoystick = pNewJoystick->pNext;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   869
        }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   870
    }
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   871
}
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   872
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   873
/* we need to poll if we have pending hotplug device changes or connected devices */
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   874
SDL_bool SDL_SYS_JoystickNeedsPolling()
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   875
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   876
    /* we have a new device or one was pulled, we need to think this frame please */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   877
    if ( s_bDeviceAdded || s_bDeviceRemoved )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   878
        return SDL_TRUE;
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   879
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   880
    return SDL_FALSE;
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   881
}
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   882
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   883
/* Function to get the device-dependent name of a joystick */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   884
const char *
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   885
SDL_SYS_JoystickNameForDeviceIndex(int device_index)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   886
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   887
    JoyStick_DeviceData *device = SYS_Joystick;
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   888
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   889
    for (; device_index > 0; device_index--)
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   890
        device = device->pNext;
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   891
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   892
    return device->joystickname;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   893
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   894
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   895
/* Function to perform the mapping between current device instance and this joysticks instance id */
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   896
SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   897
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   898
    JoyStick_DeviceData *device = SYS_Joystick;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   899
    int index;
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   900
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   901
    for (index = device_index; index > 0; index--)
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   902
        device = device->pNext;
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   903
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   904
    return device->nInstanceID;
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   905
}
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   906
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   907
/* Function to open a joystick for use.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   908
   The joystick to open is specified by the index field of the joystick.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   909
   This should fill the nbuttons and naxes fields of the joystick structure.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   910
   It returns 0, or -1 if there is an error.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   911
 */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   912
int
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   913
SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   914
{
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   915
    HRESULT result;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   916
    JoyStick_DeviceData *joystickdevice = SYS_Joystick;
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   917
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   918
    for (; device_index > 0; device_index--)
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   919
        joystickdevice = joystickdevice->pNext;
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   920
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   921
    /* allocate memory for system specific hardware data */
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   922
    joystick->instance_id = joystickdevice->nInstanceID;
6965
ab4bb4e99961 add hint to allow disabling the use of Xinput.
Edward Rudd <urkle@outoforder.cc>
parents: 6885
diff changeset
   923
    joystick->closed = 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   924
    joystick->hwdata =
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2198
diff changeset
   925
        (struct joystick_hwdata *) SDL_malloc(sizeof(struct joystick_hwdata));
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   926
    if (joystick->hwdata == NULL) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6993
diff changeset
   927
        return SDL_OutOfMemory();
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   928
    }
7707
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   929
    SDL_zerop(joystick->hwdata);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   930
7707
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   931
    if (joystickdevice->bXInputDevice) {
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   932
        const SDL_bool bIs14OrLater = (SDL_XInputVersion >= ((1<<16)|4));
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   933
        const Uint8 userId = joystickdevice->XInputUserId;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   934
        XINPUT_CAPABILITIES capabilities;
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   935
7707
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   936
        SDL_assert(s_bXInputEnabled);
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   937
        SDL_assert(XINPUTGETCAPABILITIES);
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   938
        SDL_assert(userId >= 0);
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   939
        SDL_assert(userId < SDL_XINPUT_MAX_DEVICES);
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   940
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   941
        joystick->hwdata->bXInputDevice = SDL_TRUE;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   942
7707
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   943
        if (XINPUTGETCAPABILITIES(userId, XINPUT_FLAG_GAMEPAD, &capabilities) != ERROR_SUCCESS) {
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   944
            SDL_free(joystick->hwdata);
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   945
            joystick->hwdata = NULL;
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   946
            return SDL_SetError("Failed to obtain XInput device capabilities. Device disconnected?");
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   947
        } else {
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   948
            /* Current version of XInput mistakenly returns 0 as the Type. Ignore it and ensure the subtype is a gamepad. */
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   949
            SDL_assert(capabilities.SubType == XINPUT_DEVSUBTYPE_GAMEPAD);
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   950
            if ((!bIs14OrLater) || (capabilities.Flags & XINPUT_CAPS_FFB_SUPPORTED)) {
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   951
                joystick->hwdata->bXInputHaptic = SDL_TRUE;
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   952
            }
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   953
            joystick->hwdata->userid = userId;
7684
dee82553d409 Fix SDL xinput code to work at all when xinput has devices at high indexes but no device connected at lower index, for instance 0->disconnected, 1->wireles, 2->wired. Previously the SDL code assumed the indexes were always used up in order which is not true at all and lead to a bunch of failure cases where controllers would go unrecognized.
Sam Lantinga <slouken@libsdl.org>
parents: 7663
diff changeset
   954
7707
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   955
            /* The XInput API has a hard coded button/axis mapping, so we just match it */
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   956
            joystick->naxes = 6;
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   957
            joystick->nbuttons = 15;
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   958
            joystick->nballs = 0;
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   959
            joystick->nhats = 0;
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   960
		}
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   961
    } else {  /* use DirectInput, not XInput. */
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   962
        LPDIRECTINPUTDEVICE8 device;
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   963
        DIPROPDWORD dipdw;
7684
dee82553d409 Fix SDL xinput code to work at all when xinput has devices at high indexes but no device connected at lower index, for instance 0->disconnected, 1->wireles, 2->wired. Previously the SDL code assumed the indexes were always used up in order which is not true at all and lead to a bunch of failure cases where controllers would go unrecognized.
Sam Lantinga <slouken@libsdl.org>
parents: 7663
diff changeset
   964
7707
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   965
        joystick->hwdata->buffered = 1;
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   966
        joystick->hwdata->removed = 0;
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   967
        joystick->hwdata->Capabilities.dwSize = sizeof(DIDEVCAPS);
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   968
        joystick->hwdata->guid = joystickdevice->guid;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   969
7707
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   970
        SDL_zero(dipdw);
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   971
        dipdw.diph.dwSize = sizeof(DIPROPDWORD);
37e02f8fcfa8 Reworked XInput and DirectInput joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 7706
diff changeset
   972
        dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   973
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   974
        result =
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   975
            IDirectInput8_CreateDevice(dinput,
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   976
                                      &(joystickdevice->dxdevice.guidInstance), &device, NULL);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   977
        if (FAILED(result)) {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   978
            return SetDIerror("IDirectInput::CreateDevice", result);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   979
        }
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   980
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   981
        /* Now get the IDirectInputDevice8 interface, instead. */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   982
        result = IDirectInputDevice8_QueryInterface(device,
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   983
                                                   &IID_IDirectInputDevice8,
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   984
                                                   (LPVOID *) & joystick->
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   985
                                                   hwdata->InputDevice);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   986
        /* We are done with this object.  Use the stored one from now on. */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   987
        IDirectInputDevice8_Release(device);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   988
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   989
        if (FAILED(result)) {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   990
            return SetDIerror("IDirectInputDevice8::QueryInterface", result);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   991
        }
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   992
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   993
        /* Acquire shared access. Exclusive access is required for forces,
75360622e65f File style cleanup for