2 * The Wine project - Xinput Joystick Library
3 * Copyright 2008 Andrew Fenn
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/debug.h"
31 #include "xinput_private.h"
33 /* Not defined in the headers, used only by XInputGetStateEx */
34 #define XINPUT_GAMEPAD_GUIDE 0x0400
36 WINE_DEFAULT_DEBUG_CHANNEL(xinput
);
38 xinput_controller controllers
[XUSER_MAX_COUNT
];
40 BOOL WINAPI
DllMain(HINSTANCE inst
, DWORD reason
, LPVOID reserved
)
44 case DLL_PROCESS_ATTACH
:
45 DisableThreadLibraryCalls(inst
);
47 case DLL_PROCESS_DETACH
:
49 HID_destroy_gamepads(controllers
);
55 void WINAPI DECLSPEC_HOTPATCH
XInputEnable(BOOL enable
)
59 TRACE("(enable %d)\n", enable
);
61 /* Setting to false will stop messages from XInputSetState being sent
62 to the controllers. Setting to true will send the last vibration
63 value (sent to XInputSetState) to the controller and allow messages to
65 HID_find_gamepads(controllers
);
67 for (index
= 0; index
< XUSER_MAX_COUNT
; index
++)
69 if (!controllers
[index
].connected
) continue;
70 HID_enable(&controllers
[index
], enable
);
74 DWORD WINAPI
XInputSetState(DWORD index
, XINPUT_VIBRATION
* vibration
)
76 TRACE("(index %u, vibration %p)\n", index
, vibration
);
78 HID_find_gamepads(controllers
);
80 if (index
>= XUSER_MAX_COUNT
)
81 return ERROR_BAD_ARGUMENTS
;
82 if (!controllers
[index
].connected
)
83 return ERROR_DEVICE_NOT_CONNECTED
;
85 return HID_set_state(&controllers
[index
], vibration
);
88 DWORD WINAPI DECLSPEC_HOTPATCH
XInputGetState(DWORD index
, XINPUT_STATE
* state
)
92 TRACE("(index %u, state %p)!\n", index
, state
);
94 ret
= XInputGetStateEx(index
, state
);
95 if (ret
!= ERROR_SUCCESS
)
98 /* The main difference between this and the Ex version is the media guide button */
99 state
->Gamepad
.wButtons
&= ~XINPUT_GAMEPAD_GUIDE
;
101 return ERROR_SUCCESS
;
104 DWORD WINAPI DECLSPEC_HOTPATCH
XInputGetStateEx(DWORD index
, XINPUT_STATE
* state
)
106 TRACE("(index %u, state %p)!\n", index
, state
);
108 HID_find_gamepads(controllers
);
110 if (index
>= XUSER_MAX_COUNT
)
111 return ERROR_BAD_ARGUMENTS
;
112 if (!controllers
[index
].connected
)
113 return ERROR_DEVICE_NOT_CONNECTED
;
115 HID_update_state(&controllers
[index
]);
116 memcpy(state
, &controllers
[index
].state
, sizeof(XINPUT_STATE
));
118 return ERROR_SUCCESS
;
121 DWORD WINAPI
XInputGetKeystroke(DWORD index
, DWORD reserved
, PXINPUT_KEYSTROKE keystroke
)
123 static int warn_once
;
126 FIXME("(index %u, reserved %u, keystroke %p) Stub!\n", index
, reserved
, keystroke
);
128 if (index
>= XUSER_MAX_COUNT
)
129 return ERROR_BAD_ARGUMENTS
;
130 if (!controllers
[index
].connected
)
131 return ERROR_DEVICE_NOT_CONNECTED
;
133 return ERROR_NOT_SUPPORTED
;
136 DWORD WINAPI
XInputGetCapabilities(DWORD index
, DWORD flags
, XINPUT_CAPABILITIES
* capabilities
)
138 TRACE("(index %u, flags 0x%x, capabilities %p)\n", index
, flags
, capabilities
);
140 HID_find_gamepads(controllers
);
142 if (index
>= XUSER_MAX_COUNT
)
143 return ERROR_BAD_ARGUMENTS
;
144 if (!controllers
[index
].connected
)
145 return ERROR_DEVICE_NOT_CONNECTED
;
146 if (flags
& XINPUT_FLAG_GAMEPAD
&& controllers
[index
].caps
.SubType
!= XINPUT_DEVSUBTYPE_GAMEPAD
)
147 return ERROR_DEVICE_NOT_CONNECTED
;
149 memcpy(capabilities
, &controllers
[index
].caps
, sizeof(*capabilities
));
151 return ERROR_SUCCESS
;
154 DWORD WINAPI
XInputGetDSoundAudioDeviceGuids(DWORD index
, GUID
* render_guid
, GUID
* capture_guid
)
156 FIXME("(index %u, render guid %p, capture guid %p) Stub!\n", index
, render_guid
, capture_guid
);
158 if (index
>= XUSER_MAX_COUNT
)
159 return ERROR_BAD_ARGUMENTS
;
160 if (!controllers
[index
].connected
)
161 return ERROR_DEVICE_NOT_CONNECTED
;
163 return ERROR_NOT_SUPPORTED
;
166 DWORD WINAPI
XInputGetBatteryInformation(DWORD index
, BYTE type
, XINPUT_BATTERY_INFORMATION
* battery
)
171 FIXME("(index %u, type %u, battery %p) Stub!\n", index
, type
, battery
);
173 if (index
>= XUSER_MAX_COUNT
)
174 return ERROR_BAD_ARGUMENTS
;
175 if (!controllers
[index
].connected
)
176 return ERROR_DEVICE_NOT_CONNECTED
;
178 return ERROR_NOT_SUPPORTED
;