xinput: Implement XInputSetState.
[wine.git] / dlls / xinput1_3 / xinput_main.c
blob680aba33a8c2e244274220085a1326edb3a97fa1
1 /*
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
20 #include "config.h"
21 #include <assert.h>
22 #include <stdarg.h>
23 #include <string.h>
25 #include "wine/debug.h"
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winerror.h"
30 #include "xinput.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)
42 switch(reason)
44 case DLL_PROCESS_ATTACH:
45 DisableThreadLibraryCalls(inst);
46 break;
47 case DLL_PROCESS_DETACH:
48 if (reserved) break;
49 HID_destroy_gamepads(controllers);
50 break;
52 return TRUE;
55 void WINAPI DECLSPEC_HOTPATCH XInputEnable(BOOL enable)
57 /* Setting to false will stop messages from XInputSetState being sent
58 to the controllers. Setting to true will send the last vibration
59 value (sent to XInputSetState) to the controller and allow messages to
60 be sent */
61 FIXME("(enable %d) Stub!\n", enable);
64 DWORD WINAPI XInputSetState(DWORD index, XINPUT_VIBRATION* vibration)
66 TRACE("(index %u, vibration %p)\n", index, vibration);
68 HID_find_gamepads(controllers);
70 if (index >= XUSER_MAX_COUNT)
71 return ERROR_BAD_ARGUMENTS;
72 if (!controllers[index].connected)
73 return ERROR_DEVICE_NOT_CONNECTED;
75 return HID_set_state(&controllers[index], vibration);
78 DWORD WINAPI DECLSPEC_HOTPATCH XInputGetState(DWORD index, XINPUT_STATE* state)
80 DWORD ret;
82 TRACE("(index %u, state %p)!\n", index, state);
84 ret = XInputGetStateEx(index, state);
85 if (ret != ERROR_SUCCESS)
86 return ret;
88 /* The main difference between this and the Ex version is the media guide button */
89 state->Gamepad.wButtons &= ~XINPUT_GAMEPAD_GUIDE;
91 return ERROR_SUCCESS;
94 DWORD WINAPI DECLSPEC_HOTPATCH XInputGetStateEx(DWORD index, XINPUT_STATE* state)
96 TRACE("(index %u, state %p)!\n", index, state);
98 HID_find_gamepads(controllers);
100 if (index >= XUSER_MAX_COUNT)
101 return ERROR_BAD_ARGUMENTS;
102 if (!controllers[index].connected)
103 return ERROR_DEVICE_NOT_CONNECTED;
105 HID_update_state(&controllers[index]);
106 memcpy(state, &controllers[index].state, sizeof(XINPUT_STATE));
108 return ERROR_SUCCESS;
111 DWORD WINAPI XInputGetKeystroke(DWORD index, DWORD reserved, PXINPUT_KEYSTROKE keystroke)
113 static int warn_once;
115 if (!warn_once++)
116 FIXME("(index %u, reserved %u, keystroke %p) Stub!\n", index, reserved, keystroke);
118 if (index >= XUSER_MAX_COUNT)
119 return ERROR_BAD_ARGUMENTS;
120 if (!controllers[index].connected)
121 return ERROR_DEVICE_NOT_CONNECTED;
123 return ERROR_NOT_SUPPORTED;
126 DWORD WINAPI XInputGetCapabilities(DWORD index, DWORD flags, XINPUT_CAPABILITIES* capabilities)
128 TRACE("(index %u, flags 0x%x, capabilities %p)\n", index, flags, capabilities);
130 HID_find_gamepads(controllers);
132 if (index >= XUSER_MAX_COUNT)
133 return ERROR_BAD_ARGUMENTS;
134 if (!controllers[index].connected)
135 return ERROR_DEVICE_NOT_CONNECTED;
136 if (flags & XINPUT_FLAG_GAMEPAD && controllers[index].caps.SubType != XINPUT_DEVSUBTYPE_GAMEPAD)
137 return ERROR_DEVICE_NOT_CONNECTED;
139 memcpy(capabilities, &controllers[index].caps, sizeof(*capabilities));
141 return ERROR_SUCCESS;
144 DWORD WINAPI XInputGetDSoundAudioDeviceGuids(DWORD index, GUID* render_guid, GUID* capture_guid)
146 FIXME("(index %u, render guid %p, capture guid %p) Stub!\n", index, render_guid, capture_guid);
148 if (index >= XUSER_MAX_COUNT)
149 return ERROR_BAD_ARGUMENTS;
150 if (!controllers[index].connected)
151 return ERROR_DEVICE_NOT_CONNECTED;
153 return ERROR_NOT_SUPPORTED;
156 DWORD WINAPI XInputGetBatteryInformation(DWORD index, BYTE type, XINPUT_BATTERY_INFORMATION* battery)
158 FIXME("(index %u, type %u, battery %p) Stub!\n", index, type, battery);
160 if (index >= XUSER_MAX_COUNT)
161 return ERROR_BAD_ARGUMENTS;
162 if (!controllers[index].connected)
163 return ERROR_DEVICE_NOT_CONNECTED;
165 return ERROR_NOT_SUPPORTED;