2010-09-07 17:34:51 +02:00
|
|
|
//========================================================================
|
2016-08-18 23:42:15 +02:00
|
|
|
// GLFW 3.3 Win32 - www.glfw.org
|
2010-09-07 17:34:51 +02:00
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// Copyright (c) 2002-2006 Marcus Geelnard
|
2016-11-21 16:23:59 +01:00
|
|
|
// Copyright (c) 2006-2016 Camilla Löwy <elmindreda@glfw.org>
|
2010-09-07 17:34:51 +02:00
|
|
|
//
|
|
|
|
// This software is provided 'as-is', without any express or implied
|
|
|
|
// warranty. In no event will the authors be held liable for any damages
|
|
|
|
// arising from the use of this software.
|
|
|
|
//
|
|
|
|
// Permission is granted to anyone to use this software for any purpose,
|
|
|
|
// including commercial applications, and to alter it and redistribute it
|
|
|
|
// freely, subject to the following restrictions:
|
|
|
|
//
|
|
|
|
// 1. The origin of this software must not be misrepresented; you must not
|
|
|
|
// claim that you wrote the original software. If you use this software
|
|
|
|
// in a product, an acknowledgment in the product documentation would
|
|
|
|
// be appreciated but is not required.
|
|
|
|
//
|
|
|
|
// 2. Altered source versions must be plainly marked as such, and must not
|
|
|
|
// be misrepresented as being the original software.
|
|
|
|
//
|
|
|
|
// 3. This notice may not be removed or altered from any source
|
|
|
|
// distribution.
|
|
|
|
//
|
|
|
|
//========================================================================
|
|
|
|
|
|
|
|
#include "internal.h"
|
|
|
|
|
2010-10-13 04:04:43 +02:00
|
|
|
#include <stdlib.h>
|
2012-08-14 13:51:39 +02:00
|
|
|
#include <malloc.h>
|
2010-10-13 04:04:43 +02:00
|
|
|
|
2014-08-15 15:08:09 +02:00
|
|
|
#include <initguid.h>
|
|
|
|
DEFINE_GUID(GUID_DEVINTERFACE_HID,0x4d1e55b2,0xf16f,0x11cf,0x88,0xcb,0x00,0x11,0x11,0x00,0x00,0x30);
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2015-05-29 13:08:12 +02:00
|
|
|
#if defined(_GLFW_USE_HYBRID_HPG) || defined(_GLFW_USE_OPTIMUS_HPG)
|
2013-08-07 18:07:33 +02:00
|
|
|
|
|
|
|
// Applications exporting this symbol with this value will be automatically
|
2015-05-29 13:08:12 +02:00
|
|
|
// directed to the high-performance GPU on Nvidia Optimus systems with
|
|
|
|
// up-to-date drivers
|
2013-08-07 18:07:33 +02:00
|
|
|
//
|
2015-05-29 13:08:12 +02:00
|
|
|
__declspec(dllexport) DWORD NvOptimusEnablement = 1;
|
2013-08-07 18:07:33 +02:00
|
|
|
|
2015-05-29 13:08:12 +02:00
|
|
|
// Applications exporting this symbol with this value will be automatically
|
|
|
|
// directed to the high-performance GPU on AMD PowerXpress systems with
|
|
|
|
// up-to-date drivers
|
|
|
|
//
|
|
|
|
__declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
|
|
|
|
|
|
|
|
#endif // _GLFW_USE_HYBRID_HPG
|
2013-08-07 18:07:33 +02:00
|
|
|
|
2012-09-12 21:23:04 +02:00
|
|
|
#if defined(_GLFW_BUILD_DLL)
|
2013-02-04 13:22:10 +01:00
|
|
|
|
|
|
|
// GLFW DLL entry point
|
|
|
|
//
|
2012-09-12 21:23:04 +02:00
|
|
|
BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-02-04 13:22:10 +01:00
|
|
|
#endif // _GLFW_BUILD_DLL
|
2012-09-12 21:23:04 +02:00
|
|
|
|
2010-09-07 17:50:43 +02:00
|
|
|
// Load necessary libraries (DLLs)
|
2013-02-04 13:22:10 +01:00
|
|
|
//
|
2015-11-03 15:18:20 +01:00
|
|
|
static GLFWbool loadLibraries(void)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2015-11-08 15:32:25 +01:00
|
|
|
_glfw.win32.winmm.instance = LoadLibraryA("winmm.dll");
|
2013-01-02 01:40:42 +01:00
|
|
|
if (!_glfw.win32.winmm.instance)
|
2014-01-29 15:14:49 +01:00
|
|
|
{
|
2015-10-15 02:46:07 +02:00
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR, "Win32: Failed to load winmm.dll");
|
2015-08-23 19:30:04 +02:00
|
|
|
return GLFW_FALSE;
|
2014-01-29 15:14:49 +01:00
|
|
|
}
|
2010-09-14 04:27:02 +02:00
|
|
|
|
2016-12-06 20:10:51 +01:00
|
|
|
_glfw.win32.winmm.timeGetTime = (PFN_timeGetTime)
|
2013-01-02 01:40:42 +01:00
|
|
|
GetProcAddress(_glfw.win32.winmm.instance, "timeGetTime");
|
|
|
|
|
2015-11-08 15:32:25 +01:00
|
|
|
_glfw.win32.user32.instance = LoadLibraryA("user32.dll");
|
2015-10-15 02:46:07 +02:00
|
|
|
if (!_glfw.win32.user32.instance)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2015-10-15 02:46:07 +02:00
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR, "Win32: Failed to load user32.dll");
|
2015-08-23 19:30:04 +02:00
|
|
|
return GLFW_FALSE;
|
2010-09-14 04:27:02 +02:00
|
|
|
}
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2016-12-06 20:10:51 +01:00
|
|
|
_glfw.win32.user32.SetProcessDPIAware = (PFN_SetProcessDPIAware)
|
2015-10-15 02:46:07 +02:00
|
|
|
GetProcAddress(_glfw.win32.user32.instance, "SetProcessDPIAware");
|
2016-12-06 20:10:51 +01:00
|
|
|
_glfw.win32.user32.ChangeWindowMessageFilterEx = (PFN_ChangeWindowMessageFilterEx)
|
2015-10-15 02:46:07 +02:00
|
|
|
GetProcAddress(_glfw.win32.user32.instance, "ChangeWindowMessageFilterEx");
|
2013-03-10 19:23:42 +01:00
|
|
|
|
2016-02-16 23:06:29 +01:00
|
|
|
_glfw.win32.dinput8.instance = LoadLibraryA("dinput8.dll");
|
|
|
|
if (_glfw.win32.dinput8.instance)
|
|
|
|
{
|
2016-12-06 20:10:51 +01:00
|
|
|
_glfw.win32.dinput8.DirectInput8Create = (PFN_DirectInput8Create)
|
2016-02-16 23:06:29 +01:00
|
|
|
GetProcAddress(_glfw.win32.dinput8.instance, "DirectInput8Create");
|
|
|
|
}
|
|
|
|
|
2014-08-15 15:08:09 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
const char* names[] =
|
|
|
|
{
|
|
|
|
"xinput1_4.dll",
|
|
|
|
"xinput1_3.dll",
|
|
|
|
"xinput9_1_0.dll",
|
|
|
|
"xinput1_2.dll",
|
|
|
|
"xinput1_1.dll",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
for (i = 0; names[i]; i++)
|
|
|
|
{
|
|
|
|
_glfw.win32.xinput.instance = LoadLibraryA(names[i]);
|
|
|
|
if (_glfw.win32.xinput.instance)
|
|
|
|
{
|
2016-12-06 20:10:51 +01:00
|
|
|
_glfw.win32.xinput.XInputGetCapabilities = (PFN_XInputGetCapabilities)
|
2014-08-15 15:08:09 +02:00
|
|
|
GetProcAddress(_glfw.win32.xinput.instance, "XInputGetCapabilities");
|
2016-12-06 20:10:51 +01:00
|
|
|
_glfw.win32.xinput.XInputGetState = (PFN_XInputGetState)
|
2014-08-15 15:08:09 +02:00
|
|
|
GetProcAddress(_glfw.win32.xinput.instance, "XInputGetState");
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-08 15:32:25 +01:00
|
|
|
_glfw.win32.dwmapi.instance = LoadLibraryA("dwmapi.dll");
|
2013-03-11 20:54:32 +01:00
|
|
|
if (_glfw.win32.dwmapi.instance)
|
|
|
|
{
|
2016-12-06 20:10:51 +01:00
|
|
|
_glfw.win32.dwmapi.DwmIsCompositionEnabled = (PFN_DwmIsCompositionEnabled)
|
2013-03-11 20:54:32 +01:00
|
|
|
GetProcAddress(_glfw.win32.dwmapi.instance, "DwmIsCompositionEnabled");
|
2016-12-06 20:10:51 +01:00
|
|
|
_glfw.win32.dwmapi.DwmFlush = (PFN_DwmFlush)
|
2015-05-21 14:48:11 +02:00
|
|
|
GetProcAddress(_glfw.win32.dwmapi.instance, "DwmFlush");
|
2013-03-11 20:54:32 +01:00
|
|
|
}
|
2013-12-22 16:38:56 +01:00
|
|
|
|
2015-11-08 15:32:25 +01:00
|
|
|
_glfw.win32.shcore.instance = LoadLibraryA("shcore.dll");
|
2015-11-01 17:29:13 +01:00
|
|
|
if (_glfw.win32.shcore.instance)
|
|
|
|
{
|
2016-12-06 20:10:51 +01:00
|
|
|
_glfw.win32.shcore.SetProcessDpiAwareness = (PFN_SetProcessDpiAwareness)
|
2015-12-30 15:20:40 +01:00
|
|
|
GetProcAddress(_glfw.win32.shcore.instance, "SetProcessDpiAwareness");
|
2015-11-01 17:29:13 +01:00
|
|
|
}
|
|
|
|
|
2015-08-23 19:30:04 +02:00
|
|
|
return GLFW_TRUE;
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
2010-09-07 17:50:43 +02:00
|
|
|
// Unload used libraries (DLLs)
|
2013-02-04 13:22:10 +01:00
|
|
|
//
|
2015-11-03 15:18:20 +01:00
|
|
|
static void freeLibraries(void)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2014-08-15 15:08:09 +02:00
|
|
|
if (_glfw.win32.xinput.instance)
|
|
|
|
FreeLibrary(_glfw.win32.xinput.instance);
|
|
|
|
|
2016-02-16 23:06:29 +01:00
|
|
|
if (_glfw.win32.dinput8.instance)
|
|
|
|
FreeLibrary(_glfw.win32.dinput8.instance);
|
|
|
|
|
2014-08-15 14:50:41 +02:00
|
|
|
if (_glfw.win32.winmm.instance)
|
2013-01-02 01:40:42 +01:00
|
|
|
FreeLibrary(_glfw.win32.winmm.instance);
|
2013-06-26 14:04:07 +02:00
|
|
|
|
|
|
|
if (_glfw.win32.user32.instance)
|
|
|
|
FreeLibrary(_glfw.win32.user32.instance);
|
|
|
|
|
|
|
|
if (_glfw.win32.dwmapi.instance)
|
|
|
|
FreeLibrary(_glfw.win32.dwmapi.instance);
|
2015-11-01 17:29:13 +01:00
|
|
|
|
|
|
|
if (_glfw.win32.shcore.instance)
|
|
|
|
FreeLibrary(_glfw.win32.shcore.instance);
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
2014-03-30 16:23:22 +02:00
|
|
|
// Create key code translation tables
|
|
|
|
//
|
|
|
|
static void createKeyTables(void)
|
|
|
|
{
|
2015-07-02 14:24:50 +02:00
|
|
|
int scancode;
|
|
|
|
|
2016-09-07 15:43:39 +02:00
|
|
|
memset(_glfw.win32.keycodes, -1, sizeof(_glfw.win32.keycodes));
|
|
|
|
memset(_glfw.win32.scancodes, -1, sizeof(_glfw.win32.scancodes));
|
|
|
|
|
|
|
|
_glfw.win32.keycodes[0x00B] = GLFW_KEY_0;
|
|
|
|
_glfw.win32.keycodes[0x002] = GLFW_KEY_1;
|
|
|
|
_glfw.win32.keycodes[0x003] = GLFW_KEY_2;
|
|
|
|
_glfw.win32.keycodes[0x004] = GLFW_KEY_3;
|
|
|
|
_glfw.win32.keycodes[0x005] = GLFW_KEY_4;
|
|
|
|
_glfw.win32.keycodes[0x006] = GLFW_KEY_5;
|
|
|
|
_glfw.win32.keycodes[0x007] = GLFW_KEY_6;
|
|
|
|
_glfw.win32.keycodes[0x008] = GLFW_KEY_7;
|
|
|
|
_glfw.win32.keycodes[0x009] = GLFW_KEY_8;
|
|
|
|
_glfw.win32.keycodes[0x00A] = GLFW_KEY_9;
|
|
|
|
_glfw.win32.keycodes[0x01E] = GLFW_KEY_A;
|
|
|
|
_glfw.win32.keycodes[0x030] = GLFW_KEY_B;
|
|
|
|
_glfw.win32.keycodes[0x02E] = GLFW_KEY_C;
|
|
|
|
_glfw.win32.keycodes[0x020] = GLFW_KEY_D;
|
|
|
|
_glfw.win32.keycodes[0x012] = GLFW_KEY_E;
|
|
|
|
_glfw.win32.keycodes[0x021] = GLFW_KEY_F;
|
|
|
|
_glfw.win32.keycodes[0x022] = GLFW_KEY_G;
|
|
|
|
_glfw.win32.keycodes[0x023] = GLFW_KEY_H;
|
|
|
|
_glfw.win32.keycodes[0x017] = GLFW_KEY_I;
|
|
|
|
_glfw.win32.keycodes[0x024] = GLFW_KEY_J;
|
|
|
|
_glfw.win32.keycodes[0x025] = GLFW_KEY_K;
|
|
|
|
_glfw.win32.keycodes[0x026] = GLFW_KEY_L;
|
|
|
|
_glfw.win32.keycodes[0x032] = GLFW_KEY_M;
|
|
|
|
_glfw.win32.keycodes[0x031] = GLFW_KEY_N;
|
|
|
|
_glfw.win32.keycodes[0x018] = GLFW_KEY_O;
|
|
|
|
_glfw.win32.keycodes[0x019] = GLFW_KEY_P;
|
|
|
|
_glfw.win32.keycodes[0x010] = GLFW_KEY_Q;
|
|
|
|
_glfw.win32.keycodes[0x013] = GLFW_KEY_R;
|
|
|
|
_glfw.win32.keycodes[0x01F] = GLFW_KEY_S;
|
|
|
|
_glfw.win32.keycodes[0x014] = GLFW_KEY_T;
|
|
|
|
_glfw.win32.keycodes[0x016] = GLFW_KEY_U;
|
|
|
|
_glfw.win32.keycodes[0x02F] = GLFW_KEY_V;
|
|
|
|
_glfw.win32.keycodes[0x011] = GLFW_KEY_W;
|
|
|
|
_glfw.win32.keycodes[0x02D] = GLFW_KEY_X;
|
|
|
|
_glfw.win32.keycodes[0x015] = GLFW_KEY_Y;
|
|
|
|
_glfw.win32.keycodes[0x02C] = GLFW_KEY_Z;
|
|
|
|
|
|
|
|
_glfw.win32.keycodes[0x028] = GLFW_KEY_APOSTROPHE;
|
|
|
|
_glfw.win32.keycodes[0x02B] = GLFW_KEY_BACKSLASH;
|
|
|
|
_glfw.win32.keycodes[0x033] = GLFW_KEY_COMMA;
|
|
|
|
_glfw.win32.keycodes[0x00D] = GLFW_KEY_EQUAL;
|
|
|
|
_glfw.win32.keycodes[0x029] = GLFW_KEY_GRAVE_ACCENT;
|
|
|
|
_glfw.win32.keycodes[0x01A] = GLFW_KEY_LEFT_BRACKET;
|
|
|
|
_glfw.win32.keycodes[0x00C] = GLFW_KEY_MINUS;
|
|
|
|
_glfw.win32.keycodes[0x034] = GLFW_KEY_PERIOD;
|
|
|
|
_glfw.win32.keycodes[0x01B] = GLFW_KEY_RIGHT_BRACKET;
|
|
|
|
_glfw.win32.keycodes[0x027] = GLFW_KEY_SEMICOLON;
|
|
|
|
_glfw.win32.keycodes[0x035] = GLFW_KEY_SLASH;
|
|
|
|
_glfw.win32.keycodes[0x056] = GLFW_KEY_WORLD_2;
|
|
|
|
|
|
|
|
_glfw.win32.keycodes[0x00E] = GLFW_KEY_BACKSPACE;
|
|
|
|
_glfw.win32.keycodes[0x153] = GLFW_KEY_DELETE;
|
|
|
|
_glfw.win32.keycodes[0x14F] = GLFW_KEY_END;
|
|
|
|
_glfw.win32.keycodes[0x01C] = GLFW_KEY_ENTER;
|
|
|
|
_glfw.win32.keycodes[0x001] = GLFW_KEY_ESCAPE;
|
|
|
|
_glfw.win32.keycodes[0x147] = GLFW_KEY_HOME;
|
|
|
|
_glfw.win32.keycodes[0x152] = GLFW_KEY_INSERT;
|
|
|
|
_glfw.win32.keycodes[0x15D] = GLFW_KEY_MENU;
|
|
|
|
_glfw.win32.keycodes[0x151] = GLFW_KEY_PAGE_DOWN;
|
|
|
|
_glfw.win32.keycodes[0x149] = GLFW_KEY_PAGE_UP;
|
|
|
|
_glfw.win32.keycodes[0x045] = GLFW_KEY_PAUSE;
|
|
|
|
_glfw.win32.keycodes[0x146] = GLFW_KEY_PAUSE;
|
|
|
|
_glfw.win32.keycodes[0x039] = GLFW_KEY_SPACE;
|
|
|
|
_glfw.win32.keycodes[0x00F] = GLFW_KEY_TAB;
|
|
|
|
_glfw.win32.keycodes[0x03A] = GLFW_KEY_CAPS_LOCK;
|
|
|
|
_glfw.win32.keycodes[0x145] = GLFW_KEY_NUM_LOCK;
|
|
|
|
_glfw.win32.keycodes[0x046] = GLFW_KEY_SCROLL_LOCK;
|
|
|
|
_glfw.win32.keycodes[0x03B] = GLFW_KEY_F1;
|
|
|
|
_glfw.win32.keycodes[0x03C] = GLFW_KEY_F2;
|
|
|
|
_glfw.win32.keycodes[0x03D] = GLFW_KEY_F3;
|
|
|
|
_glfw.win32.keycodes[0x03E] = GLFW_KEY_F4;
|
|
|
|
_glfw.win32.keycodes[0x03F] = GLFW_KEY_F5;
|
|
|
|
_glfw.win32.keycodes[0x040] = GLFW_KEY_F6;
|
|
|
|
_glfw.win32.keycodes[0x041] = GLFW_KEY_F7;
|
|
|
|
_glfw.win32.keycodes[0x042] = GLFW_KEY_F8;
|
|
|
|
_glfw.win32.keycodes[0x043] = GLFW_KEY_F9;
|
|
|
|
_glfw.win32.keycodes[0x044] = GLFW_KEY_F10;
|
|
|
|
_glfw.win32.keycodes[0x057] = GLFW_KEY_F11;
|
|
|
|
_glfw.win32.keycodes[0x058] = GLFW_KEY_F12;
|
|
|
|
_glfw.win32.keycodes[0x064] = GLFW_KEY_F13;
|
|
|
|
_glfw.win32.keycodes[0x065] = GLFW_KEY_F14;
|
|
|
|
_glfw.win32.keycodes[0x066] = GLFW_KEY_F15;
|
|
|
|
_glfw.win32.keycodes[0x067] = GLFW_KEY_F16;
|
|
|
|
_glfw.win32.keycodes[0x068] = GLFW_KEY_F17;
|
|
|
|
_glfw.win32.keycodes[0x069] = GLFW_KEY_F18;
|
|
|
|
_glfw.win32.keycodes[0x06A] = GLFW_KEY_F19;
|
|
|
|
_glfw.win32.keycodes[0x06B] = GLFW_KEY_F20;
|
|
|
|
_glfw.win32.keycodes[0x06C] = GLFW_KEY_F21;
|
|
|
|
_glfw.win32.keycodes[0x06D] = GLFW_KEY_F22;
|
|
|
|
_glfw.win32.keycodes[0x06E] = GLFW_KEY_F23;
|
|
|
|
_glfw.win32.keycodes[0x076] = GLFW_KEY_F24;
|
|
|
|
_glfw.win32.keycodes[0x038] = GLFW_KEY_LEFT_ALT;
|
|
|
|
_glfw.win32.keycodes[0x01D] = GLFW_KEY_LEFT_CONTROL;
|
|
|
|
_glfw.win32.keycodes[0x02A] = GLFW_KEY_LEFT_SHIFT;
|
|
|
|
_glfw.win32.keycodes[0x15B] = GLFW_KEY_LEFT_SUPER;
|
|
|
|
_glfw.win32.keycodes[0x137] = GLFW_KEY_PRINT_SCREEN;
|
|
|
|
_glfw.win32.keycodes[0x138] = GLFW_KEY_RIGHT_ALT;
|
|
|
|
_glfw.win32.keycodes[0x11D] = GLFW_KEY_RIGHT_CONTROL;
|
|
|
|
_glfw.win32.keycodes[0x036] = GLFW_KEY_RIGHT_SHIFT;
|
|
|
|
_glfw.win32.keycodes[0x15C] = GLFW_KEY_RIGHT_SUPER;
|
|
|
|
_glfw.win32.keycodes[0x150] = GLFW_KEY_DOWN;
|
|
|
|
_glfw.win32.keycodes[0x14B] = GLFW_KEY_LEFT;
|
|
|
|
_glfw.win32.keycodes[0x14D] = GLFW_KEY_RIGHT;
|
|
|
|
_glfw.win32.keycodes[0x148] = GLFW_KEY_UP;
|
|
|
|
|
|
|
|
_glfw.win32.keycodes[0x052] = GLFW_KEY_KP_0;
|
|
|
|
_glfw.win32.keycodes[0x04F] = GLFW_KEY_KP_1;
|
|
|
|
_glfw.win32.keycodes[0x050] = GLFW_KEY_KP_2;
|
|
|
|
_glfw.win32.keycodes[0x051] = GLFW_KEY_KP_3;
|
|
|
|
_glfw.win32.keycodes[0x04B] = GLFW_KEY_KP_4;
|
|
|
|
_glfw.win32.keycodes[0x04C] = GLFW_KEY_KP_5;
|
|
|
|
_glfw.win32.keycodes[0x04D] = GLFW_KEY_KP_6;
|
|
|
|
_glfw.win32.keycodes[0x047] = GLFW_KEY_KP_7;
|
|
|
|
_glfw.win32.keycodes[0x048] = GLFW_KEY_KP_8;
|
|
|
|
_glfw.win32.keycodes[0x049] = GLFW_KEY_KP_9;
|
|
|
|
_glfw.win32.keycodes[0x04E] = GLFW_KEY_KP_ADD;
|
|
|
|
_glfw.win32.keycodes[0x053] = GLFW_KEY_KP_DECIMAL;
|
|
|
|
_glfw.win32.keycodes[0x135] = GLFW_KEY_KP_DIVIDE;
|
|
|
|
_glfw.win32.keycodes[0x11C] = GLFW_KEY_KP_ENTER;
|
|
|
|
_glfw.win32.keycodes[0x037] = GLFW_KEY_KP_MULTIPLY;
|
|
|
|
_glfw.win32.keycodes[0x04A] = GLFW_KEY_KP_SUBTRACT;
|
2015-07-02 14:24:50 +02:00
|
|
|
|
|
|
|
for (scancode = 0; scancode < 512; scancode++)
|
|
|
|
{
|
2016-09-07 15:43:39 +02:00
|
|
|
if (_glfw.win32.keycodes[scancode] > 0)
|
|
|
|
_glfw.win32.scancodes[_glfw.win32.keycodes[scancode]] = scancode;
|
2015-07-02 14:24:50 +02:00
|
|
|
}
|
2014-03-30 16:23:22 +02:00
|
|
|
}
|
|
|
|
|
2015-11-03 15:28:56 +01:00
|
|
|
// Creates a dummy window for behind-the-scenes work
|
|
|
|
//
|
|
|
|
static HWND createHelperWindow(void)
|
|
|
|
{
|
2016-10-25 21:25:04 +02:00
|
|
|
MSG msg;
|
2015-11-03 15:28:56 +01:00
|
|
|
HWND window = CreateWindowExW(WS_EX_OVERLAPPEDWINDOW,
|
|
|
|
_GLFW_WNDCLASSNAME,
|
|
|
|
L"GLFW helper window",
|
|
|
|
WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
|
|
|
|
0, 0, 1, 1,
|
2016-02-08 16:39:08 +01:00
|
|
|
HWND_MESSAGE, NULL,
|
2015-11-03 15:28:56 +01:00
|
|
|
GetModuleHandleW(NULL),
|
|
|
|
NULL);
|
|
|
|
if (!window)
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
|
|
"Win32: Failed to create helper window");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-07-12 16:04:02 +02:00
|
|
|
// HACK: The first call to ShowWindow is ignored if the parent process
|
|
|
|
// passed along a STARTUPINFO, so clear that flag with a no-op call
|
|
|
|
ShowWindow(window, SW_HIDE);
|
|
|
|
|
2014-08-15 15:08:09 +02:00
|
|
|
// Register for HID device notifications
|
|
|
|
{
|
|
|
|
DEV_BROADCAST_DEVICEINTERFACE_W dbi;
|
|
|
|
ZeroMemory(&dbi, sizeof(dbi));
|
|
|
|
dbi.dbcc_size = sizeof(dbi);
|
|
|
|
dbi.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
|
|
|
|
dbi.dbcc_classguid = GUID_DEVINTERFACE_HID;
|
|
|
|
|
|
|
|
RegisterDeviceNotificationW(window,
|
|
|
|
(DEV_BROADCAST_HDR*) &dbi,
|
|
|
|
DEVICE_NOTIFY_WINDOW_HANDLE);
|
|
|
|
}
|
|
|
|
|
2016-10-25 21:25:04 +02:00
|
|
|
while (PeekMessageW(&msg, _glfw.win32.helperWindowHandle, 0, 0, PM_REMOVE))
|
|
|
|
{
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessageW(&msg);
|
|
|
|
}
|
|
|
|
|
2014-08-15 15:08:09 +02:00
|
|
|
return window;
|
2015-11-03 15:28:56 +01:00
|
|
|
}
|
|
|
|
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2012-02-05 02:07:50 +01:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW internal API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// Returns a wide string version of the specified UTF-8 string
|
2013-02-04 13:22:10 +01:00
|
|
|
//
|
2015-12-03 18:16:46 +01:00
|
|
|
WCHAR* _glfwCreateWideStringFromUTF8Win32(const char* source)
|
2012-02-05 02:07:50 +01:00
|
|
|
{
|
|
|
|
WCHAR* target;
|
|
|
|
int length;
|
|
|
|
|
|
|
|
length = MultiByteToWideChar(CP_UTF8, 0, source, -1, NULL, 0);
|
|
|
|
if (!length)
|
|
|
|
return NULL;
|
|
|
|
|
2014-10-11 21:02:57 +02:00
|
|
|
target = calloc(length, sizeof(WCHAR));
|
2012-02-05 02:07:50 +01:00
|
|
|
|
2014-10-11 21:02:57 +02:00
|
|
|
if (!MultiByteToWideChar(CP_UTF8, 0, source, -1, target, length))
|
2012-02-05 02:07:50 +01:00
|
|
|
{
|
2012-02-07 15:40:47 +01:00
|
|
|
free(target);
|
2012-02-05 02:07:50 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return target;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns a UTF-8 string version of the specified wide string
|
2013-02-04 13:22:10 +01:00
|
|
|
//
|
2015-12-03 18:16:46 +01:00
|
|
|
char* _glfwCreateUTF8FromWideStringWin32(const WCHAR* source)
|
2012-02-05 02:07:50 +01:00
|
|
|
{
|
|
|
|
char* target;
|
|
|
|
int length;
|
|
|
|
|
|
|
|
length = WideCharToMultiByte(CP_UTF8, 0, source, -1, NULL, 0, NULL, NULL);
|
|
|
|
if (!length)
|
|
|
|
return NULL;
|
|
|
|
|
2016-08-04 13:19:07 +02:00
|
|
|
target = calloc(length, 1);
|
2012-02-05 02:07:50 +01:00
|
|
|
|
2014-10-11 21:02:57 +02:00
|
|
|
if (!WideCharToMultiByte(CP_UTF8, 0, source, -1, target, length, NULL, NULL))
|
2012-02-05 02:07:50 +01:00
|
|
|
{
|
2012-02-07 15:40:47 +01:00
|
|
|
free(target);
|
2012-02-05 02:07:50 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return target;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-10 22:03:36 +02:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW platform API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2010-09-10 22:03:36 +02:00
|
|
|
int _glfwPlatformInit(void)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2015-12-03 18:16:46 +01:00
|
|
|
if (!_glfwInitThreadLocalStorageWin32())
|
|
|
|
return GLFW_FALSE;
|
|
|
|
|
2010-09-13 23:50:04 +02:00
|
|
|
// To make SetForegroundWindow work as we want, we need to fiddle
|
2010-09-07 17:34:51 +02:00
|
|
|
// with the FOREGROUNDLOCKTIMEOUT system setting (we do this as early
|
|
|
|
// as possible in the hope of still being the foreground process)
|
2014-03-06 18:30:14 +01:00
|
|
|
SystemParametersInfoW(SPI_GETFOREGROUNDLOCKTIMEOUT, 0,
|
|
|
|
&_glfw.win32.foregroundLockTimeout, 0);
|
|
|
|
SystemParametersInfoW(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, UIntToPtr(0),
|
|
|
|
SPIF_SENDCHANGE);
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2015-11-03 15:18:20 +01:00
|
|
|
if (!loadLibraries())
|
2015-08-23 19:30:04 +02:00
|
|
|
return GLFW_FALSE;
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2014-03-30 16:23:22 +02:00
|
|
|
createKeyTables();
|
|
|
|
|
2015-12-30 15:20:40 +01:00
|
|
|
if (_glfw_SetProcessDpiAwareness)
|
|
|
|
_glfw_SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE);
|
2015-11-01 17:29:13 +01:00
|
|
|
else if (_glfw_SetProcessDPIAware)
|
2013-03-10 19:23:42 +01:00
|
|
|
_glfw_SetProcessDPIAware();
|
|
|
|
|
2015-12-03 18:16:46 +01:00
|
|
|
if (!_glfwRegisterWindowClassWin32())
|
2015-08-23 19:30:04 +02:00
|
|
|
return GLFW_FALSE;
|
2014-08-31 14:17:31 +02:00
|
|
|
|
2016-05-30 21:19:00 +02:00
|
|
|
_glfw.win32.helperWindowHandle = createHelperWindow();
|
|
|
|
if (!_glfw.win32.helperWindowHandle)
|
2015-11-03 15:28:56 +01:00
|
|
|
return GLFW_FALSE;
|
|
|
|
|
2015-12-03 18:16:46 +01:00
|
|
|
_glfwInitTimerWin32();
|
|
|
|
_glfwInitJoysticksWin32();
|
2013-01-02 01:52:28 +01:00
|
|
|
|
2015-08-23 19:30:04 +02:00
|
|
|
return GLFW_TRUE;
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
2012-12-30 01:15:48 +01:00
|
|
|
void _glfwPlatformTerminate(void)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2016-05-30 21:19:00 +02:00
|
|
|
if (_glfw.win32.helperWindowHandle)
|
|
|
|
DestroyWindow(_glfw.win32.helperWindowHandle);
|
2016-02-11 16:41:39 +01:00
|
|
|
|
2015-12-03 18:16:46 +01:00
|
|
|
_glfwUnregisterWindowClassWin32();
|
2010-09-14 02:17:18 +02:00
|
|
|
|
2013-06-24 14:38:00 +02:00
|
|
|
// Restore previous foreground lock timeout system setting
|
2014-03-06 18:30:14 +01:00
|
|
|
SystemParametersInfoW(SPI_SETFOREGROUNDLOCKTIMEOUT, 0,
|
|
|
|
UIntToPtr(_glfw.win32.foregroundLockTimeout),
|
|
|
|
SPIF_SENDCHANGE);
|
2013-06-24 14:38:00 +02:00
|
|
|
|
|
|
|
free(_glfw.win32.clipboardString);
|
|
|
|
|
2015-12-03 18:16:46 +01:00
|
|
|
_glfwTerminateWGL();
|
|
|
|
_glfwTerminateEGL();
|
|
|
|
|
|
|
|
_glfwTerminateJoysticksWin32();
|
|
|
|
_glfwTerminateThreadLocalStorageWin32();
|
2015-11-03 15:18:20 +01:00
|
|
|
|
|
|
|
freeLibraries();
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
2010-09-14 01:05:03 +02:00
|
|
|
const char* _glfwPlatformGetVersionString(void)
|
|
|
|
{
|
2016-03-28 13:19:31 +02:00
|
|
|
return _GLFW_VERSION_NUMBER " Win32 WGL EGL"
|
2010-09-14 01:05:03 +02:00
|
|
|
#if defined(__MINGW32__)
|
|
|
|
" MinGW"
|
|
|
|
#elif defined(_MSC_VER)
|
2013-12-24 00:48:28 +01:00
|
|
|
" VisualC"
|
2013-02-14 13:13:07 +01:00
|
|
|
#endif
|
2015-09-01 17:12:22 +02:00
|
|
|
#if defined(_GLFW_USE_HYBRID_HPG) || defined(_GLFW_USE_OPTIMUS_HPG)
|
|
|
|
" hybrid-GPU"
|
|
|
|
#endif
|
2012-03-25 17:40:30 +02:00
|
|
|
#if defined(_GLFW_BUILD_DLL)
|
2010-09-14 01:05:03 +02:00
|
|
|
" DLL"
|
|
|
|
#endif
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|