Win32 port work dump.

This commit is contained in:
Camilla Berglund 2010-09-12 16:26:00 +02:00
parent 8c507dc333
commit 90df26ac3c
8 changed files with 355 additions and 421 deletions

View File

@ -307,7 +307,6 @@ typedef struct _GLFWwindowWin32
HWND handle; // Window handle HWND handle; // Window handle
ATOM classAtom; // Window class atom ATOM classAtom; // Window class atom
int modeID; // Mode ID for fullscreen mode int modeID; // Mode ID for fullscreen mode
HHOOK keyboardHook; // Keyboard hook handle
DWORD dwStyle; // Window styles used for window creation DWORD dwStyle; // Window styles used for window creation
DWORD dwExStyle; // --"-- DWORD dwExStyle; // --"--
@ -326,8 +325,9 @@ typedef struct _GLFWwindowWin32
//------------------------------------------------------------------------ //------------------------------------------------------------------------
typedef struct _GLFWlibraryWin32 typedef struct _GLFWlibraryWin32
{ {
// Instance of the application HINSTANCE instance; // Instance of the application
HINSTANCE instance; HHOOK keyboardHook; // Keyboard hook handle
DWORD foregroundLockTimeout;
// Timer data // Timer data
struct { struct {
@ -340,8 +340,6 @@ typedef struct _GLFWlibraryWin32
// System information // System information
struct { struct {
int winVer; int winVer;
int hasUnicode;
DWORD foregroundLockTimeout;
} sys; } sys;
#if !defined(_GLFW_NO_DLOAD_WINMM) || !defined(_GLFW_NO_DLOAD_GDI32) #if !defined(_GLFW_NO_DLOAD_WINMM) || !defined(_GLFW_NO_DLOAD_GDI32)

View File

@ -78,9 +78,11 @@ static LRESULT CALLBACK keyboardHook(int nCode, WPARAM wParam, LPARAM lParam)
// Was it a system key combination (e.g. ALT+TAB)? // Was it a system key combination (e.g. ALT+TAB)?
if (syskeys) if (syskeys)
{ {
_GLFWwindow* window = _glfwLibrary.activeWindow;
// Pass the key event to our window message loop // Pass the key event to our window message loop
if (_glfwWin.opened) if (window)
PostMessage(_glfwWin.window, (UINT) wParam, p->vkCode, 0); PostMessage(window->Win32.handle, (UINT) wParam, p->vkCode, 0);
// We've taken care of it - don't let the system know about this // We've taken care of it - don't let the system know about this
// key event // key event
@ -89,7 +91,7 @@ static LRESULT CALLBACK keyboardHook(int nCode, WPARAM wParam, LPARAM lParam)
else else
{ {
// It's a harmless key press, let the system deal with it // It's a harmless key press, let the system deal with it
return CallNextHookEx(_glfwWin.keyboardHook, nCode, wParam, lParam); return CallNextHookEx(_glfwLibrary.Win32.keyboardHook, nCode, wParam, lParam);
} }
} }
@ -104,20 +106,12 @@ static LRESULT CALLBACK keyboardHook(int nCode, WPARAM wParam, LPARAM lParam)
void _glfwPlatformEnableSystemKeys(void) void _glfwPlatformEnableSystemKeys(void)
{ {
BOOL dummy; if (_glfwLibrary.Win32.keyboardHook != NULL)
// Use different methods depending on operating system version
if (_glfwLibrary.Sys.winVer >= _GLFW_WIN_NT4)
{ {
if (_glfwWin.keyboardHook != NULL) UnhookWindowsHookEx(_glfwLibrary.Win32.keyboardHook);
{ _glfwLibrary.Win32.keyboardHook = NULL;
UnhookWindowsHookEx(_glfwWin.keyboardHook);
_glfwWin.keyboardHook = NULL;
} }
} }
else
SystemParametersInfo(SPI_SETSCREENSAVERRUNNING, FALSE, &dummy, 0);
}
//======================================================================== //========================================================================
@ -126,22 +120,9 @@ void _glfwPlatformEnableSystemKeys(void)
void _glfwPlatformDisableSystemKeys(void) void _glfwPlatformDisableSystemKeys(void)
{ {
BOOL dummy; _glfwLibrary.Win32.keyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL,
// Use different methods depending on operating system version
if (_glfwLibrary.Sys.winVer >= _GLFW_WIN_NT4)
{
// Under Windows NT, install a low level keyboard hook
_glfwWin.keyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL,
keyboardHook, keyboardHook,
_glfwLibrary.instance, _glfwLibrary.Win32.instance,
0); 0);
} }
else
{
// Under Windows 95/98/ME, fool Windows that a screensaver
// is running => prevents ALT+TAB, CTRL+ESC and CTRL+ALT+DEL
SystemParametersInfo(SPI_SETSCREENSAVERRUNNING, TRUE, &dummy, 0);
}
}

View File

@ -43,9 +43,11 @@ int _glfwPlatformExtensionSupported(const char* extension)
{ {
const GLubyte* extensions; const GLubyte* extensions;
if (_glfwWin.GetExtensionsStringEXT != NULL) _GLFWwindow* window = _glfwLibrary.currentWindow;
if (window->WGL.GetExtensionsStringEXT != NULL)
{ {
extensions = (GLubyte*) _glfwWin.GetExtensionsStringEXT(); extensions = (GLubyte*) window->WGL.GetExtensionsStringEXT();
if (extensions != NULL) if (extensions != NULL)
{ {
if (_glfwStringInExtensionString(extension, extensions)) if (_glfwStringInExtensionString(extension, extensions))
@ -53,9 +55,9 @@ int _glfwPlatformExtensionSupported(const char* extension)
} }
} }
if (_glfwWin.GetExtensionsStringARB != NULL) if (window->WGL.GetExtensionsStringARB != NULL)
{ {
extensions = (GLubyte*) _glfwWin.GetExtensionsStringARB(_glfwWin.DC); extensions = (GLubyte*) window->WGL.GetExtensionsStringARB(window->WGL.DC);
if (extensions != NULL) if (extensions != NULL)
{ {
if (_glfwStringInExtensionString(extension, extensions)) if (_glfwStringInExtensionString(extension, extensions))

View File

@ -44,28 +44,28 @@ static GLboolean initLibraries(void)
{ {
// gdi32.dll (OpenGL pixel format functions & SwapBuffers) // gdi32.dll (OpenGL pixel format functions & SwapBuffers)
#ifndef _GLFW_NO_DLOAD_GDI32 #ifndef _GLFW_NO_DLOAD_GDI32
_glfwLibrary.Libs.gdi32 = LoadLibrary("gdi32.dll"); _glfwLibrary.Win32.libs.gdi32 = LoadLibrary("gdi32.dll");
if (_glfwLibrary.Libs.gdi32 != NULL) if (_glfwLibrary.Win32.libs.gdi32 != NULL)
{ {
_glfwLibrary.Libs.ChoosePixelFormat = (CHOOSEPIXELFORMAT_T) _glfwLibrary.Win32.libs.ChoosePixelFormat = (CHOOSEPIXELFORMAT_T)
GetProcAddress(_glfwLibrary.Libs.gdi32, "ChoosePixelFormat"); GetProcAddress(_glfwLibrary.Win32.libs.gdi32, "ChoosePixelFormat");
_glfwLibrary.Libs.DescribePixelFormat = (DESCRIBEPIXELFORMAT_T) _glfwLibrary.Win32.libs.DescribePixelFormat = (DESCRIBEPIXELFORMAT_T)
GetProcAddress(_glfwLibrary.Libs.gdi32, "DescribePixelFormat"); GetProcAddress(_glfwLibrary.Win32.libs.gdi32, "DescribePixelFormat");
_glfwLibrary.Libs.GetPixelFormat = (GETPIXELFORMAT_T) _glfwLibrary.Win32.libs.GetPixelFormat = (GETPIXELFORMAT_T)
GetProcAddress(_glfwLibrary.Libs.gdi32, "GetPixelFormat"); GetProcAddress(_glfwLibrary.Win32.libs.gdi32, "GetPixelFormat");
_glfwLibrary.Libs.SetPixelFormat = (SETPIXELFORMAT_T) _glfwLibrary.Win32.libs.SetPixelFormat = (SETPIXELFORMAT_T)
GetProcAddress(_glfwLibrary.Libs.gdi32, "SetPixelFormat"); GetProcAddress(_glfwLibrary.Win32.libs.gdi32, "SetPixelFormat");
_glfwLibrary.Libs.SwapBuffers = (SWAPBUFFERS_T) _glfwLibrary.Win32.libs.SwapBuffers = (SWAPBUFFERS_T)
GetProcAddress(_glfwLibrary.Libs.gdi32, "SwapBuffers"); GetProcAddress(_glfwLibrary.Win32.libs.gdi32, "SwapBuffers");
if (_glfwLibrary.Libs.ChoosePixelFormat && if (_glfwLibrary.Win32.libs.ChoosePixelFormat &&
_glfwLibrary.Libs.DescribePixelFormat && _glfwLibrary.Win32.libs.DescribePixelFormat &&
_glfwLibrary.Libs.GetPixelFormat && _glfwLibrary.Win32.libs.GetPixelFormat &&
_glfwLibrary.Libs.SetPixelFormat && _glfwLibrary.Win32.libs.SetPixelFormat &&
_glfwLibrary.Libs.SwapBuffers) _glfwLibrary.Win32.libs.SwapBuffers)
{ {
FreeLibrary(_glfwLibrary.Libs.gdi32); FreeLibrary(_glfwLibrary.Win32.libs.gdi32);
_glfwLibrary.Libs.gdi32 = NULL; _glfwLibrary.Win32.libs.gdi32 = NULL;
return GL_FALSE; return GL_FALSE;
} }
} }
@ -75,25 +75,25 @@ static GLboolean initLibraries(void)
// winmm.dll (for joystick and timer support) // winmm.dll (for joystick and timer support)
#ifndef _GLFW_NO_DLOAD_WINMM #ifndef _GLFW_NO_DLOAD_WINMM
_glfwLibrary.Libs.winmm = LoadLibrary("winmm.dll"); _glfwLibrary.Win32.libs.winmm = LoadLibrary("winmm.dll");
if (_glfwLibrary.Libs.winmm != NULL) if (_glfwLibrary.Win32.libs.winmm != NULL)
{ {
_glfwLibrary.Libs.joyGetDevCapsA = (JOYGETDEVCAPSA_T) _glfwLibrary.Win32.libs.joyGetDevCapsA = (JOYGETDEVCAPSA_T)
GetProcAddress(_glfwLibrary.Libs.winmm, "joyGetDevCapsA"); GetProcAddress(_glfwLibrary.Win32.libs.winmm, "joyGetDevCapsA");
_glfwLibrary.Libs.joyGetPos = (JOYGETPOS_T) _glfwLibrary.Win32.libs.joyGetPos = (JOYGETPOS_T)
GetProcAddress(_glfwLibrary.Libs.winmm, "joyGetPos"); GetProcAddress(_glfwLibrary.Win32.libs.winmm, "joyGetPos");
_glfwLibrary.Libs.joyGetPosEx = (JOYGETPOSEX_T) _glfwLibrary.Win32.libs.joyGetPosEx = (JOYGETPOSEX_T)
GetProcAddress(_glfwLibrary.Libs.winmm, "joyGetPosEx"); GetProcAddress(_glfwLibrary.Win32.libs.winmm, "joyGetPosEx");
_glfwLibrary.Libs.timeGetTime = (TIMEGETTIME_T) _glfwLibrary.Win32.libs.timeGetTime = (TIMEGETTIME_T)
GetProcAddress(_glfwLibrary.Libs.winmm, "timeGetTime"); GetProcAddress(_glfwLibrary.Win32.libs.winmm, "timeGetTime");
if (_glfwLibrary.Libs.joyGetDevCapsA && if (_glfwLibrary.Win32.libs.joyGetDevCapsA &&
_glfwLibrary.Libs.joyGetPos && _glfwLibrary.Win32.libs.joyGetPos &&
_glfwLibrary.Libs.joyGetPosEx && _glfwLibrary.Win32.libs.joyGetPosEx &&
_glfwLibrary.Libs.timeGetTime) _glfwLibrary.Win32.libs.timeGetTime)
{ {
FreeLibrary(_glfwLibrary.Libs.winmm); FreeLibrary(_glfwLibrary.Win32.libs.winmm);
_glfwLibrary.Libs.winmm = NULL; _glfwLibrary.Win32.libs.winmm = NULL;
return GL_FALSE; return GL_FALSE;
} }
} }
@ -113,19 +113,19 @@ static void freeLibraries(void)
{ {
// gdi32.dll // gdi32.dll
#ifndef _GLFW_NO_DLOAD_GDI32 #ifndef _GLFW_NO_DLOAD_GDI32
if (_glfwLibrary.Libs.gdi32 != NULL) if (_glfwLibrary.Win32.libs.gdi32 != NULL)
{ {
FreeLibrary(_glfwLibrary.Libs.gdi32); FreeLibrary(_glfwLibrary.Win32.libs.gdi32);
_glfwLibrary.Libs.gdi32 = NULL; _glfwLibrary.Win32.libs.gdi32 = NULL;
} }
#endif // _GLFW_NO_DLOAD_GDI32 #endif // _GLFW_NO_DLOAD_GDI32
// winmm.dll // winmm.dll
#ifndef _GLFW_NO_DLOAD_WINMM #ifndef _GLFW_NO_DLOAD_WINMM
if (_glfwLibrary.Libs.winmm != NULL) if (_glfwLibrary.Win32.libs.winmm != NULL)
{ {
FreeLibrary(_glfwLibrary.Libs.winmm); FreeLibrary(_glfwLibrary.Win32.libs.winmm);
_glfwLibrary.Libs.winmm = NULL; _glfwLibrary.Win32.libs.winmm = NULL;
} }
#endif // _GLFW_NO_DLOAD_WINMM #endif // _GLFW_NO_DLOAD_WINMM
} }
@ -157,7 +157,7 @@ int _glfwPlatformInit(void)
// with the FOREGROUNDLOCKTIMEOUT system setting (we do this as early // with the FOREGROUNDLOCKTIMEOUT system setting (we do this as early
// as possible in the hope of still being the foreground process) // as possible in the hope of still being the foreground process)
SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0, SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0,
&_glfwLibrary.Sys.foregroundLockTimeout, 0); &_glfwLibrary.Win32.foregroundLockTimeout, 0);
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, (LPVOID) 0, SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, (LPVOID) 0,
SPIF_SENDCHANGE); SPIF_SENDCHANGE);
@ -165,43 +165,31 @@ int _glfwPlatformInit(void)
osi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); osi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&osi); GetVersionEx(&osi);
_glfwLibrary.Sys.winVer = _GLFW_WIN_UNKNOWN; _glfwLibrary.Win32.sys.winVer = _GLFW_WIN_UNKNOWN;
if (osi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) if (osi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
{ {
if (osi.dwMajorVersion == 4 && osi.dwMinorVersion < 10) if (osi.dwMajorVersion == 4 && osi.dwMinorVersion < 10)
_glfwLibrary.Sys.winVer = _GLFW_WIN_95; _glfwLibrary.Win32.sys.winVer = _GLFW_WIN_95;
else if (osi.dwMajorVersion == 4 && osi.dwMinorVersion < 90) else if (osi.dwMajorVersion == 4 && osi.dwMinorVersion < 90)
_glfwLibrary.Sys.winVer = _GLFW_WIN_98; _glfwLibrary.Win32.sys.winVer = _GLFW_WIN_98;
else if (osi.dwMajorVersion == 4 && osi.dwMinorVersion == 90) else if (osi.dwMajorVersion == 4 && osi.dwMinorVersion == 90)
_glfwLibrary.Sys.winVer = _GLFW_WIN_ME; _glfwLibrary.Win32.sys.winVer = _GLFW_WIN_ME;
else if (osi.dwMajorVersion >= 4) else if (osi.dwMajorVersion >= 4)
_glfwLibrary.Sys.winVer = _GLFW_WIN_UNKNOWN_9x; _glfwLibrary.Win32.sys.winVer = _GLFW_WIN_UNKNOWN_9x;
} }
else if (osi.dwPlatformId == VER_PLATFORM_WIN32_NT) else if (osi.dwPlatformId == VER_PLATFORM_WIN32_NT)
{ {
if (osi.dwMajorVersion == 4 && osi.dwMinorVersion == 0) if (osi.dwMajorVersion == 4 && osi.dwMinorVersion == 0)
_glfwLibrary.Sys.winVer = _GLFW_WIN_NT4; _glfwLibrary.Win32.sys.winVer = _GLFW_WIN_NT4;
else if (osi.dwMajorVersion == 5 && osi.dwMinorVersion == 0) else if (osi.dwMajorVersion == 5 && osi.dwMinorVersion == 0)
_glfwLibrary.Sys.winVer = _GLFW_WIN_2K; _glfwLibrary.Win32.sys.winVer = _GLFW_WIN_2K;
else if (osi.dwMajorVersion == 5 && osi.dwMinorVersion == 1) else if (osi.dwMajorVersion == 5 && osi.dwMinorVersion == 1)
_glfwLibrary.Sys.winVer = _GLFW_WIN_XP; _glfwLibrary.Win32.sys.winVer = _GLFW_WIN_XP;
else if (osi.dwMajorVersion == 5 && osi.dwMinorVersion == 2) else if (osi.dwMajorVersion == 5 && osi.dwMinorVersion == 2)
_glfwLibrary.Sys.winVer = _GLFW_WIN_NET_SERVER; _glfwLibrary.Win32.sys.winVer = _GLFW_WIN_NET_SERVER;
else if (osi.dwMajorVersion >= 5) else if (osi.dwMajorVersion >= 5)
_glfwLibrary.Sys.winVer = _GLFW_WIN_UNKNOWN_NT; _glfwLibrary.Win32.sys.winVer = _GLFW_WIN_UNKNOWN_NT;
}
// Do we have Unicode support?
if (_glfwLibrary.Sys.winVer >= _GLFW_WIN_NT4)
{
// Windows NT/2000/XP/.NET has Unicode support
_glfwLibrary.Sys.hasUnicode = GL_TRUE;
}
else
{
// Windows 9x/ME does not have Unicode support
_glfwLibrary.Sys.hasUnicode = GL_FALSE;
} }
// Load libraries (DLLs) // Load libraries (DLLs)
@ -215,10 +203,10 @@ int _glfwPlatformInit(void)
#endif #endif
// Retrieve GLFW instance handle // Retrieve GLFW instance handle
_glfwLibrary.instance = GetModuleHandle(NULL); _glfwLibrary.Win32.instance = GetModuleHandle(NULL);
// System keys are not disabled // System keys are not disabled
_glfwWin.keyboardHook = NULL; _glfwLibrary.Win32.keyboardHook = NULL;
// Install atexit() routine // Install atexit() routine
atexit(glfw_atexit); atexit(glfw_atexit);
@ -247,7 +235,7 @@ int _glfwPlatformTerminate(void)
// Restore FOREGROUNDLOCKTIMEOUT system setting // Restore FOREGROUNDLOCKTIMEOUT system setting
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0,
(LPVOID) _glfwLibrary.Sys.foregroundLockTimeout, (LPVOID) _glfwLibrary.Win32.foregroundLockTimeout,
SPIF_SENDCHANGE); SPIF_SENDCHANGE);
return GL_TRUE; return GL_TRUE;

View File

@ -43,11 +43,6 @@ static GLboolean isJoystickPresent(int joy)
{ {
JOYINFO ji; JOYINFO ji;
// Windows NT 4.0 MMSYSTEM only supports 2 sticks (other Windows
// versions support 16 sticks)
if (_glfwLibrary.Sys.winVer == _GLFW_WIN_NT4 && joy > GLFW_JOYSTICK_2)
return GL_FALSE;
// Is it a valid stick ID (Windows don't support more than 16 sticks)? // Is it a valid stick ID (Windows don't support more than 16 sticks)?
if (joy < GLFW_JOYSTICK_1 || joy > GLFW_JOYSTICK_16) if (joy < GLFW_JOYSTICK_1 || joy > GLFW_JOYSTICK_16)
return GL_FALSE; return GL_FALSE;

View File

@ -47,24 +47,24 @@ void _glfwInitTimer(void)
if (QueryPerformanceFrequency((LARGE_INTEGER*) &freq)) if (QueryPerformanceFrequency((LARGE_INTEGER*) &freq))
{ {
// Performance counter is available => use it! // Performance counter is available => use it!
_glfwLibrary.Timer.HasPerformanceCounter = GL_TRUE; _glfwLibrary.Win32.timer.HasPerformanceCounter = GL_TRUE;
// Counter resolution is 1 / counter frequency // Counter resolution is 1 / counter frequency
_glfwLibrary.Timer.Resolution = 1.0 / (double) freq; _glfwLibrary.Win32.timer.Resolution = 1.0 / (double) freq;
// Set start time for timer // Set start time for timer
QueryPerformanceCounter((LARGE_INTEGER*) &_glfwLibrary.Timer.t0_64); QueryPerformanceCounter((LARGE_INTEGER*) &_glfwLibrary.Win32.timer.t0_64);
} }
else else
{ {
// No performace counter available => use the tick counter // No performace counter available => use the tick counter
_glfwLibrary.Timer.HasPerformanceCounter = GL_FALSE; _glfwLibrary.Win32.timer.HasPerformanceCounter = GL_FALSE;
// Counter resolution is 1 ms // Counter resolution is 1 ms
_glfwLibrary.Timer.Resolution = 0.001; _glfwLibrary.Win32.timer.Resolution = 0.001;
// Set start time for timer // Set start time for timer
_glfwLibrary.Timer.t0_32 = _glfw_timeGetTime(); _glfwLibrary.Win32.timer.t0_32 = _glfw_timeGetTime();
} }
} }
@ -82,16 +82,16 @@ double _glfwPlatformGetTime(void)
double t; double t;
__int64 t_64; __int64 t_64;
if (_glfwLibrary.Timer.HasPerformanceCounter) if (_glfwLibrary.Win32.timer.HasPerformanceCounter)
{ {
QueryPerformanceCounter((LARGE_INTEGER*) &t_64); QueryPerformanceCounter((LARGE_INTEGER*) &t_64);
t = (double)(t_64 - _glfwLibrary.Timer.t0_64); t = (double)(t_64 - _glfwLibrary.Win32.timer.t0_64);
} }
else else
t = (double)(_glfw_timeGetTime() - _glfwLibrary.Timer.t0_32); t = (double)(_glfw_timeGetTime() - _glfwLibrary.Win32.timer.t0_32);
// Calculate the current time in seconds // Calculate the current time in seconds
return t * _glfwLibrary.Timer.Resolution; return t * _glfwLibrary.Win32.timer.Resolution;
} }
@ -103,12 +103,12 @@ void _glfwPlatformSetTime(double t)
{ {
__int64 t_64; __int64 t_64;
if (_glfwLibrary.Timer.HasPerformanceCounter) if (_glfwLibrary.Win32.timer.HasPerformanceCounter)
{ {
QueryPerformanceCounter((LARGE_INTEGER*) &t_64); QueryPerformanceCounter((LARGE_INTEGER*) &t_64);
_glfwLibrary.Timer.t0_64 = t_64 - (__int64) (t / _glfwLibrary.Timer.Resolution); _glfwLibrary.Win32.timer.t0_64 = t_64 - (__int64) (t / _glfwLibrary.Win32.timer.Resolution);
} }
else else
_glfwLibrary.Timer.t0_32 = _glfw_timeGetTime() - (int)(t * 1000.0); _glfwLibrary.Win32.timer.t0_32 = _glfw_timeGetTime() - (int)(t * 1000.0);
} }

File diff suppressed because it is too large Load Diff