src/joystick/windows/SDL_windowsjoystick.c
author Sam Lantinga <slouken@libsdl.org>
Fri, 26 Aug 2016 12:18:08 -0700
changeset 10281 cb13d22b7f09
parent 10147 ddbdc9c1b92f
permissions -rw-r--r--
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved() Updated the removal code to iterate over all joystick add messages instead of just the first one.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8972
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     1
/*
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     2
  Simple DirectMedia Layer
9998
f67cf37e9cd4 Updated copyright to 2016
Sam Lantinga <slouken@libsdl.org>
parents: 9619
diff changeset
     3
  Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
8972
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     4
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     5
  This software is provided 'as-is', without any express or implied
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     7
  arising from the use of this software.
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     8
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    11
  freely, subject to the following restrictions:
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    14
     claim that you wrote the original software. If you use this software
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    16
     appreciated but is not required.
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    18
     misrepresented as being the original software.
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
*/
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    21
#include "../../SDL_internal.h"
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    22
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    23
#if SDL_JOYSTICK_DINPUT || SDL_JOYSTICK_XINPUT
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    24
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    25
/* DirectInput joystick driver; written by Glenn Maynard, based on Andrei de
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    26
 * A. Formiga's WINMM driver.
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    27
 *
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    28
 * Hats and sliders are completely untested; the app I'm writing this for mostly
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    29
 * doesn't use them and I don't own any joysticks with them.
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    30
 *
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    31
 * We don't bother to use event notification here.  It doesn't seem to work
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    32
 * with polled devices, and it's fine to call IDirectInputDevice8_GetDeviceData and
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    33
 * let it return 0 events. */
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    34
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    35
#include "SDL_error.h"
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    36
#include "SDL_assert.h"
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    37
#include "SDL_events.h"
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    38
#include "SDL_timer.h"
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    39
#include "SDL_mutex.h"
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    40
#include "SDL_events.h"
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    41
#include "SDL_hints.h"
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    42
#include "SDL_joystick.h"
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    43
#include "../SDL_sysjoystick.h"
10147
ddbdc9c1b92f Patched to compile on various platforms.
Ryan C. Gordon <icculus@icculus.org>
parents: 10146
diff changeset
    44
#include "../../thread/SDL_systhread.h"
8972
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    45
#include "../../core/windows/SDL_windows.h"
9166
e5a2e31d4bee WinRT build fix
David Ludwig <dludwig@pobox.com>
parents: 8988
diff changeset
    46
#if !defined(__WINRT__)
8972
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    47
#include <dbt.h>
9166
e5a2e31d4bee WinRT build fix
David Ludwig <dludwig@pobox.com>
parents: 8988
diff changeset
    48
#endif
8972
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    49
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    50
#define INITGUID /* Only set here, if set twice will cause mingw32 to break. */
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    51
#include "SDL_windowsjoystick_c.h"
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    52
#include "SDL_dinputjoystick_c.h"
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    53
#include "SDL_xinputjoystick_c.h"
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    54
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    55
#include "../../haptic/windows/SDL_dinputhaptic_c.h"    /* For haptic hot plugging */
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    56
#include "../../haptic/windows/SDL_xinputhaptic_c.h"    /* For haptic hot plugging */
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    57
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    58
8988
1deb2998dbae Hopefully fixed Cygwin build
Sam Lantinga <slouken@libsdl.org>
parents: 8972
diff changeset
    59
#ifndef DEVICE_NOTIFY_WINDOW_HANDLE
1deb2998dbae Hopefully fixed Cygwin build
Sam Lantinga <slouken@libsdl.org>
parents: 8972
diff changeset
    60
#define DEVICE_NOTIFY_WINDOW_HANDLE 0x00000000
1deb2998dbae Hopefully fixed Cygwin build
Sam Lantinga <slouken@libsdl.org>
parents: 8972
diff changeset
    61
#endif
1deb2998dbae Hopefully fixed Cygwin build
Sam Lantinga <slouken@libsdl.org>
parents: 8972
diff changeset
    62
8972
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    63
/* local variables */
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    64
static SDL_bool s_bDeviceAdded = SDL_FALSE;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    65
static SDL_bool s_bDeviceRemoved = SDL_FALSE;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    66
static SDL_JoystickID s_nInstanceID = -1;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    67
static SDL_cond *s_condJoystickThread = NULL;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    68
static SDL_mutex *s_mutexJoyStickEnum = NULL;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    69
static SDL_Thread *s_threadJoystick = NULL;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    70
static SDL_bool s_bJoystickThreadQuit = SDL_FALSE;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    71
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    72
JoyStick_DeviceData *SYS_Joystick;    /* array to hold joystick ID values */
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    73
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    74
static SDL_bool s_bWindowsDeviceChanged = SDL_FALSE;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    75
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    76
#ifdef __WINRT__
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    77
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    78
typedef struct
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    79
{
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    80
    int unused;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    81
} SDL_DeviceNotificationData;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    82
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    83
static void
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    84
SDL_CleanupDeviceNotification(SDL_DeviceNotificationData *data)
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    85
{
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    86
}
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    87
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    88
static int
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    89
SDL_CreateDeviceNotification(SDL_DeviceNotificationData *data)
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    90
{
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    91
    return 0;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    92
}
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    93
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    94
static void
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    95
SDL_CheckDeviceNotification(SDL_DeviceNotificationData *data)
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    96
{
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    97
}
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    98
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    99
#else /* !__WINRT__ */
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   100
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   101
typedef struct
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   102
{
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   103
    HRESULT coinitialized;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   104
    WNDCLASSEX wincl;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   105
    HWND messageWindow;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   106
    HDEVNOTIFY hNotify;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   107
} SDL_DeviceNotificationData;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   108
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   109
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   110
/* windowproc for our joystick detect thread message only window, to detect any USB device addition/removal */
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   111
static LRESULT CALLBACK
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   112
SDL_PrivateJoystickDetectProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   113
{
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   114
    switch (message) {
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   115
    case WM_DEVICECHANGE:
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   116
        switch (wParam) {
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   117
        case DBT_DEVICEARRIVAL:
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   118
            if (((DEV_BROADCAST_HDR*)lParam)->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE) {
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   119
                s_bWindowsDeviceChanged = SDL_TRUE;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   120
            }
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   121
            break;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   122
        case DBT_DEVICEREMOVECOMPLETE:
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   123
            if (((DEV_BROADCAST_HDR*)lParam)->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE) {
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   124
                s_bWindowsDeviceChanged = SDL_TRUE;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   125
            }
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   126
            break;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   127
        }
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   128
        return 0;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   129
    }
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   130
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   131
    return DefWindowProc (hwnd, message, wParam, lParam);
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   132
}
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   133
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   134
static void
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   135
SDL_CleanupDeviceNotification(SDL_DeviceNotificationData *data)
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   136
{
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   137
    if (data->hNotify)
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   138
        UnregisterDeviceNotification(data->hNotify);
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   139
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   140
    if (data->messageWindow)
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   141
        DestroyWindow(data->messageWindow);
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   142
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   143
    UnregisterClass(data->wincl.lpszClassName, data->wincl.hInstance);
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   144
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   145
    if (data->coinitialized == S_OK) {
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   146
        WIN_CoUninitialize();
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   147
    }
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   148
}
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   149
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   150
static int
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   151
SDL_CreateDeviceNotification(SDL_DeviceNotificationData *data)
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   152
{
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   153
    DEV_BROADCAST_DEVICEINTERFACE dbh;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   154
    GUID GUID_DEVINTERFACE_HID = { 0x4D1E55B2L, 0xF16F, 0x11CF, { 0x88, 0xCB, 0x00, 0x11, 0x11, 0x00, 0x00, 0x30 } };
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   155
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   156
    SDL_zerop(data);
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   157
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   158
    data->coinitialized = WIN_CoInitialize();
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   159
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   160
    data->wincl.hInstance = GetModuleHandle(NULL);
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   161
    data->wincl.lpszClassName = L"Message";
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   162
    data->wincl.lpfnWndProc = SDL_PrivateJoystickDetectProc;      /* This function is called by windows */
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   163
    data->wincl.cbSize = sizeof (WNDCLASSEX);
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   164
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   165
    if (!RegisterClassEx(&data->wincl)) {
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   166
        WIN_SetError("Failed to create register class for joystick autodetect");
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   167
        SDL_CleanupDeviceNotification(data);
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   168
        return -1;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   169
    }
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   170
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   171
    data->messageWindow = (HWND)CreateWindowEx(0,  L"Message", NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, NULL, NULL);
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   172
    if (!data->messageWindow) {
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   173
        WIN_SetError("Failed to create message window for joystick autodetect");
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   174
        SDL_CleanupDeviceNotification(data);
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   175
        return -1;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   176
    }
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   177
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   178
    SDL_zero(dbh);
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   179
    dbh.dbcc_size = sizeof(dbh);
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   180
    dbh.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   181
    dbh.dbcc_classguid = GUID_DEVINTERFACE_HID;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   182
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   183
    data->hNotify = RegisterDeviceNotification(data->messageWindow, &dbh, DEVICE_NOTIFY_WINDOW_HANDLE);
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   184
    if (!data->hNotify) {
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   185
        WIN_SetError("Failed to create notify device for joystick autodetect");
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   186
        SDL_CleanupDeviceNotification(data);
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   187
        return -1;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   188
    }
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   189
    return 0;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   190
}
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   191
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   192
static void
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   193
SDL_CheckDeviceNotification(SDL_DeviceNotificationData *data)
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   194
{
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   195
    MSG msg;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   196
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   197
    if (!data->messageWindow) {
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   198
        return;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   199
    }
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   200
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   201
    while (PeekMessage(&msg, data->messageWindow, 0, 0, PM_NOREMOVE)) {
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   202
        if (GetMessage(&msg, data->messageWindow, 0, 0) != 0)  {
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   203
            TranslateMessage(&msg);
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   204
            DispatchMessage(&msg);
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   205
        }
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   206
    }
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   207
}
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   208
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   209
#endif /* __WINRT__ */
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   210
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   211
/* Function/thread to scan the system for joysticks. */
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   212
static int
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   213
SDL_JoystickThread(void *_data)
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   214
{
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   215
    SDL_DeviceNotificationData notification_data;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   216
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   217
#if SDL_JOYSTICK_XINPUT
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   218
    SDL_bool bOpenedXInputDevices[XUSER_MAX_COUNT];
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   219
    SDL_zero(bOpenedXInputDevices);
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   220
#endif
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   221
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   222
    if (SDL_CreateDeviceNotification(&notification_data) < 0) {
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   223
        return -1;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   224
    }
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   225
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   226
    SDL_LockMutex(s_mutexJoyStickEnum);
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   227
    while (s_bJoystickThreadQuit == SDL_FALSE) {
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   228
        SDL_bool bXInputChanged = SDL_FALSE;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   229
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   230
        SDL_CondWaitTimeout(s_condJoystickThread, s_mutexJoyStickEnum, 300);
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   231
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   232
        SDL_CheckDeviceNotification(&notification_data);
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   233
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   234
#if SDL_JOYSTICK_XINPUT
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   235
        if (SDL_XINPUT_Enabled() && XINPUTGETCAPABILITIES) {
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   236
            /* scan for any change in XInput devices */
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   237
            Uint8 userId;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   238
            for (userId = 0; userId < XUSER_MAX_COUNT; userId++) {
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   239
                XINPUT_CAPABILITIES capabilities;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   240
                const DWORD result = XINPUTGETCAPABILITIES(userId, XINPUT_FLAG_GAMEPAD, &capabilities);
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   241
                const SDL_bool available = (result == ERROR_SUCCESS);
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   242
                if (bOpenedXInputDevices[userId] != available) {
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   243
                    bXInputChanged = SDL_TRUE;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   244
                    bOpenedXInputDevices[userId] = available;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   245
                }
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   246
            }
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   247
        }
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   248
#endif /* SDL_JOYSTICK_XINPUT */
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   249
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   250
        if (s_bWindowsDeviceChanged || bXInputChanged) {
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   251
            SDL_UnlockMutex(s_mutexJoyStickEnum);  /* let main thread go while we SDL_Delay(). */
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   252
            SDL_Delay(300); /* wait for direct input to find out about this device */
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   253
            SDL_LockMutex(s_mutexJoyStickEnum);
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   254
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   255
            s_bDeviceRemoved = SDL_TRUE;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   256
            s_bDeviceAdded = SDL_TRUE;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   257
            s_bWindowsDeviceChanged = SDL_FALSE;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   258
        }
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   259
    }
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   260
    SDL_UnlockMutex(s_mutexJoyStickEnum);
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   261
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   262
    SDL_CleanupDeviceNotification(&notification_data);
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   263
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   264
    return 1;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   265
}
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   266
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   267
void SDL_SYS_AddJoystickDevice(JoyStick_DeviceData *device)
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   268
{
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   269
    device->send_add_event = SDL_TRUE;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   270
    device->nInstanceID = ++s_nInstanceID;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   271
    device->pNext = SYS_Joystick;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   272
    SYS_Joystick = device;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   273
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   274
    s_bDeviceAdded = SDL_TRUE;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   275
}
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   276
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   277
/* Function to scan the system for joysticks.
9311
a4b031e28de8 Fixed wrong documentation in joystick implementation source.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9166
diff changeset
   278
 * Joystick 0 should be the system default joystick.
8972
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   279
 * It should return 0, or -1 on an unrecoverable fatal error.
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   280
 */
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   281
int
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   282
SDL_SYS_JoystickInit(void)
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   283
{
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   284
    if (SDL_DINPUT_JoystickInit() < 0) {
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   285
        SDL_SYS_JoystickQuit();
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   286
        return -1;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   287
    }
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   288
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   289
    if (SDL_XINPUT_JoystickInit() < 0) {
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   290
        SDL_SYS_JoystickQuit();
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   291
        return -1;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   292
    }
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   293
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   294
    s_mutexJoyStickEnum = SDL_CreateMutex();
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   295
    s_condJoystickThread = SDL_CreateCond();
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   296
    s_bDeviceAdded = SDL_TRUE; /* force a scan of the system for joysticks this first time */
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   297
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   298
    SDL_SYS_JoystickDetect();
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   299
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   300
    if (!s_threadJoystick) {
10146
471eb08040ce threads: Move SDL's own thread creation to a new internal API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   301
        /* spin up the thread to detect hotplug of devices */
8972
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   302
        s_bJoystickThreadQuit = SDL_FALSE;
10146
471eb08040ce threads: Move SDL's own thread creation to a new internal API.
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   303
        s_threadJoystick = SDL_CreateThreadInternal(SDL_JoystickThread, "SDL_joystick", 64 * 1024, NULL);
8972
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   304
    }
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   305
    return SDL_SYS_NumJoysticks();
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   306
}
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   307
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   308
/* return the number of joysticks that are connected right now */
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   309
int
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   310
SDL_SYS_NumJoysticks()
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   311
{
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   312
    int nJoysticks = 0;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   313
    JoyStick_DeviceData *device = SYS_Joystick;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   314
    while (device) {
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   315
        nJoysticks++;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   316
        device = device->pNext;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   317
    }
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   318
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   319
    return nJoysticks;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   320
}
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   321
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   322
/* detect any new joysticks being inserted into the system */
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   323
void
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   324
SDL_SYS_JoystickDetect()
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   325
{
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   326
    JoyStick_DeviceData *pCurList = NULL;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   327
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   328
    /* only enum the devices if the joystick thread told us something changed */
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   329
    if (!s_bDeviceAdded && !s_bDeviceRemoved) {
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   330
        return;  /* thread hasn't signaled, nothing to do right now. */
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   331
    }
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   332
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   333
    SDL_LockMutex(s_mutexJoyStickEnum);
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   334
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   335
    s_bDeviceAdded = SDL_FALSE;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   336
    s_bDeviceRemoved = SDL_FALSE;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   337
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   338
    pCurList = SYS_Joystick;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   339
    SYS_Joystick = NULL;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   340
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   341
    /* Look for DirectInput joysticks, wheels, head trackers, gamepads, etc.. */
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   342
    SDL_DINPUT_JoystickDetect(&pCurList);
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   343
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   344
    /* Look for XInput devices. Do this last, so they're first in the final list. */
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   345
    SDL_XINPUT_JoystickDetect(&pCurList);
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   346
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   347
    SDL_UnlockMutex(s_mutexJoyStickEnum);
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   348
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   349
    while (pCurList) {
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   350
        JoyStick_DeviceData *pListNext = NULL;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   351
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   352
        if (pCurList->bXInputDevice) {
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   353
            SDL_XINPUT_MaybeRemoveDevice(pCurList->XInputUserId);
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   354
        } else {
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   355
            SDL_DINPUT_MaybeRemoveDevice(&pCurList->dxdevice);
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   356
        }
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   357
10281
cb13d22b7f09 Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents: 10147
diff changeset
   358
        SDL_PrivateJoystickRemoved(pCurList->nInstanceID);
8972
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   359
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   360
        pListNext = pCurList->pNext;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   361
        SDL_free(pCurList->joystickname);
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   362
        SDL_free(pCurList);
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   363
        pCurList = pListNext;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   364
    }
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   365
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   366
    if (s_bDeviceAdded) {
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   367
        JoyStick_DeviceData *pNewJoystick;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   368
        int device_index = 0;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   369
        s_bDeviceAdded = SDL_FALSE;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   370
        pNewJoystick = SYS_Joystick;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   371
        while (pNewJoystick) {
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   372
            if (pNewJoystick->send_add_event) {
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   373
                if (pNewJoystick->bXInputDevice) {
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   374
                    SDL_XINPUT_MaybeAddDevice(pNewJoystick->XInputUserId);
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   375
                } else {
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   376
                    SDL_DINPUT_MaybeAddDevice(&pNewJoystick->dxdevice);
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   377
                }
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   378
10281
cb13d22b7f09 Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents: 10147
diff changeset
   379
                SDL_PrivateJoystickAdded(device_index);
8972
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   380
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   381
                pNewJoystick->send_add_event = SDL_FALSE;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   382
            }
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   383
            device_index++;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   384
            pNewJoystick = pNewJoystick->pNext;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   385
        }
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   386
    }
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   387
}
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   388
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   389
/* Function to get the device-dependent name of a joystick */
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   390
const char *
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   391
SDL_SYS_JoystickNameForDeviceIndex(int device_index)
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   392
{
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   393
    JoyStick_DeviceData *device = SYS_Joystick;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   394
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   395
    for (; device_index > 0; device_index--)
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   396
        device = device->pNext;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   397
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   398
    return device->joystickname;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   399
}
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   400
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   401
/* Function to perform the mapping between current device instance and this joysticks instance id */
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   402
SDL_JoystickID
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   403
SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   404
{
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   405
    JoyStick_DeviceData *device = SYS_Joystick;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   406
    int index;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   407
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   408
    for (index = device_index; index > 0; index--)
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   409
        device = device->pNext;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   410
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   411
    return device->nInstanceID;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   412
}
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   413
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   414
/* Function to open a joystick for use.
9380
07b7c1005a23 Updated internal documentation comments.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9311
diff changeset
   415
   The joystick to open is specified by the device index.
8972
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   416
   This should fill the nbuttons and naxes fields of the joystick structure.
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   417
   It returns 0, or -1 if there is an error.
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   418
 */
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   419
int
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   420
SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   421
{
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   422
    JoyStick_DeviceData *joystickdevice = SYS_Joystick;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   423
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   424
    for (; device_index > 0; device_index--)
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   425
        joystickdevice = joystickdevice->pNext;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   426
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   427
    /* allocate memory for system specific hardware data */
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   428
    joystick->instance_id = joystickdevice->nInstanceID;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   429
    joystick->hwdata =
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   430
        (struct joystick_hwdata *) SDL_malloc(sizeof(struct joystick_hwdata));
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   431
    if (joystick->hwdata == NULL) {
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   432
        return SDL_OutOfMemory();
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   433
    }
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   434
    SDL_zerop(joystick->hwdata);
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   435
    joystick->hwdata->guid = joystickdevice->guid;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   436
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   437
    if (joystickdevice->bXInputDevice) {
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   438
        return SDL_XINPUT_JoystickOpen(joystick, joystickdevice);
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   439
    } else {
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   440
        return SDL_DINPUT_JoystickOpen(joystick, joystickdevice);
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   441
    }
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   442
}
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   443
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   444
/* return true if this joystick is plugged in right now */
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   445
SDL_bool 
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   446
SDL_SYS_JoystickAttached(SDL_Joystick * joystick)
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   447
{
9433
bd062398b648 Cleanups in the joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 9380
diff changeset
   448
    return joystick->hwdata && !joystick->hwdata->removed;
8972
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   449
}
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   450
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   451
void
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   452
SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   453
{
9433
bd062398b648 Cleanups in the joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 9380
diff changeset
   454
    if (!joystick->hwdata || joystick->hwdata->removed) {
8972
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   455
        return;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   456
    }
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   457
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   458
    if (joystick->hwdata->bXInputDevice) {
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   459
        SDL_XINPUT_JoystickUpdate(joystick);
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   460
    } else {
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   461
        SDL_DINPUT_JoystickUpdate(joystick);
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   462
    }
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   463
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   464
    if (joystick->hwdata->removed) {
9433
bd062398b648 Cleanups in the joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents: 9380
diff changeset
   465
        joystick->force_recentering = SDL_TRUE;
8972
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   466
    }
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   467
}
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   468
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   469
/* Function to close a joystick after use */
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   470
void
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   471
SDL_SYS_JoystickClose(SDL_Joystick * joystick)
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   472
{
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   473
    if (joystick->hwdata->bXInputDevice) {
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   474
        SDL_XINPUT_JoystickClose(joystick);
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   475
    } else {
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   476
        SDL_DINPUT_JoystickClose(joystick);
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   477
    }
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   478
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   479
    SDL_free(joystick->hwdata);
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   480
}
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   481
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   482
/* Function to perform any system-specific joystick related cleanup */
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   483
void
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   484
SDL_SYS_JoystickQuit(void)
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   485
{
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   486
    JoyStick_DeviceData *device = SYS_Joystick;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   487
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   488
    while (device) {
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   489
        JoyStick_DeviceData *device_next = device->pNext;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   490
        SDL_free(device->joystickname);
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   491
        SDL_free(device);
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   492
        device = device_next;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   493
    }
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   494
    SYS_Joystick = NULL;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   495
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   496
    if (s_threadJoystick) {
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   497
        SDL_LockMutex(s_mutexJoyStickEnum);
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   498
        s_bJoystickThreadQuit = SDL_TRUE;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   499
        SDL_CondBroadcast(s_condJoystickThread); /* signal the joystick thread to quit */
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   500
        SDL_UnlockMutex(s_mutexJoyStickEnum);
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   501
        SDL_WaitThread(s_threadJoystick, NULL); /* wait for it to bugger off */
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   502
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   503
        SDL_DestroyMutex(s_mutexJoyStickEnum);
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   504
        SDL_DestroyCond(s_condJoystickThread);
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   505
        s_condJoystickThread= NULL;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   506
        s_mutexJoyStickEnum = NULL;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   507
        s_threadJoystick = NULL;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   508
    }
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   509
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   510
    SDL_DINPUT_JoystickQuit();
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   511
    SDL_XINPUT_JoystickQuit();
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   512
}
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   513
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   514
/* return the stable device guid for this device index */
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   515
SDL_JoystickGUID
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   516
SDL_SYS_JoystickGetDeviceGUID(int device_index)
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   517
{
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   518
    JoyStick_DeviceData *device = SYS_Joystick;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   519
    int index;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   520
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   521
    for (index = device_index; index > 0; index--)
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   522
        device = device->pNext;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   523
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   524
    return device->guid;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   525
}
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   526
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   527
SDL_JoystickGUID
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   528
SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   529
{
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   530
    return joystick->hwdata->guid;
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   531
}
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   532
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   533
#endif /* SDL_JOYSTICK_DINPUT || SDL_JOYSTICK_XINPUT */
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   534
dfc759d7486f Split the XInput and DirectInput code so Windows RT can use the existing XInput support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   535
/* vi: set ts=4 sw=4 expandtab: */