1b877906bSopenharmony_ci//========================================================================
2b877906bSopenharmony_ci// GLFW 3.5 Win32 - www.glfw.org
3b877906bSopenharmony_ci//------------------------------------------------------------------------
4b877906bSopenharmony_ci// Copyright (c) 2002-2006 Marcus Geelnard
5b877906bSopenharmony_ci// Copyright (c) 2006-2019 Camilla Löwy <elmindreda@glfw.org>
6b877906bSopenharmony_ci//
7b877906bSopenharmony_ci// This software is provided 'as-is', without any express or implied
8b877906bSopenharmony_ci// warranty. In no event will the authors be held liable for any damages
9b877906bSopenharmony_ci// arising from the use of this software.
10b877906bSopenharmony_ci//
11b877906bSopenharmony_ci// Permission is granted to anyone to use this software for any purpose,
12b877906bSopenharmony_ci// including commercial applications, and to alter it and redistribute it
13b877906bSopenharmony_ci// freely, subject to the following restrictions:
14b877906bSopenharmony_ci//
15b877906bSopenharmony_ci// 1. The origin of this software must not be misrepresented; you must not
16b877906bSopenharmony_ci//    claim that you wrote the original software. If you use this software
17b877906bSopenharmony_ci//    in a product, an acknowledgment in the product documentation would
18b877906bSopenharmony_ci//    be appreciated but is not required.
19b877906bSopenharmony_ci//
20b877906bSopenharmony_ci// 2. Altered source versions must be plainly marked as such, and must not
21b877906bSopenharmony_ci//    be misrepresented as being the original software.
22b877906bSopenharmony_ci//
23b877906bSopenharmony_ci// 3. This notice may not be removed or altered from any source
24b877906bSopenharmony_ci//    distribution.
25b877906bSopenharmony_ci//
26b877906bSopenharmony_ci//========================================================================
27b877906bSopenharmony_ci
28b877906bSopenharmony_ci#include "internal.h"
29b877906bSopenharmony_ci
30b877906bSopenharmony_ci#if defined(_GLFW_WIN32)
31b877906bSopenharmony_ci
32b877906bSopenharmony_ci#include <stdlib.h>
33b877906bSopenharmony_ci
34b877906bSopenharmony_cistatic const GUID _glfw_GUID_DEVINTERFACE_HID =
35b877906bSopenharmony_ci    {0x4d1e55b2,0xf16f,0x11cf,{0x88,0xcb,0x00,0x11,0x11,0x00,0x00,0x30}};
36b877906bSopenharmony_ci
37b877906bSopenharmony_ci#define GUID_DEVINTERFACE_HID _glfw_GUID_DEVINTERFACE_HID
38b877906bSopenharmony_ci
39b877906bSopenharmony_ci#if defined(_GLFW_USE_HYBRID_HPG) || defined(_GLFW_USE_OPTIMUS_HPG)
40b877906bSopenharmony_ci
41b877906bSopenharmony_ci#if defined(_GLFW_BUILD_DLL)
42b877906bSopenharmony_ci #pragma message("These symbols must be exported by the executable and have no effect in a DLL")
43b877906bSopenharmony_ci#endif
44b877906bSopenharmony_ci
45b877906bSopenharmony_ci// Executables (but not DLLs) exporting this symbol with this value will be
46b877906bSopenharmony_ci// automatically directed to the high-performance GPU on Nvidia Optimus systems
47b877906bSopenharmony_ci// with up-to-date drivers
48b877906bSopenharmony_ci//
49b877906bSopenharmony_ci__declspec(dllexport) DWORD NvOptimusEnablement = 1;
50b877906bSopenharmony_ci
51b877906bSopenharmony_ci// Executables (but not DLLs) exporting this symbol with this value will be
52b877906bSopenharmony_ci// automatically directed to the high-performance GPU on AMD PowerXpress systems
53b877906bSopenharmony_ci// with up-to-date drivers
54b877906bSopenharmony_ci//
55b877906bSopenharmony_ci__declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
56b877906bSopenharmony_ci
57b877906bSopenharmony_ci#endif // _GLFW_USE_HYBRID_HPG
58b877906bSopenharmony_ci
59b877906bSopenharmony_ci#if defined(_GLFW_BUILD_DLL)
60b877906bSopenharmony_ci
61b877906bSopenharmony_ci// GLFW DLL entry point
62b877906bSopenharmony_ci//
63b877906bSopenharmony_ciBOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved)
64b877906bSopenharmony_ci{
65b877906bSopenharmony_ci    return TRUE;
66b877906bSopenharmony_ci}
67b877906bSopenharmony_ci
68b877906bSopenharmony_ci#endif // _GLFW_BUILD_DLL
69b877906bSopenharmony_ci
70b877906bSopenharmony_ci// Load necessary libraries (DLLs)
71b877906bSopenharmony_ci//
72b877906bSopenharmony_cistatic GLFWbool loadLibraries(void)
73b877906bSopenharmony_ci{
74b877906bSopenharmony_ci    if (!GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
75b877906bSopenharmony_ci                                GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
76b877906bSopenharmony_ci                            (const WCHAR*) &_glfw,
77b877906bSopenharmony_ci                            (HMODULE*) &_glfw.win32.instance))
78b877906bSopenharmony_ci    {
79b877906bSopenharmony_ci        _glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
80b877906bSopenharmony_ci                             "Win32: Failed to retrieve own module handle");
81b877906bSopenharmony_ci        return GLFW_FALSE;
82b877906bSopenharmony_ci    }
83b877906bSopenharmony_ci
84b877906bSopenharmony_ci    _glfw.win32.user32.instance = _glfwPlatformLoadModule("user32.dll");
85b877906bSopenharmony_ci    if (!_glfw.win32.user32.instance)
86b877906bSopenharmony_ci    {
87b877906bSopenharmony_ci        _glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
88b877906bSopenharmony_ci                             "Win32: Failed to load user32.dll");
89b877906bSopenharmony_ci        return GLFW_FALSE;
90b877906bSopenharmony_ci    }
91b877906bSopenharmony_ci
92b877906bSopenharmony_ci    _glfw.win32.user32.SetProcessDPIAware_ = (PFN_SetProcessDPIAware)
93b877906bSopenharmony_ci        _glfwPlatformGetModuleSymbol(_glfw.win32.user32.instance, "SetProcessDPIAware");
94b877906bSopenharmony_ci    _glfw.win32.user32.ChangeWindowMessageFilterEx_ = (PFN_ChangeWindowMessageFilterEx)
95b877906bSopenharmony_ci        _glfwPlatformGetModuleSymbol(_glfw.win32.user32.instance, "ChangeWindowMessageFilterEx");
96b877906bSopenharmony_ci    _glfw.win32.user32.EnableNonClientDpiScaling_ = (PFN_EnableNonClientDpiScaling)
97b877906bSopenharmony_ci        _glfwPlatformGetModuleSymbol(_glfw.win32.user32.instance, "EnableNonClientDpiScaling");
98b877906bSopenharmony_ci    _glfw.win32.user32.SetProcessDpiAwarenessContext_ = (PFN_SetProcessDpiAwarenessContext)
99b877906bSopenharmony_ci        _glfwPlatformGetModuleSymbol(_glfw.win32.user32.instance, "SetProcessDpiAwarenessContext");
100b877906bSopenharmony_ci    _glfw.win32.user32.GetDpiForWindow_ = (PFN_GetDpiForWindow)
101b877906bSopenharmony_ci        _glfwPlatformGetModuleSymbol(_glfw.win32.user32.instance, "GetDpiForWindow");
102b877906bSopenharmony_ci    _glfw.win32.user32.AdjustWindowRectExForDpi_ = (PFN_AdjustWindowRectExForDpi)
103b877906bSopenharmony_ci        _glfwPlatformGetModuleSymbol(_glfw.win32.user32.instance, "AdjustWindowRectExForDpi");
104b877906bSopenharmony_ci    _glfw.win32.user32.GetSystemMetricsForDpi_ = (PFN_GetSystemMetricsForDpi)
105b877906bSopenharmony_ci        _glfwPlatformGetModuleSymbol(_glfw.win32.user32.instance, "GetSystemMetricsForDpi");
106b877906bSopenharmony_ci
107b877906bSopenharmony_ci    _glfw.win32.dinput8.instance = _glfwPlatformLoadModule("dinput8.dll");
108b877906bSopenharmony_ci    if (_glfw.win32.dinput8.instance)
109b877906bSopenharmony_ci    {
110b877906bSopenharmony_ci        _glfw.win32.dinput8.Create = (PFN_DirectInput8Create)
111b877906bSopenharmony_ci            _glfwPlatformGetModuleSymbol(_glfw.win32.dinput8.instance, "DirectInput8Create");
112b877906bSopenharmony_ci    }
113b877906bSopenharmony_ci
114b877906bSopenharmony_ci    {
115b877906bSopenharmony_ci        int i;
116b877906bSopenharmony_ci        const char* names[] =
117b877906bSopenharmony_ci        {
118b877906bSopenharmony_ci            "xinput1_4.dll",
119b877906bSopenharmony_ci            "xinput1_3.dll",
120b877906bSopenharmony_ci            "xinput9_1_0.dll",
121b877906bSopenharmony_ci            "xinput1_2.dll",
122b877906bSopenharmony_ci            "xinput1_1.dll",
123b877906bSopenharmony_ci            NULL
124b877906bSopenharmony_ci        };
125b877906bSopenharmony_ci
126b877906bSopenharmony_ci        for (i = 0;  names[i];  i++)
127b877906bSopenharmony_ci        {
128b877906bSopenharmony_ci            _glfw.win32.xinput.instance = _glfwPlatformLoadModule(names[i]);
129b877906bSopenharmony_ci            if (_glfw.win32.xinput.instance)
130b877906bSopenharmony_ci            {
131b877906bSopenharmony_ci                _glfw.win32.xinput.GetCapabilities = (PFN_XInputGetCapabilities)
132b877906bSopenharmony_ci                    _glfwPlatformGetModuleSymbol(_glfw.win32.xinput.instance, "XInputGetCapabilities");
133b877906bSopenharmony_ci                _glfw.win32.xinput.GetState = (PFN_XInputGetState)
134b877906bSopenharmony_ci                    _glfwPlatformGetModuleSymbol(_glfw.win32.xinput.instance, "XInputGetState");
135b877906bSopenharmony_ci
136b877906bSopenharmony_ci                break;
137b877906bSopenharmony_ci            }
138b877906bSopenharmony_ci        }
139b877906bSopenharmony_ci    }
140b877906bSopenharmony_ci
141b877906bSopenharmony_ci    _glfw.win32.dwmapi.instance = _glfwPlatformLoadModule("dwmapi.dll");
142b877906bSopenharmony_ci    if (_glfw.win32.dwmapi.instance)
143b877906bSopenharmony_ci    {
144b877906bSopenharmony_ci        _glfw.win32.dwmapi.IsCompositionEnabled = (PFN_DwmIsCompositionEnabled)
145b877906bSopenharmony_ci            _glfwPlatformGetModuleSymbol(_glfw.win32.dwmapi.instance, "DwmIsCompositionEnabled");
146b877906bSopenharmony_ci        _glfw.win32.dwmapi.Flush = (PFN_DwmFlush)
147b877906bSopenharmony_ci            _glfwPlatformGetModuleSymbol(_glfw.win32.dwmapi.instance, "DwmFlush");
148b877906bSopenharmony_ci        _glfw.win32.dwmapi.EnableBlurBehindWindow = (PFN_DwmEnableBlurBehindWindow)
149b877906bSopenharmony_ci            _glfwPlatformGetModuleSymbol(_glfw.win32.dwmapi.instance, "DwmEnableBlurBehindWindow");
150b877906bSopenharmony_ci        _glfw.win32.dwmapi.GetColorizationColor = (PFN_DwmGetColorizationColor)
151b877906bSopenharmony_ci            _glfwPlatformGetModuleSymbol(_glfw.win32.dwmapi.instance, "DwmGetColorizationColor");
152b877906bSopenharmony_ci    }
153b877906bSopenharmony_ci
154b877906bSopenharmony_ci    _glfw.win32.shcore.instance = _glfwPlatformLoadModule("shcore.dll");
155b877906bSopenharmony_ci    if (_glfw.win32.shcore.instance)
156b877906bSopenharmony_ci    {
157b877906bSopenharmony_ci        _glfw.win32.shcore.SetProcessDpiAwareness_ = (PFN_SetProcessDpiAwareness)
158b877906bSopenharmony_ci            _glfwPlatformGetModuleSymbol(_glfw.win32.shcore.instance, "SetProcessDpiAwareness");
159b877906bSopenharmony_ci        _glfw.win32.shcore.GetDpiForMonitor_ = (PFN_GetDpiForMonitor)
160b877906bSopenharmony_ci            _glfwPlatformGetModuleSymbol(_glfw.win32.shcore.instance, "GetDpiForMonitor");
161b877906bSopenharmony_ci    }
162b877906bSopenharmony_ci
163b877906bSopenharmony_ci    _glfw.win32.ntdll.instance = _glfwPlatformLoadModule("ntdll.dll");
164b877906bSopenharmony_ci    if (_glfw.win32.ntdll.instance)
165b877906bSopenharmony_ci    {
166b877906bSopenharmony_ci        _glfw.win32.ntdll.RtlVerifyVersionInfo_ = (PFN_RtlVerifyVersionInfo)
167b877906bSopenharmony_ci            _glfwPlatformGetModuleSymbol(_glfw.win32.ntdll.instance, "RtlVerifyVersionInfo");
168b877906bSopenharmony_ci    }
169b877906bSopenharmony_ci
170b877906bSopenharmony_ci    return GLFW_TRUE;
171b877906bSopenharmony_ci}
172b877906bSopenharmony_ci
173b877906bSopenharmony_ci// Unload used libraries (DLLs)
174b877906bSopenharmony_ci//
175b877906bSopenharmony_cistatic void freeLibraries(void)
176b877906bSopenharmony_ci{
177b877906bSopenharmony_ci    if (_glfw.win32.xinput.instance)
178b877906bSopenharmony_ci        _glfwPlatformFreeModule(_glfw.win32.xinput.instance);
179b877906bSopenharmony_ci
180b877906bSopenharmony_ci    if (_glfw.win32.dinput8.instance)
181b877906bSopenharmony_ci        _glfwPlatformFreeModule(_glfw.win32.dinput8.instance);
182b877906bSopenharmony_ci
183b877906bSopenharmony_ci    if (_glfw.win32.user32.instance)
184b877906bSopenharmony_ci        _glfwPlatformFreeModule(_glfw.win32.user32.instance);
185b877906bSopenharmony_ci
186b877906bSopenharmony_ci    if (_glfw.win32.dwmapi.instance)
187b877906bSopenharmony_ci        _glfwPlatformFreeModule(_glfw.win32.dwmapi.instance);
188b877906bSopenharmony_ci
189b877906bSopenharmony_ci    if (_glfw.win32.shcore.instance)
190b877906bSopenharmony_ci        _glfwPlatformFreeModule(_glfw.win32.shcore.instance);
191b877906bSopenharmony_ci
192b877906bSopenharmony_ci    if (_glfw.win32.ntdll.instance)
193b877906bSopenharmony_ci        _glfwPlatformFreeModule(_glfw.win32.ntdll.instance);
194b877906bSopenharmony_ci}
195b877906bSopenharmony_ci
196b877906bSopenharmony_ci// Create key code translation tables
197b877906bSopenharmony_ci//
198b877906bSopenharmony_cistatic void createKeyTables(void)
199b877906bSopenharmony_ci{
200b877906bSopenharmony_ci    int scancode;
201b877906bSopenharmony_ci
202b877906bSopenharmony_ci    memset(_glfw.win32.keycodes, -1, sizeof(_glfw.win32.keycodes));
203b877906bSopenharmony_ci    memset(_glfw.win32.scancodes, -1, sizeof(_glfw.win32.scancodes));
204b877906bSopenharmony_ci
205b877906bSopenharmony_ci    _glfw.win32.keycodes[0x00B] = GLFW_KEY_0;
206b877906bSopenharmony_ci    _glfw.win32.keycodes[0x002] = GLFW_KEY_1;
207b877906bSopenharmony_ci    _glfw.win32.keycodes[0x003] = GLFW_KEY_2;
208b877906bSopenharmony_ci    _glfw.win32.keycodes[0x004] = GLFW_KEY_3;
209b877906bSopenharmony_ci    _glfw.win32.keycodes[0x005] = GLFW_KEY_4;
210b877906bSopenharmony_ci    _glfw.win32.keycodes[0x006] = GLFW_KEY_5;
211b877906bSopenharmony_ci    _glfw.win32.keycodes[0x007] = GLFW_KEY_6;
212b877906bSopenharmony_ci    _glfw.win32.keycodes[0x008] = GLFW_KEY_7;
213b877906bSopenharmony_ci    _glfw.win32.keycodes[0x009] = GLFW_KEY_8;
214b877906bSopenharmony_ci    _glfw.win32.keycodes[0x00A] = GLFW_KEY_9;
215b877906bSopenharmony_ci    _glfw.win32.keycodes[0x01E] = GLFW_KEY_A;
216b877906bSopenharmony_ci    _glfw.win32.keycodes[0x030] = GLFW_KEY_B;
217b877906bSopenharmony_ci    _glfw.win32.keycodes[0x02E] = GLFW_KEY_C;
218b877906bSopenharmony_ci    _glfw.win32.keycodes[0x020] = GLFW_KEY_D;
219b877906bSopenharmony_ci    _glfw.win32.keycodes[0x012] = GLFW_KEY_E;
220b877906bSopenharmony_ci    _glfw.win32.keycodes[0x021] = GLFW_KEY_F;
221b877906bSopenharmony_ci    _glfw.win32.keycodes[0x022] = GLFW_KEY_G;
222b877906bSopenharmony_ci    _glfw.win32.keycodes[0x023] = GLFW_KEY_H;
223b877906bSopenharmony_ci    _glfw.win32.keycodes[0x017] = GLFW_KEY_I;
224b877906bSopenharmony_ci    _glfw.win32.keycodes[0x024] = GLFW_KEY_J;
225b877906bSopenharmony_ci    _glfw.win32.keycodes[0x025] = GLFW_KEY_K;
226b877906bSopenharmony_ci    _glfw.win32.keycodes[0x026] = GLFW_KEY_L;
227b877906bSopenharmony_ci    _glfw.win32.keycodes[0x032] = GLFW_KEY_M;
228b877906bSopenharmony_ci    _glfw.win32.keycodes[0x031] = GLFW_KEY_N;
229b877906bSopenharmony_ci    _glfw.win32.keycodes[0x018] = GLFW_KEY_O;
230b877906bSopenharmony_ci    _glfw.win32.keycodes[0x019] = GLFW_KEY_P;
231b877906bSopenharmony_ci    _glfw.win32.keycodes[0x010] = GLFW_KEY_Q;
232b877906bSopenharmony_ci    _glfw.win32.keycodes[0x013] = GLFW_KEY_R;
233b877906bSopenharmony_ci    _glfw.win32.keycodes[0x01F] = GLFW_KEY_S;
234b877906bSopenharmony_ci    _glfw.win32.keycodes[0x014] = GLFW_KEY_T;
235b877906bSopenharmony_ci    _glfw.win32.keycodes[0x016] = GLFW_KEY_U;
236b877906bSopenharmony_ci    _glfw.win32.keycodes[0x02F] = GLFW_KEY_V;
237b877906bSopenharmony_ci    _glfw.win32.keycodes[0x011] = GLFW_KEY_W;
238b877906bSopenharmony_ci    _glfw.win32.keycodes[0x02D] = GLFW_KEY_X;
239b877906bSopenharmony_ci    _glfw.win32.keycodes[0x015] = GLFW_KEY_Y;
240b877906bSopenharmony_ci    _glfw.win32.keycodes[0x02C] = GLFW_KEY_Z;
241b877906bSopenharmony_ci
242b877906bSopenharmony_ci    _glfw.win32.keycodes[0x028] = GLFW_KEY_APOSTROPHE;
243b877906bSopenharmony_ci    _glfw.win32.keycodes[0x02B] = GLFW_KEY_BACKSLASH;
244b877906bSopenharmony_ci    _glfw.win32.keycodes[0x033] = GLFW_KEY_COMMA;
245b877906bSopenharmony_ci    _glfw.win32.keycodes[0x00D] = GLFW_KEY_EQUAL;
246b877906bSopenharmony_ci    _glfw.win32.keycodes[0x029] = GLFW_KEY_GRAVE_ACCENT;
247b877906bSopenharmony_ci    _glfw.win32.keycodes[0x01A] = GLFW_KEY_LEFT_BRACKET;
248b877906bSopenharmony_ci    _glfw.win32.keycodes[0x00C] = GLFW_KEY_MINUS;
249b877906bSopenharmony_ci    _glfw.win32.keycodes[0x034] = GLFW_KEY_PERIOD;
250b877906bSopenharmony_ci    _glfw.win32.keycodes[0x01B] = GLFW_KEY_RIGHT_BRACKET;
251b877906bSopenharmony_ci    _glfw.win32.keycodes[0x027] = GLFW_KEY_SEMICOLON;
252b877906bSopenharmony_ci    _glfw.win32.keycodes[0x035] = GLFW_KEY_SLASH;
253b877906bSopenharmony_ci    _glfw.win32.keycodes[0x056] = GLFW_KEY_WORLD_2;
254b877906bSopenharmony_ci
255b877906bSopenharmony_ci    _glfw.win32.keycodes[0x00E] = GLFW_KEY_BACKSPACE;
256b877906bSopenharmony_ci    _glfw.win32.keycodes[0x153] = GLFW_KEY_DELETE;
257b877906bSopenharmony_ci    _glfw.win32.keycodes[0x14F] = GLFW_KEY_END;
258b877906bSopenharmony_ci    _glfw.win32.keycodes[0x01C] = GLFW_KEY_ENTER;
259b877906bSopenharmony_ci    _glfw.win32.keycodes[0x001] = GLFW_KEY_ESCAPE;
260b877906bSopenharmony_ci    _glfw.win32.keycodes[0x147] = GLFW_KEY_HOME;
261b877906bSopenharmony_ci    _glfw.win32.keycodes[0x152] = GLFW_KEY_INSERT;
262b877906bSopenharmony_ci    _glfw.win32.keycodes[0x15D] = GLFW_KEY_MENU;
263b877906bSopenharmony_ci    _glfw.win32.keycodes[0x151] = GLFW_KEY_PAGE_DOWN;
264b877906bSopenharmony_ci    _glfw.win32.keycodes[0x149] = GLFW_KEY_PAGE_UP;
265b877906bSopenharmony_ci    _glfw.win32.keycodes[0x045] = GLFW_KEY_PAUSE;
266b877906bSopenharmony_ci    _glfw.win32.keycodes[0x039] = GLFW_KEY_SPACE;
267b877906bSopenharmony_ci    _glfw.win32.keycodes[0x00F] = GLFW_KEY_TAB;
268b877906bSopenharmony_ci    _glfw.win32.keycodes[0x03A] = GLFW_KEY_CAPS_LOCK;
269b877906bSopenharmony_ci    _glfw.win32.keycodes[0x145] = GLFW_KEY_NUM_LOCK;
270b877906bSopenharmony_ci    _glfw.win32.keycodes[0x046] = GLFW_KEY_SCROLL_LOCK;
271b877906bSopenharmony_ci    _glfw.win32.keycodes[0x03B] = GLFW_KEY_F1;
272b877906bSopenharmony_ci    _glfw.win32.keycodes[0x03C] = GLFW_KEY_F2;
273b877906bSopenharmony_ci    _glfw.win32.keycodes[0x03D] = GLFW_KEY_F3;
274b877906bSopenharmony_ci    _glfw.win32.keycodes[0x03E] = GLFW_KEY_F4;
275b877906bSopenharmony_ci    _glfw.win32.keycodes[0x03F] = GLFW_KEY_F5;
276b877906bSopenharmony_ci    _glfw.win32.keycodes[0x040] = GLFW_KEY_F6;
277b877906bSopenharmony_ci    _glfw.win32.keycodes[0x041] = GLFW_KEY_F7;
278b877906bSopenharmony_ci    _glfw.win32.keycodes[0x042] = GLFW_KEY_F8;
279b877906bSopenharmony_ci    _glfw.win32.keycodes[0x043] = GLFW_KEY_F9;
280b877906bSopenharmony_ci    _glfw.win32.keycodes[0x044] = GLFW_KEY_F10;
281b877906bSopenharmony_ci    _glfw.win32.keycodes[0x057] = GLFW_KEY_F11;
282b877906bSopenharmony_ci    _glfw.win32.keycodes[0x058] = GLFW_KEY_F12;
283b877906bSopenharmony_ci    _glfw.win32.keycodes[0x064] = GLFW_KEY_F13;
284b877906bSopenharmony_ci    _glfw.win32.keycodes[0x065] = GLFW_KEY_F14;
285b877906bSopenharmony_ci    _glfw.win32.keycodes[0x066] = GLFW_KEY_F15;
286b877906bSopenharmony_ci    _glfw.win32.keycodes[0x067] = GLFW_KEY_F16;
287b877906bSopenharmony_ci    _glfw.win32.keycodes[0x068] = GLFW_KEY_F17;
288b877906bSopenharmony_ci    _glfw.win32.keycodes[0x069] = GLFW_KEY_F18;
289b877906bSopenharmony_ci    _glfw.win32.keycodes[0x06A] = GLFW_KEY_F19;
290b877906bSopenharmony_ci    _glfw.win32.keycodes[0x06B] = GLFW_KEY_F20;
291b877906bSopenharmony_ci    _glfw.win32.keycodes[0x06C] = GLFW_KEY_F21;
292b877906bSopenharmony_ci    _glfw.win32.keycodes[0x06D] = GLFW_KEY_F22;
293b877906bSopenharmony_ci    _glfw.win32.keycodes[0x06E] = GLFW_KEY_F23;
294b877906bSopenharmony_ci    _glfw.win32.keycodes[0x076] = GLFW_KEY_F24;
295b877906bSopenharmony_ci    _glfw.win32.keycodes[0x038] = GLFW_KEY_LEFT_ALT;
296b877906bSopenharmony_ci    _glfw.win32.keycodes[0x01D] = GLFW_KEY_LEFT_CONTROL;
297b877906bSopenharmony_ci    _glfw.win32.keycodes[0x02A] = GLFW_KEY_LEFT_SHIFT;
298b877906bSopenharmony_ci    _glfw.win32.keycodes[0x15B] = GLFW_KEY_LEFT_SUPER;
299b877906bSopenharmony_ci    _glfw.win32.keycodes[0x137] = GLFW_KEY_PRINT_SCREEN;
300b877906bSopenharmony_ci    _glfw.win32.keycodes[0x138] = GLFW_KEY_RIGHT_ALT;
301b877906bSopenharmony_ci    _glfw.win32.keycodes[0x11D] = GLFW_KEY_RIGHT_CONTROL;
302b877906bSopenharmony_ci    _glfw.win32.keycodes[0x036] = GLFW_KEY_RIGHT_SHIFT;
303b877906bSopenharmony_ci    _glfw.win32.keycodes[0x15C] = GLFW_KEY_RIGHT_SUPER;
304b877906bSopenharmony_ci    _glfw.win32.keycodes[0x150] = GLFW_KEY_DOWN;
305b877906bSopenharmony_ci    _glfw.win32.keycodes[0x14B] = GLFW_KEY_LEFT;
306b877906bSopenharmony_ci    _glfw.win32.keycodes[0x14D] = GLFW_KEY_RIGHT;
307b877906bSopenharmony_ci    _glfw.win32.keycodes[0x148] = GLFW_KEY_UP;
308b877906bSopenharmony_ci
309b877906bSopenharmony_ci    _glfw.win32.keycodes[0x052] = GLFW_KEY_KP_0;
310b877906bSopenharmony_ci    _glfw.win32.keycodes[0x04F] = GLFW_KEY_KP_1;
311b877906bSopenharmony_ci    _glfw.win32.keycodes[0x050] = GLFW_KEY_KP_2;
312b877906bSopenharmony_ci    _glfw.win32.keycodes[0x051] = GLFW_KEY_KP_3;
313b877906bSopenharmony_ci    _glfw.win32.keycodes[0x04B] = GLFW_KEY_KP_4;
314b877906bSopenharmony_ci    _glfw.win32.keycodes[0x04C] = GLFW_KEY_KP_5;
315b877906bSopenharmony_ci    _glfw.win32.keycodes[0x04D] = GLFW_KEY_KP_6;
316b877906bSopenharmony_ci    _glfw.win32.keycodes[0x047] = GLFW_KEY_KP_7;
317b877906bSopenharmony_ci    _glfw.win32.keycodes[0x048] = GLFW_KEY_KP_8;
318b877906bSopenharmony_ci    _glfw.win32.keycodes[0x049] = GLFW_KEY_KP_9;
319b877906bSopenharmony_ci    _glfw.win32.keycodes[0x04E] = GLFW_KEY_KP_ADD;
320b877906bSopenharmony_ci    _glfw.win32.keycodes[0x053] = GLFW_KEY_KP_DECIMAL;
321b877906bSopenharmony_ci    _glfw.win32.keycodes[0x135] = GLFW_KEY_KP_DIVIDE;
322b877906bSopenharmony_ci    _glfw.win32.keycodes[0x11C] = GLFW_KEY_KP_ENTER;
323b877906bSopenharmony_ci    _glfw.win32.keycodes[0x059] = GLFW_KEY_KP_EQUAL;
324b877906bSopenharmony_ci    _glfw.win32.keycodes[0x037] = GLFW_KEY_KP_MULTIPLY;
325b877906bSopenharmony_ci    _glfw.win32.keycodes[0x04A] = GLFW_KEY_KP_SUBTRACT;
326b877906bSopenharmony_ci
327b877906bSopenharmony_ci    for (scancode = 0;  scancode < 512;  scancode++)
328b877906bSopenharmony_ci    {
329b877906bSopenharmony_ci        if (_glfw.win32.keycodes[scancode] > 0)
330b877906bSopenharmony_ci            _glfw.win32.scancodes[_glfw.win32.keycodes[scancode]] = scancode;
331b877906bSopenharmony_ci    }
332b877906bSopenharmony_ci}
333b877906bSopenharmony_ci
334b877906bSopenharmony_ci// Window procedure for the hidden helper window
335b877906bSopenharmony_ci//
336b877906bSopenharmony_cistatic LRESULT CALLBACK helperWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
337b877906bSopenharmony_ci{
338b877906bSopenharmony_ci    switch (uMsg)
339b877906bSopenharmony_ci    {
340b877906bSopenharmony_ci        case WM_DISPLAYCHANGE:
341b877906bSopenharmony_ci            _glfwPollMonitorsWin32();
342b877906bSopenharmony_ci            break;
343b877906bSopenharmony_ci
344b877906bSopenharmony_ci        case WM_DEVICECHANGE:
345b877906bSopenharmony_ci        {
346b877906bSopenharmony_ci            if (!_glfw.joysticksInitialized)
347b877906bSopenharmony_ci                break;
348b877906bSopenharmony_ci
349b877906bSopenharmony_ci            if (wParam == DBT_DEVICEARRIVAL)
350b877906bSopenharmony_ci            {
351b877906bSopenharmony_ci                DEV_BROADCAST_HDR* dbh = (DEV_BROADCAST_HDR*) lParam;
352b877906bSopenharmony_ci                if (dbh && dbh->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE)
353b877906bSopenharmony_ci                    _glfwDetectJoystickConnectionWin32();
354b877906bSopenharmony_ci            }
355b877906bSopenharmony_ci            else if (wParam == DBT_DEVICEREMOVECOMPLETE)
356b877906bSopenharmony_ci            {
357b877906bSopenharmony_ci                DEV_BROADCAST_HDR* dbh = (DEV_BROADCAST_HDR*) lParam;
358b877906bSopenharmony_ci                if (dbh && dbh->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE)
359b877906bSopenharmony_ci                    _glfwDetectJoystickDisconnectionWin32();
360b877906bSopenharmony_ci            }
361b877906bSopenharmony_ci
362b877906bSopenharmony_ci            break;
363b877906bSopenharmony_ci        }
364b877906bSopenharmony_ci    }
365b877906bSopenharmony_ci
366b877906bSopenharmony_ci    return DefWindowProcW(hWnd, uMsg, wParam, lParam);
367b877906bSopenharmony_ci}
368b877906bSopenharmony_ci
369b877906bSopenharmony_ci// Creates a dummy window for behind-the-scenes work
370b877906bSopenharmony_ci//
371b877906bSopenharmony_cistatic GLFWbool createHelperWindow(void)
372b877906bSopenharmony_ci{
373b877906bSopenharmony_ci    MSG msg;
374b877906bSopenharmony_ci    WNDCLASSEXW wc = { sizeof(wc) };
375b877906bSopenharmony_ci
376b877906bSopenharmony_ci    wc.style         = CS_OWNDC;
377b877906bSopenharmony_ci    wc.lpfnWndProc   = (WNDPROC) helperWindowProc;
378b877906bSopenharmony_ci    wc.hInstance     = _glfw.win32.instance;
379b877906bSopenharmony_ci    wc.lpszClassName = L"GLFW3 Helper";
380b877906bSopenharmony_ci
381b877906bSopenharmony_ci    _glfw.win32.helperWindowClass = RegisterClassExW(&wc);
382b877906bSopenharmony_ci    if (!_glfw.win32.helperWindowClass)
383b877906bSopenharmony_ci    {
384b877906bSopenharmony_ci        _glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
385b877906bSopenharmony_ci                             "Win32: Failed to register helper window class");
386b877906bSopenharmony_ci        return GLFW_FALSE;
387b877906bSopenharmony_ci    }
388b877906bSopenharmony_ci
389b877906bSopenharmony_ci    _glfw.win32.helperWindowHandle =
390b877906bSopenharmony_ci        CreateWindowExW(WS_EX_OVERLAPPEDWINDOW,
391b877906bSopenharmony_ci                        MAKEINTATOM(_glfw.win32.helperWindowClass),
392b877906bSopenharmony_ci                        L"GLFW message window",
393b877906bSopenharmony_ci                        WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
394b877906bSopenharmony_ci                        0, 0, 1, 1,
395b877906bSopenharmony_ci                        NULL, NULL,
396b877906bSopenharmony_ci                        _glfw.win32.instance,
397b877906bSopenharmony_ci                        NULL);
398b877906bSopenharmony_ci
399b877906bSopenharmony_ci    if (!_glfw.win32.helperWindowHandle)
400b877906bSopenharmony_ci    {
401b877906bSopenharmony_ci        _glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
402b877906bSopenharmony_ci                             "Win32: Failed to create helper window");
403b877906bSopenharmony_ci        return GLFW_FALSE;
404b877906bSopenharmony_ci    }
405b877906bSopenharmony_ci
406b877906bSopenharmony_ci    // HACK: The command to the first ShowWindow call is ignored if the parent
407b877906bSopenharmony_ci    //       process passed along a STARTUPINFO, so clear that with a no-op call
408b877906bSopenharmony_ci    ShowWindow(_glfw.win32.helperWindowHandle, SW_HIDE);
409b877906bSopenharmony_ci
410b877906bSopenharmony_ci    // Register for HID device notifications
411b877906bSopenharmony_ci    {
412b877906bSopenharmony_ci        DEV_BROADCAST_DEVICEINTERFACE_W dbi;
413b877906bSopenharmony_ci        ZeroMemory(&dbi, sizeof(dbi));
414b877906bSopenharmony_ci        dbi.dbcc_size = sizeof(dbi);
415b877906bSopenharmony_ci        dbi.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
416b877906bSopenharmony_ci        dbi.dbcc_classguid = GUID_DEVINTERFACE_HID;
417b877906bSopenharmony_ci
418b877906bSopenharmony_ci        _glfw.win32.deviceNotificationHandle =
419b877906bSopenharmony_ci            RegisterDeviceNotificationW(_glfw.win32.helperWindowHandle,
420b877906bSopenharmony_ci                                        (DEV_BROADCAST_HDR*) &dbi,
421b877906bSopenharmony_ci                                        DEVICE_NOTIFY_WINDOW_HANDLE);
422b877906bSopenharmony_ci    }
423b877906bSopenharmony_ci
424b877906bSopenharmony_ci    while (PeekMessageW(&msg, _glfw.win32.helperWindowHandle, 0, 0, PM_REMOVE))
425b877906bSopenharmony_ci    {
426b877906bSopenharmony_ci        TranslateMessage(&msg);
427b877906bSopenharmony_ci        DispatchMessageW(&msg);
428b877906bSopenharmony_ci    }
429b877906bSopenharmony_ci
430b877906bSopenharmony_ci   return GLFW_TRUE;
431b877906bSopenharmony_ci}
432b877906bSopenharmony_ci
433b877906bSopenharmony_ci//////////////////////////////////////////////////////////////////////////
434b877906bSopenharmony_ci//////                       GLFW internal API                      //////
435b877906bSopenharmony_ci//////////////////////////////////////////////////////////////////////////
436b877906bSopenharmony_ci
437b877906bSopenharmony_ci// Returns a wide string version of the specified UTF-8 string
438b877906bSopenharmony_ci//
439b877906bSopenharmony_ciWCHAR* _glfwCreateWideStringFromUTF8Win32(const char* source)
440b877906bSopenharmony_ci{
441b877906bSopenharmony_ci    WCHAR* target;
442b877906bSopenharmony_ci    int count;
443b877906bSopenharmony_ci
444b877906bSopenharmony_ci    count = MultiByteToWideChar(CP_UTF8, 0, source, -1, NULL, 0);
445b877906bSopenharmony_ci    if (!count)
446b877906bSopenharmony_ci    {
447b877906bSopenharmony_ci        _glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
448b877906bSopenharmony_ci                             "Win32: Failed to convert string from UTF-8");
449b877906bSopenharmony_ci        return NULL;
450b877906bSopenharmony_ci    }
451b877906bSopenharmony_ci
452b877906bSopenharmony_ci    target = _glfw_calloc(count, sizeof(WCHAR));
453b877906bSopenharmony_ci
454b877906bSopenharmony_ci    if (!MultiByteToWideChar(CP_UTF8, 0, source, -1, target, count))
455b877906bSopenharmony_ci    {
456b877906bSopenharmony_ci        _glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
457b877906bSopenharmony_ci                             "Win32: Failed to convert string from UTF-8");
458b877906bSopenharmony_ci        _glfw_free(target);
459b877906bSopenharmony_ci        return NULL;
460b877906bSopenharmony_ci    }
461b877906bSopenharmony_ci
462b877906bSopenharmony_ci    return target;
463b877906bSopenharmony_ci}
464b877906bSopenharmony_ci
465b877906bSopenharmony_ci// Returns a UTF-8 string version of the specified wide string
466b877906bSopenharmony_ci//
467b877906bSopenharmony_cichar* _glfwCreateUTF8FromWideStringWin32(const WCHAR* source)
468b877906bSopenharmony_ci{
469b877906bSopenharmony_ci    char* target;
470b877906bSopenharmony_ci    int size;
471b877906bSopenharmony_ci
472b877906bSopenharmony_ci    size = WideCharToMultiByte(CP_UTF8, 0, source, -1, NULL, 0, NULL, NULL);
473b877906bSopenharmony_ci    if (!size)
474b877906bSopenharmony_ci    {
475b877906bSopenharmony_ci        _glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
476b877906bSopenharmony_ci                             "Win32: Failed to convert string to UTF-8");
477b877906bSopenharmony_ci        return NULL;
478b877906bSopenharmony_ci    }
479b877906bSopenharmony_ci
480b877906bSopenharmony_ci    target = _glfw_calloc(size, 1);
481b877906bSopenharmony_ci
482b877906bSopenharmony_ci    if (!WideCharToMultiByte(CP_UTF8, 0, source, -1, target, size, NULL, NULL))
483b877906bSopenharmony_ci    {
484b877906bSopenharmony_ci        _glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
485b877906bSopenharmony_ci                             "Win32: Failed to convert string to UTF-8");
486b877906bSopenharmony_ci        _glfw_free(target);
487b877906bSopenharmony_ci        return NULL;
488b877906bSopenharmony_ci    }
489b877906bSopenharmony_ci
490b877906bSopenharmony_ci    return target;
491b877906bSopenharmony_ci}
492b877906bSopenharmony_ci
493b877906bSopenharmony_ci// Reports the specified error, appending information about the last Win32 error
494b877906bSopenharmony_ci//
495b877906bSopenharmony_civoid _glfwInputErrorWin32(int error, const char* description)
496b877906bSopenharmony_ci{
497b877906bSopenharmony_ci    WCHAR buffer[_GLFW_MESSAGE_SIZE] = L"";
498b877906bSopenharmony_ci    char message[_GLFW_MESSAGE_SIZE] = "";
499b877906bSopenharmony_ci
500b877906bSopenharmony_ci    FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM |
501b877906bSopenharmony_ci                       FORMAT_MESSAGE_IGNORE_INSERTS |
502b877906bSopenharmony_ci                       FORMAT_MESSAGE_MAX_WIDTH_MASK,
503b877906bSopenharmony_ci                   NULL,
504b877906bSopenharmony_ci                   GetLastError() & 0xffff,
505b877906bSopenharmony_ci                   MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
506b877906bSopenharmony_ci                   buffer,
507b877906bSopenharmony_ci                   sizeof(buffer) / sizeof(WCHAR),
508b877906bSopenharmony_ci                   NULL);
509b877906bSopenharmony_ci    WideCharToMultiByte(CP_UTF8, 0, buffer, -1, message, sizeof(message), NULL, NULL);
510b877906bSopenharmony_ci
511b877906bSopenharmony_ci    _glfwInputError(error, "%s: %s", description, message);
512b877906bSopenharmony_ci}
513b877906bSopenharmony_ci
514b877906bSopenharmony_ci// Updates key names according to the current keyboard layout
515b877906bSopenharmony_ci//
516b877906bSopenharmony_civoid _glfwUpdateKeyNamesWin32(void)
517b877906bSopenharmony_ci{
518b877906bSopenharmony_ci    int key;
519b877906bSopenharmony_ci    BYTE state[256] = {0};
520b877906bSopenharmony_ci
521b877906bSopenharmony_ci    memset(_glfw.win32.keynames, 0, sizeof(_glfw.win32.keynames));
522b877906bSopenharmony_ci
523b877906bSopenharmony_ci    for (key = GLFW_KEY_SPACE;  key <= GLFW_KEY_LAST;  key++)
524b877906bSopenharmony_ci    {
525b877906bSopenharmony_ci        UINT vk;
526b877906bSopenharmony_ci        int scancode, length;
527b877906bSopenharmony_ci        WCHAR chars[16];
528b877906bSopenharmony_ci
529b877906bSopenharmony_ci        scancode = _glfw.win32.scancodes[key];
530b877906bSopenharmony_ci        if (scancode == -1)
531b877906bSopenharmony_ci            continue;
532b877906bSopenharmony_ci
533b877906bSopenharmony_ci        if (key >= GLFW_KEY_KP_0 && key <= GLFW_KEY_KP_ADD)
534b877906bSopenharmony_ci        {
535b877906bSopenharmony_ci            const UINT vks[] = {
536b877906bSopenharmony_ci                VK_NUMPAD0,  VK_NUMPAD1,  VK_NUMPAD2, VK_NUMPAD3,
537b877906bSopenharmony_ci                VK_NUMPAD4,  VK_NUMPAD5,  VK_NUMPAD6, VK_NUMPAD7,
538b877906bSopenharmony_ci                VK_NUMPAD8,  VK_NUMPAD9,  VK_DECIMAL, VK_DIVIDE,
539b877906bSopenharmony_ci                VK_MULTIPLY, VK_SUBTRACT, VK_ADD
540b877906bSopenharmony_ci            };
541b877906bSopenharmony_ci
542b877906bSopenharmony_ci            vk = vks[key - GLFW_KEY_KP_0];
543b877906bSopenharmony_ci        }
544b877906bSopenharmony_ci        else
545b877906bSopenharmony_ci            vk = MapVirtualKeyW(scancode, MAPVK_VSC_TO_VK);
546b877906bSopenharmony_ci
547b877906bSopenharmony_ci        length = ToUnicode(vk, scancode, state,
548b877906bSopenharmony_ci                           chars, sizeof(chars) / sizeof(WCHAR),
549b877906bSopenharmony_ci                           0);
550b877906bSopenharmony_ci
551b877906bSopenharmony_ci        if (length == -1)
552b877906bSopenharmony_ci        {
553b877906bSopenharmony_ci            // This is a dead key, so we need a second simulated key press
554b877906bSopenharmony_ci            // to make it output its own character (usually a diacritic)
555b877906bSopenharmony_ci            length = ToUnicode(vk, scancode, state,
556b877906bSopenharmony_ci                               chars, sizeof(chars) / sizeof(WCHAR),
557b877906bSopenharmony_ci                               0);
558b877906bSopenharmony_ci        }
559b877906bSopenharmony_ci
560b877906bSopenharmony_ci        if (length < 1)
561b877906bSopenharmony_ci            continue;
562b877906bSopenharmony_ci
563b877906bSopenharmony_ci        WideCharToMultiByte(CP_UTF8, 0, chars, 1,
564b877906bSopenharmony_ci                            _glfw.win32.keynames[key],
565b877906bSopenharmony_ci                            sizeof(_glfw.win32.keynames[key]),
566b877906bSopenharmony_ci                            NULL, NULL);
567b877906bSopenharmony_ci    }
568b877906bSopenharmony_ci}
569b877906bSopenharmony_ci
570b877906bSopenharmony_ci// Replacement for IsWindowsVersionOrGreater, as we cannot rely on the
571b877906bSopenharmony_ci// application having a correct embedded manifest
572b877906bSopenharmony_ci//
573b877906bSopenharmony_ciBOOL _glfwIsWindowsVersionOrGreaterWin32(WORD major, WORD minor, WORD sp)
574b877906bSopenharmony_ci{
575b877906bSopenharmony_ci    OSVERSIONINFOEXW osvi = { sizeof(osvi), major, minor, 0, 0, {0}, sp };
576b877906bSopenharmony_ci    DWORD mask = VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR;
577b877906bSopenharmony_ci    ULONGLONG cond = VerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL);
578b877906bSopenharmony_ci    cond = VerSetConditionMask(cond, VER_MINORVERSION, VER_GREATER_EQUAL);
579b877906bSopenharmony_ci    cond = VerSetConditionMask(cond, VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL);
580b877906bSopenharmony_ci    // HACK: Use RtlVerifyVersionInfo instead of VerifyVersionInfoW as the
581b877906bSopenharmony_ci    //       latter lies unless the user knew to embed a non-default manifest
582b877906bSopenharmony_ci    //       announcing support for Windows 10 via supportedOS GUID
583b877906bSopenharmony_ci    return RtlVerifyVersionInfo(&osvi, mask, cond) == 0;
584b877906bSopenharmony_ci}
585b877906bSopenharmony_ci
586b877906bSopenharmony_ci// Checks whether we are on at least the specified build of Windows 10
587b877906bSopenharmony_ci//
588b877906bSopenharmony_ciBOOL _glfwIsWindows10BuildOrGreaterWin32(WORD build)
589b877906bSopenharmony_ci{
590b877906bSopenharmony_ci    OSVERSIONINFOEXW osvi = { sizeof(osvi), 10, 0, build };
591b877906bSopenharmony_ci    DWORD mask = VER_MAJORVERSION | VER_MINORVERSION | VER_BUILDNUMBER;
592b877906bSopenharmony_ci    ULONGLONG cond = VerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL);
593b877906bSopenharmony_ci    cond = VerSetConditionMask(cond, VER_MINORVERSION, VER_GREATER_EQUAL);
594b877906bSopenharmony_ci    cond = VerSetConditionMask(cond, VER_BUILDNUMBER, VER_GREATER_EQUAL);
595b877906bSopenharmony_ci    // HACK: Use RtlVerifyVersionInfo instead of VerifyVersionInfoW as the
596b877906bSopenharmony_ci    //       latter lies unless the user knew to embed a non-default manifest
597b877906bSopenharmony_ci    //       announcing support for Windows 10 via supportedOS GUID
598b877906bSopenharmony_ci    return RtlVerifyVersionInfo(&osvi, mask, cond) == 0;
599b877906bSopenharmony_ci}
600b877906bSopenharmony_ci
601b877906bSopenharmony_ciGLFWbool _glfwConnectWin32(int platformID, _GLFWplatform* platform)
602b877906bSopenharmony_ci{
603b877906bSopenharmony_ci    const _GLFWplatform win32 =
604b877906bSopenharmony_ci    {
605b877906bSopenharmony_ci        .platformID = GLFW_PLATFORM_WIN32,
606b877906bSopenharmony_ci        .init = _glfwInitWin32,
607b877906bSopenharmony_ci        .terminate = _glfwTerminateWin32,
608b877906bSopenharmony_ci        .getCursorPos = _glfwGetCursorPosWin32,
609b877906bSopenharmony_ci        .setCursorPos = _glfwSetCursorPosWin32,
610b877906bSopenharmony_ci        .setCursorMode = _glfwSetCursorModeWin32,
611b877906bSopenharmony_ci        .setRawMouseMotion = _glfwSetRawMouseMotionWin32,
612b877906bSopenharmony_ci        .rawMouseMotionSupported = _glfwRawMouseMotionSupportedWin32,
613b877906bSopenharmony_ci        .createCursor = _glfwCreateCursorWin32,
614b877906bSopenharmony_ci        .createStandardCursor = _glfwCreateStandardCursorWin32,
615b877906bSopenharmony_ci        .destroyCursor = _glfwDestroyCursorWin32,
616b877906bSopenharmony_ci        .setCursor = _glfwSetCursorWin32,
617b877906bSopenharmony_ci        .getScancodeName = _glfwGetScancodeNameWin32,
618b877906bSopenharmony_ci        .getKeyScancode = _glfwGetKeyScancodeWin32,
619b877906bSopenharmony_ci        .setClipboardString = _glfwSetClipboardStringWin32,
620b877906bSopenharmony_ci        .getClipboardString = _glfwGetClipboardStringWin32,
621b877906bSopenharmony_ci        .initJoysticks = _glfwInitJoysticksWin32,
622b877906bSopenharmony_ci        .terminateJoysticks = _glfwTerminateJoysticksWin32,
623b877906bSopenharmony_ci        .pollJoystick = _glfwPollJoystickWin32,
624b877906bSopenharmony_ci        .getMappingName = _glfwGetMappingNameWin32,
625b877906bSopenharmony_ci        .updateGamepadGUID = _glfwUpdateGamepadGUIDWin32,
626b877906bSopenharmony_ci        .freeMonitor = _glfwFreeMonitorWin32,
627b877906bSopenharmony_ci        .getMonitorPos = _glfwGetMonitorPosWin32,
628b877906bSopenharmony_ci        .getMonitorContentScale = _glfwGetMonitorContentScaleWin32,
629b877906bSopenharmony_ci        .getMonitorWorkarea = _glfwGetMonitorWorkareaWin32,
630b877906bSopenharmony_ci        .getVideoModes = _glfwGetVideoModesWin32,
631b877906bSopenharmony_ci        .getVideoMode = _glfwGetVideoModeWin32,
632b877906bSopenharmony_ci        .getGammaRamp = _glfwGetGammaRampWin32,
633b877906bSopenharmony_ci        .setGammaRamp = _glfwSetGammaRampWin32,
634b877906bSopenharmony_ci        .createWindow = _glfwCreateWindowWin32,
635b877906bSopenharmony_ci        .destroyWindow = _glfwDestroyWindowWin32,
636b877906bSopenharmony_ci        .setWindowTitle = _glfwSetWindowTitleWin32,
637b877906bSopenharmony_ci        .setWindowIcon = _glfwSetWindowIconWin32,
638b877906bSopenharmony_ci        .getWindowPos = _glfwGetWindowPosWin32,
639b877906bSopenharmony_ci        .setWindowPos = _glfwSetWindowPosWin32,
640b877906bSopenharmony_ci        .getWindowSize = _glfwGetWindowSizeWin32,
641b877906bSopenharmony_ci        .setWindowSize = _glfwSetWindowSizeWin32,
642b877906bSopenharmony_ci        .setWindowSizeLimits = _glfwSetWindowSizeLimitsWin32,
643b877906bSopenharmony_ci        .setWindowAspectRatio = _glfwSetWindowAspectRatioWin32,
644b877906bSopenharmony_ci        .getFramebufferSize = _glfwGetFramebufferSizeWin32,
645b877906bSopenharmony_ci        .getWindowFrameSize = _glfwGetWindowFrameSizeWin32,
646b877906bSopenharmony_ci        .getWindowContentScale = _glfwGetWindowContentScaleWin32,
647b877906bSopenharmony_ci        .iconifyWindow = _glfwIconifyWindowWin32,
648b877906bSopenharmony_ci        .restoreWindow = _glfwRestoreWindowWin32,
649b877906bSopenharmony_ci        .maximizeWindow = _glfwMaximizeWindowWin32,
650b877906bSopenharmony_ci        .showWindow = _glfwShowWindowWin32,
651b877906bSopenharmony_ci        .hideWindow = _glfwHideWindowWin32,
652b877906bSopenharmony_ci        .requestWindowAttention = _glfwRequestWindowAttentionWin32,
653b877906bSopenharmony_ci        .focusWindow = _glfwFocusWindowWin32,
654b877906bSopenharmony_ci        .setWindowMonitor = _glfwSetWindowMonitorWin32,
655b877906bSopenharmony_ci        .windowFocused = _glfwWindowFocusedWin32,
656b877906bSopenharmony_ci        .windowIconified = _glfwWindowIconifiedWin32,
657b877906bSopenharmony_ci        .windowVisible = _glfwWindowVisibleWin32,
658b877906bSopenharmony_ci        .windowMaximized = _glfwWindowMaximizedWin32,
659b877906bSopenharmony_ci        .windowHovered = _glfwWindowHoveredWin32,
660b877906bSopenharmony_ci        .framebufferTransparent = _glfwFramebufferTransparentWin32,
661b877906bSopenharmony_ci        .getWindowOpacity = _glfwGetWindowOpacityWin32,
662b877906bSopenharmony_ci        .setWindowResizable = _glfwSetWindowResizableWin32,
663b877906bSopenharmony_ci        .setWindowDecorated = _glfwSetWindowDecoratedWin32,
664b877906bSopenharmony_ci        .setWindowFloating = _glfwSetWindowFloatingWin32,
665b877906bSopenharmony_ci        .setWindowOpacity = _glfwSetWindowOpacityWin32,
666b877906bSopenharmony_ci        .setWindowMousePassthrough = _glfwSetWindowMousePassthroughWin32,
667b877906bSopenharmony_ci        .pollEvents = _glfwPollEventsWin32,
668b877906bSopenharmony_ci        .waitEvents = _glfwWaitEventsWin32,
669b877906bSopenharmony_ci        .waitEventsTimeout = _glfwWaitEventsTimeoutWin32,
670b877906bSopenharmony_ci        .postEmptyEvent = _glfwPostEmptyEventWin32,
671b877906bSopenharmony_ci        .getEGLPlatform = _glfwGetEGLPlatformWin32,
672b877906bSopenharmony_ci        .getEGLNativeDisplay = _glfwGetEGLNativeDisplayWin32,
673b877906bSopenharmony_ci        .getEGLNativeWindow = _glfwGetEGLNativeWindowWin32,
674b877906bSopenharmony_ci        .getRequiredInstanceExtensions = _glfwGetRequiredInstanceExtensionsWin32,
675b877906bSopenharmony_ci        .getPhysicalDevicePresentationSupport = _glfwGetPhysicalDevicePresentationSupportWin32,
676b877906bSopenharmony_ci        .createWindowSurface = _glfwCreateWindowSurfaceWin32
677b877906bSopenharmony_ci    };
678b877906bSopenharmony_ci
679b877906bSopenharmony_ci    *platform = win32;
680b877906bSopenharmony_ci    return GLFW_TRUE;
681b877906bSopenharmony_ci}
682b877906bSopenharmony_ci
683b877906bSopenharmony_ciint _glfwInitWin32(void)
684b877906bSopenharmony_ci{
685b877906bSopenharmony_ci    if (!loadLibraries())
686b877906bSopenharmony_ci        return GLFW_FALSE;
687b877906bSopenharmony_ci
688b877906bSopenharmony_ci    createKeyTables();
689b877906bSopenharmony_ci    _glfwUpdateKeyNamesWin32();
690b877906bSopenharmony_ci
691b877906bSopenharmony_ci    if (_glfwIsWindows10Version1703OrGreaterWin32())
692b877906bSopenharmony_ci        SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
693b877906bSopenharmony_ci    else if (IsWindows8Point1OrGreater())
694b877906bSopenharmony_ci        SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE);
695b877906bSopenharmony_ci    else if (IsWindowsVistaOrGreater())
696b877906bSopenharmony_ci        SetProcessDPIAware();
697b877906bSopenharmony_ci
698b877906bSopenharmony_ci    if (!createHelperWindow())
699b877906bSopenharmony_ci        return GLFW_FALSE;
700b877906bSopenharmony_ci
701b877906bSopenharmony_ci    _glfwPollMonitorsWin32();
702b877906bSopenharmony_ci    return GLFW_TRUE;
703b877906bSopenharmony_ci}
704b877906bSopenharmony_ci
705b877906bSopenharmony_civoid _glfwTerminateWin32(void)
706b877906bSopenharmony_ci{
707b877906bSopenharmony_ci    if (_glfw.win32.blankCursor)
708b877906bSopenharmony_ci        DestroyIcon((HICON) _glfw.win32.blankCursor);
709b877906bSopenharmony_ci
710b877906bSopenharmony_ci    if (_glfw.win32.deviceNotificationHandle)
711b877906bSopenharmony_ci        UnregisterDeviceNotification(_glfw.win32.deviceNotificationHandle);
712b877906bSopenharmony_ci
713b877906bSopenharmony_ci    if (_glfw.win32.helperWindowHandle)
714b877906bSopenharmony_ci        DestroyWindow(_glfw.win32.helperWindowHandle);
715b877906bSopenharmony_ci    if (_glfw.win32.helperWindowClass)
716b877906bSopenharmony_ci        UnregisterClassW(MAKEINTATOM(_glfw.win32.helperWindowClass), _glfw.win32.instance);
717b877906bSopenharmony_ci    if (_glfw.win32.mainWindowClass)
718b877906bSopenharmony_ci        UnregisterClassW(MAKEINTATOM(_glfw.win32.mainWindowClass), _glfw.win32.instance);
719b877906bSopenharmony_ci
720b877906bSopenharmony_ci    _glfw_free(_glfw.win32.clipboardString);
721b877906bSopenharmony_ci    _glfw_free(_glfw.win32.rawInput);
722b877906bSopenharmony_ci
723b877906bSopenharmony_ci    _glfwTerminateWGL();
724b877906bSopenharmony_ci    _glfwTerminateEGL();
725b877906bSopenharmony_ci    _glfwTerminateOSMesa();
726b877906bSopenharmony_ci
727b877906bSopenharmony_ci    freeLibraries();
728b877906bSopenharmony_ci}
729b877906bSopenharmony_ci
730b877906bSopenharmony_ci#endif // _GLFW_WIN32
731b877906bSopenharmony_ci
732