1 //======================================================================== 2 // GLFW 3.2 Win32 - www.glfw.org 3 //------------------------------------------------------------------------ 4 // Copyright (c) 2002-2006 Marcus Geelnard 5 // Copyright (c) 2006-2016 Camilla Berglund <elmindreda@glfw.org> 6 // 7 // This software is provided 'as-is', without any express or implied 8 // warranty. In no event will the authors be held liable for any damages 9 // arising from the use of this software. 10 // 11 // Permission is granted to anyone to use this software for any purpose, 12 // including commercial applications, and to alter it and redistribute it 13 // freely, subject to the following restrictions: 14 // 15 // 1. The origin of this software must not be misrepresented; you must not 16 // claim that you wrote the original software. If you use this software 17 // in a product, an acknowledgment in the product documentation would 18 // be appreciated but is not required. 19 // 20 // 2. Altered source versions must be plainly marked as such, and must not 21 // be misrepresented as being the original software. 22 // 23 // 3. This notice may not be removed or altered from any source 24 // distribution. 25 // 26 //======================================================================== 27 28 #ifndef _glfw3_win32_platform_h_ 29 #define _glfw3_win32_platform_h_ 30 31 // We don't need all the fancy stuff 32 #ifndef NOMINMAX 33 #define NOMINMAX 34 #endif 35 36 #ifndef VC_EXTRALEAN 37 #define VC_EXTRALEAN 38 #endif 39 40 #ifndef WIN32_LEAN_AND_MEAN 41 #define WIN32_LEAN_AND_MEAN 42 #endif 43 44 // This is a workaround for the fact that glfw3.h needs to export APIENTRY (for 45 // example to allow applications to correctly declare a GL_ARB_debug_output 46 // callback) but windows.h assumes no one will define APIENTRY before it does 47 #undef APIENTRY 48 49 // GLFW on Windows is Unicode only and does not work in MBCS mode 50 #ifndef UNICODE 51 #define UNICODE 52 #endif 53 54 // GLFW requires Windows XP or later 55 #if WINVER < 0x0501 56 #undef WINVER 57 #define WINVER 0x0501 58 #endif 59 #if _WIN32_WINNT < 0x0501 60 #undef _WIN32_WINNT 61 #define _WIN32_WINNT 0x0501 62 #endif 63 64 // GLFW uses DirectInput8 interfaces 65 #define DIRECTINPUT_VERSION 0x0800 66 67 #include <wctype.h> 68 #include <windows.h> 69 #include <mmsystem.h> 70 #include <dinput.h> 71 #include <xinput.h> 72 #include <dbt.h> 73 74 #if defined(_MSC_VER) 75 #include <malloc.h> 76 #define strdup _strdup 77 #endif 78 79 // HACK: Define macros that some windows.h variants don't 80 #ifndef WM_MOUSEHWHEEL 81 #define WM_MOUSEHWHEEL 0x020E 82 #endif 83 #ifndef WM_DWMCOMPOSITIONCHANGED 84 #define WM_DWMCOMPOSITIONCHANGED 0x031E 85 #endif 86 #ifndef WM_COPYGLOBALDATA 87 #define WM_COPYGLOBALDATA 0x0049 88 #endif 89 #ifndef WM_UNICHAR 90 #define WM_UNICHAR 0x0109 91 #endif 92 #ifndef UNICODE_NOCHAR 93 #define UNICODE_NOCHAR 0xFFFF 94 #endif 95 #ifndef WM_DPICHANGED 96 #define WM_DPICHANGED 0x02E0 97 #endif 98 #ifndef GET_XBUTTON_WPARAM 99 #define GET_XBUTTON_WPARAM(w) (HIWORD(w)) 100 #endif 101 #ifndef EDS_ROTATEDMODE 102 #define EDS_ROTATEDMODE 0x00000004 103 #endif 104 #ifndef DISPLAY_DEVICE_ACTIVE 105 #define DISPLAY_DEVICE_ACTIVE 0x00000001 106 #endif 107 108 #if WINVER < 0x0601 109 typedef struct tagCHANGEFILTERSTRUCT 110 { 111 DWORD cbSize; 112 DWORD ExtStatus; 113 114 } CHANGEFILTERSTRUCT, *PCHANGEFILTERSTRUCT; 115 #ifndef MSGFLT_ALLOW 116 #define MSGFLT_ALLOW 1 117 #endif 118 #endif /*Windows 7*/ 119 120 #ifndef DPI_ENUMS_DECLARED 121 typedef enum PROCESS_DPI_AWARENESS 122 { 123 PROCESS_DPI_UNAWARE = 0, 124 PROCESS_SYSTEM_DPI_AWARE = 1, 125 PROCESS_PER_MONITOR_DPI_AWARE = 2 126 } PROCESS_DPI_AWARENESS; 127 #endif /*DPI_ENUMS_DECLARED*/ 128 129 // HACK: Define macros that some xinput.h variants don't 130 #ifndef XINPUT_CAPS_WIRELESS 131 #define XINPUT_CAPS_WIRELESS 0x0002 132 #endif 133 #ifndef XINPUT_DEVSUBTYPE_WHEEL 134 #define XINPUT_DEVSUBTYPE_WHEEL 0x02 135 #endif 136 #ifndef XINPUT_DEVSUBTYPE_ARCADE_STICK 137 #define XINPUT_DEVSUBTYPE_ARCADE_STICK 0x03 138 #endif 139 #ifndef XINPUT_DEVSUBTYPE_FLIGHT_STICK 140 #define XINPUT_DEVSUBTYPE_FLIGHT_STICK 0x04 141 #endif 142 #ifndef XINPUT_DEVSUBTYPE_DANCE_PAD 143 #define XINPUT_DEVSUBTYPE_DANCE_PAD 0x05 144 #endif 145 #ifndef XINPUT_DEVSUBTYPE_GUITAR 146 #define XINPUT_DEVSUBTYPE_GUITAR 0x06 147 #endif 148 #ifndef XINPUT_DEVSUBTYPE_DRUM_KIT 149 #define XINPUT_DEVSUBTYPE_DRUM_KIT 0x08 150 #endif 151 #ifndef XINPUT_DEVSUBTYPE_ARCADE_PAD 152 #define XINPUT_DEVSUBTYPE_ARCADE_PAD 0x13 153 #endif 154 #ifndef XUSER_MAX_COUNT 155 #define XUSER_MAX_COUNT 4 156 #endif 157 158 // HACK: Define macros that some dinput.h variants don't 159 #ifndef DIDFT_OPTIONAL 160 #define DIDFT_OPTIONAL 0x80000000 161 #endif 162 163 // winmm.dll function pointer typedefs 164 typedef DWORD (WINAPI * TIMEGETTIME_T)(void); 165 #define _glfw_timeGetTime _glfw.win32.winmm.timeGetTime 166 167 // xinput.dll function pointer typedefs 168 typedef DWORD (WINAPI * XINPUTGETCAPABILITIES_T)(DWORD,DWORD,XINPUT_CAPABILITIES*); 169 typedef DWORD (WINAPI * XINPUTGETSTATE_T)(DWORD,XINPUT_STATE*); 170 #define _glfw_XInputGetCapabilities _glfw.win32.xinput.XInputGetCapabilities 171 #define _glfw_XInputGetState _glfw.win32.xinput.XInputGetState 172 173 // dinput8.dll function pointer typedefs 174 typedef HRESULT (WINAPI * DIRECTINPUT8CREATE_T)(HINSTANCE,DWORD,REFIID,LPVOID*,LPUNKNOWN); 175 #define _glfw_DirectInput8Create _glfw.win32.dinput8.DirectInput8Create 176 177 // user32.dll function pointer typedefs 178 typedef BOOL (WINAPI * SETPROCESSDPIAWARE_T)(void); 179 typedef BOOL (WINAPI * CHANGEWINDOWMESSAGEFILTEREX_T)(HWND,UINT,DWORD,PCHANGEFILTERSTRUCT); 180 #define _glfw_SetProcessDPIAware _glfw.win32.user32.SetProcessDPIAware 181 #define _glfw_ChangeWindowMessageFilterEx _glfw.win32.user32.ChangeWindowMessageFilterEx 182 183 // dwmapi.dll function pointer typedefs 184 typedef HRESULT (WINAPI * DWMISCOMPOSITIONENABLED_T)(BOOL*); 185 typedef HRESULT (WINAPI * DWMFLUSH_T)(VOID); 186 #define _glfw_DwmIsCompositionEnabled _glfw.win32.dwmapi.DwmIsCompositionEnabled 187 #define _glfw_DwmFlush _glfw.win32.dwmapi.DwmFlush 188 189 // shcore.dll function pointer typedefs 190 typedef HRESULT (WINAPI * SETPROCESSDPIAWARENESS_T)(PROCESS_DPI_AWARENESS); 191 #define _glfw_SetProcessDpiAwareness _glfw.win32.shcore.SetProcessDpiAwareness 192 193 typedef VkFlags VkWin32SurfaceCreateFlagsKHR; 194 195 typedef struct VkWin32SurfaceCreateInfoKHR 196 { 197 VkStructureType sType; 198 const void* pNext; 199 VkWin32SurfaceCreateFlagsKHR flags; 200 HINSTANCE hinstance; 201 HWND hwnd; 202 } VkWin32SurfaceCreateInfoKHR; 203 204 typedef VkResult (APIENTRY *PFN_vkCreateWin32SurfaceKHR)(VkInstance,const VkWin32SurfaceCreateInfoKHR*,const VkAllocationCallbacks*,VkSurfaceKHR*); 205 typedef VkBool32 (APIENTRY *PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR)(VkPhysicalDevice,uint32_t); 206 207 #include "win32_joystick.h" 208 #include "wgl_context.h" 209 #include "egl_context.h" 210 211 #define _GLFW_WNDCLASSNAME L"GLFW30" 212 213 #define _glfw_dlopen(name) LoadLibraryA(name) 214 #define _glfw_dlclose(handle) FreeLibrary((HMODULE) handle) 215 #define _glfw_dlsym(handle, name) GetProcAddress((HMODULE) handle, name) 216 217 #define _GLFW_EGL_NATIVE_WINDOW ((EGLNativeWindowType) window->win32.handle) 218 #define _GLFW_EGL_NATIVE_DISPLAY EGL_DEFAULT_DISPLAY 219 220 #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowWin32 win32 221 #define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryWin32 win32 222 #define _GLFW_PLATFORM_LIBRARY_TIME_STATE _GLFWtimeWin32 win32_time 223 #define _GLFW_PLATFORM_LIBRARY_TLS_STATE _GLFWtlsWin32 win32_tls 224 #define _GLFW_PLATFORM_MONITOR_STATE _GLFWmonitorWin32 win32 225 #define _GLFW_PLATFORM_CURSOR_STATE _GLFWcursorWin32 win32 226 227 228 // Win32-specific per-window data 229 // 230 typedef struct _GLFWwindowWin32 231 { 232 HWND handle; 233 HICON bigIcon; 234 HICON smallIcon; 235 236 GLFWbool cursorTracked; 237 GLFWbool iconified; 238 239 // The last received cursor position, regardless of source 240 int lastCursorPosX, lastCursorPosY; 241 242 } _GLFWwindowWin32; 243 244 // Win32-specific global data 245 // 246 typedef struct _GLFWlibraryWin32 247 { 248 HWND helperWindowHandle; 249 DWORD foregroundLockTimeout; 250 char* clipboardString; 251 char keyName[64]; 252 short int publicKeys[512]; 253 short int nativeKeys[GLFW_KEY_LAST + 1]; 254 // Where to place the cursor when re-enabled 255 double restoreCursorPosX, restoreCursorPosY; 256 // The window whose disabled cursor mode is active 257 _GLFWwindow* disabledCursorWindow; 258 259 struct { 260 HINSTANCE instance; 261 TIMEGETTIME_T timeGetTime; 262 } winmm; 263 264 struct { 265 HINSTANCE instance; 266 DIRECTINPUT8CREATE_T DirectInput8Create; 267 IDirectInput8W* api; 268 } dinput8; 269 270 struct { 271 HINSTANCE instance; 272 XINPUTGETCAPABILITIES_T XInputGetCapabilities; 273 XINPUTGETSTATE_T XInputGetState; 274 } xinput; 275 276 struct { 277 HINSTANCE instance; 278 SETPROCESSDPIAWARE_T SetProcessDPIAware; 279 CHANGEWINDOWMESSAGEFILTEREX_T ChangeWindowMessageFilterEx; 280 } user32; 281 282 struct { 283 HINSTANCE instance; 284 DWMISCOMPOSITIONENABLED_T DwmIsCompositionEnabled; 285 DWMFLUSH_T DwmFlush; 286 } dwmapi; 287 288 struct { 289 HINSTANCE instance; 290 SETPROCESSDPIAWARENESS_T SetProcessDpiAwareness; 291 } shcore; 292 293 } _GLFWlibraryWin32; 294 295 // Win32-specific per-monitor data 296 // 297 typedef struct _GLFWmonitorWin32 298 { 299 // This size matches the static size of DISPLAY_DEVICE.DeviceName 300 WCHAR adapterName[32]; 301 WCHAR displayName[32]; 302 char publicAdapterName[64]; 303 char publicDisplayName[64]; 304 GLFWbool modesPruned; 305 GLFWbool modeChanged; 306 307 } _GLFWmonitorWin32; 308 309 // Win32-specific per-cursor data 310 // 311 typedef struct _GLFWcursorWin32 312 { 313 HCURSOR handle; 314 315 } _GLFWcursorWin32; 316 317 // Win32-specific global timer data 318 // 319 typedef struct _GLFWtimeWin32 320 { 321 GLFWbool hasPC; 322 uint64_t frequency; 323 324 } _GLFWtimeWin32; 325 326 // Win32-specific global TLS data 327 // 328 typedef struct _GLFWtlsWin32 329 { 330 GLFWbool allocated; 331 DWORD context; 332 333 } _GLFWtlsWin32; 334 335 336 GLFWbool _glfwRegisterWindowClassWin32(void); 337 void _glfwUnregisterWindowClassWin32(void); 338 339 GLFWbool _glfwInitThreadLocalStorageWin32(void); 340 void _glfwTerminateThreadLocalStorageWin32(void); 341 342 WCHAR* _glfwCreateWideStringFromUTF8Win32(const char* source); 343 char* _glfwCreateUTF8FromWideStringWin32(const WCHAR* source); 344 345 void _glfwInitTimerWin32(void); 346 347 GLFWbool _glfwSetVideoModeWin32(_GLFWmonitor* monitor, const GLFWvidmode* desired); 348 void _glfwRestoreVideoModeWin32(_GLFWmonitor* monitor); 349 350 #endif // _glfw3_win32_platform_h_ 351