SDL  2.0
SDL_xinputjoystick.c
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
4 
5  This software is provided 'as-is', without any express or implied
6  warranty. In no event will the authors be held liable for any damages
7  arising from the use of this software.
8 
9  Permission is granted to anyone to use this software for any purpose,
10  including commercial applications, and to alter it and redistribute it
11  freely, subject to the following restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not
14  claim that you wrote the original software. If you use this software
15  in a product, an acknowledgment in the product documentation would be
16  appreciated but is not required.
17  2. Altered source versions must be plainly marked as such, and must not be
18  misrepresented as being the original software.
19  3. This notice may not be removed or altered from any source distribution.
20 */
21 #include "../../SDL_internal.h"
22 
23 #include "../SDL_sysjoystick.h"
24 
25 #if SDL_JOYSTICK_XINPUT
26 
27 #include "SDL_assert.h"
28 #include "SDL_hints.h"
29 #include "SDL_log.h"
30 #include "SDL_timer.h"
31 #include "SDL_windowsjoystick_c.h"
32 #include "SDL_xinputjoystick_c.h"
33 #include "../hidapi/SDL_hidapijoystick_c.h"
34 
35 /*
36  * Internal stuff.
37  */
38 static SDL_bool s_bXInputEnabled = SDL_TRUE;
39 static char *s_arrXInputDevicePath[XUSER_MAX_COUNT];
40 
41 
42 static SDL_bool
43 SDL_XInputUseOldJoystickMapping()
44 {
45 #ifdef __WINRT__
46  /* TODO: remove this __WINRT__ block, but only after integrating with UWP/WinRT's HID API */
47  /* FIXME: Why are Win8/10 different here? -flibit */
48  return (NTDDI_VERSION < NTDDI_WIN10);
49 #else
50  static int s_XInputUseOldJoystickMapping = -1;
51  if (s_XInputUseOldJoystickMapping < 0) {
53  }
54  return (s_XInputUseOldJoystickMapping > 0);
55 #endif
56 }
57 
59 {
60  return s_bXInputEnabled;
61 }
62 
63 int
65 {
67 
68  if (s_bXInputEnabled && WIN_LoadXInputDLL() < 0) {
69  s_bXInputEnabled = SDL_FALSE; /* oh well. */
70  }
71  return 0;
72 }
73 
74 static char *
75 GetXInputName(const Uint8 userid, BYTE SubType)
76 {
77  char name[32];
78 
79  if (SDL_XInputUseOldJoystickMapping()) {
80  SDL_snprintf(name, sizeof(name), "X360 Controller #%u", 1 + userid);
81  } else {
82  switch (SubType) {
83  case XINPUT_DEVSUBTYPE_GAMEPAD:
84  SDL_snprintf(name, sizeof(name), "XInput Controller #%u", 1 + userid);
85  break;
86  case XINPUT_DEVSUBTYPE_WHEEL:
87  SDL_snprintf(name, sizeof(name), "XInput Wheel #%u", 1 + userid);
88  break;
89  case XINPUT_DEVSUBTYPE_ARCADE_STICK:
90  SDL_snprintf(name, sizeof(name), "XInput ArcadeStick #%u", 1 + userid);
91  break;
92  case XINPUT_DEVSUBTYPE_FLIGHT_STICK:
93  SDL_snprintf(name, sizeof(name), "XInput FlightStick #%u", 1 + userid);
94  break;
95  case XINPUT_DEVSUBTYPE_DANCE_PAD:
96  SDL_snprintf(name, sizeof(name), "XInput DancePad #%u", 1 + userid);
97  break;
98  case XINPUT_DEVSUBTYPE_GUITAR:
99  case XINPUT_DEVSUBTYPE_GUITAR_ALTERNATE:
100  case XINPUT_DEVSUBTYPE_GUITAR_BASS:
101  SDL_snprintf(name, sizeof(name), "XInput Guitar #%u", 1 + userid);
102  break;
103  case XINPUT_DEVSUBTYPE_DRUM_KIT:
104  SDL_snprintf(name, sizeof(name), "XInput DrumKit #%u", 1 + userid);
105  break;
106  case XINPUT_DEVSUBTYPE_ARCADE_PAD:
107  SDL_snprintf(name, sizeof(name), "XInput ArcadePad #%u", 1 + userid);
108  break;
109  default:
110  SDL_snprintf(name, sizeof(name), "XInput Device #%u", 1 + userid);
111  break;
112  }
113  }
114  return SDL_strdup(name);
115 }
116 
117 /* We can't really tell what device is being used for XInput, but we can guess
118  and we'll be correct for the case where only one device is connected.
119  */
120 static void
121 GuessXInputDevice(Uint8 userid, Uint16 *pVID, Uint16 *pPID, Uint16 *pVersion)
122 {
123 #ifndef __WINRT__ /* TODO: remove this ifndef __WINRT__ block, but only after integrating with UWP/WinRT's HID API */
124 
125  PRAWINPUTDEVICELIST devices = NULL;
126  UINT i, j, device_count = 0;
127 
128  if ((GetRawInputDeviceList(NULL, &device_count, sizeof(RAWINPUTDEVICELIST)) == -1) || (!device_count)) {
129  return; /* oh well. */
130  }
131 
132  devices = (PRAWINPUTDEVICELIST)SDL_malloc(sizeof(RAWINPUTDEVICELIST) * device_count);
133  if (devices == NULL) {
134  return;
135  }
136 
137  if (GetRawInputDeviceList(devices, &device_count, sizeof(RAWINPUTDEVICELIST)) == -1) {
138  SDL_free(devices);
139  return; /* oh well. */
140  }
141 
142  /* First see if we have a cached entry for this index */
143  if (s_arrXInputDevicePath[userid]) {
144  for (i = 0; i < device_count; i++) {
145  RID_DEVICE_INFO rdi;
146  char devName[128];
147  UINT rdiSize = sizeof(rdi);
148  UINT nameSize = SDL_arraysize(devName);
149 
150  rdi.cbSize = sizeof(rdi);
151  if (devices[i].dwType == RIM_TYPEHID &&
152  GetRawInputDeviceInfoA(devices[i].hDevice, RIDI_DEVICEINFO, &rdi, &rdiSize) != (UINT)-1 &&
153  GetRawInputDeviceInfoA(devices[i].hDevice, RIDI_DEVICENAME, devName, &nameSize) != (UINT)-1) {
154  if (SDL_strcmp(devName, s_arrXInputDevicePath[userid]) == 0) {
155  *pVID = (Uint16)rdi.hid.dwVendorId;
156  *pPID = (Uint16)rdi.hid.dwProductId;
157  *pVersion = (Uint16)rdi.hid.dwVersionNumber;
158  return;
159  }
160  }
161  }
162  }
163 
164  for (i = 0; i < device_count; i++) {
165  RID_DEVICE_INFO rdi;
166  char devName[128];
167  UINT rdiSize = sizeof(rdi);
168  UINT nameSize = SDL_arraysize(devName);
169 
170  rdi.cbSize = sizeof(rdi);
171  if (devices[i].dwType == RIM_TYPEHID &&
172  GetRawInputDeviceInfoA(devices[i].hDevice, RIDI_DEVICEINFO, &rdi, &rdiSize) != (UINT)-1 &&
173  GetRawInputDeviceInfoA(devices[i].hDevice, RIDI_DEVICENAME, devName, &nameSize) != (UINT)-1) {
174 #ifdef DEBUG_JOYSTICK
175  SDL_Log("Raw input device: VID = 0x%x, PID = 0x%x, %s\n", rdi.hid.dwVendorId, rdi.hid.dwProductId, devName);
176 #endif
177  if (SDL_strstr(devName, "IG_") != NULL) {
178  SDL_bool found = SDL_FALSE;
179  for (j = 0; j < SDL_arraysize(s_arrXInputDevicePath); ++j) {
180  if (!s_arrXInputDevicePath[j]) {
181  continue;
182  }
183  if (SDL_strcmp(devName, s_arrXInputDevicePath[j]) == 0) {
184  found = SDL_TRUE;
185  break;
186  }
187  }
188  if (found) {
189  /* We already have this device in our XInput device list */
190  continue;
191  }
192 
193  /* We don't actually know if this is the right device for this
194  * userid, but we'll record it so we'll at least be consistent
195  * when the raw device list changes.
196  */
197  *pVID = (Uint16)rdi.hid.dwVendorId;
198  *pPID = (Uint16)rdi.hid.dwProductId;
199  *pVersion = (Uint16)rdi.hid.dwVersionNumber;
200  if (s_arrXInputDevicePath[userid]) {
201  SDL_free(s_arrXInputDevicePath[userid]);
202  }
203  s_arrXInputDevicePath[userid] = SDL_strdup(devName);
204  return;
205  }
206  }
207  }
208  SDL_free(devices);
209 #endif /* ifndef __WINRT__ */
210 
211  /* The device wasn't in the raw HID device list, it's probably Bluetooth */
212  *pVID = 0x045e; /* Microsoft */
213  *pPID = 0x02fd; /* XBox One S Bluetooth */
214  *pVersion = 0;
215 }
216 
217 static void
218 AddXInputDevice(Uint8 userid, BYTE SubType, JoyStick_DeviceData **pContext)
219 {
220  Uint16 vendor = 0;
221  Uint16 product = 0;
222  Uint16 version = 0;
223  const char *name;
224  JoyStick_DeviceData *pPrevJoystick = NULL;
225  JoyStick_DeviceData *pNewJoystick = *pContext;
226 
227  if (SDL_XInputUseOldJoystickMapping() && SubType != XINPUT_DEVSUBTYPE_GAMEPAD)
228  return;
229 
230  if (SubType == XINPUT_DEVSUBTYPE_UNKNOWN)
231  return;
232 
233  while (pNewJoystick) {
234  if (pNewJoystick->bXInputDevice && (pNewJoystick->XInputUserId == userid) && (pNewJoystick->SubType == SubType)) {
235  /* if we are replacing the front of the list then update it */
236  if (pNewJoystick == *pContext) {
237  *pContext = pNewJoystick->pNext;
238  } else if (pPrevJoystick) {
239  pPrevJoystick->pNext = pNewJoystick->pNext;
240  }
241 
242  pNewJoystick->pNext = SYS_Joystick;
243  SYS_Joystick = pNewJoystick;
244  return; /* already in the list. */
245  }
246 
247  pPrevJoystick = pNewJoystick;
248  pNewJoystick = pNewJoystick->pNext;
249  }
250 
251  pNewJoystick = (JoyStick_DeviceData *)SDL_calloc(1, sizeof(JoyStick_DeviceData));
252  if (!pNewJoystick) {
253  return; /* better luck next time? */
254  }
255 
256  pNewJoystick->bXInputDevice = SDL_TRUE;
257  if (!SDL_XInputUseOldJoystickMapping()) {
258  Uint16 *guid16 = (Uint16 *)pNewJoystick->guid.data;
259 
260  GuessXInputDevice(userid, &vendor, &product, &version);
261 
262  *guid16++ = SDL_SwapLE16(SDL_HARDWARE_BUS_USB);
263  *guid16++ = 0;
264  *guid16++ = SDL_SwapLE16(vendor);
265  *guid16++ = 0;
266  *guid16++ = SDL_SwapLE16(product);
267  *guid16++ = 0;
268  *guid16++ = SDL_SwapLE16(version);
269  *guid16++ = 0;
270 
271  /* Note that this is an XInput device and what subtype it is */
272  pNewJoystick->guid.data[14] = 'x';
273  pNewJoystick->guid.data[15] = SubType;
274  }
275  pNewJoystick->SubType = SubType;
276  pNewJoystick->XInputUserId = userid;
277 
278  name = SDL_GetCustomJoystickName(vendor, product);
279  if (name) {
280  pNewJoystick->joystickname = SDL_strdup(name);
281  } else {
282  pNewJoystick->joystickname = GetXInputName(userid, SubType);
283  }
284  if (!pNewJoystick->joystickname) {
285  SDL_free(pNewJoystick);
286  return; /* better luck next time? */
287  }
288 
289  if (SDL_ShouldIgnoreJoystick(pNewJoystick->joystickname, pNewJoystick->guid)) {
290  SDL_free(pNewJoystick);
291  return;
292  }
293 
294 #ifdef SDL_JOYSTICK_HIDAPI
295  if (HIDAPI_IsDevicePresent(vendor, product, version, pNewJoystick->joystickname)) {
296  /* The HIDAPI driver is taking care of this device */
297  SDL_free(pNewJoystick);
298  return;
299  }
300 #endif
301 
302  WINDOWS_AddJoystickDevice(pNewJoystick);
303 }
304 
305 static void
306 DelXInputDevice(Uint8 userid)
307 {
308  if (s_arrXInputDevicePath[userid]) {
309  SDL_free(s_arrXInputDevicePath[userid]);
310  s_arrXInputDevicePath[userid] = NULL;
311  }
312 }
313 
314 void
316 {
317  int iuserid;
318 
319  if (!s_bXInputEnabled) {
320  return;
321  }
322 
323  /* iterate in reverse, so these are in the final list in ascending numeric order. */
324  for (iuserid = XUSER_MAX_COUNT - 1; iuserid >= 0; iuserid--) {
325  const Uint8 userid = (Uint8)iuserid;
326  XINPUT_CAPABILITIES capabilities;
327  if (XINPUTGETCAPABILITIES(userid, XINPUT_FLAG_GAMEPAD, &capabilities) == ERROR_SUCCESS) {
328  AddXInputDevice(userid, capabilities.SubType, pContext);
329  } else {
330  DelXInputDevice(userid);
331  }
332  }
333 }
334 
335 int
336 SDL_XINPUT_JoystickOpen(SDL_Joystick * joystick, JoyStick_DeviceData *joystickdevice)
337 {
338  const Uint8 userId = joystickdevice->XInputUserId;
339  XINPUT_CAPABILITIES capabilities;
340  XINPUT_VIBRATION state;
341 
342  SDL_assert(s_bXInputEnabled);
343  SDL_assert(XINPUTGETCAPABILITIES);
344  SDL_assert(XINPUTSETSTATE);
345  SDL_assert(userId < XUSER_MAX_COUNT);
346 
347  joystick->hwdata->bXInputDevice = SDL_TRUE;
348 
349  if (XINPUTGETCAPABILITIES(userId, XINPUT_FLAG_GAMEPAD, &capabilities) != ERROR_SUCCESS) {
350  SDL_free(joystick->hwdata);
351  joystick->hwdata = NULL;
352  return SDL_SetError("Failed to obtain XInput device capabilities. Device disconnected?");
353  }
354  SDL_zero(state);
355  joystick->hwdata->bXInputHaptic = (XINPUTSETSTATE(userId, &state) == ERROR_SUCCESS);
356  joystick->hwdata->userid = userId;
357 
358  /* The XInput API has a hard coded button/axis mapping, so we just match it */
359  if (SDL_XInputUseOldJoystickMapping()) {
360  joystick->naxes = 6;
361  joystick->nbuttons = 15;
362  } else {
363  joystick->naxes = 6;
364  joystick->nbuttons = 11;
365  joystick->nhats = 1;
366  }
367  return 0;
368 }
369 
370 static void
371 UpdateXInputJoystickBatteryInformation(SDL_Joystick * joystick, XINPUT_BATTERY_INFORMATION_EX *pBatteryInformation)
372 {
373  if (pBatteryInformation->BatteryType != BATTERY_TYPE_UNKNOWN) {
375  if (pBatteryInformation->BatteryType == BATTERY_TYPE_WIRED) {
376  ePowerLevel = SDL_JOYSTICK_POWER_WIRED;
377  } else {
378  switch (pBatteryInformation->BatteryLevel) {
379  case BATTERY_LEVEL_EMPTY:
380  ePowerLevel = SDL_JOYSTICK_POWER_EMPTY;
381  break;
382  case BATTERY_LEVEL_LOW:
383  ePowerLevel = SDL_JOYSTICK_POWER_LOW;
384  break;
385  case BATTERY_LEVEL_MEDIUM:
386  ePowerLevel = SDL_JOYSTICK_POWER_MEDIUM;
387  break;
388  default:
389  case BATTERY_LEVEL_FULL:
390  ePowerLevel = SDL_JOYSTICK_POWER_FULL;
391  break;
392  }
393  }
394 
395  SDL_PrivateJoystickBatteryLevel(joystick, ePowerLevel);
396  }
397 }
398 
399 static void
400 UpdateXInputJoystickState_OLD(SDL_Joystick * joystick, XINPUT_STATE_EX *pXInputState, XINPUT_BATTERY_INFORMATION_EX *pBatteryInformation)
401 {
402  static WORD s_XInputButtons[] = {
403  XINPUT_GAMEPAD_DPAD_UP, XINPUT_GAMEPAD_DPAD_DOWN, XINPUT_GAMEPAD_DPAD_LEFT, XINPUT_GAMEPAD_DPAD_RIGHT,
404  XINPUT_GAMEPAD_START, XINPUT_GAMEPAD_BACK, XINPUT_GAMEPAD_LEFT_THUMB, XINPUT_GAMEPAD_RIGHT_THUMB,
405  XINPUT_GAMEPAD_LEFT_SHOULDER, XINPUT_GAMEPAD_RIGHT_SHOULDER,
406  XINPUT_GAMEPAD_A, XINPUT_GAMEPAD_B, XINPUT_GAMEPAD_X, XINPUT_GAMEPAD_Y,
407  XINPUT_GAMEPAD_GUIDE
408  };
409  WORD wButtons = pXInputState->Gamepad.wButtons;
410  Uint8 button;
411 
412  SDL_PrivateJoystickAxis(joystick, 0, (Sint16)pXInputState->Gamepad.sThumbLX);
413  SDL_PrivateJoystickAxis(joystick, 1, (Sint16)(-SDL_max(-32767, pXInputState->Gamepad.sThumbLY)));
414  SDL_PrivateJoystickAxis(joystick, 2, (Sint16)pXInputState->Gamepad.sThumbRX);
415  SDL_PrivateJoystickAxis(joystick, 3, (Sint16)(-SDL_max(-32767, pXInputState->Gamepad.sThumbRY)));
416  SDL_PrivateJoystickAxis(joystick, 4, (Sint16)(((int)pXInputState->Gamepad.bLeftTrigger * 65535 / 255) - 32768));
417  SDL_PrivateJoystickAxis(joystick, 5, (Sint16)(((int)pXInputState->Gamepad.bRightTrigger * 65535 / 255) - 32768));
418 
419  for (button = 0; button < SDL_arraysize(s_XInputButtons); ++button) {
420  SDL_PrivateJoystickButton(joystick, button, (wButtons & s_XInputButtons[button]) ? SDL_PRESSED : SDL_RELEASED);
421  }
422 
423  UpdateXInputJoystickBatteryInformation(joystick, pBatteryInformation);
424 }
425 
426 static void
427 UpdateXInputJoystickState(SDL_Joystick * joystick, XINPUT_STATE_EX *pXInputState, XINPUT_BATTERY_INFORMATION_EX *pBatteryInformation)
428 {
429  static WORD s_XInputButtons[] = {
430  XINPUT_GAMEPAD_A, XINPUT_GAMEPAD_B, XINPUT_GAMEPAD_X, XINPUT_GAMEPAD_Y,
431  XINPUT_GAMEPAD_LEFT_SHOULDER, XINPUT_GAMEPAD_RIGHT_SHOULDER, XINPUT_GAMEPAD_BACK, XINPUT_GAMEPAD_START,
432  XINPUT_GAMEPAD_LEFT_THUMB, XINPUT_GAMEPAD_RIGHT_THUMB,
433  XINPUT_GAMEPAD_GUIDE
434  };
435  WORD wButtons = pXInputState->Gamepad.wButtons;
436  Uint8 button;
437  Uint8 hat = SDL_HAT_CENTERED;
438 
439  SDL_PrivateJoystickAxis(joystick, 0, pXInputState->Gamepad.sThumbLX);
440  SDL_PrivateJoystickAxis(joystick, 1, ~pXInputState->Gamepad.sThumbLY);
441  SDL_PrivateJoystickAxis(joystick, 2, ((int)pXInputState->Gamepad.bLeftTrigger * 257) - 32768);
442  SDL_PrivateJoystickAxis(joystick, 3, pXInputState->Gamepad.sThumbRX);
443  SDL_PrivateJoystickAxis(joystick, 4, ~pXInputState->Gamepad.sThumbRY);
444  SDL_PrivateJoystickAxis(joystick, 5, ((int)pXInputState->Gamepad.bRightTrigger * 257) - 32768);
445 
446  for (button = 0; button < SDL_arraysize(s_XInputButtons); ++button) {
447  SDL_PrivateJoystickButton(joystick, button, (wButtons & s_XInputButtons[button]) ? SDL_PRESSED : SDL_RELEASED);
448  }
449 
450  if (wButtons & XINPUT_GAMEPAD_DPAD_UP) {
451  hat |= SDL_HAT_UP;
452  }
453  if (wButtons & XINPUT_GAMEPAD_DPAD_DOWN) {
454  hat |= SDL_HAT_DOWN;
455  }
456  if (wButtons & XINPUT_GAMEPAD_DPAD_LEFT) {
457  hat |= SDL_HAT_LEFT;
458  }
459  if (wButtons & XINPUT_GAMEPAD_DPAD_RIGHT) {
460  hat |= SDL_HAT_RIGHT;
461  }
462  SDL_PrivateJoystickHat(joystick, 0, hat);
463 
464  UpdateXInputJoystickBatteryInformation(joystick, pBatteryInformation);
465 }
466 
467 int
468 SDL_XINPUT_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
469 {
470  XINPUT_VIBRATION XVibration;
471 
472  if (!XINPUTSETSTATE) {
473  return SDL_Unsupported();
474  }
475 
476  XVibration.wLeftMotorSpeed = low_frequency_rumble;
477  XVibration.wRightMotorSpeed = high_frequency_rumble;
478  if (XINPUTSETSTATE(joystick->hwdata->userid, &XVibration) != ERROR_SUCCESS) {
479  return SDL_SetError("XInputSetState() failed");
480  }
481  return 0;
482 }
483 
484 void
485 SDL_XINPUT_JoystickUpdate(SDL_Joystick * joystick)
486 {
487  HRESULT result;
488  XINPUT_STATE_EX XInputState;
489  XINPUT_BATTERY_INFORMATION_EX XBatteryInformation;
490 
491  if (!XINPUTGETSTATE)
492  return;
493 
494  result = XINPUTGETSTATE(joystick->hwdata->userid, &XInputState);
495  if (result == ERROR_DEVICE_NOT_CONNECTED) {
496  return;
497  }
498 
499  SDL_zero(XBatteryInformation);
500  if (XINPUTGETBATTERYINFORMATION) {
501  result = XINPUTGETBATTERYINFORMATION(joystick->hwdata->userid, BATTERY_DEVTYPE_GAMEPAD, &XBatteryInformation);
502  }
503 
504  /* only fire events if the data changed from last time */
505  if (XInputState.dwPacketNumber && XInputState.dwPacketNumber != joystick->hwdata->dwPacketNumber) {
506  if (SDL_XInputUseOldJoystickMapping()) {
507  UpdateXInputJoystickState_OLD(joystick, &XInputState, &XBatteryInformation);
508  } else {
509  UpdateXInputJoystickState(joystick, &XInputState, &XBatteryInformation);
510  }
511  joystick->hwdata->dwPacketNumber = XInputState.dwPacketNumber;
512  }
513 }
514 
515 void
516 SDL_XINPUT_JoystickClose(SDL_Joystick * joystick)
517 {
518 }
519 
520 void
522 {
523  if (s_bXInputEnabled) {
524  WIN_UnloadXInputDLL();
525  }
526 }
527 
528 #else /* !SDL_JOYSTICK_XINPUT */
529 
531 
533 {
534  return SDL_FALSE;
535 }
536 
537 int
539 {
540  return 0;
541 }
542 
543 void
545 {
546 }
547 
548 int
549 SDL_XINPUT_JoystickOpen(SDL_Joystick * joystick, JoyStick_DeviceData *joystickdevice)
550 {
551  return SDL_Unsupported();
552 }
553 
554 int
555 SDL_XINPUT_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
556 {
557  return SDL_Unsupported();
558 }
559 
560 void
561 SDL_XINPUT_JoystickUpdate(SDL_Joystick * joystick)
562 {
563 }
564 
565 void
566 SDL_XINPUT_JoystickClose(SDL_Joystick * joystick)
567 {
568 }
569 
570 void
572 {
573 }
574 
575 #endif /* SDL_JOYSTICK_XINPUT */
576 
577 /* vi: set ts=4 sw=4 expandtab: */
SDL_zero
#define SDL_zero(x)
Definition: SDL_stdinc.h:418
SYS_Joystick
JoyStick_DeviceData * SYS_Joystick
SDL_ShouldIgnoreJoystick
SDL_bool SDL_ShouldIgnoreJoystick(const char *name, SDL_JoystickGUID guid)
Definition: SDL_joystick.c:1698
SDL_XINPUT_JoystickQuit
void SDL_XINPUT_JoystickQuit(void)
Definition: SDL_xinputjoystick.c:571
SDL_XINPUT_Enabled
SDL_bool SDL_XINPUT_Enabled(void)
Definition: SDL_xinputjoystick.c:532
SDL_GetCustomJoystickName
const char * SDL_GetCustomJoystickName(Uint16 vendor, Uint16 product)
Definition: SDL_joystick.c:1386
SDL_XINPUT_JoystickInit
int SDL_XINPUT_JoystickInit(void)
Definition: SDL_xinputjoystick.c:538
if
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro pixld1_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl else error unsupported endif endm macro pixld2_s mem_operand if mov asr add asl add asl mov asr sub UNIT_X add asl mov asr add asl add asl mov asr add UNIT_X add asl else pixld1_s mem_operand pixld1_s mem_operand endif endm macro pixld0_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl endif endm macro pixld_s_internal mem_operand if mem_operand pixld2_s mem_operand pixdeinterleave basereg elseif mem_operand elseif mem_operand elseif mem_operand elseif mem_operand pixld0_s mem_operand else pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else error unsupported mem_operand if bpp mem_operand endif endm macro vuzp8 reg2 vuzp d d &reg2 endm macro vzip8 reg2 vzip d d &reg2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld[DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld if[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro fetch_mask_pixblock pixld mask_basereg pixblock_size MASK endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp skip1(dst_w_bpp<=(lowbit *8)) &&((lowbit *8)<(pixblock_size *dst_w_bpp)) .if lowbit< 16 tst DST_R
Definition: pixman-arm-neon-asm.h:469
SDL_HAT_CENTERED
#define SDL_HAT_CENTERED
Definition: SDL_joystick.h:339
NULL
#define NULL
Definition: begin_code.h:167
SDL_HAT_DOWN
#define SDL_HAT_DOWN
Definition: SDL_joystick.h:342
SDL_timer.h
SDL_log.h
WINDOWS_AddJoystickDevice
void WINDOWS_AddJoystickDevice(JoyStick_DeviceData *device)
JoyStick_DeviceData::guid
SDL_JoystickGUID guid
Definition: SDL_windowsjoystick_c.h:32
devices
EGLDeviceEXT * devices
Definition: eglext.h:621
SDL_JoystickPowerLevel
SDL_JoystickPowerLevel
Definition: SDL_joystick.h:97
HIDAPI_IsDevicePresent
SDL_bool HIDAPI_IsDevicePresent(Uint16 vendor_id, Uint16 product_id, Uint16 version, const char *name)
SDL_XINPUT_JoystickRumble
int SDL_XINPUT_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
Definition: SDL_xinputjoystick.c:555
JoyStick_DeviceData
Definition: SDL_windowsjoystick_c.h:30
SDL_JOYSTICK_POWER_LOW
@ SDL_JOYSTICK_POWER_LOW
Definition: SDL_joystick.h:101
SDL_JoystickGUID::data
Uint8 data[16]
Definition: SDL_joystick.h:71
SDL_RELEASED
#define SDL_RELEASED
Definition: SDL_events.h:49
SDL_JOYSTICK_POWER_EMPTY
@ SDL_JOYSTICK_POWER_EMPTY
Definition: SDL_joystick.h:100
SDL_SwapLE16
#define SDL_SwapLE16(X)
Definition: SDL_endian.h:244
result
GLuint64EXT * result
Definition: SDL_opengl_glext.h:9435
JoyStick_DeviceData::bXInputDevice
SDL_bool bXInputDevice
Definition: SDL_windowsjoystick_c.h:36
SDL_PrivateJoystickAxis
int SDL_PrivateJoystickAxis(SDL_Joystick *joystick, Uint8 axis, Sint16 value)
Definition: SDL_joystick.c:1023
SDL_windowsjoystick_c.h
SDL_PRESSED
#define SDL_PRESSED
Definition: SDL_events.h:50
Sint16
int16_t Sint16
Definition: SDL_stdinc.h:185
SDL_GetHintBoolean
#define SDL_GetHintBoolean
Definition: SDL_dynapi_overrides.h:608
SDL_FALSE
@ SDL_FALSE
Definition: SDL_stdinc.h:163
SDL_JOYSTICK_POWER_MEDIUM
@ SDL_JOYSTICK_POWER_MEDIUM
Definition: SDL_joystick.h:102
SDL_HINT_XINPUT_ENABLED
#define SDL_HINT_XINPUT_ENABLED
A variable that lets you disable the detection and use of Xinput gamepad devices.
Definition: SDL_hints.h:460
SDL_JOYSTICK_POWER_UNKNOWN
@ SDL_JOYSTICK_POWER_UNKNOWN
Definition: SDL_joystick.h:99
SDL_Log
#define SDL_Log
Definition: SDL_dynapi_overrides.h:31
SDL_free
#define SDL_free
Definition: SDL_dynapi_overrides.h:377
JoyStick_DeviceData::XInputUserId
Uint8 XInputUserId
Definition: SDL_windowsjoystick_c.h:38
SDL_max
#define SDL_max(x, y)
Definition: SDL_stdinc.h:407
name
GLuint const GLchar * name
Definition: SDL_opengl_glext.h:663
SDL_JOYSTICK_POWER_WIRED
@ SDL_JOYSTICK_POWER_WIRED
Definition: SDL_joystick.h:104
SDL_PrivateJoystickButton
int SDL_PrivateJoystickButton(SDL_Joystick *joystick, Uint8 button, Uint8 state)
Definition: SDL_joystick.c:1162
Uint16
uint16_t Uint16
Definition: SDL_stdinc.h:191
SDL_HAT_LEFT
#define SDL_HAT_LEFT
Definition: SDL_joystick.h:343
SDL_assert.h
SDL_PrivateJoystickBatteryLevel
void SDL_PrivateJoystickBatteryLevel(SDL_Joystick *joystick, SDL_JoystickPowerLevel ePowerLevel)
Definition: SDL_joystick.c:2035
SDL_assert
#define SDL_assert(condition)
Definition: SDL_assert.h:169
SDL_HARDWARE_BUS_USB
#define SDL_HARDWARE_BUS_USB
Definition: SDL_sysjoystick.h:82
SDL_XINPUT_JoystickDetect
void SDL_XINPUT_JoystickDetect(JoyStick_DeviceData **pContext)
Definition: SDL_xinputjoystick.c:544
SDL_XINPUT_JoystickUpdate
void SDL_XINPUT_JoystickUpdate(SDL_Joystick *joystick)
Definition: SDL_xinputjoystick.c:561
SDL_PrivateJoystickHat
int SDL_PrivateJoystickHat(SDL_Joystick *joystick, Uint8 hat, Uint8 value)
Definition: SDL_joystick.c:1086
SDL_arraysize
#define SDL_arraysize(array)
Definition: SDL_stdinc.h:115
SDL_calloc
#define SDL_calloc
Definition: SDL_dynapi_overrides.h:375
SDL_TRUE
@ SDL_TRUE
Definition: SDL_stdinc.h:164
SDL_xinputjoystick_c.h
SDL_HAT_RIGHT
#define SDL_HAT_RIGHT
Definition: SDL_joystick.h:341
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:30
SDL_snprintf
#define SDL_snprintf
Definition: SDL_dynapi_overrides.h:40
SDL_hints.h
SDL_JOYSTICK_POWER_FULL
@ SDL_JOYSTICK_POWER_FULL
Definition: SDL_joystick.h:103
SDL_HINT_XINPUT_USE_OLD_JOYSTICK_MAPPING
#define SDL_HINT_XINPUT_USE_OLD_JOYSTICK_MAPPING
A variable that causes SDL to use the old axis and button mapping for XInput devices.
Definition: SDL_hints.h:469
SDL_strdup
#define SDL_strdup
Definition: SDL_dynapi_overrides.h:397
JoyStick_DeviceData::joystickname
char * joystickname
Definition: SDL_windowsjoystick_c.h:33
SDL_HAT_UP
#define SDL_HAT_UP
Definition: SDL_joystick.h:340
NTDDI_WIN10
#define NTDDI_WIN10
Definition: SDL_config_winrt.h:40
j
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int int in j)
Definition: SDL_x11sym.h:50
SDL_Unsupported
#define SDL_Unsupported()
Definition: SDL_error.h:53
SDL_malloc
#define SDL_malloc
Definition: SDL_dynapi_overrides.h:374
SDL_XINPUT_JoystickOpen
int SDL_XINPUT_JoystickOpen(SDL_Joystick *joystick, JoyStick_DeviceData *joystickdevice)
Definition: SDL_xinputjoystick.c:549
SDL_strcmp
#define SDL_strcmp
Definition: SDL_dynapi_overrides.h:417
SDL_strstr
#define SDL_strstr
Definition: SDL_dynapi_overrides.h:403
SDL_XINPUT_JoystickClose
void SDL_XINPUT_JoystickClose(SDL_Joystick *joystick)
Definition: SDL_xinputjoystick.c:566
state
struct xkb_state * state
Definition: SDL_waylandsym.h:114
JoyStick_DeviceData::pNext
struct JoyStick_DeviceData * pNext
Definition: SDL_windowsjoystick_c.h:41
JoyStick_DeviceData::SubType
BYTE SubType
Definition: SDL_windowsjoystick_c.h:37
button
SDL_Texture * button
Definition: testgamecontroller.c:67
i
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
SDL_bool
SDL_bool
Definition: SDL_stdinc.h:161
Uint8
uint8_t Uint8
Definition: SDL_stdinc.h:179