src/joystick/windows/SDL_dxjoystick.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 26 May 2013 11:34:04 -0700
changeset 7223 76fa20889de8
parent 7191 75360622e65f
child 7230 757e9812ef1c
permissions -rw-r--r--
Fixed compile errors building with mingw64
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"
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
    38
#include "SDL_joystick.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
    39
#include "../SDL_sysjoystick.h"
3013
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
    40
#define INITGUID /* Only set here, if set twice will cause mingw32 to break. */
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2198
diff changeset
    41
#include "SDL_dxjoystick_c.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
    42
#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
    43
#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
    44
#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
    45
#include "SDL_events.h"
6971
5ded971ee761 Fixed compile errors on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 6965
diff changeset
    46
#include "SDL_hints.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
    47
#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
    48
#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
    49
#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
    50
2761
0c544c2eff77 Almost got this compiling on Cygwin32, just needs DirectInput 7
Sam Lantinga <slouken@libsdl.org>
parents: 2760
diff changeset
    51
#ifndef DIDFT_OPTIONAL
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
    52
#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
    53
#endif
0c544c2eff77 Almost got this compiling on Cygwin32, just needs DirectInput 7
Sam Lantinga <slouken@libsdl.org>
parents: 2760
diff changeset
    54
0c544c2eff77 Almost got this compiling on Cygwin32, just needs DirectInput 7
Sam Lantinga <slouken@libsdl.org>
parents: 2760
diff changeset
    55
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
    56
#define INPUT_QSIZE 32      /* Buffer up to 32 input messages */
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
    57
#define MAX_JOYSTICKS 8
7191
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 GUID *s_pKnownJoystickGUIDs = 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_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
    74
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
    75
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
    76
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
    77
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
    78
6991
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
    79
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
    80
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
    81
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
    82
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
    83
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 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
    85
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
    86
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
    87
int
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
    88
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
    89
{
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
    90
    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
    91
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
    92
    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
    93
        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
    94
        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
    95
        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
    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
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
    98
    version = (1 << 16) | 4;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
    99
    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
   100
    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
   101
        version = (1 << 16) | 3;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   102
        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
   103
    }
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
   104
    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
   105
        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
   106
    }
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
   107
    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
   108
        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
   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
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_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
   112
    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
   113
    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
   114
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
   115
    /* 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
   116
    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
   117
    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
   118
    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
   119
    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
   120
        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
   121
        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
   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
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
   124
    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
   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
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
   127
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
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
   129
{
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
   130
    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
   131
        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
   132
        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
   133
            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
   134
            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
   135
        }
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
   136
    } else {
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
   137
        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
   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
ff49588e3ddb Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
Ryan C. Gordon <icculus@icculus.org>
parents: 6990
diff changeset
   141
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   142
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
   143
                                       LPDIRECTINPUT * ppDI,
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   144
                                       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
   145
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
   146
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   147
    SDL_JoystickGUID guid;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   148
    DIDEVICEINSTANCE dxdevice;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   149
    char *joystickname;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   150
    Uint8 send_add_event;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   151
    SDL_JoystickID nInstanceID;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   152
    SDL_bool bXInputDevice;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   153
    Uint8 XInputUserId;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   154
    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
   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
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   157
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
   158
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   159
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
   160
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   161
/* local prototypes */
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6993
diff changeset
   162
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
   163
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
   164
                                           pdidInstance, VOID * pContext);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   165
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
   166
                                            LPVOID pvRef);
6220
c36934808194 Fixed bug 1371 - DX joystick axis ordering fix
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   167
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
   168
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
   169
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
   170
                                       Sint16 value);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   171
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
   172
                                      Uint8 value);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   173
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
   174
                                         Uint8 button, Uint8 state);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   175
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   176
/* Taken from Wine - Thanks! */
2760
02aa80d7905f Updated Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 2717
diff changeset
   177
DIOBJECTDATAFORMAT dfDIJoystick2[] = {
3013
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   178
  { &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
   179
  { &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
   180
  { &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
   181
  { &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
   182
  { &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
   183
  { &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
   184
  { &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
   185
  { &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
   186
  { &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
   187
  { &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
   188
  { &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
   189
  { &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
   190
  { 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
   191
  { 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
   192
  { 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
   193
  { 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
   194
  { 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
   195
  { 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
   196
  { 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
   197
  { 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
   198
  { 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
   199
  { 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
   200
  { 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
   201
  { 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
   202
  { 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
   203
  { 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
   204
  { 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
   205
  { 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
   206
  { 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
   207
  { 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
   208
  { 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
   209
  { 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
   210
  { 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
   211
  { 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
   212
  { 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
   213
  { 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
   214
  { 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
   215
  { 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
   216
  { 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
   217
  { 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
   218
  { 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
   219
  { 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
   220
  { 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
   221
  { 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
   222
  { 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
   223
  { 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
   224
  { 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
   225
  { 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
   226
  { 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
   227
  { 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
   228
  { 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
   229
  { 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
   230
  { 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
   231
  { 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
   232
  { 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
   233
  { 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
   234
  { 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
   235
  { 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
   236
  { 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
   237
  { 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
   238
  { 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
   239
  { 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
   240
  { 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
   241
  { 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
   242
  { 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
   243
  { 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
   244
  { 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
   245
  { 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
   246
  { 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
   247
  { 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
   248
  { 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
   249
  { 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
   250
  { 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
   251
  { 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
   252
  { 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
   253
  { 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
   254
  { 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
   255
  { 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
   256
  { 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
   257
  { 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
   258
  { 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
   259
  { 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
   260
  { 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
   261
  { 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
   262
  { 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
   263
  { 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
   264
  { 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
   265
  { 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
   266
  { 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
   267
  { 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
   268
  { 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
   269
  { 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
   270
  { 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
   271
  { 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
   272
  { 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
   273
  { 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
   274
  { 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
   275
  { 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
   276
  { 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
   277
  { 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
   278
  { 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
   279
  { 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
   280
  { 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
   281
  { 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
   282
  { 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
   283
  { 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
   284
  { 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
   285
  { 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
   286
  { 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
   287
  { 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
   288
  { 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
   289
  { 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
   290
  { 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
   291
  { 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
   292
  { 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
   293
  { 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
   294
  { 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
   295
  { 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
   296
  { 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
   297
  { 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
   298
  { 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
   299
  { 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
   300
  { 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
   301
  { 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
   302
  { 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
   303
  { 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
   304
  { 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
   305
  { 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
   306
  { 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
   307
  { 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
   308
  { 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
   309
  { 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
   310
  { 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
   311
  { 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
   312
  { 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
   313
  { 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
   314
  { 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
   315
  { 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
   316
  { 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
   317
  { 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
   318
  { &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
   319
  { &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
   320
  { &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
   321
  { &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
   322
  { &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
   323
  { &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
   324
  { &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
   325
  { &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
   326
  { &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
   327
  { &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
   328
  { &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
   329
  { &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
   330
  { &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
   331
  { &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
   332
  { &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
   333
  { &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
   334
  { &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
   335
  { &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
   336
  { &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
   337
  { &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
   338
  { &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
   339
  { &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
   340
  { &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
   341
  { &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
   342
};
02aa80d7905f Updated Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 2717
diff changeset
   343
02aa80d7905f Updated Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 2717
diff changeset
   344
const DIDATAFORMAT c_dfDIJoystick2 = {
02aa80d7905f Updated Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 2717
diff changeset
   345
    sizeof(DIDATAFORMAT),
02aa80d7905f Updated Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 2717
diff changeset
   346
    sizeof(DIOBJECTDATAFORMAT),
02aa80d7905f Updated Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 2717
diff changeset
   347
    DIDF_ABSAXIS,
02aa80d7905f Updated Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 2717
diff changeset
   348
    sizeof(DIJOYSTATE2),
02aa80d7905f Updated Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 2717
diff changeset
   349
    SDL_arraysize(dfDIJoystick2),
02aa80d7905f Updated Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 2717
diff changeset
   350
    dfDIJoystick2
02aa80d7905f Updated Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 2717
diff changeset
   351
};
02aa80d7905f Updated Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 2717
diff changeset
   352
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   353
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
   354
/* 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
   355
static int
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   356
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
   357
{
2760
02aa80d7905f Updated Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 2717
diff changeset
   358
    /*
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6993
diff changeset
   359
    return SDL_SetError("%s() [%s]: %s", function,
3013
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   360
                 DXGetErrorString9A(code), DXGetErrorDescription9A(code));
2760
02aa80d7905f Updated Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 2717
diff changeset
   361
     */
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6993
diff changeset
   362
    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
   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
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
   365
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   366
#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
   367
{                                                   \
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   368
    if (p) {                                        \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   369
        (p)->lpVtbl->Release((p));                  \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   370
        (p) = 0;                                    \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   371
    }                                               \
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   372
}
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   373
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   374
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   375
DEFINE_GUID(CLSID_WbemLocator,   0x4590f811,0x1d3a,0x11d0,0x89,0x1F,0x00,0xaa,0x00,0x4b,0x2e,0x24);
7223
76fa20889de8 Fixed compile errors building with mingw64
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   376
#ifndef __IWbemLocator_INTERFACE_DEFINED__
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   377
DEFINE_GUID(IID_IWbemLocator,    0xdc12a687,0x737f,0x11cf,0x88,0x4d,0x00,0xaa,0x00,0x4b,0x2e,0x24);
7223
76fa20889de8 Fixed compile errors building with mingw64
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   378
#endif
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   379
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   380
/*-----------------------------------------------------------------------------
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   381
 *
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   382
 * code from MSDN: http://msdn.microsoft.com/en-us/library/windows/desktop/ee417014(v=vs.85).aspx
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   383
 *
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   384
 * Enum each PNP device using WMI and check each device ID to see if it contains
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   385
 * "IG_" (ex. "VID_045E&PID_028E&IG_00").  If it does, then it's an XInput device
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   386
 * Unfortunately this information can not be found by just using DirectInput
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
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
BOOL IsXInputDevice( const GUID* pGuidProductFromDirectInput )
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   389
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   390
    IWbemLocator*           pIWbemLocator  = NULL;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   391
    IEnumWbemClassObject*   pEnumDevices   = NULL;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   392
    IWbemClassObject*       pDevices[20];
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   393
    IWbemServices*          pIWbemServices = NULL;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   394
    DWORD                   uReturned      = 0;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   395
    BSTR                    bstrNamespace  = NULL;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   396
    BSTR                    bstrDeviceID   = NULL;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   397
    BSTR                    bstrClassName  = NULL;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   398
    SDL_bool                bIsXinputDevice= SDL_FALSE;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   399
    UINT                    iDevice        = 0;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   400
    VARIANT                 var;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   401
    HRESULT                 hr;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   402
    DWORD bCleanupCOM;
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   403
6965
ab4bb4e99961 add hint to allow disabling the use of Xinput.
Edward Rudd <urkle@outoforder.cc>
parents: 6885
diff changeset
   404
    if (!s_bXInputEnabled)
ab4bb4e99961 add hint to allow disabling the use of Xinput.
Edward Rudd <urkle@outoforder.cc>
parents: 6885
diff changeset
   405
    {
ab4bb4e99961 add hint to allow disabling the use of Xinput.
Edward Rudd <urkle@outoforder.cc>
parents: 6885
diff changeset
   406
        return SDL_FALSE;
ab4bb4e99961 add hint to allow disabling the use of Xinput.
Edward Rudd <urkle@outoforder.cc>
parents: 6885
diff changeset
   407
    }
ab4bb4e99961 add hint to allow disabling the use of Xinput.
Edward Rudd <urkle@outoforder.cc>
parents: 6885
diff changeset
   408
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   409
    SDL_memset( pDevices, 0x0, sizeof(pDevices) );
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   410
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   411
    /* CoInit if needed */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   412
    hr = CoInitialize(NULL);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   413
    bCleanupCOM = SUCCEEDED(hr);
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   414
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   415
    /* Create WMI */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   416
    hr = CoCreateInstance( &CLSID_WbemLocator,
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   417
        NULL,
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   418
        CLSCTX_INPROC_SERVER,
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   419
        &IID_IWbemLocator,
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   420
        (LPVOID*) &pIWbemLocator);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   421
    if( FAILED(hr) || pIWbemLocator == NULL )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   422
        goto LCleanup;
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
    bstrNamespace = SysAllocString( L"\\\\.\\root\\cimv2" );if( bstrNamespace == NULL ) goto LCleanup;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   425
    bstrClassName = SysAllocString( L"Win32_PNPEntity" );   if( bstrClassName == NULL ) goto LCleanup;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   426
    bstrDeviceID  = SysAllocString( L"DeviceID" );          if( bstrDeviceID == NULL )  goto LCleanup;
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   427
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   428
    /* Connect to WMI */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   429
    hr = IWbemLocator_ConnectServer( pIWbemLocator, bstrNamespace, NULL, NULL, 0L,
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   430
        0L, NULL, NULL, &pIWbemServices );
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   431
    if( FAILED(hr) || pIWbemServices == NULL )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   432
        goto LCleanup;
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   433
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   434
    /* Switch security level to IMPERSONATE. */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   435
    CoSetProxyBlanket( (IUnknown *)pIWbemServices, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, NULL,
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   436
        RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE );
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   437
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   438
    hr = IWbemServices_CreateInstanceEnum( pIWbemServices, bstrClassName, 0, NULL, &pEnumDevices );
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   439
    if( FAILED(hr) || pEnumDevices == NULL )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   440
        goto LCleanup;
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   441
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   442
    /* Loop over all devices */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   443
    for( ;; )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   444
    {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   445
        /* Get 20 at a time */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   446
        hr = IEnumWbemClassObject_Next( pEnumDevices, 10000, 20, pDevices, &uReturned );
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   447
        if( FAILED(hr) )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   448
            goto LCleanup;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   449
        if( uReturned == 0 )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   450
            break;
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   451
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   452
        for( iDevice=0; iDevice<uReturned; iDevice++ )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   453
        {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   454
            /* For each device, get its device ID */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   455
            hr = IWbemClassObject_Get( pDevices[iDevice], bstrDeviceID, 0L, &var, NULL, NULL );
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   456
            if(  SUCCEEDED( hr ) && var.vt == VT_BSTR && var.bstrVal != NULL )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   457
            {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   458
                /* Check if the device ID contains "IG_".  If it does, then it's an XInput device */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   459
                /* This information can not be found from DirectInput */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   460
                char *pDeviceString = WIN_StringToUTF8( var.bstrVal );
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   461
                if( SDL_strstr( pDeviceString, "IG_" ) )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   462
                {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   463
                    /* If it does, then get the VID/PID from var.bstrVal */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   464
                    long dwPid = 0, dwVid = 0;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   465
                    char * strPid = NULL;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   466
                    DWORD dwVidPid = 0;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   467
                    char * strVid = SDL_strstr( pDeviceString, "VID_" );
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   468
                    if( strVid )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   469
                    {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   470
                        dwVid = SDL_strtol( strVid + 4, NULL, 16 );
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   471
                    }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   472
                    strPid = SDL_strstr( pDeviceString, "PID_" );
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   473
                    if( strPid  )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   474
                    {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   475
                        dwPid = SDL_strtol( strPid + 4, NULL, 16 );
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   476
                    }
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   477
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   478
                    /* Compare the VID/PID to the DInput device */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   479
                    dwVidPid = MAKELONG( dwVid, dwPid );
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   480
                    if( dwVidPid == pGuidProductFromDirectInput->Data1 )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   481
                    {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   482
                        bIsXinputDevice = SDL_TRUE;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   483
                    }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   484
                }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   485
                if ( pDeviceString )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   486
                    SDL_free( pDeviceString );
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   487
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   488
                if ( bIsXinputDevice )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   489
                    break;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   490
            }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   491
            SAFE_RELEASE( pDevices[iDevice] );
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   492
        }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   493
    }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   494
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   495
LCleanup:
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   496
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   497
    for( iDevice=0; iDevice<20; iDevice++ )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   498
        SAFE_RELEASE( pDevices[iDevice] );
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   499
    SAFE_RELEASE( pEnumDevices );
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   500
    SAFE_RELEASE( pIWbemLocator );
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   501
    SAFE_RELEASE( pIWbemServices );
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   502
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   503
    if ( bstrNamespace )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   504
        SysFreeString( bstrNamespace );
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   505
    if ( bstrClassName )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   506
        SysFreeString( bstrClassName );
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   507
    if ( bstrDeviceID )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   508
        SysFreeString( bstrDeviceID );
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   509
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   510
    if( bCleanupCOM )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   511
        CoUninitialize();
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   512
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   513
    return bIsXinputDevice;
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   514
}
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   515
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   516
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   517
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
   518
7133
87d4cb9bb66c Corrected spelling in C source files.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7037
diff changeset
   519
/* 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
   520
 */
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   521
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
   522
    switch (message)    {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   523
    case WM_DEVICECHANGE:
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   524
        switch (wParam) {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   525
        case DBT_DEVICEARRIVAL:
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   526
            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
   527
                s_bWindowsDeviceChanged = SDL_TRUE;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   528
            }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   529
            break;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   530
        case DBT_DEVICEREMOVECOMPLETE:
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   531
            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
   532
                s_bWindowsDeviceChanged = SDL_TRUE;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   533
            }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   534
            break;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   535
        }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   536
        return 0;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   537
    }
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   538
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   539
    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
   540
}
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   541
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   542
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   543
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
   544
    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
   545
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   546
/* 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
   547
 */
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   548
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
   549
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
   550
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   551
    HWND messageWindow = 0;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   552
    HDEVNOTIFY hNotify = 0;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   553
    DEV_BROADCAST_DEVICEINTERFACE dbh;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   554
    SDL_bool bOpenedXInputDevices[4];
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   555
    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
   556
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   557
    SDL_memset( bOpenedXInputDevices, 0x0, sizeof(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
   558
7223
76fa20889de8 Fixed compile errors building with mingw64
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   559
    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
   560
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   561
    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
   562
    wincl.hInstance = GetModuleHandle( NULL );
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   563
    wincl.lpszClassName = L"Message";
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   564
    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
   565
    wincl.cbSize = sizeof (WNDCLASSEX);
6712
05f046f5886b Fixed crashes in new joystick code
Sam Lantinga <slouken@libsdl.org>
parents: 6710
diff changeset
   566
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   567
    if (!RegisterClassEx (&wincl))
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   568
    {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   569
        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
   570
    }
6712
05f046f5886b Fixed crashes in new joystick code
Sam Lantinga <slouken@libsdl.org>
parents: 6710
diff changeset
   571
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   572
    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
   573
    if ( !messageWindow )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   574
    {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   575
        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
   576
    }
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   577
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   578
    SDL_memset(&dbh, 0x0, sizeof(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
   579
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   580
    dbh.dbcc_size = sizeof(dbh);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   581
    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
   582
    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
   583
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   584
    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
   585
    if ( !hNotify )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   586
    {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   587
        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
   588
    }
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   589
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   590
    SDL_LockMutex( s_mutexJoyStickEnum );
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   591
    while ( s_bJoystickThreadQuit == SDL_FALSE )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   592
    {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   593
        MSG messages;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   594
        Uint8 userId;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   595
        int nCurrentOpenedXInputDevices = 0;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   596
        int nNewOpenedXInputDevices = 0;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   597
        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
   598
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   599
        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
   600
        {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   601
            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
   602
                TranslateMessage(&messages);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   603
                DispatchMessage(&messages);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   604
            }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   605
        }
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   606
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   607
        if ( s_bXInputEnabled && XINPUTGETCAPABILITIES )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   608
        {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   609
            /* scan for any change in XInput devices */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   610
            for ( userId = 0; userId < 4; userId++ )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   611
            {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   612
                XINPUT_CAPABILITIES capabilities;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   613
                DWORD result;
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
   614
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   615
                if ( bOpenedXInputDevices[userId] == SDL_TRUE )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   616
                    nCurrentOpenedXInputDevices++;
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
   617
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   618
                result = XINPUTGETCAPABILITIES( userId, XINPUT_FLAG_GAMEPAD, &capabilities );
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   619
                if ( result == ERROR_SUCCESS )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   620
                {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   621
                    bOpenedXInputDevices[userId] = SDL_TRUE;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   622
                    nNewOpenedXInputDevices++;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   623
                }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   624
                else
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   625
                {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   626
                    bOpenedXInputDevices[userId] = SDL_FALSE;
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
            }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   629
        }
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
   630
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   631
        if ( s_pKnownJoystickGUIDs && ( s_bWindowsDeviceChanged || nNewOpenedXInputDevices != nCurrentOpenedXInputDevices ) )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   632
        {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   633
            SDL_Delay( 300 ); /* wait for direct input to find out about this 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
   634
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   635
            s_bDeviceRemoved = SDL_TRUE;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   636
            s_bDeviceAdded = SDL_TRUE;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   637
            s_bWindowsDeviceChanged = SDL_FALSE;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   638
        }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   639
    }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   640
    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
   641
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   642
    if ( hNotify )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   643
        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
   644
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   645
    if ( messageWindow )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   646
        DestroyWindow( messageWindow );
6712
05f046f5886b Fixed crashes in new joystick code
Sam Lantinga <slouken@libsdl.org>
parents: 6710
diff changeset
   647
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   648
    UnregisterClass( wincl.lpszClassName, wincl.hInstance );
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   649
    messageWindow = 0;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   650
    WIN_CoUninitialize();
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   651
    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
   652
}
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   653
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   654
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
   655
/* 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
   656
 * 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
   657
 * 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
   658
 * 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
   659
 */
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
   660
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
   661
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
   662
{
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
   663
    HRESULT result;
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2198
diff changeset
   664
    HINSTANCE instance;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   665
    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
   666
    if (env && !SDL_atoi(env)) {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   667
        s_bXInputEnabled = SDL_FALSE;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   668
    }
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
   669
5591
17beb16fa838 Cleaned up CoInitialize() politics on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   670
    result = WIN_CoInitialize();
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   671
    if (FAILED(result)) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6993
diff changeset
   672
        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
   673
    }
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
   674
5591
17beb16fa838 Cleaned up CoInitialize() politics on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   675
    coinitialized = SDL_TRUE;
17beb16fa838 Cleaned up CoInitialize() politics on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   676
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   677
    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
   678
                              &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
   679
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   680
    if (FAILED(result)) {
5591
17beb16fa838 Cleaned up CoInitialize() politics on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   681
        SDL_SYS_JoystickQuit();
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6993
diff changeset
   682
        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
   683
    }
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   684
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   685
    /* 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
   686
    instance = GetModuleHandle(NULL);
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2198
diff changeset
   687
    if (instance == NULL) {
5591
17beb16fa838 Cleaned up CoInitialize() politics on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   688
        SDL_SYS_JoystickQuit();
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6993
diff changeset
   689
        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
   690
    }
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6403
diff changeset
   691
    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
   692
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   693
    if (FAILED(result)) {
5591
17beb16fa838 Cleaned up CoInitialize() politics on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   694
        SDL_SYS_JoystickQuit();
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6993
diff changeset
   695
        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
   696
    }
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   697
6990
2514368c2aaf First shot at Windows XInput haptics.
Ryan C. Gordon <icculus@icculus.org>
parents: 6977
diff changeset
   698
    s_mutexJoyStickEnum = SDL_CreateMutex();
2514368c2aaf First shot at Windows XInput haptics.
Ryan C. Gordon <icculus@icculus.org>
parents: 6977
diff changeset
   699
    s_condJoystickThread = SDL_CreateCond();
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   700
    s_bDeviceAdded = SDL_TRUE; /* force a scan of the system for joysticks this first time */
6990
2514368c2aaf First shot at Windows XInput haptics.
Ryan C. Gordon <icculus@icculus.org>
parents: 6977
diff changeset
   701
    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
   702
6990
2514368c2aaf First shot at Windows XInput haptics.
Ryan C. Gordon <icculus@icculus.org>
parents: 6977
diff changeset
   703
    if ((s_bXInputEnabled) && (WIN_LoadXInputDLL() == -1)) {
2514368c2aaf First shot at Windows XInput haptics.
Ryan C. Gordon <icculus@icculus.org>
parents: 6977
diff changeset
   704
        s_bXInputEnabled = SDL_FALSE;  /* oh well. */
6965
ab4bb4e99961 add hint to allow disabling the use of Xinput.
Edward Rudd <urkle@outoforder.cc>
parents: 6885
diff changeset
   705
    }
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   706
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   707
    if ( !s_threadJoystick )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   708
    {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   709
        s_bJoystickThreadQuit = SDL_FALSE;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   710
        /* 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
   711
#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
   712
#undef SDL_CreateThread
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   713
        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
   714
#else
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   715
        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
   716
#endif
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   717
    }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   718
        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
   719
}
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   720
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   721
/* 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
   722
int SDL_SYS_NumJoysticks()
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   723
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   724
    int nJoysticks = 0;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   725
    JoyStick_DeviceData *device = SYS_Joystick;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   726
    while ( device )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   727
    {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   728
        nJoysticks++;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   729
        device = device->pNext;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   730
    }
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   731
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   732
    return nJoysticks;
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   733
}
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   734
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   735
static int s_iNewGUID = 0;
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   736
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   737
/* 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
   738
static BOOL CALLBACK
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   739
    EnumJoysticksCallback(const DIDEVICEINSTANCE * pdidInstance, VOID * pContext)
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   740
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   741
    JoyStick_DeviceData *pNewJoystick;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   742
    JoyStick_DeviceData *pPrevJoystick = NULL;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   743
    SDL_bool bXInputDevice;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   744
    pNewJoystick = *(JoyStick_DeviceData **)pContext;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   745
    while ( pNewJoystick )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   746
    {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   747
        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
   748
        {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   749
            /* 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
   750
            if ( pNewJoystick == *(JoyStick_DeviceData **)pContext )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   751
            {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   752
                *(JoyStick_DeviceData **)pContext = pNewJoystick->pNext;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   753
            }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   754
            else if ( pPrevJoystick )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   755
            {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   756
                pPrevJoystick->pNext = pNewJoystick->pNext;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   757
            }
6712
05f046f5886b Fixed crashes in new joystick code
Sam Lantinga <slouken@libsdl.org>
parents: 6710
diff changeset
   758
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   759
            pNewJoystick->pNext = SYS_Joystick;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   760
            SYS_Joystick = pNewJoystick;
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   761
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   762
            s_pKnownJoystickGUIDs[ s_iNewGUID ] = pdidInstance->guidInstance;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   763
            s_iNewGUID++;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   764
            if ( s_iNewGUID < MAX_JOYSTICKS )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   765
                return DIENUM_CONTINUE; /* already have this joystick loaded, just keep going */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   766
            else
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   767
                return DIENUM_STOP;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   768
        }
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   769
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   770
        pPrevJoystick = pNewJoystick;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   771
        pNewJoystick = pNewJoystick->pNext;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   772
    }
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   773
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   774
    s_bDeviceAdded = SDL_TRUE;
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   775
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   776
    bXInputDevice = IsXInputDevice( &pdidInstance->guidProduct );
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   777
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   778
    pNewJoystick = (JoyStick_DeviceData *)SDL_malloc( sizeof(JoyStick_DeviceData) );
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   779
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   780
    if ( bXInputDevice )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   781
    {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   782
        pNewJoystick->bXInputDevice = SDL_TRUE;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   783
        pNewJoystick->XInputUserId = INVALID_XINPUT_USERID;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   784
    }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   785
    else
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   786
    {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   787
        pNewJoystick->bXInputDevice = SDL_FALSE;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   788
    }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   789
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   790
    SDL_memcpy(&(pNewJoystick->dxdevice), pdidInstance,
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   791
        sizeof(DIDEVICEINSTANCE));
6712
05f046f5886b Fixed crashes in new joystick code
Sam Lantinga <slouken@libsdl.org>
parents: 6710
diff changeset
   792
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   793
    pNewJoystick->joystickname = WIN_StringToUTF8(pdidInstance->tszProductName);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   794
    pNewJoystick->send_add_event = 1;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   795
    pNewJoystick->nInstanceID = ++s_nInstanceID;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   796
    SDL_memcpy( &pNewJoystick->guid, &pdidInstance->guidProduct, sizeof(pNewJoystick->guid) );
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   797
    pNewJoystick->pNext = NULL;
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   798
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   799
    if ( SYS_Joystick )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   800
    {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   801
        pNewJoystick->pNext = SYS_Joystick;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   802
    }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   803
    SYS_Joystick = pNewJoystick;
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   804
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   805
    s_pKnownJoystickGUIDs[ s_iNewGUID ] = pdidInstance->guidInstance;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   806
    s_iNewGUID++;
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   807
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   808
    if ( s_iNewGUID < MAX_JOYSTICKS )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   809
        return DIENUM_CONTINUE; /* already have this joystick loaded, just keep going */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   810
    else
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   811
        return DIENUM_STOP;
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   812
}
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   813
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   814
/* 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
   815
void SDL_SYS_JoystickDetect()
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
    JoyStick_DeviceData *pCurList = NULL;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   818
    /* 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
   819
    if ( s_bDeviceAdded || s_bDeviceRemoved )
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
        s_bDeviceAdded = SDL_FALSE;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   822
        s_bDeviceRemoved = SDL_FALSE;
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   823
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   824
        pCurList = SYS_Joystick;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   825
        SYS_Joystick = NULL;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   826
        s_iNewGUID = 0;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   827
        SDL_LockMutex( s_mutexJoyStickEnum );
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   828
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   829
        if ( !s_pKnownJoystickGUIDs )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   830
            s_pKnownJoystickGUIDs = SDL_malloc( sizeof(GUID)*MAX_JOYSTICKS );
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
        SDL_memset( s_pKnownJoystickGUIDs, 0x0, sizeof(GUID)*MAX_JOYSTICKS );
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   833
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   834
        /* Look for joysticks, wheels, head trackers, gamepads, etc.. */
7223
76fa20889de8 Fixed compile errors building with mingw64
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   835
        IDirectInput8_EnumDevices(dinput,
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   836
            DI8DEVCLASS_GAMECTRL,
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   837
            EnumJoysticksCallback,
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   838
            &pCurList, DIEDFL_ATTACHEDONLY);
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   839
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   840
        SDL_UnlockMutex( s_mutexJoyStickEnum );
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 ( pCurList )
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
        while ( pCurList )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   846
        {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   847
            JoyStick_DeviceData *pListNext = NULL;
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   848
#if !SDL_EVENTS_DISABLED
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   849
            SDL_Event event;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   850
            event.type = SDL_JOYDEVICEREMOVED;
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   851
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   852
            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
   853
                event.jdevice.which = pCurList->nInstanceID;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   854
                if ((SDL_EventOK == NULL)
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   855
                    || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   856
                        SDL_PushEvent(&event);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   857
                }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   858
            }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   859
#endif /* !SDL_EVENTS_DISABLED */
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   860
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   861
            pListNext = pCurList->pNext;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   862
            SDL_free(pCurList->joystickname);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   863
            SDL_free( pCurList );
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   864
            pCurList = pListNext;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   865
        }
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   866
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   867
    }
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   868
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   869
    if ( s_bDeviceAdded )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   870
    {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   871
        JoyStick_DeviceData *pNewJoystick;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   872
        int device_index = 0;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   873
        s_bDeviceAdded = SDL_FALSE;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   874
        pNewJoystick = SYS_Joystick;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   875
        while ( pNewJoystick )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   876
        {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   877
            if ( pNewJoystick->send_add_event )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   878
            {
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   879
#if !SDL_EVENTS_DISABLED
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   880
                SDL_Event event;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   881
                event.type = SDL_JOYDEVICEADDED;
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   882
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   883
                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
   884
                    event.jdevice.which = device_index;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   885
                    if ((SDL_EventOK == NULL)
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   886
                        || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   887
                            SDL_PushEvent(&event);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   888
                    }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   889
                }
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   890
#endif /* !SDL_EVENTS_DISABLED */
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   891
                pNewJoystick->send_add_event = 0;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   892
            }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   893
            device_index++;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   894
            pNewJoystick = pNewJoystick->pNext;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   895
        }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   896
    }
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   897
}
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   898
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   899
/* 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
   900
SDL_bool SDL_SYS_JoystickNeedsPolling()
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   901
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   902
    /* 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
   903
    if ( s_bDeviceAdded || s_bDeviceRemoved )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   904
        return SDL_TRUE;
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   905
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   906
    return SDL_FALSE;
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   907
}
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   908
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
   909
/* 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
   910
const char *
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   911
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
   912
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   913
    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
   914
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   915
    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
   916
        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
   917
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   918
    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
   919
}
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
   920
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   921
/* 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
   922
SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   923
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   924
    JoyStick_DeviceData *device = SYS_Joystick;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   925
    int index;
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   926
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   927
    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
   928
        device = device->pNext;
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   929
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   930
    return device->nInstanceID;
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   931
}
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   932
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
   933
/* 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
   934
   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
   935
   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
   936
   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
   937
 */
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
   938
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
   939
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
   940
{
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
   941
    HRESULT result;
6716
1616f6b3738c Move all DirectInput code from DI2 to DI8.
Ryan C. Gordon <icculus@icculus.org>
parents: 6712
diff changeset
   942
    LPDIRECTINPUTDEVICE8 device;
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   943
    DIPROPDWORD dipdw;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   944
    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
   945
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   946
    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
   947
        joystickdevice = joystickdevice->pNext;
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   948
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2198
diff changeset
   949
    SDL_memset(&dipdw, 0, sizeof(DIPROPDWORD));
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   950
    dipdw.diph.dwSize = sizeof(DIPROPDWORD);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   951
    dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   952
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
   953
    /* 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
   954
    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
   955
    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
   956
    joystick->hwdata =
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2198
diff changeset
   957
        (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
   958
    if (joystick->hwdata == NULL) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6993
diff changeset
   959
        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
   960
    }
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2198
diff changeset
   961
    SDL_memset(joystick->hwdata, 0, 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
   962
    joystick->hwdata->buffered = 1;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   963
    joystick->hwdata->removed = 0;
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   964
    joystick->hwdata->Capabilities.dwSize = sizeof(DIDEVCAPS);
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   965
    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
   966
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   967
    if ( joystickdevice->bXInputDevice )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   968
    {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   969
        XINPUT_CAPABILITIES capabilities;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   970
        Uint8 userId = 0;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   971
        DWORD result;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   972
        JoyStick_DeviceData *joysticklist = SYS_Joystick;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   973
        /* scan the opened joysticks and pick the next free xinput userid for this one */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   974
        for( ; joysticklist; joysticklist = joysticklist->pNext)
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   975
        {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   976
            if ( joysticklist->bXInputDevice && joysticklist->XInputUserId == userId )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   977
                userId++;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   978
        }
2198
fe19afb86473 Split acinclude.m4 into its component parts for easy updating
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   979
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   980
        if ( s_bXInputEnabled && XINPUTGETCAPABILITIES )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   981
        {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   982
            result = XINPUTGETCAPABILITIES( userId, XINPUT_FLAG_GAMEPAD, &capabilities );
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   983
            if ( result == ERROR_SUCCESS )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   984
            {
6990
2514368c2aaf First shot at Windows XInput haptics.
Ryan C. Gordon <icculus@icculus.org>
parents: 6977
diff changeset
   985
                const SDL_bool bIs14OrLater = (SDL_XInputVersion >= ((1<<16)|4));
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   986
                SDL_bool bIsSupported = SDL_FALSE;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   987
                /* Current version of XInput mistakenly returns 0 as the Type. Ignore it and ensure the subtype is a gamepad. */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   988
                bIsSupported = ( capabilities.SubType == XINPUT_DEVSUBTYPE_GAMEPAD );
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
   989
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   990
                if ( !bIsSupported )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   991
                {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   992
                    joystickdevice->bXInputDevice = SDL_FALSE;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   993
                }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   994
                else
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   995
                {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   996
                    /* valid */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   997
                    joystick->hwdata->bXInputDevice = SDL_TRUE;
6990
2514368c2aaf First shot at Windows XInput haptics.
Ryan C. Gordon <icculus@icculus.org>
parents: 6977
diff changeset
   998
                    if ((!bIs14OrLater) || (capabilities.Flags & XINPUT_CAPS_FFB_SUPPORTED)) {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   999
                        joystick->hwdata->bXInputHaptic = SDL_TRUE;
6990
2514368c2aaf First shot at Windows XInput haptics.
Ryan C. Gordon <icculus@icculus.org>
parents: 6977
diff