35static const GUID _glfw_GUID_DEVINTERFACE_HID =
36 {0x4d1e55b2,0xf16f,0x11cf,{0x88,0xcb,0x00,0x11,0x11,0x00,0x00,0x30}};
38#define GUID_DEVINTERFACE_HID _glfw_GUID_DEVINTERFACE_HID
40#if defined(_GLFW_USE_HYBRID_HPG) || defined(_GLFW_USE_OPTIMUS_HPG)
42#if defined(_GLFW_BUILD_DLL)
43 #warning "These symbols must be exported by the executable and have no effect in a DLL"
50__declspec(dllexport) DWORD NvOptimusEnablement = 1;
56__declspec(dllexport)
int AmdPowerXpressRequestHighPerformance = 1;
60#if defined(_GLFW_BUILD_DLL)
64BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved)
75 _glfw.win32.winmm.instance = LoadLibraryA(
"winmm.dll");
76 if (!
_glfw.win32.winmm.instance)
79 "Win32: Failed to load winmm.dll");
84 GetProcAddress(
_glfw.win32.winmm.instance,
"timeGetTime");
86 _glfw.win32.user32.instance = LoadLibraryA(
"user32.dll");
87 if (!
_glfw.win32.user32.instance)
90 "Win32: Failed to load user32.dll");
95 GetProcAddress(
_glfw.win32.user32.instance,
"SetProcessDPIAware");
97 GetProcAddress(
_glfw.win32.user32.instance,
"ChangeWindowMessageFilterEx");
99 GetProcAddress(
_glfw.win32.user32.instance,
"EnableNonClientDpiScaling");
101 GetProcAddress(
_glfw.win32.user32.instance,
"SetProcessDpiAwarenessContext");
103 GetProcAddress(
_glfw.win32.user32.instance,
"GetDpiForWindow");
105 GetProcAddress(
_glfw.win32.user32.instance,
"AdjustWindowRectExForDpi");
107 _glfw.win32.dinput8.instance = LoadLibraryA(
"dinput8.dll");
108 if (
_glfw.win32.dinput8.instance)
111 GetProcAddress(
_glfw.win32.dinput8.instance,
"DirectInput8Create");
116 const char* names[] =
126 for (i = 0; names[i]; i++)
128 _glfw.win32.xinput.instance = LoadLibraryA(names[i]);
129 if (
_glfw.win32.xinput.instance)
132 GetProcAddress(
_glfw.win32.xinput.instance,
"XInputGetCapabilities");
134 GetProcAddress(
_glfw.win32.xinput.instance,
"XInputGetState");
141 _glfw.win32.dwmapi.instance = LoadLibraryA(
"dwmapi.dll");
142 if (
_glfw.win32.dwmapi.instance)
145 GetProcAddress(
_glfw.win32.dwmapi.instance,
"DwmIsCompositionEnabled");
147 GetProcAddress(
_glfw.win32.dwmapi.instance,
"DwmFlush");
149 GetProcAddress(
_glfw.win32.dwmapi.instance,
"DwmEnableBlurBehindWindow");
151 GetProcAddress(
_glfw.win32.dwmapi.instance,
"DwmGetColorizationColor");
154 _glfw.win32.shcore.instance = LoadLibraryA(
"shcore.dll");
155 if (
_glfw.win32.shcore.instance)
158 GetProcAddress(
_glfw.win32.shcore.instance,
"SetProcessDpiAwareness");
160 GetProcAddress(
_glfw.win32.shcore.instance,
"GetDpiForMonitor");
163 _glfw.win32.ntdll.instance = LoadLibraryA(
"ntdll.dll");
164 if (
_glfw.win32.ntdll.instance)
167 GetProcAddress(
_glfw.win32.ntdll.instance,
"RtlVerifyVersionInfo");
175static void freeLibraries(
void)
177 if (
_glfw.win32.xinput.instance)
178 FreeLibrary(
_glfw.win32.xinput.instance);
180 if (
_glfw.win32.dinput8.instance)
181 FreeLibrary(
_glfw.win32.dinput8.instance);
183 if (
_glfw.win32.winmm.instance)
184 FreeLibrary(
_glfw.win32.winmm.instance);
186 if (
_glfw.win32.user32.instance)
187 FreeLibrary(
_glfw.win32.user32.instance);
189 if (
_glfw.win32.dwmapi.instance)
190 FreeLibrary(
_glfw.win32.dwmapi.instance);
192 if (
_glfw.win32.shcore.instance)
193 FreeLibrary(
_glfw.win32.shcore.instance);
195 if (
_glfw.win32.ntdll.instance)
196 FreeLibrary(
_glfw.win32.ntdll.instance);
201static void createKeyTables(
void)
205 memset(
_glfw.win32.keycodes, -1,
sizeof(
_glfw.win32.keycodes));
206 memset(
_glfw.win32.scancodes, -1,
sizeof(
_glfw.win32.scancodes));
331 for (scancode = 0; scancode < 512; scancode++)
333 if (
_glfw.win32.keycodes[scancode] > 0)
334 _glfw.win32.scancodes[
_glfw.win32.keycodes[scancode]] = scancode;
340static GLFWbool createHelperWindow(
void)
344 _glfw.win32.helperWindowHandle =
345 CreateWindowExW(WS_EX_OVERLAPPEDWINDOW,
347 L
"GLFW message window",
348 WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
351 GetModuleHandleW(
NULL),
354 if (!
_glfw.win32.helperWindowHandle)
357 "Win32: Failed to create helper window");
363 ShowWindow(
_glfw.win32.helperWindowHandle, SW_HIDE);
367 DEV_BROADCAST_DEVICEINTERFACE_W dbi;
368 ZeroMemory(&dbi,
sizeof(dbi));
369 dbi.dbcc_size =
sizeof(dbi);
370 dbi.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
373 _glfw.win32.deviceNotificationHandle =
374 RegisterDeviceNotificationW(
_glfw.win32.helperWindowHandle,
375 (DEV_BROADCAST_HDR*) &dbi,
376 DEVICE_NOTIFY_WINDOW_HANDLE);
379 while (PeekMessageW(&msg,
_glfw.win32.helperWindowHandle, 0, 0, PM_REMOVE))
381 TranslateMessage(&msg);
382 DispatchMessageW(&msg);
400 count = MultiByteToWideChar(CP_UTF8, 0, source, -1,
NULL, 0);
404 "Win32: Failed to convert string from UTF-8");
408 target = calloc(count,
sizeof(WCHAR));
410 if (!MultiByteToWideChar(CP_UTF8, 0, source, -1, target, count))
413 "Win32: Failed to convert string from UTF-8");
428 size = WideCharToMultiByte(CP_UTF8, 0, source, -1,
NULL, 0,
NULL,
NULL);
432 "Win32: Failed to convert string to UTF-8");
436 target = calloc(size, 1);
438 if (!WideCharToMultiByte(CP_UTF8, 0, source, -1, target, size,
NULL,
NULL))
441 "Win32: Failed to convert string to UTF-8");
456 FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM |
457 FORMAT_MESSAGE_IGNORE_INSERTS |
458 FORMAT_MESSAGE_MAX_WIDTH_MASK,
460 GetLastError() & 0xffff,
461 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
463 sizeof(buffer) /
sizeof(WCHAR),
465 WideCharToMultiByte(CP_UTF8, 0, buffer, -1, message,
sizeof(message),
NULL,
NULL);
475 BYTE state[256] = {0};
477 memset(
_glfw.win32.keynames, 0,
sizeof(
_glfw.win32.keynames));
482 int scancode, length;
485 scancode =
_glfw.win32.scancodes[key];
492 VK_NUMPAD0, VK_NUMPAD1, VK_NUMPAD2, VK_NUMPAD3,
493 VK_NUMPAD4, VK_NUMPAD5, VK_NUMPAD6, VK_NUMPAD7,
494 VK_NUMPAD8, VK_NUMPAD9, VK_DECIMAL, VK_DIVIDE,
495 VK_MULTIPLY, VK_SUBTRACT, VK_ADD
501 vk = MapVirtualKey(scancode, MAPVK_VSC_TO_VK);
503 length = ToUnicode(vk, scancode, state,
504 chars,
sizeof(chars) /
sizeof(WCHAR),
509 length = ToUnicode(vk, scancode, state,
510 chars,
sizeof(chars) /
sizeof(WCHAR),
517 WideCharToMultiByte(CP_UTF8, 0, chars, 1,
518 _glfw.win32.keynames[key],
519 sizeof(
_glfw.win32.keynames[key]),
528 OSVERSIONINFOEXW osvi = {
sizeof(osvi), major, minor, 0, 0, {0}, sp };
529 DWORD mask = VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR;
530 ULONGLONG cond = VerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL);
531 cond = VerSetConditionMask(cond, VER_MINORVERSION, VER_GREATER_EQUAL);
532 cond = VerSetConditionMask(cond, VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL);
543 OSVERSIONINFOEXW osvi = {
sizeof(osvi), 10, 0, build };
544 DWORD mask = VER_MAJORVERSION | VER_MINORVERSION | VER_BUILDNUMBER;
545 ULONGLONG cond = VerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL);
546 cond = VerSetConditionMask(cond, VER_MINORVERSION, VER_GREATER_EQUAL);
547 cond = VerSetConditionMask(cond, VER_BUILDNUMBER, VER_GREATER_EQUAL);
564 SystemParametersInfoW(SPI_GETFOREGROUNDLOCKTIMEOUT, 0,
565 &
_glfw.win32.foregroundLockTimeout, 0);
566 SystemParametersInfoW(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, UIntToPtr(0),
569 if (!loadLibraries())
585 if (!createHelperWindow())
596 if (
_glfw.win32.deviceNotificationHandle)
597 UnregisterDeviceNotification(
_glfw.win32.deviceNotificationHandle);
599 if (
_glfw.win32.helperWindowHandle)
600 DestroyWindow(
_glfw.win32.helperWindowHandle);
605 SystemParametersInfoW(SPI_SETFOREGROUNDLOCKTIMEOUT, 0,
606 UIntToPtr(
_glfw.win32.foregroundLockTimeout),
609 free(
_glfw.win32.clipboardString);
610 free(
_glfw.win32.rawInput);
621#if defined(__MINGW64_VERSION_MAJOR)
623#elif defined(__MINGW32__)
625#elif defined(_MSC_VER)
628#if defined(_GLFW_USE_HYBRID_HPG) || defined(_GLFW_USE_OPTIMUS_HPG)
631#if defined(_GLFW_BUILD_DLL)
void _glfwTerminateEGL(void)
#define GLFW_PLATFORM_ERROR
A platform-specific error occurred that does not match any of the more specific categories.
#define GLFW_KEY_NUM_LOCK
#define GLFW_KEY_KP_DECIMAL
#define GLFW_KEY_KP_ENTER
#define GLFW_KEY_APOSTROPHE
#define GLFW_KEY_RIGHT_ALT
#define GLFW_KEY_BACKSPACE
#define GLFW_KEY_GRAVE_ACCENT
#define GLFW_KEY_LEFT_ALT
#define GLFW_KEY_SEMICOLON
#define GLFW_KEY_RIGHT_BRACKET
#define GLFW_KEY_LEFT_SHIFT
#define GLFW_KEY_CAPS_LOCK
#define GLFW_KEY_KP_MULTIPLY
#define GLFW_KEY_LEFT_CONTROL
#define GLFW_KEY_KP_SUBTRACT
#define GLFW_KEY_BACKSLASH
#define GLFW_KEY_KP_DIVIDE
#define GLFW_KEY_LEFT_BRACKET
#define GLFW_KEY_RIGHT_CONTROL
#define GLFW_KEY_RIGHT_SUPER
#define GLFW_KEY_KP_EQUAL
#define GLFW_KEY_PAGE_DOWN
#define GLFW_KEY_SCROLL_LOCK
#define GLFW_KEY_PRINT_SCREEN
#define GLFW_KEY_LEFT_SUPER
#define GLFW_KEY_RIGHT_SHIFT
void _glfwInputError(int code, const char *format,...)
#define _GLFW_VERSION_NUMBER
#define _GLFW_MESSAGE_SIZE
void _glfwTerminateWGL(void)
const char * _glfwPlatformGetVersionString(void)
void _glfwInputErrorWin32(int error, const char *description)
BOOL _glfwIsWindows10BuildOrGreaterWin32(WORD build)
BOOL _glfwIsWindowsVersionOrGreaterWin32(WORD major, WORD minor, WORD sp)
void _glfwPlatformTerminate(void)
WCHAR * _glfwCreateWideStringFromUTF8Win32(const char *source)
int _glfwPlatformInit(void)
char * _glfwCreateUTF8FromWideStringWin32(const WCHAR *source)
#define GUID_DEVINTERFACE_HID
void _glfwUpdateKeyNamesWin32(void)
void _glfwPollMonitorsWin32(void)