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