1 /// Translated from C to D 2 module glfw3.win32_platform; 3 4 extern(C): @nogc: nothrow: __gshared: 5 //======================================================================== 6 // GLFW 3.3 Win32 - www.glfw.org 7 //------------------------------------------------------------------------ 8 // Copyright (c) 2002-2006 Marcus Geelnard 9 // Copyright (c) 2006-2019 Camilla Löwy <elmindreda@glfw.org> 10 // 11 // This software is provided 'as-is', without any express or implied 12 // warranty. In no event will the authors be held liable for any damages 13 // arising from the use of this software. 14 // 15 // Permission is granted to anyone to use this software for any purpose, 16 // including commercial applications, and to alter it and redistribute it 17 // freely, subject to the following restrictions: 18 // 19 // 1. The origin of this software must not be misrepresented; you must not 20 // claim that you wrote the original software. If you use this software 21 // in a product, an acknowledgment in the product documentation would 22 // be appreciated but is not required. 23 // 24 // 2. Altered source versions must be plainly marked as such, and must not 25 // be misrepresented as being the original software. 26 // 27 // 3. This notice may not be removed or altered from any source 28 // distribution. 29 // 30 //======================================================================== 31 32 // GLFW uses DirectInput8 interfaces 33 enum DIRECTINPUT_VERSION = 0x0800; 34 35 public import core.stdc.wctype; 36 public import core.sys.windows.windows; 37 public import core.sys.windows.winuser; 38 public import glfw3.directinput8; 39 public import glfw3.xinput; 40 public import core.sys.windows.objbase; // GUID 41 public import core.sys.windows.dbt; 42 43 // TODO: make this @nogc nothrow upstream 44 @nogc nothrow extern (Windows) ULONGLONG VerSetConditionMask(ULONGLONG, DWORD, BYTE); 45 46 // HACK: Define macros that some windows.h variants don't 47 enum WM_MOUSEHWHEEL = 0x020E; 48 enum WM_DWMCOMPOSITIONCHANGED = 0x031E; 49 enum WM_COPYGLOBALDATA = 0x0049; 50 //enum UNICODE_NOCHAR = 0xFFFF; 51 enum WM_DPICHANGED = 0x02E0; 52 int GET_XBUTTON_WPARAM(ulong w) {return HIWORD(w);} 53 enum EDS_ROTATEDMODE = 0x00000004; 54 enum DISPLAY_DEVICE_ACTIVE = 0x00000001; 55 enum _WIN32_WINNT_WINBLUE = 0x0602; 56 enum _WIN32_WINNT_WIN8 = 0x0602; 57 enum WM_GETDPISCALEDSIZE = 0x02e4; 58 enum USER_DEFAULT_SCREEN_DPI = 96; 59 enum OCR_HAND = 32649; 60 61 // WINVER < 0x0601 62 version(all) { 63 struct _CHANGEFILTERSTRUCT { 64 DWORD cbSize; 65 DWORD ExtStatus; 66 } 67 alias _CHANGEFILTERSTRUCT CHANGEFILTERSTRUCT; 68 69 enum MSGFLT_ALLOW = 1; 70 } /*Windows 7*/ 71 72 // WINVER < 0x0600 73 version(all) { 74 enum DWM_BB_ENABLE = 0x00000001; 75 enum DWM_BB_BLURREGION = 0x00000002; 76 struct _DWM_BLURBEHIND { 77 DWORD dwFlags; 78 BOOL fEnable; 79 HRGN hRgnBlur; 80 BOOL fTransitionOnMaximized; 81 } 82 alias _DWM_BLURBEHIND DWM_BLURBEHIND; 83 } else { 84 //public import dwmapi; 85 } 86 87 version (all) { 88 enum PROCESS_DPI_AWARENESS { 89 PROCESS_DPI_UNAWARE = 0, 90 PROCESS_SYSTEM_DPI_AWARE = 1, 91 PROCESS_PER_MONITOR_DPI_AWARE = 2 92 } 93 enum MONITOR_DPI_TYPE { 94 MDT_EFFECTIVE_DPI = 0, 95 MDT_ANGULAR_DPI = 1, 96 MDT_RAW_DPI = 2, 97 MDT_DEFAULT = MDT_EFFECTIVE_DPI 98 } 99 100 enum DISP_CHANGE_BADDUALVIEW = -6; 101 } 102 103 enum DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 = cast(HANDLE) -4; 104 105 // HACK: Define versionhelpers.h functions manually as MinGW lacks the header 106 static { 107 private enum _WIN32_WINNT_WINXP = 0x0501; 108 private enum _WIN32_WINNT_VISTA = 0x0600; 109 private enum _WIN32_WINNT_WIN7 = 0x0601; 110 111 // note: already in core.sys.windows.winver, but not @nogc 112 bool IsWindowsXPOrGreater() { 113 return cast(bool) _glfwIsWindowsVersionOrGreaterWin32(HIBYTE(_WIN32_WINNT_WINXP), 114 LOBYTE(_WIN32_WINNT_WINXP), 0); 115 } 116 bool IsWindowsVistaOrGreater() { 117 return cast(bool) _glfwIsWindowsVersionOrGreaterWin32(HIBYTE(_WIN32_WINNT_VISTA), 118 LOBYTE(_WIN32_WINNT_VISTA), 0); 119 } 120 bool IsWindows7OrGreater() { 121 return cast(bool) _glfwIsWindowsVersionOrGreaterWin32(HIBYTE(_WIN32_WINNT_WIN7), 122 LOBYTE(_WIN32_WINNT_WIN7), 0); 123 } 124 bool IsWindows8OrGreater() { 125 return cast(bool) _glfwIsWindowsVersionOrGreaterWin32(HIBYTE(_WIN32_WINNT_WIN8), 126 LOBYTE(_WIN32_WINNT_WIN8), 0); 127 } 128 bool IsWindows8Point1OrGreater() { 129 return cast(bool) _glfwIsWindowsVersionOrGreaterWin32(HIBYTE(_WIN32_WINNT_WINBLUE), 130 LOBYTE(_WIN32_WINNT_WINBLUE), 0); 131 } 132 133 bool _glfwIsWindows10AnniversaryUpdateOrGreaterWin32() { 134 return cast(bool) _glfwIsWindows10BuildOrGreaterWin32(14393); 135 } 136 bool _glfwIsWindows10CreatorsUpdateOrGreaterWin32() { 137 return cast(bool) _glfwIsWindows10BuildOrGreaterWin32(15063); 138 } 139 140 auto GET_X_LPARAM(T)(T lp) { 141 import core.sys.windows.windef : LOWORD; 142 return (cast(int)cast(short)LOWORD(lp)); 143 } 144 auto GET_Y_LPARAM(T)(T lp) { 145 import core.sys.windows.windef : HIWORD; 146 return (cast(int)cast(short)HIWORD(lp)); 147 } 148 } 149 150 // HACK: Define macros that some xinput.h variants don't 151 enum XINPUT_CAPS_WIRELESS = 0x0002; 152 enum XINPUT_DEVSUBTYPE_WHEEL = 0x02; 153 enum XINPUT_DEVSUBTYPE_ARCADE_STICK = 0x03; 154 enum XINPUT_DEVSUBTYPE_FLIGHT_STICK = 0x04; 155 enum XINPUT_DEVSUBTYPE_DANCE_PAD = 0x05; 156 enum XINPUT_DEVSUBTYPE_GUITAR = 0x06; 157 enum XINPUT_DEVSUBTYPE_DRUM_KIT = 0x08; 158 enum XINPUT_DEVSUBTYPE_ARCADE_PAD = 0x13; 159 enum XUSER_MAX_COUNT = 4; 160 161 // HACK: Define macros that some dinput.h variants don't 162 enum DIDFT_OPTIONAL = 0x80000000; 163 164 extern(Windows) { 165 // winmm.dll function pointer typedefs 166 alias PFN_timeGetTime = DWORD function(); 167 enum timeGetTime = "_glfw.win32.winmm.GetTime"; 168 169 // xinput.dll function pointer typedefs 170 alias PFN_XInputGetCapabilities = DWORD function(DWORD,DWORD,XINPUT_CAPABILITIES*); 171 alias PFN_XInputGetState = DWORD function(DWORD,XINPUT_STATE*); 172 enum XInputGetCapabilities = "_glfw.win32.xinput.GetCapabilities"; 173 enum XInputGetState = "_glfw.win32.xinput.GetState"; 174 175 // dinput8.dll function pointer typedefs 176 alias PFN_DirectInput8Create = HRESULT function(HINSTANCE,DWORD,REFIID,LPVOID*,LPUNKNOWN); 177 enum DirectInput8Create = "_glfw.win32.dinput8.Create"; 178 179 // user32.dll function pointer typedefs 180 alias PFN_SetProcessDPIAware = BOOL function(); 181 alias PFN_ChangeWindowMessageFilterEx = BOOL function(HWND,UINT,DWORD,CHANGEFILTERSTRUCT*); 182 alias PFN_EnableNonClientDpiScaling = BOOL function(HWND); 183 alias PFN_SetProcessDpiAwarenessContext = BOOL function(HANDLE); 184 alias PFN_GetDpiForWindow = UINT function(HWND); 185 alias PFN_AdjustWindowRectExForDpi = BOOL function(LPRECT,DWORD,BOOL,DWORD,UINT); 186 enum SetProcessDPIAware = "_glfw.win32.user32.SetProcessDPIAware_"; 187 enum ChangeWindowMessageFilterEx = "_glfw.win32.user32.ChangeWindowMessageFilterEx_"; 188 enum EnableNonClientDpiScaling = "_glfw.win32.user32.EnableNonClientDpiScaling_"; 189 enum SetProcessDpiAwarenessContext = "_glfw.win32.user32.SetProcessDpiAwarenessContext_"; 190 enum GetDpiForWindow = "_glfw.win32.user32.GetDpiForWindow_"; 191 enum AdjustWindowRectExForDpi = "_glfw.win32.user32.AdjustWindowRectExForDpi_"; 192 193 // dwmapi.dll function pointer typedefs 194 alias PFN_DwmIsCompositionEnabled = HRESULT function(BOOL*); 195 alias PFN_DwmFlush = HRESULT function(); 196 alias PFN_DwmEnableBlurBehindWindow = HRESULT function(HWND, const(DWM_BLURBEHIND)*); 197 enum DwmIsCompositionEnabled = "_glfw.win32.dwmapi.IsCompositionEnabled"; 198 enum DwmFlush = "_glfw.win32.dwmapi.Flush"; 199 enum DwmEnableBlurBehindWindow = "_glfw.win32.dwmapi.EnableBlurBehindWindow"; 200 201 // shcore.dll function pointer typedefs 202 alias PFN_SetProcessDpiAwareness = HRESULT function(PROCESS_DPI_AWARENESS); 203 alias PFN_GetDpiForMonitor = HRESULT function(HMONITOR,MONITOR_DPI_TYPE,UINT*,UINT*); 204 enum SetProcessDpiAwareness = "_glfw.win32.shcore.SetProcessDpiAwareness_"; 205 enum GetDpiForMonitor = "_glfw.win32.shcore.GetDpiForMonitor_"; 206 207 // ntdll.dll function pointer typedefs 208 alias PFN_RtlVerifyVersionInfo = LONG function(OSVERSIONINFOEXW*,ULONG,ULONGLONG); 209 alias RtlVerifyVersionInfo = _glfw.win32.ntdll.RtlVerifyVersionInfo_; 210 } 211 212 alias VkFlags VkWin32SurfaceCreateFlagsKHR; 213 214 struct VkWin32SurfaceCreateInfoKHR { 215 VkStructureType sType; 216 const(void)* pNext; 217 VkWin32SurfaceCreateFlagsKHR flags; 218 HINSTANCE hinstance; 219 HWND hwnd; 220 } 221 222 alias PFN_vkCreateWin32SurfaceKHR = VkResult function(VkInstance, const(VkWin32SurfaceCreateInfoKHR)*, const(VkAllocationCallbacks)*, VkSurfaceKHR*); 223 alias PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR = VkBool32 function(VkPhysicalDevice, uint32_t); 224 225 public import glfw3.win32_joystick; 226 public import glfw3.wgl_context; 227 public import glfw3.egl_context; 228 public import glfw3.osmesa_context; 229 230 enum _GLFW_WNDCLASSNAME = "GLFW30"w; 231 232 auto _glfw_dlopen(const(char)* name) { return LoadLibraryA(name); } 233 auto _glfw_dlclose(void* handle) { return FreeLibrary(cast(HMODULE) handle); } 234 auto _glfw_dlsym(void* handle, const(char)* name) { return GetProcAddress(cast(HMODULE) handle, name);} 235 236 enum _GLFW_EGL_NATIVE_WINDOW = "cast(EGLNativeWindowType) window.win32.handle"; 237 enum _GLFW_EGL_NATIVE_DISPLAY = EGL_DEFAULT_DISPLAY; 238 239 mixin template _GLFW_PLATFORM_WINDOW_STATE() { _GLFWwindowWin32 win32;} 240 mixin template _GLFW_PLATFORM_LIBRARY_WINDOW_STATE() {_GLFWlibraryWin32 win32;} 241 mixin template _GLFW_PLATFORM_LIBRARY_TIMER_STATE() { _GLFWtimerWin32 win32;} 242 mixin template _GLFW_PLATFORM_MONITOR_STATE() { _GLFWmonitorWin32 win32;} 243 mixin template _GLFW_PLATFORM_CURSOR_STATE() { _GLFWcursorWin32 win32;} 244 mixin template _GLFW_PLATFORM_TLS_STATE() { _GLFWtlsWin32 win32;} 245 mixin template _GLFW_PLATFORM_MUTEX_STATE() { _GLFWmutexWin32 win32;} 246 247 // Win32-specific per-window data 248 // 249 struct _GLFWwindowWin32 { 250 HWND handle; 251 HICON bigIcon; 252 HICON smallIcon; 253 254 GLFWbool cursorTracked; 255 GLFWbool frameAction; 256 GLFWbool iconified; 257 GLFWbool maximized; 258 // Whether to enable framebuffer transparency on DWM 259 GLFWbool transparent; 260 GLFWbool scaleToMonitor; 261 262 // The last received cursor position, regardless of source 263 int lastCursorPosX;int lastCursorPosY; 264 265 }/+alias _GLFWwindowWin32 _GLFWwindowWin32;+/ 266 267 // Win32-specific global data 268 // 269 struct _GLFWlibraryWin32 { 270 import core.sys.windows.winuser: HDEVNOTIFY; 271 HWND helperWindowHandle; 272 HDEVNOTIFY deviceNotificationHandle; 273 DWORD foregroundLockTimeout; 274 int acquiredMonitorCount; 275 char* clipboardString; 276 int[512] keycodes; 277 int[GLFW_KEY_LAST + 1] scancodes; 278 char[5][GLFW_KEY_LAST + 1] keynames; 279 // Where to place the cursor when re-enabled 280 double restoreCursorPosX;double restoreCursorPosY; 281 // The window whose disabled cursor mode is active 282 _GLFWwindow* disabledCursorWindow; 283 RAWINPUT* rawInput; 284 int rawInputSize; 285 UINT mouseTrailSize; 286 287 struct _Winmm { 288 HINSTANCE instance; 289 PFN_timeGetTime GetTime; 290 }_Winmm winmm; 291 292 struct _Dinput8 { 293 HINSTANCE instance; 294 PFN_DirectInput8Create Create; 295 IDirectInput8 api; 296 }_Dinput8 dinput8; 297 298 struct _Xinput { 299 HINSTANCE instance; 300 PFN_XInputGetCapabilities GetCapabilities; 301 PFN_XInputGetState GetState; 302 }_Xinput xinput; 303 304 struct _User32 { 305 HINSTANCE instance; 306 PFN_SetProcessDPIAware SetProcessDPIAware_; 307 PFN_ChangeWindowMessageFilterEx ChangeWindowMessageFilterEx_; 308 PFN_EnableNonClientDpiScaling EnableNonClientDpiScaling_; 309 PFN_SetProcessDpiAwarenessContext SetProcessDpiAwarenessContext_; 310 PFN_GetDpiForWindow GetDpiForWindow_; 311 PFN_AdjustWindowRectExForDpi AdjustWindowRectExForDpi_; 312 }_User32 user32; 313 314 struct _Dwmapi { 315 HINSTANCE instance; 316 PFN_DwmIsCompositionEnabled IsCompositionEnabled; 317 PFN_DwmFlush Flush; 318 PFN_DwmEnableBlurBehindWindow EnableBlurBehindWindow; 319 }_Dwmapi dwmapi; 320 321 struct _Shcore { 322 HINSTANCE instance; 323 PFN_SetProcessDpiAwareness SetProcessDpiAwareness_; 324 PFN_GetDpiForMonitor GetDpiForMonitor_; 325 }_Shcore shcore; 326 327 struct _Ntdll { 328 HINSTANCE instance; 329 PFN_RtlVerifyVersionInfo RtlVerifyVersionInfo_; 330 }_Ntdll ntdll; 331 332 }/+alias _GLFWlibraryWin32 _GLFWlibraryWin32;+/ 333 334 // Win32-specific per-monitor data 335 // 336 struct _GLFWmonitorWin32 { 337 HMONITOR handle; 338 // This size matches the static size of DISPLAY_DEVICE.DeviceName 339 WCHAR[32] adapterName; 340 WCHAR[32] displayName; 341 char[32] publicAdapterName; 342 char[32] publicDisplayName; 343 GLFWbool modesPruned; 344 GLFWbool modeChanged; 345 346 }/+alias _GLFWmonitorWin32 _GLFWmonitorWin32;+/ 347 348 // Win32-specific per-cursor data 349 // 350 struct _GLFWcursorWin32 { 351 HCURSOR handle; 352 353 }/+alias _GLFWcursorWin32 _GLFWcursorWin32;+/ 354 355 // Win32-specific global timer data 356 // 357 struct _GLFWtimerWin32 { 358 GLFWbool hasPC; 359 ulong frequency; 360 361 }/+alias _GLFWtimerWin32 _GLFWtimerWin32;+/ 362 363 // Win32-specific thread local storage data 364 // 365 struct _GLFWtlsWin32 { 366 GLFWbool allocated; 367 DWORD index; 368 369 }/+alias _GLFWtlsWin32 _GLFWtlsWin32;+/ 370 371 // Win32-specific mutex data 372 // 373 struct _GLFWmutexWin32 { 374 GLFWbool allocated; 375 CRITICAL_SECTION section; 376 377 }/+alias _GLFWmutexWin32 _GLFWmutexWin32;+/ 378 379 380 GLFWbool _glfwRegisterWindowClassWin32(); 381 void _glfwUnregisterWindowClassWin32(); 382 383 wchar* _glfwCreateWideStringFromUTF8Win32(const(char)* source); 384 char* _glfwCreateUTF8FromWideStringWin32(const(wchar)* source); 385 BOOL _glfwIsWindowsVersionOrGreaterWin32(WORD major, WORD minor, WORD sp); 386 BOOL _glfwIsWindows10BuildOrGreaterWin32(WORD build); 387 void _glfwInputErrorWin32(int error, const(char)* description); 388 void _glfwUpdateKeyNamesWin32(); 389 390 void _glfwInitTimerWin32(); 391 392 void _glfwPollMonitorsWin32(); 393 void _glfwSetVideoModeWin32(_GLFWmonitor* monitor, const(GLFWvidmode)* desired); 394 void _glfwRestoreVideoModeWin32(_GLFWmonitor* monitor); 395 void _glfwGetMonitorContentScaleWin32(HMONITOR handle, float* xscale, float* yscale);