Merge branch 'utf8' into multi-monitor

Conflicts:
	src/CMakeLists.txt
This commit is contained in:
Camilla Berglund
2012-02-04 20:12:28 +01:00
45 changed files with 2299 additions and 489 deletions
+10 -10
View File
@@ -19,26 +19,26 @@ include_directories(${GLFW_SOURCE_DIR}/src
${GLFW_BINARY_DIR}/src
${GLFW_INCLUDE_DIR})
set(common_SOURCES monitor.c enable.c error.c fullscreen.c gamma.c init.c input.c
joystick.c opengl.c time.c window.c)
set(common_SOURCES error.c fullscreen.c gamma.c init.c input.c
joystick.c monitor.c opengl.c time.c window.c)
if(_GLFW_COCOA_NSGL)
set(libglfw_SOURCES ${common_SOURCES} cocoa_enable.m cocoa_fullscreen.m
cocoa_gamma.m cocoa_init.m cocoa_joystick.m
set(libglfw_SOURCES ${common_SOURCES} cocoa_fullscreen.m cocoa_gamma.m
cocoa_init.m cocoa_input.m cocoa_joystick.m
cocoa_opengl.m cocoa_time.m cocoa_window.m)
# For some reason, CMake doesn't know about .m
set_source_files_properties(${libglfw_SOURCES} PROPERTIES LANGUAGE C)
elseif(_GLFW_WIN32_WGL)
set(libglfw_SOURCES ${common_SOURCES} win32_enable.c win32_fullscreen.c
win32_gamma.c win32_init.c win32_joystick.c
set(libglfw_SOURCES ${common_SOURCES} win32_fullscreen.c win32_gamma.c
win32_init.c win32_input.c win32_joystick.c
win32_opengl.c win32_time.c win32_window.c
win32_dllmain.c win32_monitor.c)
elseif(_GLFW_X11_GLX)
set(libglfw_SOURCES ${common_SOURCES} x11_monitor.c x11_enable.c
x11_fullscreen.c x11_gamma.c x11_init.c x11_joystick.c
x11_keysym2unicode.c x11_opengl.c x11_time.c
x11_window.c)
set(libglfw_SOURCES ${common_SOURCES} x11_fullscreen.c x11_gamma.c
x11_init.c x11_input.c x11_joystick.c
x11_keysym2unicode.c x11_monitor.c x11_opengl.c
x11_time.c x11_window.c)
else()
message(FATAL_ERROR "No supported platform was selected")
endif(_GLFW_COCOA_NSGL)
+22 -11
View File
@@ -232,11 +232,13 @@ static long getElementValue(_glfwJoystick* joystick, _glfwJoystickElement* eleme
static void removeJoystick(_glfwJoystick* joystick)
{
int i;
if (joystick->present)
{
joystick->present = GL_FALSE;
for (int i = 0; i < joystick->numAxes; i++)
for (i = 0; i < joystick->numAxes; i++)
{
_glfwJoystickElement* axes =
(_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick->axes, i);
@@ -245,7 +247,7 @@ static void removeJoystick(_glfwJoystick* joystick)
CFArrayRemoveAllValues(joystick->axes);
joystick->numAxes = 0;
for (int i = 0; i < joystick->numButtons; i++)
for (i = 0; i < joystick->numButtons; i++)
{
_glfwJoystickElement* button =
(_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick->buttons, i);
@@ -254,7 +256,7 @@ static void removeJoystick(_glfwJoystick* joystick)
CFArrayRemoveAllValues(joystick->buttons);
joystick->numButtons = 0;
for (int i = 0; i < joystick->numHats; i++)
for (i = 0; i < joystick->numHats; i++)
{
_glfwJoystickElement* hat =
(_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick->hats, i);
@@ -287,23 +289,26 @@ static void removalCallback(void* target, IOReturn result, void* refcon, void* s
static void pollJoystickEvents(void)
{
for (int i = 0; i < GLFW_JOYSTICK_LAST + 1; i++)
int i;
CFIndex j;
for (i = 0; i < GLFW_JOYSTICK_LAST + 1; i++)
{
_glfwJoystick* joystick = &_glfwJoysticks[i];
if (joystick->present)
{
for (CFIndex i = 0; i < joystick->numButtons; i++)
for (j = 0; j < joystick->numButtons; j++)
{
_glfwJoystickElement* button =
(_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick->buttons, i);
(_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick->buttons, j);
button->value = getElementValue(joystick, button);
}
for (CFIndex i = 0; i < joystick->numAxes; i++)
for (j = 0; j < joystick->numAxes; j++)
{
_glfwJoystickElement* axes =
(_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick->axes, i);
(_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick->axes, j);
axes->value = getElementValue(joystick, axes);
}
}
@@ -449,7 +454,9 @@ void _glfwInitJoysticks(void)
void _glfwTerminateJoysticks(void)
{
for (int i = 0; i < GLFW_JOYSTICK_LAST + 1; i++)
int i;
for (i = 0; i < GLFW_JOYSTICK_LAST + 1; i++)
{
_glfwJoystick* joystick = &_glfwJoysticks[i];
removeJoystick(joystick);
@@ -498,6 +505,8 @@ int _glfwPlatformGetJoystickParam(int joy, int param)
int _glfwPlatformGetJoystickPos(int joy, float* pos, int numaxes)
{
int i;
if (joy < GLFW_JOYSTICK_1 || joy > GLFW_JOYSTICK_LAST)
return 0;
@@ -514,7 +523,7 @@ int _glfwPlatformGetJoystickPos(int joy, float* pos, int numaxes)
// Update joystick state
pollJoystickEvents();
for (int i = 0; i < numaxes; i++)
for (i = 0; i < numaxes; i++)
{
_glfwJoystickElement* axes =
(_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick.axes, i);
@@ -543,6 +552,8 @@ int _glfwPlatformGetJoystickPos(int joy, float* pos, int numaxes)
int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons,
int numbuttons)
{
int i;
if (joy < GLFW_JOYSTICK_1 || joy > GLFW_JOYSTICK_LAST)
return 0;
@@ -559,7 +570,7 @@ int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons,
// Update joystick state
pollJoystickEvents();
for (int i = 0; i < numbuttons; i++)
for (i = 0; i < numbuttons; i++)
{
_glfwJoystickElement* button = (_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick.buttons, i);
buttons[i] = button->value ? GLFW_PRESS : GLFW_RELEASE;
+152 -113
View File
@@ -147,7 +147,7 @@ static const unsigned int MAC_TO_GLFW_KEYCODE_MAPPING[128] =
/* 07 */ GLFW_KEY_X,
/* 08 */ GLFW_KEY_C,
/* 09 */ GLFW_KEY_V,
/* 0a */ -1,
/* 0a */ GLFW_KEY_GRAVE_ACCENT,
/* 0b */ GLFW_KEY_B,
/* 0c */ GLFW_KEY_Q,
/* 0d */ GLFW_KEY_W,
@@ -187,7 +187,7 @@ static const unsigned int MAC_TO_GLFW_KEYCODE_MAPPING[128] =
/* 2f */ GLFW_KEY_PERIOD,
/* 30 */ GLFW_KEY_TAB,
/* 31 */ GLFW_KEY_SPACE,
/* 32 */ GLFW_KEY_GRAVE_ACCENT,
/* 32 */ GLFW_KEY_WORLD_1,
/* 33 */ GLFW_KEY_BACKSPACE,
/* 34 */ -1,
/* 35 */ GLFW_KEY_ESCAPE,
@@ -393,7 +393,7 @@ static int convertMacKeyCode(unsigned int macKeyCode)
if ([event modifierFlags] & NSCommandKeyMask)
{
if (!window->sysKeysDisabled)
if (window->systemKeys)
[super keyDown:event];
}
else
@@ -443,20 +443,66 @@ static int convertMacKeyCode(unsigned int macKeyCode)
@end
//////////////////////////////////////////////////////////////////////////
////// GLFW platform API //////
//////////////////////////////////////////////////////////////////////////
//========================================================================
// Here is where the window is created, and the OpenGL rendering context is
// created
// Create the Cocoa window
//========================================================================
int _glfwPlatformOpenWindow(_GLFWwindow* window,
const _GLFWwndconfig *wndconfig,
const _GLFWfbconfig *fbconfig)
static GLboolean createWindow(_GLFWwindow* window,
const _GLFWwndconfig* wndconfig)
{
unsigned int styleMask = 0;
if (wndconfig->mode == GLFW_WINDOWED)
{
styleMask = NSTitledWindowMask | NSClosableWindowMask |
NSMiniaturizableWindowMask;
if (wndconfig->resizable)
styleMask |= NSResizableWindowMask;
}
else
styleMask = NSBorderlessWindowMask;
window->NS.window = [[NSWindow alloc]
initWithContentRect:NSMakeRect(0, 0, window->width, window->height)
styleMask:styleMask
backing:NSBackingStoreBuffered
defer:NO];
if (window->NS.window == nil)
{
_glfwSetError(GLFW_PLATFORM_ERROR,
"Cocoa/NSOpenGL: Failed to create window");
return GL_FALSE;
}
[window->NS.window setTitle:[NSString stringWithUTF8String:wndconfig->title]];
[window->NS.window setContentView:[[GLFWContentView alloc]
initWithGlfwWindow:window]];
[window->NS.window setDelegate:window->NS.delegate];
[window->NS.window setAcceptsMouseMovedEvents:YES];
[window->NS.window center];
return GL_TRUE;
}
//========================================================================
// Create the OpenGL context
//========================================================================
static GLboolean createContext(_GLFWwindow* window,
const _GLFWwndconfig* wndconfig,
const _GLFWfbconfig* fbconfig)
{
unsigned int attributeCount = 0;
// Mac OS X needs non-zero color size, so set resonable values
int colorBits = fbconfig->redBits + fbconfig->greenBits + fbconfig->blueBits;
if (colorBits == 0)
colorBits = 24;
else if (colorBits < 15)
colorBits = 15;
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
// Fail if any OpenGL version above 2.1 other than 3.2 was requested
if (wndconfig->glMajor > 3 ||
@@ -499,104 +545,7 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
return GL_FALSE;
}
// We can only have one application delegate, but we only allocate it the
// first time we create a window to keep all window code in this file
if (_glfwLibrary.NS.delegate == nil)
{
_glfwLibrary.NS.delegate = [[GLFWApplicationDelegate alloc] init];
if (_glfwLibrary.NS.delegate == nil)
{
_glfwSetError(GLFW_PLATFORM_ERROR,
"Cocoa/NSOpenGL: Failed to create application "
"delegate");
return GL_FALSE;
}
[NSApp setDelegate:_glfwLibrary.NS.delegate];
}
window->NS.delegate = [[GLFWWindowDelegate alloc] initWithGlfwWindow:window];
if (window->NS.delegate == nil)
{
_glfwSetError(GLFW_PLATFORM_ERROR,
"Cocoa/NSOpenGL: Failed to create window delegate");
return GL_FALSE;
}
// Mac OS X needs non-zero color size, so set resonable values
int colorBits = fbconfig->redBits + fbconfig->greenBits + fbconfig->blueBits;
if (colorBits == 0)
colorBits = 24;
else if (colorBits < 15)
colorBits = 15;
// Ignored hints:
// OpenGLMajor, OpenGLMinor, OpenGLForward:
// pending Mac OS X support for OpenGL 3.x
// OpenGLDebug
// pending it meaning anything on Mac OS X
// Don't use accumulation buffer support; it's not accelerated
// Aux buffers probably aren't accelerated either
CFDictionaryRef fullscreenMode = NULL;
if (wndconfig->mode == GLFW_FULLSCREEN)
{
// I think it's safe to pass 0 to the refresh rate for this function
// rather than conditionalizing the code to call the version which
// doesn't specify refresh...
fullscreenMode =
CGDisplayBestModeForParametersAndRefreshRateWithProperty(
CGMainDisplayID(),
colorBits + fbconfig->alphaBits,
window->width, window->height,
wndconfig->refreshRate,
// Controversial, see macosx_fullscreen.m for discussion
kCGDisplayModeIsSafeForHardware,
NULL);
window->width =
[[(id)fullscreenMode objectForKey:(id)kCGDisplayWidth] intValue];
window->height =
[[(id)fullscreenMode objectForKey:(id)kCGDisplayHeight] intValue];
}
unsigned int styleMask = 0;
if (wndconfig->mode == GLFW_WINDOWED)
{
styleMask = NSTitledWindowMask | NSClosableWindowMask |
NSMiniaturizableWindowMask;
if (wndconfig->resizable)
styleMask |= NSResizableWindowMask;
}
else
styleMask = NSBorderlessWindowMask;
window->NS.window = [[NSWindow alloc]
initWithContentRect:NSMakeRect(0, 0, window->width, window->height)
styleMask:styleMask
backing:NSBackingStoreBuffered
defer:NO];
[window->NS.window setTitle:[NSString stringWithCString:wndconfig->title
encoding:NSISOLatin1StringEncoding]];
[window->NS.window setContentView:[[GLFWContentView alloc] initWithGlfwWindow:window]];
[window->NS.window setDelegate:window->NS.delegate];
[window->NS.window setAcceptsMouseMovedEvents:YES];
[window->NS.window center];
if (wndconfig->mode == GLFW_FULLSCREEN)
{
CGCaptureAllDisplays();
CGDisplaySwitchToMode(CGMainDisplayID(), fullscreenMode);
}
unsigned int attribute_count = 0;
#define ADD_ATTR(x) { attributes[attribute_count++] = x; }
#define ADD_ATTR(x) { attributes[attributeCount++] = x; }
#define ADD_ATTR2(x, y) { ADD_ATTR(x); ADD_ATTR(y); }
// Arbitrary array size here
@@ -675,9 +624,100 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
return GL_FALSE;
}
return GL_TRUE;
}
//////////////////////////////////////////////////////////////////////////
////// GLFW platform API //////
//////////////////////////////////////////////////////////////////////////
//========================================================================
// Here is where the window is created, and the OpenGL rendering context is
// created
//========================================================================
int _glfwPlatformOpenWindow(_GLFWwindow* window,
const _GLFWwndconfig *wndconfig,
const _GLFWfbconfig *fbconfig)
{
// We can only have one application delegate, but we only allocate it the
// first time we create a window to keep all window code in this file
if (_glfwLibrary.NS.delegate == nil)
{
_glfwLibrary.NS.delegate = [[GLFWApplicationDelegate alloc] init];
if (_glfwLibrary.NS.delegate == nil)
{
_glfwSetError(GLFW_PLATFORM_ERROR,
"Cocoa/NSOpenGL: Failed to create application "
"delegate");
return GL_FALSE;
}
[NSApp setDelegate:_glfwLibrary.NS.delegate];
}
window->NS.delegate = [[GLFWWindowDelegate alloc] initWithGlfwWindow:window];
if (window->NS.delegate == nil)
{
_glfwSetError(GLFW_PLATFORM_ERROR,
"Cocoa/NSOpenGL: Failed to create window delegate");
return GL_FALSE;
}
// Mac OS X needs non-zero color size, so set resonable values
int colorBits = fbconfig->redBits + fbconfig->greenBits + fbconfig->blueBits;
if (colorBits == 0)
colorBits = 24;
else if (colorBits < 15)
colorBits = 15;
// Ignored hints:
// OpenGLMajor, OpenGLMinor, OpenGLForward:
// pending Mac OS X support for OpenGL 3.x
// OpenGLDebug
// pending it meaning anything on Mac OS X
// Don't use accumulation buffer support; it's not accelerated
// Aux buffers probably aren't accelerated either
CFDictionaryRef fullscreenMode = NULL;
if (wndconfig->mode == GLFW_FULLSCREEN)
{
// I think it's safe to pass 0 to the refresh rate for this function
// rather than conditionalizing the code to call the version which
// doesn't specify refresh...
fullscreenMode =
CGDisplayBestModeForParametersAndRefreshRateWithProperty(
CGMainDisplayID(),
colorBits + fbconfig->alphaBits,
window->width, window->height,
wndconfig->refreshRate,
// Controversial, see macosx_fullscreen.m for discussion
kCGDisplayModeIsSafeForHardware,
NULL);
window->width =
[[(id)fullscreenMode objectForKey:(id)kCGDisplayWidth] intValue];
window->height =
[[(id)fullscreenMode objectForKey:(id)kCGDisplayHeight] intValue];
}
if (!createWindow(window, wndconfig))
return GL_FALSE;
if (!createContext(window, wndconfig, fbconfig))
return GL_FALSE;
[window->NS.window makeKeyAndOrderFront:nil];
[window->NSGL.context setView:[window->NS.window contentView]];
if (wndconfig->mode == GLFW_FULLSCREEN)
{
CGCaptureAllDisplays();
CGDisplaySwitchToMode(CGMainDisplayID(), fullscreenMode);
}
if (wndconfig->mode == GLFW_FULLSCREEN)
{
// TODO: Make this work on pre-Leopard systems
@@ -737,8 +777,7 @@ void _glfwPlatformCloseWindow(_GLFWwindow* window)
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char *title)
{
[window->NS.window setTitle:[NSString stringWithCString:title
encoding:NSISOLatin1StringEncoding]];
[window->NS.window setTitle:[NSString stringWithUTF8String:title]];
}
//========================================================================
-192
View File
@@ -1,192 +0,0 @@
//========================================================================
// GLFW - An OpenGL library
// Platform: Any
// API version: 3.0
// WWW: http://www.glfw.org/
//------------------------------------------------------------------------
// Copyright (c) 2002-2006 Marcus Geelnard
// Copyright (c) 2006-2010 Camilla Berglund <elmindreda@elmindreda.org>
//
// 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"
//========================================================================
// Enable and disable sticky keys mode
//========================================================================
static void enableStickyKeys(_GLFWwindow* window)
{
window->stickyKeys = GL_TRUE;
}
static void disableStickyKeys(_GLFWwindow* window)
{
int i;
window->stickyKeys = GL_FALSE;
// Release all sticky keys
for (i = 0; i <= GLFW_KEY_LAST; i++)
{
if (window->key[i] == GLFW_STICK)
window->key[i] = GLFW_RELEASE;
}
}
//========================================================================
// Enable and disable sticky mouse buttons mode
//========================================================================
static void enableStickyMouseButtons(_GLFWwindow* window)
{
window->stickyMouseButtons = GL_TRUE;
}
static void disableStickyMouseButtons(_GLFWwindow* window)
{
int i;
window->stickyMouseButtons = GL_FALSE;
// Release all sticky mouse buttons
for (i = 0; i <= GLFW_MOUSE_BUTTON_LAST; i++)
{
if (window->mouseButton[i] == GLFW_STICK)
window->mouseButton[i] = GLFW_RELEASE;
}
}
//========================================================================
// Enable and disable system keys
//========================================================================
static void enableSystemKeys(_GLFWwindow* window)
{
if (!window->sysKeysDisabled)
return;
_glfwPlatformEnableSystemKeys(window);
// Indicate that system keys are no longer disabled
window->sysKeysDisabled = GL_FALSE;
}
static void disableSystemKeys(_GLFWwindow* window)
{
if (window->sysKeysDisabled)
return;
_glfwPlatformDisableSystemKeys(window);
// Indicate that system keys are now disabled
window->sysKeysDisabled = GL_TRUE;
}
//========================================================================
// Enable and disable key repeat
//========================================================================
static void enableKeyRepeat(_GLFWwindow* window)
{
window->keyRepeat = GL_TRUE;
}
static void disableKeyRepeat(_GLFWwindow* window)
{
window->keyRepeat = GL_FALSE;
}
//////////////////////////////////////////////////////////////////////////
////// GLFW public API //////
//////////////////////////////////////////////////////////////////////////
//========================================================================
// Enable certain GLFW/window/system functions
//========================================================================
GLFWAPI void glfwEnable(GLFWwindow window, int token)
{
if (!_glfwInitialized)
{
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
return;
}
switch (token)
{
case GLFW_STICKY_KEYS:
enableStickyKeys(window);
break;
case GLFW_STICKY_MOUSE_BUTTONS:
enableStickyMouseButtons(window);
break;
case GLFW_SYSTEM_KEYS:
enableSystemKeys(window);
break;
case GLFW_KEY_REPEAT:
enableKeyRepeat(window);
break;
default:
_glfwSetError(GLFW_INVALID_ENUM, NULL);
break;
}
}
//========================================================================
// Disable certain GLFW/window/system functions
//========================================================================
GLFWAPI void glfwDisable(GLFWwindow window, int token)
{
if (!_glfwInitialized)
{
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
return;
}
switch (token)
{
case GLFW_STICKY_KEYS:
disableStickyKeys(window);
break;
case GLFW_STICKY_MOUSE_BUTTONS:
disableStickyMouseButtons(window);
break;
case GLFW_SYSTEM_KEYS:
disableSystemKeys(window);
break;
case GLFW_KEY_REPEAT:
disableKeyRepeat(window);
break;
default:
_glfwSetError(GLFW_INVALID_ENUM, NULL);
break;
}
}
+1 -14
View File
@@ -67,26 +67,13 @@ void _glfwFree(void* ptr)
// Initialize various GLFW state
//========================================================================
GLFWAPI int glfwInit(void)
{
return glfwInitWithModels(NULL, NULL);
}
//========================================================================
// Initialize various GLFW state using custom model interfaces
//========================================================================
GLFWAPI int glfwInitWithModels(GLFWthreadmodel* threading, GLFWallocator* allocator)
GLFWAPI int glfwInit(GLFWallocator* allocator)
{
if (_glfwInitialized)
return GL_TRUE;
memset(&_glfwLibrary, 0, sizeof(_glfwLibrary));
if (threading)
_glfwLibrary.threading = *threading;
if (allocator)
{
// Verify that the specified model is complete
+190 -48
View File
@@ -31,6 +31,122 @@
#include "internal.h"
//========================================================================
// Sets the cursor mode for the specified window
//========================================================================
static void setCursorMode(_GLFWwindow* window, int mode)
{
int centerPosX, centerPosY;
if (mode != GLFW_CURSOR_NORMAL &&
mode != GLFW_CURSOR_HIDDEN &&
mode != GLFW_CURSOR_CAPTURED)
{
_glfwSetError(GLFW_INVALID_ENUM, NULL);
return;
}
if (window->cursorMode == mode)
return;
centerPosX = window->width / 2;
centerPosY = window->height / 2;
if (mode == GLFW_CURSOR_CAPTURED)
_glfwPlatformSetMouseCursorPos(window, centerPosX, centerPosY);
else if (window->cursorMode == GLFW_CURSOR_CAPTURED)
{
_glfwPlatformSetMouseCursorPos(window, centerPosX, centerPosY);
_glfwInputCursorMotion(window,
centerPosX - window->cursorPosX,
centerPosY - window->cursorPosY);
}
_glfwPlatformSetCursorMode(window, mode);
window->cursorMode = mode;
}
//========================================================================
// Set sticky keys mode for the specified window
//========================================================================
static void setStickyKeys(_GLFWwindow* window, int enabled)
{
if (window->stickyKeys == enabled)
return;
if (!enabled)
{
int i;
// Release all sticky keys
for (i = 0; i <= GLFW_KEY_LAST; i++)
{
if (window->key[i] == GLFW_STICK)
window->key[i] = GLFW_RELEASE;
}
}
window->stickyKeys = enabled;
}
//========================================================================
// Set sticky mouse buttons mode for the specified window
//========================================================================
static void setStickyMouseButtons(_GLFWwindow* window, int enabled)
{
if (window->stickyMouseButtons == enabled)
return;
if (!enabled)
{
int i;
// Release all sticky mouse buttons
for (i = 0; i <= GLFW_MOUSE_BUTTON_LAST; i++)
{
if (window->mouseButton[i] == GLFW_STICK)
window->mouseButton[i] = GLFW_RELEASE;
}
}
window->stickyMouseButtons = enabled;
}
//========================================================================
// Set system keys for the specified window
//========================================================================
static void setSystemKeys(_GLFWwindow* window, int enabled)
{
if (window->systemKeys == enabled)
return;
if (enabled)
_glfwPlatformEnableSystemKeys(window);
else
_glfwPlatformDisableSystemKeys(window);
window->systemKeys = enabled;
}
//========================================================================
// Set key repeat for the specified window
//========================================================================
static void setKeyRepeat(_GLFWwindow* window, int enabled)
{
window->keyRepeat = enabled;
}
//////////////////////////////////////////////////////////////////////////
////// GLFW internal API //////
//////////////////////////////////////////////////////////////////////////
@@ -41,7 +157,7 @@
void _glfwInputKey(_GLFWwindow* window, int key, int action)
{
GLboolean keyrepeat = GL_FALSE;
GLboolean repeated = GL_FALSE;
if (key < 0 || key > GLFW_KEY_LAST)
return;
@@ -55,12 +171,12 @@ void _glfwInputKey(_GLFWwindow* window, int key, int action)
window->key[key] = GLFW_STICK;
else
{
keyrepeat = (window->key[key] == GLFW_PRESS) && (action == GLFW_PRESS);
repeated = (window->key[key] == GLFW_PRESS) && (action == GLFW_PRESS);
window->key[key] = (char) action;
}
// Call user callback function
if (_glfwLibrary.keyCallback && (window->keyRepeat || !keyrepeat))
if (_glfwLibrary.keyCallback && (window->keyRepeat || !repeated))
_glfwLibrary.keyCallback(window, key, action);
}
@@ -150,6 +266,77 @@ void _glfwInputCursorMotion(_GLFWwindow* window, int x, int y)
////// GLFW public API //////
//////////////////////////////////////////////////////////////////////////
//========================================================================
// Returns the specified input mode of the specified window
//========================================================================
GLFWAPI int glfwGetInputMode(GLFWwindow handle, int mode)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized)
{
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
return 0;
}
switch (mode)
{
case GLFW_CURSOR_MODE:
return window->cursorMode;
case GLFW_STICKY_KEYS:
return window->stickyKeys;
case GLFW_STICKY_MOUSE_BUTTONS:
return window->stickyMouseButtons;
case GLFW_SYSTEM_KEYS:
return window->systemKeys;
case GLFW_KEY_REPEAT:
return window->keyRepeat;
default:
_glfwSetError(GLFW_INVALID_ENUM, NULL);
return 0;
}
}
//========================================================================
// Sets the specified input mode of the specified window
//========================================================================
GLFWAPI void glfwSetInputMode(GLFWwindow handle, int mode, int value)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized)
{
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
return;
}
switch (mode)
{
case GLFW_CURSOR_MODE:
setCursorMode(window, value);
break;
case GLFW_STICKY_KEYS:
setStickyKeys(window, value ? GL_TRUE : GL_FALSE);
break;
case GLFW_STICKY_MOUSE_BUTTONS:
setStickyMouseButtons(window, value ? GL_TRUE : GL_FALSE);
break;
case GLFW_SYSTEM_KEYS:
setSystemKeys(window, value ? GL_TRUE : GL_FALSE);
break;
case GLFW_KEY_REPEAT:
setKeyRepeat(window, value ? GL_TRUE : GL_FALSE);
break;
default:
_glfwSetError(GLFW_INVALID_ENUM, NULL);
break;
}
}
//========================================================================
// Returns the state of the specified key for the specified window
//========================================================================
@@ -300,51 +487,6 @@ GLFWAPI void glfwGetScrollOffset(GLFWwindow handle, int* xoffset, int* yoffset)
}
//========================================================================
// Sets the cursor mode for the specified window
//========================================================================
GLFWAPI void glfwSetCursorMode(GLFWwindow handle, int mode)
{
int centerPosX, centerPosY;
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized)
{
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
return;
}
if (mode != GLFW_CURSOR_NORMAL &&
mode != GLFW_CURSOR_HIDDEN &&
mode != GLFW_CURSOR_CAPTURED)
{
_glfwSetError(GLFW_INVALID_ENUM, NULL);
return;
}
if (window->cursorMode == mode)
return;
centerPosX = window->width / 2;
centerPosY = window->height / 2;
if (mode == GLFW_CURSOR_CAPTURED)
_glfwPlatformSetMouseCursorPos(window, centerPosX, centerPosY);
else if (window->cursorMode == GLFW_CURSOR_CAPTURED)
{
_glfwPlatformSetMouseCursorPos(window, centerPosX, centerPosY);
_glfwInputCursorMotion(window,
centerPosX - window->cursorPosX,
centerPosY - window->cursorPosY);
}
_glfwPlatformSetCursorMode(window, mode);
window->cursorMode = mode;
}
//========================================================================
// Set callback function for keyboard input
//========================================================================
+4 -5
View File
@@ -184,7 +184,7 @@ struct _GLFWwindow
GLboolean stickyKeys;
GLboolean stickyMouseButtons;
GLboolean keyRepeat;
GLboolean sysKeysDisabled; // system keys disabled flag
GLboolean systemKeys; // system keys enabled flag
int cursorPosX, cursorPosY;
int cursorMode;
int scrollX, scrollY;
@@ -266,7 +266,6 @@ struct _GLFWlibrary
GLFWcharfun charCallback;
GLFWmonitordevicefun monitorCallback;
GLFWthreadmodel threading;
GLFWallocator allocator;
GLFWgammaramp currentRamp;
@@ -301,7 +300,7 @@ int _glfwPlatformInit(void);
int _glfwPlatformTerminate(void);
const char* _glfwPlatformGetVersionString(void);
// Enable/Disable
// Input
void _glfwPlatformEnableSystemKeys(_GLFWwindow* window);
void _glfwPlatformDisableSystemKeys(_GLFWwindow* window);
@@ -365,14 +364,14 @@ void _glfwSetError(int error, const char* description);
// Window management (window.c)
void _glfwSetDefaultWindowHints(void);
// WIndow event notification
// Window event notification (window.c)
void _glfwInputWindowFocus(_GLFWwindow* window, GLboolean activated);
void _glfwInputWindowPos(_GLFWwindow* window, int x, int y);
void _glfwInputWindowSize(_GLFWwindow* window, int width, int height);
void _glfwInputWindowIconify(_GLFWwindow* window, int iconified);
void _glfwInputWindowDamage(_GLFWwindow* window);
// Input event notification
// Input event notification (input.c)
void _glfwInputKey(_GLFWwindow* window, int key, int action);
void _glfwInputChar(_GLFWwindow* window, int character);
void _glfwInputScroll(_GLFWwindow* window, int x, int y);
+5 -5
View File
@@ -47,7 +47,7 @@ static GLboolean initLibraries(void)
#ifndef _GLFW_NO_DLOAD_GDI32
// gdi32.dll (OpenGL pixel format functions & SwapBuffers)
_glfwLibrary.Win32.gdi.instance = LoadLibrary("gdi32.dll");
_glfwLibrary.Win32.gdi.instance = LoadLibrary(L"gdi32.dll");
if (!_glfwLibrary.Win32.gdi.instance)
return GL_FALSE;
@@ -81,12 +81,12 @@ static GLboolean initLibraries(void)
#ifndef _GLFW_NO_DLOAD_WINMM
// winmm.dll (for joystick and timer support)
_glfwLibrary.Win32.winmm.instance = LoadLibrary("winmm.dll");
_glfwLibrary.Win32.winmm.instance = LoadLibrary(L"winmm.dll");
if (!_glfwLibrary.Win32.winmm.instance)
return GL_FALSE;
_glfwLibrary.Win32.winmm.joyGetDevCapsA = (JOYGETDEVCAPSA_T)
GetProcAddress(_glfwLibrary.Win32.winmm.instance, "joyGetDevCapsA");
_glfwLibrary.Win32.winmm.joyGetDevCaps = (JOYGETDEVCAPS_T)
GetProcAddress(_glfwLibrary.Win32.winmm.instance, "joyGetDevCapsW");
_glfwLibrary.Win32.winmm.joyGetPos = (JOYGETPOS_T)
GetProcAddress(_glfwLibrary.Win32.winmm.instance, "joyGetPos");
_glfwLibrary.Win32.winmm.joyGetPosEx = (JOYGETPOSEX_T)
@@ -94,7 +94,7 @@ static GLboolean initLibraries(void)
_glfwLibrary.Win32.winmm.timeGetTime = (TIMEGETTIME_T)
GetProcAddress(_glfwLibrary.Win32.winmm.instance, "timeGetTime");
if (!_glfwLibrary.Win32.winmm.joyGetDevCapsA ||
if (!_glfwLibrary.Win32.winmm.joyGetDevCaps ||
!_glfwLibrary.Win32.winmm.joyGetPos ||
!_glfwLibrary.Win32.winmm.joyGetPosEx ||
!_glfwLibrary.Win32.winmm.timeGetTime)
+7 -5
View File
@@ -45,6 +45,8 @@
// thinks it is the only one that gets to do so
#undef APIENTRY
#define UNICODE
#include <windows.h>
#include <mmsystem.h>
#include <Dbt.h>
@@ -163,7 +165,7 @@ typedef BOOL (WINAPI * SETDEVICEGAMMARAMP_T) (HDC,PVOID);
// winmm.dll function pointer typedefs
#ifndef _GLFW_NO_DLOAD_WINMM
typedef MMRESULT (WINAPI * JOYGETDEVCAPSA_T) (UINT,LPJOYCAPSA,UINT);
typedef MMRESULT (WINAPI * JOYGETDEVCAPS_T) (UINT,LPJOYCAPS,UINT);
typedef MMRESULT (WINAPI * JOYGETPOS_T) (UINT,LPJOYINFO);
typedef MMRESULT (WINAPI * JOYGETPOSEX_T) (UINT,LPJOYINFOEX);
typedef DWORD (WINAPI * TIMEGETTIME_T) (void);
@@ -191,12 +193,12 @@ typedef DWORD (WINAPI * TIMEGETTIME_T) (void);
// winmm.dll shortcuts
#ifndef _GLFW_NO_DLOAD_WINMM
#define _glfw_joyGetDevCaps _glfwLibrary.Win32.winmm.joyGetDevCapsA
#define _glfw_joyGetDevCaps _glfwLibrary.Win32.winmm.joyGetDevCaps
#define _glfw_joyGetPos _glfwLibrary.Win32.winmm.joyGetPos
#define _glfw_joyGetPosEx _glfwLibrary.Win32.winmm.joyGetPosEx
#define _glfw_timeGetTime _glfwLibrary.Win32.winmm.timeGetTime
#else
#define _glfw_joyGetDevCaps joyGetDevCapsA
#define _glfw_joyGetDevCaps joyGetDevCaps
#define _glfw_joyGetPos joyGetPos
#define _glfw_joyGetPosEx joyGetPosEx
#define _glfw_timeGetTime timeGetTime
@@ -205,7 +207,7 @@ typedef DWORD (WINAPI * TIMEGETTIME_T) (void);
// We use versioned window class names in order not to cause conflicts
// between applications using different versions of GLFW
#define _GLFW_WNDCLASSNAME "GLFW30"
#define _GLFW_WNDCLASSNAME L"GLFW30"
#define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowWin32 Win32
@@ -311,7 +313,7 @@ typedef struct _GLFWlibraryWin32
// winmm.dll
struct {
HINSTANCE instance;
JOYGETDEVCAPSA_T joyGetDevCapsA;
JOYGETDEVCAPS_T joyGetDevCaps;
JOYGETPOS_T joyGetPos;
JOYGETPOSEX_T joyGetPosEx;
TIMEGETTIME_T timeGetTime;
+50 -4
View File
@@ -33,6 +33,31 @@
#include <stdlib.h>
//========================================================================
// Convert the specified UTF-8 string to a wide string
//========================================================================
static WCHAR* createWideStringFromUTF8(const char* source)
{
WCHAR* target;
int length;
length = MultiByteToWideChar(CP_UTF8, 0, source, -1, NULL, 0);
if (!length)
return NULL;
target = (WCHAR*) _glfwMalloc(sizeof(WCHAR) * (length + 1));
if (!MultiByteToWideChar(CP_UTF8, 0, source, -1, target, length + 1))
{
_glfwFree(target);
return NULL;
}
return target;
}
//========================================================================
// Convert BPP to RGB bits based on "best guess"
//========================================================================
@@ -1229,7 +1254,7 @@ static ATOM registerWindowClass(void)
wc.lpszClassName = _GLFW_WNDCLASSNAME; // Set class name
// Load user-provided icon if available
wc.hIcon = LoadIcon(_glfwLibrary.Win32.instance, "GLFW_ICON");
wc.hIcon = LoadIcon(_glfwLibrary.Win32.instance, L"GLFW_ICON");
if (!wc.hIcon)
{
// Load default icon
@@ -1289,9 +1314,10 @@ static int createWindow(_GLFWwindow* window,
const _GLFWfbconfig* fbconfig)
{
DWORD dwStyle, dwExStyle;
int pixelFormat, fullWidth, fullHeight;
int length, pixelFormat, fullWidth, fullHeight;
RECT wa;
POINT pos;
WCHAR* wideTitle;
// Set common window styles
dwStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
@@ -1340,9 +1366,17 @@ static int createWindow(_GLFWwindow* window,
else
SystemParametersInfo(SPI_GETWORKAREA, 0, &wa, 0);
wideTitle = createWideStringFromUTF8(wndconfig->title);
if (!wideTitle)
{
_glfwSetError(GLFW_PLATFORM_ERROR,
"glfwOpenWindow: Failed to convert title to wide string");
return;
}
window->Win32.handle = CreateWindowEx(window->Win32.dwExStyle,
_GLFW_WNDCLASSNAME,
wndconfig->title,
wideTitle,
window->Win32.dwStyle,
wa.left, wa.top, // Window position
fullWidth, // Decorated window width
@@ -1358,6 +1392,8 @@ static int createWindow(_GLFWwindow* window,
return GL_FALSE;
}
_glfwFree(wideTitle);
window->WGL.DC = GetDC(window->Win32.handle);
if (!window->WGL.DC)
{
@@ -1577,7 +1613,17 @@ void _glfwPlatformCloseWindow(_GLFWwindow* window)
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title)
{
SetWindowText(window->Win32.handle, title);
WCHAR* wideTitle = createWideStringFromUTF8(title);
if (!wideTitle)
{
_glfwSetError(GLFW_PLATFORM_ERROR,
"glfwSetWindowTitle: Failed to convert title to wide string");
return;
}
SetWindowText(window->Win32.handle, wideTitle);
_glfwFree(wideTitle);
}
+2 -1
View File
@@ -309,6 +309,7 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height,
window->height = height;
window->mode = mode;
window->cursorMode = GLFW_CURSOR_NORMAL;
window->systemKeys = GL_TRUE;
// Open the actual window and create its context
if (!_glfwPlatformOpenWindow(window, &wndconfig, &fbconfig))
@@ -330,7 +331,7 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height,
// The GLFW specification states that fullscreen windows have the cursor
// captured by default
if (mode == GLFW_FULLSCREEN)
glfwSetCursorMode(window, GLFW_CURSOR_CAPTURED);
glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_CAPTURED);
// Clearing the front buffer to black to avoid garbage pixels left over
// from previous uses of our bit of VRAM
+1 -2
View File
@@ -31,8 +31,7 @@
#include "internal.h"
void (*glXGetProcAddress(const GLubyte* procName))();
void (*glXGetProcAddressARB(const GLubyte* procName))();
// This is the only glXGetProcAddress variant not declared by glxext.h
void (*glXGetProcAddressEXT(const GLubyte* procName))();
+2 -7
View File
@@ -46,13 +46,6 @@
// extensions and not all operating systems come with an up-to-date version
#include "../support/GL/glxext.h"
// We need declarations for GLX version 1.3 or above even if the server doesn't
// support version 1.3
#ifndef GLX_VERSION_1_3
#error "GLX header version 1.3 or above is required"
#endif
// With XFree86, we can use the XF86VidMode extension
#if defined(_GLFW_HAS_XF86VIDMODE)
#include <X11/extensions/xf86vmode.h>
@@ -142,6 +135,8 @@ typedef struct _GLFWwindowX11
Colormap colormap; // Window colormap
Window handle; // Window handle
Atom wmDeleteWindow; // WM_DELETE_WINDOW atom
Atom wmName; // _NET_WM_NAME atom
Atom wmIconName; // _NET_WM_ICON_NAME atom
Atom wmPing; // _NET_WM_PING atom
Atom wmState; // _NET_WM_STATE atom
Atom wmStateFullscreen; // _NET_WM_STATE_FULLSCREEN atom
+39 -3
View File
@@ -195,6 +195,12 @@ static GLboolean hasEWMH(_GLFWwindow* window)
window->X11.wmStateFullscreen =
getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_STATE_FULLSCREEN");
window->X11.wmName =
getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_NAME");
window->X11.wmIconName =
getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_ICON_NAME");
window->X11.wmPing =
getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_PING");
@@ -1509,9 +1515,39 @@ void _glfwPlatformCloseWindow(_GLFWwindow* window)
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title)
{
// Set window & icon title
XStoreName(_glfwLibrary.X11.display, window->X11.handle, title);
XSetIconName(_glfwLibrary.X11.display, window->X11.handle, title);
Atom type = XInternAtom(_glfwLibrary.X11.display, "UTF8_STRING", False);
#if defined(X_HAVE_UTF8_STRING)
Xutf8SetWMProperties(_glfwLibrary.X11.display,
window->X11.handle,
title, title,
NULL, 0,
NULL, NULL, NULL);
#else
// This may be a slightly better fallback than using XStoreName and
// XSetIconName, which always store their arguments using STRING
XmbSetWMProperties(_glfwLibrary.X11.display,
window->X11.handle,
title, title,
NULL, 0,
NULL, NULL, NULL);
#endif
if (window->X11.wmName != None)
{
XChangeProperty(_glfwLibrary.X11.display, window->X11.handle,
window->X11.wmName, type, 8,
PropModeReplace,
(unsigned char*) title, strlen(title));
}
if (window->X11.wmIconName != None)
{
XChangeProperty(_glfwLibrary.X11.display, window->X11.handle,
window->X11.wmIconName, type, 8,
PropModeReplace,
(unsigned char*) title, strlen(title));
}
}