35#define _GLFW_TYPE_AXIS 0
36#define _GLFW_TYPE_SLIDER 1
37#define _GLFW_TYPE_BUTTON 2
38#define _GLFW_TYPE_POV 3
55static const GUID _glfw_IID_IDirectInput8W =
56 {0xbf798031,0x483a,0x4da2,{0xaa,0x99,0x5d,0x64,0xed,0x36,0x97,0x00}};
57static const GUID _glfw_GUID_XAxis =
58 {0xa36d02e0,0xc9f3,0x11cf,{0xbf,0xc7,0x44,0x45,0x53,0x54,0x00,0x00}};
59static const GUID _glfw_GUID_YAxis =
60 {0xa36d02e1,0xc9f3,0x11cf,{0xbf,0xc7,0x44,0x45,0x53,0x54,0x00,0x00}};
61static const GUID _glfw_GUID_ZAxis =
62 {0xa36d02e2,0xc9f3,0x11cf,{0xbf,0xc7,0x44,0x45,0x53,0x54,0x00,0x00}};
63static const GUID _glfw_GUID_RxAxis =
64 {0xa36d02f4,0xc9f3,0x11cf,{0xbf,0xc7,0x44,0x45,0x53,0x54,0x00,0x00}};
65static const GUID _glfw_GUID_RyAxis =
66 {0xa36d02f5,0xc9f3,0x11cf,{0xbf,0xc7,0x44,0x45,0x53,0x54,0x00,0x00}};
67static const GUID _glfw_GUID_RzAxis =
68 {0xa36d02e3,0xc9f3,0x11cf,{0xbf,0xc7,0x44,0x45,0x53,0x54,0x00,0x00}};
69static const GUID _glfw_GUID_Slider =
70 {0xa36d02e4,0xc9f3,0x11cf,{0xbf,0xc7,0x44,0x45,0x53,0x54,0x00,0x00}};
71static const GUID _glfw_GUID_POV =
72 {0xa36d02f2,0xc9f3,0x11cf,{0xbf,0xc7,0x44,0x45,0x53,0x54,0x00,0x00}};
74#define IID_IDirectInput8W _glfw_IID_IDirectInput8W
75#define GUID_XAxis _glfw_GUID_XAxis
76#define GUID_YAxis _glfw_GUID_YAxis
77#define GUID_ZAxis _glfw_GUID_ZAxis
78#define GUID_RxAxis _glfw_GUID_RxAxis
79#define GUID_RyAxis _glfw_GUID_RyAxis
80#define GUID_RzAxis _glfw_GUID_RzAxis
81#define GUID_Slider _glfw_GUID_Slider
82#define GUID_POV _glfw_GUID_POV
144 _glfwObjectDataFormats
154 return "XInput Wheel";
156 return "XInput Arcade Stick";
158 return "XInput Flight Stick";
160 return "XInput Dance Pad";
162 return "XInput Guitar";
164 return "XInput Drum Kit";
168 return "Wireless Xbox Controller";
170 return "Xbox Controller";
174 return "Unknown XInput Device";
179static int compareJoystickObjects(
const void* first,
const void* second)
193static GLFWbool supportsXInput(
const GUID* guid)
196 RAWINPUTDEVICELIST* ridl;
199 if (GetRawInputDeviceList(
NULL, &count,
sizeof(RAWINPUTDEVICELIST)) != 0)
202 ridl = calloc(count,
sizeof(RAWINPUTDEVICELIST));
204 if (GetRawInputDeviceList(ridl, &count,
sizeof(RAWINPUTDEVICELIST)) == (UINT) -1)
210 for (i = 0; i < count; i++)
216 if (ridl[i].dwType != RIM_TYPEHID)
219 ZeroMemory(&rdi,
sizeof(rdi));
220 rdi.cbSize =
sizeof(rdi);
223 if ((INT) GetRawInputDeviceInfoA(ridl[i].hDevice,
230 if (MAKELONG(rdi.hid.dwVendorId, rdi.hid.dwProductId) != (LONG) guid->Data1)
233 memset(name, 0,
sizeof(name));
236 if ((INT) GetRawInputDeviceInfoA(ridl[i].hDevice,
243 name[
sizeof(name) - 1] =
'\0';
244 if (strstr(name,
"IG_"))
259 if (js->win32.device)
265 free(js->win32.objects);
301 ZeroMemory(&dipr,
sizeof(dipr));
346static BOOL CALLBACK deviceCallback(
const DIDEVICEINSTANCE* di,
void* user)
362 if (memcmp(&js->win32.
guid, &di->guidInstance,
sizeof(GUID)) == 0)
367 if (supportsXInput(&di->guidProduct))
382 "Win32: Failed to set device data format");
388 ZeroMemory(&dc,
sizeof(dc));
394 "Win32: Failed to query device capabilities");
400 ZeroMemory(&dipd,
sizeof(dipd));
411 "Win32: Failed to set device axis mode");
417 memset(&data, 0,
sizeof(data));
423 deviceObjectCallback,
428 "Win32: Failed to enumerate device objects");
437 compareJoystickObjects);
439 if (!WideCharToMultiByte(CP_UTF8, 0,
440 di->tszInstanceName, -1,
445 "Win32: Failed to convert joystick name to UTF-8");
453 if (memcmp(&di->guidProduct.Data4[2],
"PIDVID", 6) == 0)
455 sprintf(guid,
"03000000%02x%02x0000%02x%02x000000000000",
456 (
uint8_t) di->guidProduct.Data1,
457 (
uint8_t) (di->guidProduct.Data1 >> 8),
458 (
uint8_t) (di->guidProduct.Data1 >> 16),
459 (
uint8_t) (di->guidProduct.Data1 >> 24));
463 sprintf(guid,
"05000000%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x00",
464 name[0], name[1], name[2], name[3],
465 name[4], name[5], name[6], name[7],
466 name[8], name[9], name[10]);
480 js->win32.device = device;
481 js->win32.
guid = di->guidInstance;
482 js->win32.objects = data.
objects;
498 if (
_glfw.win32.xinput.instance)
526 sprintf(guid,
"78696e707574%02x000000000000000000",
533 js->win32.index = index;
539 if (
_glfw.win32.dinput8.api)
548 "Failed to enumerate DirectInput8 devices");
575 if (
_glfw.win32.dinput8.instance)
580 (
void**) &
_glfw.win32.dinput8.api,
584 "Win32: Failed to create interface");
600 if (
_glfw.win32.dinput8.api)
606 if (js->win32.device)
608 int i, ai = 0, bi = 0, pi = 0;
634 for (i = 0; i < js->win32.objectCount; i++)
636 const void* data = (
char*) &state + js->win32.objects[i].offset;
638 switch (js->win32.objects[i].type)
643 const float value = (*((LONG*) data) + 0.5f) / 32767.5f;
651 const char value = (*((BYTE*) data) & 0x80) != 0;
659 const int states[9] =
673 int stateIndex = LOWORD(*(DWORD*) data) / (45 *
DI_DEGREES);
674 if (stateIndex < 0 || stateIndex > 8)
689 const WORD buttons[10] =
704 if (result != ERROR_SUCCESS)
706 if (result == ERROR_DEVICE_NOT_CONNECTED)
722 for (i = 0; i < 10; i++)
745 if (strcmp(guid + 20,
"504944564944") == 0)
748 strncpy(original, guid,
sizeof(original) - 1);
749 sprintf(guid,
"03000000%.4s0000%.4s000000000000",
750 original, original + 4);
#define GLFW_DISCONNECTED
#define GLFW_PLATFORM_ERROR
A platform-specific error occurred that does not match any of the more specific categories.
#define GLFW_HAT_LEFT_DOWN
#define GLFW_HAT_RIGHT_UP
#define GLFW_HAT_RIGHT_DOWN
#define GLFW_HAT_CENTERED
#define GLFW_JOYSTICK_LAST
void _glfwInputError(int code, const char *format,...)
#define _GLFW_POLL_PRESENCE
_GLFWjoystick joysticks[GLFW_JOYSTICK_LAST+1]
IDirectInputDevice8W * device
_GLFWjoyobjectWin32 * objects
void _glfwDetectJoystickDisconnectionWin32(void)
void _glfwPlatformTerminateJoysticks(void)
int _glfwPlatformPollJoystick(_GLFWjoystick *js, int mode)
GLFWbool _glfwPlatformInitJoysticks(void)
#define _GLFW_TYPE_SLIDER
#define IID_IDirectInput8W
#define _GLFW_TYPE_BUTTON
void _glfwDetectJoystickConnectionWin32(void)
void _glfwPlatformUpdateGamepadGUID(char *guid)