twitchapon-anim

Basic Twitchapon Receiver/Visuals
git clone git://bsandro.tech/twitchapon-anim
Log | Files | Refs | README | LICENSE

win32_platform.h (15230B)


      1 //========================================================================
      2 // GLFW 3.3 Win32 - www.glfw.org
      3 //------------------------------------------------------------------------
      4 // Copyright (c) 2002-2006 Marcus Geelnard
      5 // Copyright (c) 2006-2019 Camilla Löwy <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 // We don't need all the fancy stuff
     29 #ifndef NOMINMAX
     30  #define NOMINMAX
     31 #endif
     32 
     33 #ifndef VC_EXTRALEAN
     34  #define VC_EXTRALEAN
     35 #endif
     36 
     37 #ifndef WIN32_LEAN_AND_MEAN
     38  #define WIN32_LEAN_AND_MEAN
     39 #endif
     40 
     41 // This is a workaround for the fact that glfw3.h needs to export APIENTRY (for
     42 // example to allow applications to correctly declare a GL_ARB_debug_output
     43 // callback) but windows.h assumes no one will define APIENTRY before it does
     44 #undef APIENTRY
     45 
     46 // GLFW on Windows is Unicode only and does not work in MBCS mode
     47 #ifndef UNICODE
     48  #define UNICODE
     49 #endif
     50 
     51 // GLFW requires Windows XP or later
     52 #if WINVER < 0x0501
     53  #undef WINVER
     54  #define WINVER 0x0501
     55 #endif
     56 #if _WIN32_WINNT < 0x0501
     57  #undef _WIN32_WINNT
     58  #define _WIN32_WINNT 0x0501
     59 #endif
     60 
     61 // GLFW uses DirectInput8 interfaces
     62 #define DIRECTINPUT_VERSION 0x0800
     63 
     64 // GLFW uses OEM cursor resources
     65 #define OEMRESOURCE
     66 
     67 #include <wctype.h>
     68 #include <windows.h>
     69 #include <dinput.h>
     70 #include <xinput.h>
     71 #include <dbt.h>
     72 
     73 // HACK: Define macros that some windows.h variants don't
     74 #ifndef WM_MOUSEHWHEEL
     75  #define WM_MOUSEHWHEEL 0x020E
     76 #endif
     77 #ifndef WM_DWMCOMPOSITIONCHANGED
     78  #define WM_DWMCOMPOSITIONCHANGED 0x031E
     79 #endif
     80 #ifndef WM_COPYGLOBALDATA
     81  #define WM_COPYGLOBALDATA 0x0049
     82 #endif
     83 #ifndef WM_UNICHAR
     84  #define WM_UNICHAR 0x0109
     85 #endif
     86 #ifndef UNICODE_NOCHAR
     87  #define UNICODE_NOCHAR 0xFFFF
     88 #endif
     89 #ifndef WM_DPICHANGED
     90  #define WM_DPICHANGED 0x02E0
     91 #endif
     92 #ifndef GET_XBUTTON_WPARAM
     93  #define GET_XBUTTON_WPARAM(w) (HIWORD(w))
     94 #endif
     95 #ifndef EDS_ROTATEDMODE
     96  #define EDS_ROTATEDMODE 0x00000004
     97 #endif
     98 #ifndef DISPLAY_DEVICE_ACTIVE
     99  #define DISPLAY_DEVICE_ACTIVE 0x00000001
    100 #endif
    101 #ifndef _WIN32_WINNT_WINBLUE
    102  #define _WIN32_WINNT_WINBLUE 0x0602
    103 #endif
    104 #ifndef _WIN32_WINNT_WIN8
    105  #define _WIN32_WINNT_WIN8 0x0602
    106 #endif
    107 #ifndef WM_GETDPISCALEDSIZE
    108  #define WM_GETDPISCALEDSIZE 0x02e4
    109 #endif
    110 #ifndef USER_DEFAULT_SCREEN_DPI
    111  #define USER_DEFAULT_SCREEN_DPI 96
    112 #endif
    113 #ifndef OCR_HAND
    114  #define OCR_HAND 32649
    115 #endif
    116 
    117 #if WINVER < 0x0601
    118 typedef struct
    119 {
    120     DWORD cbSize;
    121     DWORD ExtStatus;
    122 } CHANGEFILTERSTRUCT;
    123 #ifndef MSGFLT_ALLOW
    124  #define MSGFLT_ALLOW 1
    125 #endif
    126 #endif /*Windows 7*/
    127 
    128 #if WINVER < 0x0600
    129 #define DWM_BB_ENABLE 0x00000001
    130 #define DWM_BB_BLURREGION 0x00000002
    131 typedef struct
    132 {
    133     DWORD dwFlags;
    134     BOOL fEnable;
    135     HRGN hRgnBlur;
    136     BOOL fTransitionOnMaximized;
    137 } DWM_BLURBEHIND;
    138 #else
    139  #include <dwmapi.h>
    140 #endif /*Windows Vista*/
    141 
    142 #ifndef DPI_ENUMS_DECLARED
    143 typedef enum
    144 {
    145     PROCESS_DPI_UNAWARE = 0,
    146     PROCESS_SYSTEM_DPI_AWARE = 1,
    147     PROCESS_PER_MONITOR_DPI_AWARE = 2
    148 } PROCESS_DPI_AWARENESS;
    149 typedef enum
    150 {
    151     MDT_EFFECTIVE_DPI = 0,
    152     MDT_ANGULAR_DPI = 1,
    153     MDT_RAW_DPI = 2,
    154     MDT_DEFAULT = MDT_EFFECTIVE_DPI
    155 } MONITOR_DPI_TYPE;
    156 #endif /*DPI_ENUMS_DECLARED*/
    157 
    158 #ifndef DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2
    159 #define DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 ((HANDLE) -4)
    160 #endif /*DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2*/
    161 
    162 // HACK: Define versionhelpers.h functions manually as MinGW lacks the header
    163 #define IsWindowsXPOrGreater()                                 \
    164     _glfwIsWindowsVersionOrGreaterWin32(HIBYTE(_WIN32_WINNT_WINXP),   \
    165                                         LOBYTE(_WIN32_WINNT_WINXP), 0)
    166 #define IsWindowsVistaOrGreater()                                     \
    167     _glfwIsWindowsVersionOrGreaterWin32(HIBYTE(_WIN32_WINNT_VISTA),   \
    168                                         LOBYTE(_WIN32_WINNT_VISTA), 0)
    169 #define IsWindows7OrGreater()                                         \
    170     _glfwIsWindowsVersionOrGreaterWin32(HIBYTE(_WIN32_WINNT_WIN7),    \
    171                                         LOBYTE(_WIN32_WINNT_WIN7), 0)
    172 #define IsWindows8OrGreater()                                         \
    173     _glfwIsWindowsVersionOrGreaterWin32(HIBYTE(_WIN32_WINNT_WIN8),    \
    174                                         LOBYTE(_WIN32_WINNT_WIN8), 0)
    175 #define IsWindows8Point1OrGreater()                                   \
    176     _glfwIsWindowsVersionOrGreaterWin32(HIBYTE(_WIN32_WINNT_WINBLUE), \
    177                                         LOBYTE(_WIN32_WINNT_WINBLUE), 0)
    178 
    179 #define _glfwIsWindows10AnniversaryUpdateOrGreaterWin32() \
    180     _glfwIsWindows10BuildOrGreaterWin32(14393)
    181 #define _glfwIsWindows10CreatorsUpdateOrGreaterWin32() \
    182     _glfwIsWindows10BuildOrGreaterWin32(15063)
    183 
    184 // HACK: Define macros that some xinput.h variants don't
    185 #ifndef XINPUT_CAPS_WIRELESS
    186  #define XINPUT_CAPS_WIRELESS 0x0002
    187 #endif
    188 #ifndef XINPUT_DEVSUBTYPE_WHEEL
    189  #define XINPUT_DEVSUBTYPE_WHEEL 0x02
    190 #endif
    191 #ifndef XINPUT_DEVSUBTYPE_ARCADE_STICK
    192  #define XINPUT_DEVSUBTYPE_ARCADE_STICK 0x03
    193 #endif
    194 #ifndef XINPUT_DEVSUBTYPE_FLIGHT_STICK
    195  #define XINPUT_DEVSUBTYPE_FLIGHT_STICK 0x04
    196 #endif
    197 #ifndef XINPUT_DEVSUBTYPE_DANCE_PAD
    198  #define XINPUT_DEVSUBTYPE_DANCE_PAD 0x05
    199 #endif
    200 #ifndef XINPUT_DEVSUBTYPE_GUITAR
    201  #define XINPUT_DEVSUBTYPE_GUITAR 0x06
    202 #endif
    203 #ifndef XINPUT_DEVSUBTYPE_DRUM_KIT
    204  #define XINPUT_DEVSUBTYPE_DRUM_KIT 0x08
    205 #endif
    206 #ifndef XINPUT_DEVSUBTYPE_ARCADE_PAD
    207  #define XINPUT_DEVSUBTYPE_ARCADE_PAD 0x13
    208 #endif
    209 #ifndef XUSER_MAX_COUNT
    210  #define XUSER_MAX_COUNT 4
    211 #endif
    212 
    213 // HACK: Define macros that some dinput.h variants don't
    214 #ifndef DIDFT_OPTIONAL
    215  #define DIDFT_OPTIONAL 0x80000000
    216 #endif
    217 
    218 // winmm.dll function pointer typedefs
    219 typedef DWORD (WINAPI * PFN_timeGetTime)(void);
    220 #define timeGetTime _glfw.win32.winmm.GetTime
    221 
    222 // xinput.dll function pointer typedefs
    223 typedef DWORD (WINAPI * PFN_XInputGetCapabilities)(DWORD,DWORD,XINPUT_CAPABILITIES*);
    224 typedef DWORD (WINAPI * PFN_XInputGetState)(DWORD,XINPUT_STATE*);
    225 #define XInputGetCapabilities _glfw.win32.xinput.GetCapabilities
    226 #define XInputGetState _glfw.win32.xinput.GetState
    227 
    228 // dinput8.dll function pointer typedefs
    229 typedef HRESULT (WINAPI * PFN_DirectInput8Create)(HINSTANCE,DWORD,REFIID,LPVOID*,LPUNKNOWN);
    230 #define DirectInput8Create _glfw.win32.dinput8.Create
    231 
    232 // user32.dll function pointer typedefs
    233 typedef BOOL (WINAPI * PFN_SetProcessDPIAware)(void);
    234 typedef BOOL (WINAPI * PFN_ChangeWindowMessageFilterEx)(HWND,UINT,DWORD,CHANGEFILTERSTRUCT*);
    235 typedef BOOL (WINAPI * PFN_EnableNonClientDpiScaling)(HWND);
    236 typedef BOOL (WINAPI * PFN_SetProcessDpiAwarenessContext)(HANDLE);
    237 typedef UINT (WINAPI * PFN_GetDpiForWindow)(HWND);
    238 typedef BOOL (WINAPI * PFN_AdjustWindowRectExForDpi)(LPRECT,DWORD,BOOL,DWORD,UINT);
    239 #define SetProcessDPIAware _glfw.win32.user32.SetProcessDPIAware_
    240 #define ChangeWindowMessageFilterEx _glfw.win32.user32.ChangeWindowMessageFilterEx_
    241 #define EnableNonClientDpiScaling _glfw.win32.user32.EnableNonClientDpiScaling_
    242 #define SetProcessDpiAwarenessContext _glfw.win32.user32.SetProcessDpiAwarenessContext_
    243 #define GetDpiForWindow _glfw.win32.user32.GetDpiForWindow_
    244 #define AdjustWindowRectExForDpi _glfw.win32.user32.AdjustWindowRectExForDpi_
    245 
    246 // dwmapi.dll function pointer typedefs
    247 typedef HRESULT (WINAPI * PFN_DwmIsCompositionEnabled)(BOOL*);
    248 typedef HRESULT (WINAPI * PFN_DwmFlush)(VOID);
    249 typedef HRESULT(WINAPI * PFN_DwmEnableBlurBehindWindow)(HWND,const DWM_BLURBEHIND*);
    250 #define DwmIsCompositionEnabled _glfw.win32.dwmapi.IsCompositionEnabled
    251 #define DwmFlush _glfw.win32.dwmapi.Flush
    252 #define DwmEnableBlurBehindWindow _glfw.win32.dwmapi.EnableBlurBehindWindow
    253 
    254 // shcore.dll function pointer typedefs
    255 typedef HRESULT (WINAPI * PFN_SetProcessDpiAwareness)(PROCESS_DPI_AWARENESS);
    256 typedef HRESULT (WINAPI * PFN_GetDpiForMonitor)(HMONITOR,MONITOR_DPI_TYPE,UINT*,UINT*);
    257 #define SetProcessDpiAwareness _glfw.win32.shcore.SetProcessDpiAwareness_
    258 #define GetDpiForMonitor _glfw.win32.shcore.GetDpiForMonitor_
    259 
    260 // ntdll.dll function pointer typedefs
    261 typedef LONG (WINAPI * PFN_RtlVerifyVersionInfo)(OSVERSIONINFOEXW*,ULONG,ULONGLONG);
    262 #define RtlVerifyVersionInfo _glfw.win32.ntdll.RtlVerifyVersionInfo_
    263 
    264 typedef VkFlags VkWin32SurfaceCreateFlagsKHR;
    265 
    266 typedef struct VkWin32SurfaceCreateInfoKHR
    267 {
    268     VkStructureType                 sType;
    269     const void*                     pNext;
    270     VkWin32SurfaceCreateFlagsKHR    flags;
    271     HINSTANCE                       hinstance;
    272     HWND                            hwnd;
    273 } VkWin32SurfaceCreateInfoKHR;
    274 
    275 typedef VkResult (APIENTRY *PFN_vkCreateWin32SurfaceKHR)(VkInstance,const VkWin32SurfaceCreateInfoKHR*,const VkAllocationCallbacks*,VkSurfaceKHR*);
    276 typedef VkBool32 (APIENTRY *PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR)(VkPhysicalDevice,uint32_t);
    277 
    278 #include "win32_joystick.h"
    279 #include "wgl_context.h"
    280 #include "egl_context.h"
    281 #include "osmesa_context.h"
    282 
    283 #if !defined(_GLFW_WNDCLASSNAME)
    284  #define _GLFW_WNDCLASSNAME L"GLFW30"
    285 #endif
    286 
    287 #define _glfw_dlopen(name) LoadLibraryA(name)
    288 #define _glfw_dlclose(handle) FreeLibrary((HMODULE) handle)
    289 #define _glfw_dlsym(handle, name) GetProcAddress((HMODULE) handle, name)
    290 
    291 #define _GLFW_EGL_NATIVE_WINDOW  ((EGLNativeWindowType) window->win32.handle)
    292 #define _GLFW_EGL_NATIVE_DISPLAY EGL_DEFAULT_DISPLAY
    293 
    294 #define _GLFW_PLATFORM_WINDOW_STATE         _GLFWwindowWin32  win32
    295 #define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryWin32 win32
    296 #define _GLFW_PLATFORM_LIBRARY_TIMER_STATE  _GLFWtimerWin32   win32
    297 #define _GLFW_PLATFORM_MONITOR_STATE        _GLFWmonitorWin32 win32
    298 #define _GLFW_PLATFORM_CURSOR_STATE         _GLFWcursorWin32  win32
    299 #define _GLFW_PLATFORM_TLS_STATE            _GLFWtlsWin32     win32
    300 #define _GLFW_PLATFORM_MUTEX_STATE          _GLFWmutexWin32   win32
    301 
    302 
    303 // Win32-specific per-window data
    304 //
    305 typedef struct _GLFWwindowWin32
    306 {
    307     HWND                handle;
    308     HICON               bigIcon;
    309     HICON               smallIcon;
    310 
    311     GLFWbool            cursorTracked;
    312     GLFWbool            frameAction;
    313     GLFWbool            iconified;
    314     GLFWbool            maximized;
    315     // Whether to enable framebuffer transparency on DWM
    316     GLFWbool            transparent;
    317     GLFWbool            scaleToMonitor;
    318 
    319     // The last received cursor position, regardless of source
    320     int                 lastCursorPosX, lastCursorPosY;
    321 
    322 } _GLFWwindowWin32;
    323 
    324 // Win32-specific global data
    325 //
    326 typedef struct _GLFWlibraryWin32
    327 {
    328     HWND                helperWindowHandle;
    329     HDEVNOTIFY          deviceNotificationHandle;
    330     DWORD               foregroundLockTimeout;
    331     int                 acquiredMonitorCount;
    332     char*               clipboardString;
    333     short int           keycodes[512];
    334     short int           scancodes[GLFW_KEY_LAST + 1];
    335     char                keynames[GLFW_KEY_LAST + 1][5];
    336     // Where to place the cursor when re-enabled
    337     double              restoreCursorPosX, restoreCursorPosY;
    338     // The window whose disabled cursor mode is active
    339     _GLFWwindow*        disabledCursorWindow;
    340     RAWINPUT*           rawInput;
    341     int                 rawInputSize;
    342     UINT                mouseTrailSize;
    343 
    344     struct {
    345         HINSTANCE                       instance;
    346         PFN_timeGetTime                 GetTime;
    347     } winmm;
    348 
    349     struct {
    350         HINSTANCE                       instance;
    351         PFN_DirectInput8Create          Create;
    352         IDirectInput8W*                 api;
    353     } dinput8;
    354 
    355     struct {
    356         HINSTANCE                       instance;
    357         PFN_XInputGetCapabilities       GetCapabilities;
    358         PFN_XInputGetState              GetState;
    359     } xinput;
    360 
    361     struct {
    362         HINSTANCE                       instance;
    363         PFN_SetProcessDPIAware          SetProcessDPIAware_;
    364         PFN_ChangeWindowMessageFilterEx ChangeWindowMessageFilterEx_;
    365         PFN_EnableNonClientDpiScaling   EnableNonClientDpiScaling_;
    366         PFN_SetProcessDpiAwarenessContext SetProcessDpiAwarenessContext_;
    367         PFN_GetDpiForWindow             GetDpiForWindow_;
    368         PFN_AdjustWindowRectExForDpi    AdjustWindowRectExForDpi_;
    369     } user32;
    370 
    371     struct {
    372         HINSTANCE                       instance;
    373         PFN_DwmIsCompositionEnabled     IsCompositionEnabled;
    374         PFN_DwmFlush                    Flush;
    375         PFN_DwmEnableBlurBehindWindow   EnableBlurBehindWindow;
    376     } dwmapi;
    377 
    378     struct {
    379         HINSTANCE                       instance;
    380         PFN_SetProcessDpiAwareness      SetProcessDpiAwareness_;
    381         PFN_GetDpiForMonitor            GetDpiForMonitor_;
    382     } shcore;
    383 
    384     struct {
    385         HINSTANCE                       instance;
    386         PFN_RtlVerifyVersionInfo        RtlVerifyVersionInfo_;
    387     } ntdll;
    388 
    389 } _GLFWlibraryWin32;
    390 
    391 // Win32-specific per-monitor data
    392 //
    393 typedef struct _GLFWmonitorWin32
    394 {
    395     HMONITOR            handle;
    396     // This size matches the static size of DISPLAY_DEVICE.DeviceName
    397     WCHAR               adapterName[32];
    398     WCHAR               displayName[32];
    399     char                publicAdapterName[32];
    400     char                publicDisplayName[32];
    401     GLFWbool            modesPruned;
    402     GLFWbool            modeChanged;
    403 
    404 } _GLFWmonitorWin32;
    405 
    406 // Win32-specific per-cursor data
    407 //
    408 typedef struct _GLFWcursorWin32
    409 {
    410     HCURSOR             handle;
    411 
    412 } _GLFWcursorWin32;
    413 
    414 // Win32-specific global timer data
    415 //
    416 typedef struct _GLFWtimerWin32
    417 {
    418     GLFWbool            hasPC;
    419     uint64_t            frequency;
    420 
    421 } _GLFWtimerWin32;
    422 
    423 // Win32-specific thread local storage data
    424 //
    425 typedef struct _GLFWtlsWin32
    426 {
    427     GLFWbool            allocated;
    428     DWORD               index;
    429 
    430 } _GLFWtlsWin32;
    431 
    432 // Win32-specific mutex data
    433 //
    434 typedef struct _GLFWmutexWin32
    435 {
    436     GLFWbool            allocated;
    437     CRITICAL_SECTION    section;
    438 
    439 } _GLFWmutexWin32;
    440 
    441 
    442 GLFWbool _glfwRegisterWindowClassWin32(void);
    443 void _glfwUnregisterWindowClassWin32(void);
    444 
    445 WCHAR* _glfwCreateWideStringFromUTF8Win32(const char* source);
    446 char* _glfwCreateUTF8FromWideStringWin32(const WCHAR* source);
    447 BOOL _glfwIsWindowsVersionOrGreaterWin32(WORD major, WORD minor, WORD sp);
    448 BOOL _glfwIsWindows10BuildOrGreaterWin32(WORD build);
    449 void _glfwInputErrorWin32(int error, const char* description);
    450 void _glfwUpdateKeyNamesWin32(void);
    451 
    452 void _glfwInitTimerWin32(void);
    453 
    454 void _glfwPollMonitorsWin32(void);
    455 void _glfwSetVideoModeWin32(_GLFWmonitor* monitor, const GLFWvidmode* desired);
    456 void _glfwRestoreVideoModeWin32(_GLFWmonitor* monitor);
    457 void _glfwGetMonitorContentScaleWin32(HMONITOR handle, float* xscale, float* yscale);
    458