mirror of
https://github.com/glfw/glfw.git
synced 2026-09-18 22:55:46 +00:00
Merge branch 'master' into clipboard
Conflicts: src/CMakeLists.txt src/libglfw.pc.cmake
This commit is contained in:
+42
-52
@@ -1,69 +1,59 @@
|
||||
|
||||
if(UNIX)
|
||||
if(_GLFW_HAS_XRANDR)
|
||||
set(GLFW_PKGLIBS "${GLFW_PKGLIBS} xrandr")
|
||||
endif(_GLFW_HAS_XRANDR)
|
||||
if(_GLFW_HAS_XF86VIDMODE)
|
||||
set(GLFW_PKGLIBS "${GLFW_PKGLIBS} xxf86vm")
|
||||
endif(_GLFW_HAS_XF86VIDMODE)
|
||||
if (_GLFW_X11_GLX)
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libglfw.pc.cmake
|
||||
${CMAKE_CURRENT_BINARY_DIR}/libglfw.pc @ONLY)
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libglfw.pc DESTINATION lib/pkgconfig)
|
||||
endif(UNIX)
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libglfw.pc
|
||||
DESTINATION lib/pkgconfig)
|
||||
endif()
|
||||
|
||||
include_directories(${GLFW_SOURCE_DIR}/src
|
||||
${GLFW_BINARY_DIR}/src
|
||||
${GLFW_INCLUDE_DIR})
|
||||
${glfw_INCLUDE_DIRS})
|
||||
|
||||
set(common_SOURCES clipboard.c error.c fullscreen.c gamma.c init.c input.c
|
||||
joystick.c opengl.c time.c window.c)
|
||||
|
||||
if(_GLFW_COCOA_NSGL)
|
||||
set(libglfw_SOURCES ${common_SOURCES} cocoa_clipboard.m cocoa_fullscreen.m
|
||||
cocoa_gamma.c cocoa_init.m cocoa_input.m
|
||||
cocoa_joystick.m cocoa_opengl.m cocoa_time.c
|
||||
cocoa_window.m)
|
||||
if (_GLFW_COCOA_NSGL)
|
||||
set(glfw_SOURCES ${common_SOURCES} cocoa_clipboard.m cocoa_fullscreen.m
|
||||
cocoa_gamma.c cocoa_init.m cocoa_input.m cocoa_joystick.m
|
||||
cocoa_opengl.m cocoa_time.c 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_clipboard.c 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)
|
||||
elseif(_GLFW_X11_GLX)
|
||||
set(libglfw_SOURCES ${common_SOURCES} x11_clipboard.c x11_fullscreen.c
|
||||
x11_gamma.c x11_init.c x11_input.c x11_joystick.c
|
||||
x11_keysym2unicode.c x11_opengl.c x11_time.c
|
||||
x11_window.c)
|
||||
else()
|
||||
message(FATAL_ERROR "No supported platform was selected")
|
||||
endif(_GLFW_COCOA_NSGL)
|
||||
set_source_files_properties(${glfw_SOURCES} PROPERTIES LANGUAGE C)
|
||||
elseif (_GLFW_WIN32_WGL)
|
||||
set(glfw_SOURCES ${common_SOURCES} win32_clipboard.c 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)
|
||||
elseif (_GLFW_X11_GLX)
|
||||
set(glfw_SOURCES ${common_SOURCES} x11_clipboard.c x11_fullscreen.c
|
||||
x11_gamma.c x11_init.c x11_input.c x11_joystick.c
|
||||
x11_keysym2unicode.c x11_opengl.c x11_time.c x11_window.c)
|
||||
endif()
|
||||
|
||||
add_library(libglfwStatic STATIC ${libglfw_SOURCES})
|
||||
add_library(libglfwShared SHARED ${libglfw_SOURCES})
|
||||
target_link_libraries(libglfwShared ${GLFW_LIBRARIES})
|
||||
set_target_properties(libglfwStatic libglfwShared PROPERTIES
|
||||
CLEAN_DIRECT_OUTPUT 1
|
||||
OUTPUT_NAME glfw)
|
||||
add_library(glfw ${glfw_SOURCES})
|
||||
|
||||
if(WIN32)
|
||||
# The GLFW DLL needs a special compile-time macro and import library name
|
||||
set_target_properties(libglfwShared PROPERTIES
|
||||
DEFINE_SYMBOL GLFW_BUILD_DLL
|
||||
PREFIX ""
|
||||
IMPORT_PREFIX ""
|
||||
IMPORT_SUFFIX "dll.lib")
|
||||
endif(WIN32)
|
||||
if (BUILD_SHARED_LIBS)
|
||||
|
||||
if(APPLE)
|
||||
# Append -fno-common to the compile flags to work around a bug in the Apple GCC
|
||||
get_target_property(CFLAGS libglfwShared COMPILE_FLAGS)
|
||||
if(NOT CFLAGS)
|
||||
set(CFLAGS "")
|
||||
endif(NOT CFLAGS)
|
||||
set_target_properties(libglfwShared PROPERTIES COMPILE_FLAGS "${CFLAGS} -fno-common")
|
||||
endif(APPLE)
|
||||
if (_GLFW_WIN32_WGL)
|
||||
# The GLFW DLL needs a special compile-time macro and import library name
|
||||
set_target_properties(glfw PROPERTIES
|
||||
COMPILE_DEFINITIONS "_GLFW_BUILD_DLL;_GLFW_NO_DLOAD_GDI32;_GLFW_NO_DLOAD_WINMM"
|
||||
PREFIX ""
|
||||
IMPORT_PREFIX ""
|
||||
IMPORT_SUFFIX "dll.lib")
|
||||
elseif (_GLFW_COCOA_NSGL)
|
||||
# Append -fno-common to the compile flags to work around a bug in the Apple GCC
|
||||
get_target_property(glfw_CFLAGS glfw COMPILE_FLAGS)
|
||||
if (NOT glfw_CFLAGS)
|
||||
set(glfw_CFLAGS "")
|
||||
endif()
|
||||
set_target_properties(glfw PROPERTIES
|
||||
COMPILE_FLAGS "${glfw_CFLAGS} -fno-common")
|
||||
endif()
|
||||
|
||||
install(TARGETS libglfwStatic libglfwShared DESTINATION lib)
|
||||
target_link_libraries(glfw ${glfw_LIBRARIES})
|
||||
target_link_libraries(glfw LINK_INTERFACE_LIBRARIES)
|
||||
endif()
|
||||
|
||||
install(TARGETS glfw DESTINATION lib)
|
||||
|
||||
|
||||
+155
-29
@@ -29,47 +29,166 @@
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Check whether the display mode should be included in enumeration
|
||||
//========================================================================
|
||||
|
||||
static BOOL modeIsGood(NSDictionary* mode)
|
||||
static GLboolean modeIsGood(CGDisplayModeRef mode)
|
||||
{
|
||||
// This is a bit controversial, if you've got something other than an
|
||||
// LCD computer monitor as an output device you might not want these
|
||||
// checks. You might also want to reject modes which are interlaced,
|
||||
// or TV out. There is no one-size-fits-all policy that can work here.
|
||||
// This seems like a decent compromise, but certain applications may
|
||||
// wish to patch this...
|
||||
return [[mode objectForKey:(id)kCGDisplayBitsPerPixel] intValue] >= 15 &&
|
||||
[mode objectForKey:(id)kCGDisplayModeIsSafeForHardware] != nil &&
|
||||
[mode objectForKey:(id)kCGDisplayModeIsStretched] == nil;
|
||||
uint32_t flags = CGDisplayModeGetIOFlags(mode);
|
||||
if (!(flags & kDisplayModeValidFlag) || !(flags & kDisplayModeSafeFlag))
|
||||
return GL_FALSE;
|
||||
|
||||
if (flags & kDisplayModeInterlacedFlag)
|
||||
return GL_FALSE;
|
||||
|
||||
if (flags & kDisplayModeTelevisionFlag)
|
||||
return GL_FALSE;
|
||||
|
||||
if (flags & kDisplayModeStretchedFlag)
|
||||
return GL_FALSE;
|
||||
|
||||
CFStringRef format = CGDisplayModeCopyPixelEncoding(mode);
|
||||
if (CFStringCompare(format, CFSTR(IO16BitDirectPixels), 0) &&
|
||||
CFStringCompare(format, CFSTR(IO32BitDirectPixels), 0))
|
||||
{
|
||||
CFRelease(format);
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
CFRelease(format);
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Convert Core Graphics display mode to GLFW video mode
|
||||
//========================================================================
|
||||
|
||||
static GLFWvidmode vidmodeFromCGDisplayMode(NSDictionary* mode)
|
||||
static GLFWvidmode vidmodeFromCGDisplayMode(CGDisplayModeRef mode)
|
||||
{
|
||||
unsigned int width =
|
||||
[[mode objectForKey:(id)kCGDisplayWidth] unsignedIntValue];
|
||||
unsigned int height =
|
||||
[[mode objectForKey:(id)kCGDisplayHeight] unsignedIntValue];
|
||||
unsigned int bps =
|
||||
[[mode objectForKey:(id)kCGDisplayBitsPerSample] unsignedIntValue];
|
||||
|
||||
GLFWvidmode result;
|
||||
result.width = width;
|
||||
result.height = height;
|
||||
result.redBits = bps;
|
||||
result.greenBits = bps;
|
||||
result.blueBits = bps;
|
||||
result.width = CGDisplayModeGetWidth(mode);
|
||||
result.height = CGDisplayModeGetHeight(mode);
|
||||
|
||||
CFStringRef format = CGDisplayModeCopyPixelEncoding(mode);
|
||||
|
||||
if (CFStringCompare(format, CFSTR(IO16BitDirectPixels), 0) == 0)
|
||||
{
|
||||
result.redBits = 5;
|
||||
result.greenBits = 5;
|
||||
result.blueBits = 5;
|
||||
}
|
||||
else
|
||||
{
|
||||
result.redBits = 8;
|
||||
result.greenBits = 8;
|
||||
result.blueBits = 8;
|
||||
}
|
||||
|
||||
CFRelease(format);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
////// GLFW internal API //////
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//========================================================================
|
||||
// Change the current video mode
|
||||
//========================================================================
|
||||
|
||||
GLboolean _glfwSetVideoMode(int* width, int* height, int* bpp, int* refreshRate)
|
||||
{
|
||||
CGDisplayModeRef bestMode = NULL;
|
||||
CFArrayRef modes;
|
||||
CFIndex count, i;
|
||||
unsigned int leastSizeDiff = UINT_MAX;
|
||||
double leastRateDiff = DBL_MAX;
|
||||
|
||||
modes = CGDisplayCopyAllDisplayModes(CGMainDisplayID(), NULL);
|
||||
count = CFArrayGetCount(modes);
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
CGDisplayModeRef mode = (CGDisplayModeRef) CFArrayGetValueAtIndex(modes, i);
|
||||
if (!modeIsGood(mode))
|
||||
continue;
|
||||
|
||||
int modeBPP;
|
||||
|
||||
// Identify display mode pixel encoding
|
||||
{
|
||||
CFStringRef format = CGDisplayModeCopyPixelEncoding(mode);
|
||||
|
||||
if (CFStringCompare(format, CFSTR(IO16BitDirectPixels), 0) == 0)
|
||||
modeBPP = 16;
|
||||
else
|
||||
modeBPP = 32;
|
||||
|
||||
CFRelease(format);
|
||||
}
|
||||
|
||||
int modeWidth = (int) CGDisplayModeGetWidth(mode);
|
||||
int modeHeight = (int) CGDisplayModeGetHeight(mode);
|
||||
|
||||
unsigned int sizeDiff = (abs(modeBPP - *bpp) << 25) |
|
||||
((modeWidth - *width) * (modeWidth - *width) +
|
||||
(modeHeight - *height) * (modeHeight - *height));
|
||||
|
||||
double rateDiff;
|
||||
|
||||
if (*refreshRate > 0)
|
||||
rateDiff = fabs(CGDisplayModeGetRefreshRate(mode) - *refreshRate);
|
||||
else
|
||||
{
|
||||
// If no refresh rate was specified, then they're all the same
|
||||
rateDiff = 0;
|
||||
}
|
||||
|
||||
if ((sizeDiff < leastSizeDiff) ||
|
||||
(sizeDiff == leastSizeDiff && (rateDiff < leastRateDiff)))
|
||||
{
|
||||
bestMode = mode;
|
||||
|
||||
leastSizeDiff = sizeDiff;
|
||||
leastRateDiff = rateDiff;
|
||||
}
|
||||
}
|
||||
|
||||
if (!bestMode)
|
||||
{
|
||||
CFRelease(modes);
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
CGDisplayCapture(CGMainDisplayID());
|
||||
CGDisplaySetDisplayMode(CGMainDisplayID(), bestMode, NULL);
|
||||
|
||||
CFRelease(modes);
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Restore the previously saved (original) video mode
|
||||
//========================================================================
|
||||
|
||||
void _glfwRestoreVideoMode(void)
|
||||
{
|
||||
CGDisplaySetDisplayMode(CGMainDisplayID(),
|
||||
_glfwLibrary.NS.desktopMode,
|
||||
NULL);
|
||||
|
||||
CGDisplayRelease(CGMainDisplayID());
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
////// GLFW platform API //////
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@@ -80,19 +199,26 @@ static GLFWvidmode vidmodeFromCGDisplayMode(NSDictionary* mode)
|
||||
|
||||
int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
|
||||
{
|
||||
NSArray* modes = (NSArray*) CGDisplayAvailableModes(CGMainDisplayID());
|
||||
unsigned int i, j = 0, n = [modes count];
|
||||
CGDisplayModeRef mode;
|
||||
CFArrayRef modes;
|
||||
CFIndex count, i;
|
||||
int stored = 0;
|
||||
|
||||
for (i = 0; i < n && j < (unsigned)maxcount; i++)
|
||||
modes = CGDisplayCopyAllDisplayModes(CGMainDisplayID(), NULL);
|
||||
count = CFArrayGetCount(modes);
|
||||
|
||||
for (i = 0; i < count && stored < maxcount; i++)
|
||||
{
|
||||
NSDictionary *mode = [modes objectAtIndex:i];
|
||||
mode = (CGDisplayModeRef) CFArrayGetValueAtIndex(modes, i);
|
||||
if (modeIsGood(mode))
|
||||
list[j++] = vidmodeFromCGDisplayMode(mode);
|
||||
list[stored++] = vidmodeFromCGDisplayMode(mode);
|
||||
}
|
||||
|
||||
return j;
|
||||
CFRelease(modes);
|
||||
return stored;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Get the desktop video mode
|
||||
//========================================================================
|
||||
|
||||
+20
-2
@@ -33,6 +33,7 @@
|
||||
//========================================================================
|
||||
// Change to our application bundle's resources directory, if present
|
||||
//========================================================================
|
||||
|
||||
static void changeToResourcesDirectory(void)
|
||||
{
|
||||
char resourcesPath[MAXPATHLEN];
|
||||
@@ -78,6 +79,8 @@ static void changeToResourcesDirectory(void)
|
||||
|
||||
int _glfwPlatformInit(void)
|
||||
{
|
||||
_glfwLibrary.NS.autoreleasePool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
_glfwLibrary.NS.OpenGLFramework =
|
||||
CFBundleGetBundleWithIdentifier(CFSTR("com.apple.opengl"));
|
||||
if (_glfwLibrary.NS.OpenGLFramework == NULL)
|
||||
@@ -89,8 +92,7 @@ int _glfwPlatformInit(void)
|
||||
|
||||
changeToResourcesDirectory();
|
||||
|
||||
_glfwLibrary.NS.desktopMode =
|
||||
(NSDictionary*) CGDisplayCurrentMode(CGMainDisplayID());
|
||||
_glfwLibrary.NS.desktopMode = CGDisplayCopyDisplayMode(CGMainDisplayID());
|
||||
|
||||
// Save the original gamma ramp
|
||||
_glfwLibrary.originalRampSize = CGDisplayGammaTableCapacity(CGMainDisplayID());
|
||||
@@ -101,9 +103,17 @@ int _glfwPlatformInit(void)
|
||||
|
||||
_glfwInitJoysticks();
|
||||
|
||||
_glfwLibrary.NS.eventSource = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
|
||||
if (!_glfwLibrary.NS.eventSource)
|
||||
return GL_FALSE;
|
||||
|
||||
CGEventSourceSetLocalEventsSuppressionInterval(_glfwLibrary.NS.eventSource,
|
||||
0.0);
|
||||
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Close window, if open, and shut down GLFW
|
||||
//========================================================================
|
||||
@@ -112,9 +122,17 @@ int _glfwPlatformTerminate(void)
|
||||
{
|
||||
// TODO: Probably other cleanup
|
||||
|
||||
if (_glfwLibrary.NS.eventSource)
|
||||
{
|
||||
CFRelease(_glfwLibrary.NS.eventSource);
|
||||
_glfwLibrary.NS.eventSource = NULL;
|
||||
}
|
||||
|
||||
// Restore the original gamma ramp
|
||||
_glfwPlatformSetGammaRamp(&_glfwLibrary.originalRamp);
|
||||
|
||||
CGDisplayModeRelease(_glfwLibrary.NS.desktopMode);
|
||||
|
||||
[NSApp setDelegate:nil];
|
||||
[_glfwLibrary.NS.delegate release];
|
||||
_glfwLibrary.NS.delegate = nil;
|
||||
|
||||
@@ -579,4 +579,3 @@ int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons,
|
||||
return numbuttons;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -59,6 +59,7 @@ void _glfwPlatformSwapBuffers(void)
|
||||
[window->NSGL.context flushBuffer];
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Set double buffering swap interval
|
||||
//========================================================================
|
||||
@@ -71,6 +72,7 @@ void _glfwPlatformSwapInterval(int interval)
|
||||
[window->NSGL.context setValues:&sync forParameter:NSOpenGLCPSwapInterval];
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Check if an OpenGL extension is available at runtime
|
||||
//========================================================================
|
||||
@@ -81,6 +83,7 @@ int _glfwPlatformExtensionSupported(const char* extension)
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Get the function pointer to an OpenGL function
|
||||
//========================================================================
|
||||
@@ -99,6 +102,7 @@ void* _glfwPlatformGetProcAddress(const char* procname)
|
||||
return symbol;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Copies the specified OpenGL state categories from src to dst
|
||||
//========================================================================
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#if defined(__OBJC__)
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#else
|
||||
#include <ApplicationServices/ApplicationServices.h>
|
||||
typedef void* id;
|
||||
#endif
|
||||
|
||||
@@ -90,10 +91,11 @@ typedef struct _GLFWlibraryNS
|
||||
} timer;
|
||||
|
||||
// dlopen handle for dynamically loading OpenGL extension entry points
|
||||
void* OpenGLFramework;
|
||||
id desktopMode;
|
||||
id delegate;
|
||||
id autoreleasePool;
|
||||
void* OpenGLFramework;
|
||||
CGDisplayModeRef desktopMode;
|
||||
CGEventSourceRef eventSource;
|
||||
id delegate;
|
||||
id autoreleasePool;
|
||||
} _GLFWlibraryNS;
|
||||
|
||||
|
||||
@@ -108,5 +110,8 @@ void _glfwInitTimer(void);
|
||||
void _glfwInitJoysticks(void);
|
||||
void _glfwTerminateJoysticks(void);
|
||||
|
||||
// Fullscreen
|
||||
GLboolean _glfwSetVideoMode(int* width, int* height, int* bpp, int* refreshRate);
|
||||
void _glfwRestoreVideoMode(void);
|
||||
|
||||
#endif // _platform_h_
|
||||
|
||||
@@ -74,6 +74,7 @@ double _glfwPlatformGetTime(void)
|
||||
_glfwLibrary.NS.timer.resolution;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Set timer value in seconds
|
||||
//========================================================================
|
||||
|
||||
+196
-200
@@ -112,6 +112,7 @@
|
||||
|
||||
@end
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Delegate for application related notifications
|
||||
//========================================================================
|
||||
@@ -133,142 +134,6 @@
|
||||
|
||||
@end
|
||||
|
||||
//========================================================================
|
||||
// Keyboard symbol translation table
|
||||
//========================================================================
|
||||
|
||||
// TODO: Need to find mappings for F13-F15, volume down/up/mute, and eject.
|
||||
static const unsigned int MAC_TO_GLFW_KEYCODE_MAPPING[128] =
|
||||
{
|
||||
/* 00 */ GLFW_KEY_A,
|
||||
/* 01 */ GLFW_KEY_S,
|
||||
/* 02 */ GLFW_KEY_D,
|
||||
/* 03 */ GLFW_KEY_F,
|
||||
/* 04 */ GLFW_KEY_H,
|
||||
/* 05 */ GLFW_KEY_G,
|
||||
/* 06 */ GLFW_KEY_Z,
|
||||
/* 07 */ GLFW_KEY_X,
|
||||
/* 08 */ GLFW_KEY_C,
|
||||
/* 09 */ GLFW_KEY_V,
|
||||
/* 0a */ GLFW_KEY_GRAVE_ACCENT,
|
||||
/* 0b */ GLFW_KEY_B,
|
||||
/* 0c */ GLFW_KEY_Q,
|
||||
/* 0d */ GLFW_KEY_W,
|
||||
/* 0e */ GLFW_KEY_E,
|
||||
/* 0f */ GLFW_KEY_R,
|
||||
/* 10 */ GLFW_KEY_Y,
|
||||
/* 11 */ GLFW_KEY_T,
|
||||
/* 12 */ GLFW_KEY_1,
|
||||
/* 13 */ GLFW_KEY_2,
|
||||
/* 14 */ GLFW_KEY_3,
|
||||
/* 15 */ GLFW_KEY_4,
|
||||
/* 16 */ GLFW_KEY_6,
|
||||
/* 17 */ GLFW_KEY_5,
|
||||
/* 18 */ GLFW_KEY_EQUAL,
|
||||
/* 19 */ GLFW_KEY_9,
|
||||
/* 1a */ GLFW_KEY_7,
|
||||
/* 1b */ GLFW_KEY_MINUS,
|
||||
/* 1c */ GLFW_KEY_8,
|
||||
/* 1d */ GLFW_KEY_0,
|
||||
/* 1e */ GLFW_KEY_RIGHT_BRACKET,
|
||||
/* 1f */ GLFW_KEY_O,
|
||||
/* 20 */ GLFW_KEY_U,
|
||||
/* 21 */ GLFW_KEY_LEFT_BRACKET,
|
||||
/* 22 */ GLFW_KEY_I,
|
||||
/* 23 */ GLFW_KEY_P,
|
||||
/* 24 */ GLFW_KEY_ENTER,
|
||||
/* 25 */ GLFW_KEY_L,
|
||||
/* 26 */ GLFW_KEY_J,
|
||||
/* 27 */ GLFW_KEY_APOSTROPHE,
|
||||
/* 28 */ GLFW_KEY_K,
|
||||
/* 29 */ GLFW_KEY_SEMICOLON,
|
||||
/* 2a */ GLFW_KEY_BACKSLASH,
|
||||
/* 2b */ GLFW_KEY_COMMA,
|
||||
/* 2c */ GLFW_KEY_SLASH,
|
||||
/* 2d */ GLFW_KEY_N,
|
||||
/* 2e */ GLFW_KEY_M,
|
||||
/* 2f */ GLFW_KEY_PERIOD,
|
||||
/* 30 */ GLFW_KEY_TAB,
|
||||
/* 31 */ GLFW_KEY_SPACE,
|
||||
/* 32 */ GLFW_KEY_WORLD_1,
|
||||
/* 33 */ GLFW_KEY_BACKSPACE,
|
||||
/* 34 */ -1,
|
||||
/* 35 */ GLFW_KEY_ESCAPE,
|
||||
/* 36 */ GLFW_KEY_RIGHT_SUPER,
|
||||
/* 37 */ GLFW_KEY_LEFT_SUPER,
|
||||
/* 38 */ GLFW_KEY_LEFT_SHIFT,
|
||||
/* 39 */ GLFW_KEY_CAPS_LOCK,
|
||||
/* 3a */ GLFW_KEY_LEFT_ALT,
|
||||
/* 3b */ GLFW_KEY_LEFT_CONTROL,
|
||||
/* 3c */ GLFW_KEY_RIGHT_SHIFT,
|
||||
/* 3d */ GLFW_KEY_RIGHT_ALT,
|
||||
/* 3e */ GLFW_KEY_RIGHT_CONTROL,
|
||||
/* 3f */ -1, /* Function */
|
||||
/* 40 */ GLFW_KEY_F17,
|
||||
/* 41 */ GLFW_KEY_KP_DECIMAL,
|
||||
/* 42 */ -1,
|
||||
/* 43 */ GLFW_KEY_KP_MULTIPLY,
|
||||
/* 44 */ -1,
|
||||
/* 45 */ GLFW_KEY_KP_ADD,
|
||||
/* 46 */ -1,
|
||||
/* 47 */ GLFW_KEY_NUM_LOCK, /* Really KeypadClear... */
|
||||
/* 48 */ -1, /* VolumeUp */
|
||||
/* 49 */ -1, /* VolumeDown */
|
||||
/* 4a */ -1, /* Mute */
|
||||
/* 4b */ GLFW_KEY_KP_DIVIDE,
|
||||
/* 4c */ GLFW_KEY_KP_ENTER,
|
||||
/* 4d */ -1,
|
||||
/* 4e */ GLFW_KEY_KP_SUBTRACT,
|
||||
/* 4f */ GLFW_KEY_F18,
|
||||
/* 50 */ GLFW_KEY_F19,
|
||||
/* 51 */ GLFW_KEY_KP_EQUAL,
|
||||
/* 52 */ GLFW_KEY_KP_0,
|
||||
/* 53 */ GLFW_KEY_KP_1,
|
||||
/* 54 */ GLFW_KEY_KP_2,
|
||||
/* 55 */ GLFW_KEY_KP_3,
|
||||
/* 56 */ GLFW_KEY_KP_4,
|
||||
/* 57 */ GLFW_KEY_KP_5,
|
||||
/* 58 */ GLFW_KEY_KP_6,
|
||||
/* 59 */ GLFW_KEY_KP_7,
|
||||
/* 5a */ GLFW_KEY_F20,
|
||||
/* 5b */ GLFW_KEY_KP_8,
|
||||
/* 5c */ GLFW_KEY_KP_9,
|
||||
/* 5d */ -1,
|
||||
/* 5e */ -1,
|
||||
/* 5f */ -1,
|
||||
/* 60 */ GLFW_KEY_F5,
|
||||
/* 61 */ GLFW_KEY_F6,
|
||||
/* 62 */ GLFW_KEY_F7,
|
||||
/* 63 */ GLFW_KEY_F3,
|
||||
/* 64 */ GLFW_KEY_F8,
|
||||
/* 65 */ GLFW_KEY_F9,
|
||||
/* 66 */ -1,
|
||||
/* 67 */ GLFW_KEY_F11,
|
||||
/* 68 */ -1,
|
||||
/* 69 */ GLFW_KEY_F13,
|
||||
/* 6a */ GLFW_KEY_F16,
|
||||
/* 6b */ GLFW_KEY_F14,
|
||||
/* 6c */ -1,
|
||||
/* 6d */ GLFW_KEY_F10,
|
||||
/* 6e */ -1,
|
||||
/* 6f */ GLFW_KEY_F12,
|
||||
/* 70 */ -1,
|
||||
/* 71 */ GLFW_KEY_F15,
|
||||
/* 72 */ GLFW_KEY_INSERT, /* Really Help... */
|
||||
/* 73 */ GLFW_KEY_HOME,
|
||||
/* 74 */ GLFW_KEY_PAGE_UP,
|
||||
/* 75 */ GLFW_KEY_DELETE,
|
||||
/* 76 */ GLFW_KEY_F4,
|
||||
/* 77 */ GLFW_KEY_END,
|
||||
/* 78 */ GLFW_KEY_F2,
|
||||
/* 79 */ GLFW_KEY_PAGE_DOWN,
|
||||
/* 7a */ GLFW_KEY_F1,
|
||||
/* 7b */ GLFW_KEY_LEFT,
|
||||
/* 7c */ GLFW_KEY_RIGHT,
|
||||
/* 7d */ GLFW_KEY_DOWN,
|
||||
/* 7e */ GLFW_KEY_UP,
|
||||
/* 7f */ -1,
|
||||
};
|
||||
|
||||
//========================================================================
|
||||
// Converts a Mac OS X keycode to a GLFW keycode
|
||||
@@ -276,15 +141,150 @@ static const unsigned int MAC_TO_GLFW_KEYCODE_MAPPING[128] =
|
||||
|
||||
static int convertMacKeyCode(unsigned int macKeyCode)
|
||||
{
|
||||
// Keyboard symbol translation table
|
||||
// TODO: Need to find mappings for F13-F15, volume down/up/mute, and eject.
|
||||
static const unsigned int table[128] =
|
||||
{
|
||||
/* 00 */ GLFW_KEY_A,
|
||||
/* 01 */ GLFW_KEY_S,
|
||||
/* 02 */ GLFW_KEY_D,
|
||||
/* 03 */ GLFW_KEY_F,
|
||||
/* 04 */ GLFW_KEY_H,
|
||||
/* 05 */ GLFW_KEY_G,
|
||||
/* 06 */ GLFW_KEY_Z,
|
||||
/* 07 */ GLFW_KEY_X,
|
||||
/* 08 */ GLFW_KEY_C,
|
||||
/* 09 */ GLFW_KEY_V,
|
||||
/* 0a */ GLFW_KEY_GRAVE_ACCENT,
|
||||
/* 0b */ GLFW_KEY_B,
|
||||
/* 0c */ GLFW_KEY_Q,
|
||||
/* 0d */ GLFW_KEY_W,
|
||||
/* 0e */ GLFW_KEY_E,
|
||||
/* 0f */ GLFW_KEY_R,
|
||||
/* 10 */ GLFW_KEY_Y,
|
||||
/* 11 */ GLFW_KEY_T,
|
||||
/* 12 */ GLFW_KEY_1,
|
||||
/* 13 */ GLFW_KEY_2,
|
||||
/* 14 */ GLFW_KEY_3,
|
||||
/* 15 */ GLFW_KEY_4,
|
||||
/* 16 */ GLFW_KEY_6,
|
||||
/* 17 */ GLFW_KEY_5,
|
||||
/* 18 */ GLFW_KEY_EQUAL,
|
||||
/* 19 */ GLFW_KEY_9,
|
||||
/* 1a */ GLFW_KEY_7,
|
||||
/* 1b */ GLFW_KEY_MINUS,
|
||||
/* 1c */ GLFW_KEY_8,
|
||||
/* 1d */ GLFW_KEY_0,
|
||||
/* 1e */ GLFW_KEY_RIGHT_BRACKET,
|
||||
/* 1f */ GLFW_KEY_O,
|
||||
/* 20 */ GLFW_KEY_U,
|
||||
/* 21 */ GLFW_KEY_LEFT_BRACKET,
|
||||
/* 22 */ GLFW_KEY_I,
|
||||
/* 23 */ GLFW_KEY_P,
|
||||
/* 24 */ GLFW_KEY_ENTER,
|
||||
/* 25 */ GLFW_KEY_L,
|
||||
/* 26 */ GLFW_KEY_J,
|
||||
/* 27 */ GLFW_KEY_APOSTROPHE,
|
||||
/* 28 */ GLFW_KEY_K,
|
||||
/* 29 */ GLFW_KEY_SEMICOLON,
|
||||
/* 2a */ GLFW_KEY_BACKSLASH,
|
||||
/* 2b */ GLFW_KEY_COMMA,
|
||||
/* 2c */ GLFW_KEY_SLASH,
|
||||
/* 2d */ GLFW_KEY_N,
|
||||
/* 2e */ GLFW_KEY_M,
|
||||
/* 2f */ GLFW_KEY_PERIOD,
|
||||
/* 30 */ GLFW_KEY_TAB,
|
||||
/* 31 */ GLFW_KEY_SPACE,
|
||||
/* 32 */ GLFW_KEY_WORLD_1,
|
||||
/* 33 */ GLFW_KEY_BACKSPACE,
|
||||
/* 34 */ -1,
|
||||
/* 35 */ GLFW_KEY_ESCAPE,
|
||||
/* 36 */ GLFW_KEY_RIGHT_SUPER,
|
||||
/* 37 */ GLFW_KEY_LEFT_SUPER,
|
||||
/* 38 */ GLFW_KEY_LEFT_SHIFT,
|
||||
/* 39 */ GLFW_KEY_CAPS_LOCK,
|
||||
/* 3a */ GLFW_KEY_LEFT_ALT,
|
||||
/* 3b */ GLFW_KEY_LEFT_CONTROL,
|
||||
/* 3c */ GLFW_KEY_RIGHT_SHIFT,
|
||||
/* 3d */ GLFW_KEY_RIGHT_ALT,
|
||||
/* 3e */ GLFW_KEY_RIGHT_CONTROL,
|
||||
/* 3f */ -1, /* Function */
|
||||
/* 40 */ GLFW_KEY_F17,
|
||||
/* 41 */ GLFW_KEY_KP_DECIMAL,
|
||||
/* 42 */ -1,
|
||||
/* 43 */ GLFW_KEY_KP_MULTIPLY,
|
||||
/* 44 */ -1,
|
||||
/* 45 */ GLFW_KEY_KP_ADD,
|
||||
/* 46 */ -1,
|
||||
/* 47 */ GLFW_KEY_NUM_LOCK, /* Really KeypadClear... */
|
||||
/* 48 */ -1, /* VolumeUp */
|
||||
/* 49 */ -1, /* VolumeDown */
|
||||
/* 4a */ -1, /* Mute */
|
||||
/* 4b */ GLFW_KEY_KP_DIVIDE,
|
||||
/* 4c */ GLFW_KEY_KP_ENTER,
|
||||
/* 4d */ -1,
|
||||
/* 4e */ GLFW_KEY_KP_SUBTRACT,
|
||||
/* 4f */ GLFW_KEY_F18,
|
||||
/* 50 */ GLFW_KEY_F19,
|
||||
/* 51 */ GLFW_KEY_KP_EQUAL,
|
||||
/* 52 */ GLFW_KEY_KP_0,
|
||||
/* 53 */ GLFW_KEY_KP_1,
|
||||
/* 54 */ GLFW_KEY_KP_2,
|
||||
/* 55 */ GLFW_KEY_KP_3,
|
||||
/* 56 */ GLFW_KEY_KP_4,
|
||||
/* 57 */ GLFW_KEY_KP_5,
|
||||
/* 58 */ GLFW_KEY_KP_6,
|
||||
/* 59 */ GLFW_KEY_KP_7,
|
||||
/* 5a */ GLFW_KEY_F20,
|
||||
/* 5b */ GLFW_KEY_KP_8,
|
||||
/* 5c */ GLFW_KEY_KP_9,
|
||||
/* 5d */ -1,
|
||||
/* 5e */ -1,
|
||||
/* 5f */ -1,
|
||||
/* 60 */ GLFW_KEY_F5,
|
||||
/* 61 */ GLFW_KEY_F6,
|
||||
/* 62 */ GLFW_KEY_F7,
|
||||
/* 63 */ GLFW_KEY_F3,
|
||||
/* 64 */ GLFW_KEY_F8,
|
||||
/* 65 */ GLFW_KEY_F9,
|
||||
/* 66 */ -1,
|
||||
/* 67 */ GLFW_KEY_F11,
|
||||
/* 68 */ -1,
|
||||
/* 69 */ GLFW_KEY_F13,
|
||||
/* 6a */ GLFW_KEY_F16,
|
||||
/* 6b */ GLFW_KEY_F14,
|
||||
/* 6c */ -1,
|
||||
/* 6d */ GLFW_KEY_F10,
|
||||
/* 6e */ -1,
|
||||
/* 6f */ GLFW_KEY_F12,
|
||||
/* 70 */ -1,
|
||||
/* 71 */ GLFW_KEY_F15,
|
||||
/* 72 */ GLFW_KEY_INSERT, /* Really Help... */
|
||||
/* 73 */ GLFW_KEY_HOME,
|
||||
/* 74 */ GLFW_KEY_PAGE_UP,
|
||||
/* 75 */ GLFW_KEY_DELETE,
|
||||
/* 76 */ GLFW_KEY_F4,
|
||||
/* 77 */ GLFW_KEY_END,
|
||||
/* 78 */ GLFW_KEY_F2,
|
||||
/* 79 */ GLFW_KEY_PAGE_DOWN,
|
||||
/* 7a */ GLFW_KEY_F1,
|
||||
/* 7b */ GLFW_KEY_LEFT,
|
||||
/* 7c */ GLFW_KEY_RIGHT,
|
||||
/* 7d */ GLFW_KEY_DOWN,
|
||||
/* 7e */ GLFW_KEY_UP,
|
||||
/* 7f */ -1,
|
||||
};
|
||||
|
||||
if (macKeyCode >= 128)
|
||||
return -1;
|
||||
|
||||
// This treats keycodes as *positional*; that is, we'll return 'a'
|
||||
// for the key left of 's', even on an AZERTY keyboard. The charInput
|
||||
// function should still get 'q' though.
|
||||
return MAC_TO_GLFW_KEYCODE_MAPPING[macKeyCode];
|
||||
return table[macKeyCode];
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Content view class for the GLFW window
|
||||
//========================================================================
|
||||
@@ -388,11 +388,11 @@ static int convertMacKeyCode(unsigned int macKeyCode)
|
||||
{
|
||||
NSUInteger i, length;
|
||||
NSString* characters;
|
||||
int code = convertMacKeyCode([event keyCode]);
|
||||
int key = convertMacKeyCode([event keyCode]);
|
||||
|
||||
if (code != -1)
|
||||
if (key != -1)
|
||||
{
|
||||
_glfwInputKey(window, code, GLFW_PRESS);
|
||||
_glfwInputKey(window, key, GLFW_PRESS);
|
||||
|
||||
if ([event modifierFlags] & NSCommandKeyMask)
|
||||
{
|
||||
@@ -412,7 +412,7 @@ static int convertMacKeyCode(unsigned int macKeyCode)
|
||||
|
||||
- (void)flagsChanged:(NSEvent *)event
|
||||
{
|
||||
int mode;
|
||||
int mode, key;
|
||||
unsigned int newModifierFlags =
|
||||
[event modifierFlags] | NSDeviceIndependentModifierFlagsMask;
|
||||
|
||||
@@ -422,14 +422,17 @@ static int convertMacKeyCode(unsigned int macKeyCode)
|
||||
mode = GLFW_RELEASE;
|
||||
|
||||
window->NS.modifierFlags = newModifierFlags;
|
||||
_glfwInputKey(window, MAC_TO_GLFW_KEYCODE_MAPPING[[event keyCode]], mode);
|
||||
|
||||
key = convertMacKeyCode([event keyCode]);
|
||||
if (key != -1)
|
||||
_glfwInputKey(window, key, mode);
|
||||
}
|
||||
|
||||
- (void)keyUp:(NSEvent *)event
|
||||
{
|
||||
int code = convertMacKeyCode([event keyCode]);
|
||||
if (code != -1)
|
||||
_glfwInputKey(window, code, GLFW_RELEASE);
|
||||
int key = convertMacKeyCode([event keyCode]);
|
||||
if (key != -1)
|
||||
_glfwInputKey(window, key, GLFW_RELEASE);
|
||||
}
|
||||
|
||||
- (void)scrollWheel:(NSEvent *)event
|
||||
@@ -446,6 +449,7 @@ static int convertMacKeyCode(unsigned int macKeyCode)
|
||||
|
||||
@end
|
||||
|
||||
|
||||
//========================================================================
|
||||
// GLFW application class
|
||||
//========================================================================
|
||||
@@ -469,13 +473,6 @@ static int convertMacKeyCode(unsigned int macKeyCode)
|
||||
@end
|
||||
|
||||
|
||||
// Prior to Snow Leopard, we need to use this oddly-named semi-private API
|
||||
// to get the application menu working properly. Need to be careful in
|
||||
// case it goes away in a future OS update.
|
||||
@interface NSApplication (NSAppleMenu)
|
||||
- (void)setAppleMenu:(NSMenu*)m;
|
||||
@end
|
||||
|
||||
//========================================================================
|
||||
// Try to figure out what the calling application is called
|
||||
//========================================================================
|
||||
@@ -523,6 +520,7 @@ static NSString* findAppName(void)
|
||||
return @"GLFW Application";
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Set up the menu bar (manually)
|
||||
// This is nasty, nasty stuff -- calls to undocumented semi-private APIs that
|
||||
@@ -530,7 +528,8 @@ static NSString* findAppName(void)
|
||||
// localize(d|able), etc. Loading a nib would save us this horror, but that
|
||||
// doesn't seem like a good thing to require of GLFW's clients.
|
||||
//========================================================================
|
||||
static void setUpMenuBar(void)
|
||||
|
||||
static void createMenuBar(void)
|
||||
{
|
||||
NSString* appName = findAppName();
|
||||
|
||||
@@ -584,37 +583,35 @@ static void setUpMenuBar(void)
|
||||
action:@selector(arrangeInFront:)
|
||||
keyEquivalent:@""];
|
||||
|
||||
// At least guard the call to private API to avoid an exception if it
|
||||
// goes away. Hopefully that means the worst we'll break in future is to
|
||||
// look ugly...
|
||||
if ([NSApp respondsToSelector:@selector(setAppleMenu:)])
|
||||
[NSApp setAppleMenu:appMenu];
|
||||
// Prior to Snow Leopard, we need to use this oddly-named semi-private API
|
||||
// to get the application menu working properly.
|
||||
[NSApp performSelector:@selector(setAppleMenu:) withObject:appMenu];
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Initialize the Cocoa Application Kit
|
||||
//========================================================================
|
||||
static GLboolean initializeCocoa(void)
|
||||
|
||||
static GLboolean initializeAppKit(void)
|
||||
{
|
||||
if (NSApp)
|
||||
return GL_TRUE;
|
||||
|
||||
_glfwLibrary.NS.autoreleasePool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
// Implicitly create shared NSApplication instance
|
||||
[GLFWApplication sharedApplication];
|
||||
|
||||
// Setting up the menu bar must go between sharedApplication
|
||||
// above and finishLaunching below, in order to properly emulate the
|
||||
// behavior of NSApplicationMain
|
||||
setUpMenuBar();
|
||||
createMenuBar();
|
||||
|
||||
[NSApp finishLaunching];
|
||||
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Create the Cocoa window
|
||||
//========================================================================
|
||||
@@ -658,6 +655,7 @@ static GLboolean createWindow(_GLFWwindow* window,
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Create the OpenGL context
|
||||
//========================================================================
|
||||
@@ -686,14 +684,23 @@ static GLboolean createContext(_GLFWwindow* window,
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
if (wndconfig->glProfile)
|
||||
if (wndconfig->glMajor > 2)
|
||||
{
|
||||
// Fail if a profile other than core was explicitly selected
|
||||
if (!wndconfig->glForward)
|
||||
{
|
||||
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
|
||||
"Cocoa/NSOpenGL: The targeted version of Mac OS X "
|
||||
"only supports OpenGL 3.2 contexts if they are "
|
||||
"forward-compatible");
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
if (wndconfig->glProfile != GLFW_OPENGL_CORE_PROFILE)
|
||||
{
|
||||
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
|
||||
"Cocoa/NSOpenGL: The targeted version of Mac OS X "
|
||||
"only supports the OpenGL core profile");
|
||||
"only supports OpenGL 3.2 contexts if they use the "
|
||||
"core profile");
|
||||
return GL_FALSE;
|
||||
}
|
||||
}
|
||||
@@ -721,13 +728,12 @@ static GLboolean createContext(_GLFWwindow* window,
|
||||
#define ADD_ATTR2(x, y) { ADD_ATTR(x); ADD_ATTR(y); }
|
||||
|
||||
// Arbitrary array size here
|
||||
NSOpenGLPixelFormatAttribute attributes[24];
|
||||
NSOpenGLPixelFormatAttribute attributes[40];
|
||||
|
||||
ADD_ATTR(NSOpenGLPFADoubleBuffer);
|
||||
|
||||
if (wndconfig->mode == GLFW_FULLSCREEN)
|
||||
{
|
||||
ADD_ATTR(NSOpenGLPFAFullScreen);
|
||||
ADD_ATTR(NSOpenGLPFANoRecovery);
|
||||
ADD_ATTR2(NSOpenGLPFAScreenMask,
|
||||
CGDisplayIDToOpenGLDisplayMask(CGMainDisplayID()));
|
||||
@@ -813,9 +819,11 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
|
||||
const _GLFWwndconfig* wndconfig,
|
||||
const _GLFWfbconfig* fbconfig)
|
||||
{
|
||||
if (!initializeCocoa())
|
||||
if (!initializeAppKit())
|
||||
return GL_FALSE;
|
||||
|
||||
window->resizable = wndconfig->resizable;
|
||||
|
||||
// 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)
|
||||
@@ -850,28 +858,6 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
|
||||
// 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;
|
||||
|
||||
@@ -883,8 +869,15 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
|
||||
|
||||
if (wndconfig->mode == GLFW_FULLSCREEN)
|
||||
{
|
||||
CGCaptureAllDisplays();
|
||||
CGDisplaySwitchToMode(CGMainDisplayID(), fullscreenMode);
|
||||
int bpp = colorBits + fbconfig->alphaBits;
|
||||
|
||||
if (!_glfwSetVideoMode(&window->width,
|
||||
&window->height,
|
||||
&bpp,
|
||||
&window->refreshRate))
|
||||
{
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
[[window->NS.window contentView] enterFullScreenMode:[NSScreen mainScreen]
|
||||
withOptions:nil];
|
||||
@@ -914,9 +907,7 @@ void _glfwPlatformCloseWindow(_GLFWwindow* window)
|
||||
{
|
||||
[[window->NS.window contentView] exitFullScreenModeWithOptions:nil];
|
||||
|
||||
CGDisplaySwitchToMode(CGMainDisplayID(),
|
||||
(CFDictionaryRef) _glfwLibrary.NS.desktopMode);
|
||||
CGReleaseAllDisplays();
|
||||
_glfwRestoreVideoMode();
|
||||
}
|
||||
|
||||
[window->NSGL.pixelFormat release];
|
||||
@@ -936,6 +927,7 @@ void _glfwPlatformCloseWindow(_GLFWwindow* window)
|
||||
// TODO: Probably more cleanup
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Set the window title
|
||||
//========================================================================
|
||||
@@ -945,6 +937,7 @@ void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char *title)
|
||||
[window->NS.window setTitle:[NSString stringWithUTF8String:title]];
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Set the window size
|
||||
//========================================================================
|
||||
@@ -954,6 +947,7 @@ void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
|
||||
[window->NS.window setContentSize:NSMakeSize(width, height)];
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Set the window position
|
||||
//========================================================================
|
||||
@@ -974,6 +968,7 @@ void _glfwPlatformSetWindowPos(_GLFWwindow* window, int x, int y)
|
||||
display:YES];
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Iconify the window
|
||||
//========================================================================
|
||||
@@ -983,6 +978,7 @@ void _glfwPlatformIconifyWindow(_GLFWwindow* window)
|
||||
[window->NS.window miniaturize:nil];
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Restore (un-iconify) the window
|
||||
//========================================================================
|
||||
@@ -992,6 +988,7 @@ void _glfwPlatformRestoreWindow(_GLFWwindow* window)
|
||||
[window->NS.window deminiaturize:nil];
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Write back window parameters into GLFW window structure
|
||||
//========================================================================
|
||||
@@ -1066,6 +1063,7 @@ void _glfwPlatformRefreshWindowParams(void)
|
||||
window->glDebug = GL_FALSE;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Poll for new window and input events
|
||||
//========================================================================
|
||||
@@ -1090,6 +1088,7 @@ void _glfwPlatformPollEvents(void)
|
||||
_glfwLibrary.NS.autoreleasePool = [[NSAutoreleasePool alloc] init];
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Wait for new window and input events
|
||||
//========================================================================
|
||||
@@ -1108,6 +1107,7 @@ void _glfwPlatformWaitEvents( void )
|
||||
_glfwPlatformPollEvents();
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Set physical mouse cursor position
|
||||
//========================================================================
|
||||
@@ -1125,11 +1125,6 @@ void _glfwPlatformSetMouseCursorPos(_GLFWwindow* window, int x, int y)
|
||||
// calculating the maximum y coordinate of all screens, since Cocoa's
|
||||
// "global coordinates" are upside down from CG's...
|
||||
|
||||
// Without this (once per app run, but it's convenient to do it here)
|
||||
// events will be suppressed for a default of 0.25 seconds after we
|
||||
// move the cursor.
|
||||
CGSetLocalEventsSuppressionInterval(0.0);
|
||||
|
||||
NSPoint localPoint = NSMakePoint(x, y);
|
||||
NSPoint globalPoint = [window->NS.window convertBaseToScreen:localPoint];
|
||||
CGPoint mainScreenOrigin = CGDisplayBounds(CGMainDisplayID()).origin;
|
||||
@@ -1140,6 +1135,7 @@ void _glfwPlatformSetMouseCursorPos(_GLFWwindow* window, int x, int y)
|
||||
CGDisplayMoveCursorToPoint(CGMainDisplayID(), targetPoint);
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Set physical mouse cursor mode
|
||||
//========================================================================
|
||||
|
||||
@@ -60,11 +60,6 @@
|
||||
// Define this to 1 if the Linux joystick API is available
|
||||
#cmakedefine _GLFW_USE_LINUX_JOYSTICKS 1
|
||||
|
||||
// Define this to 1 to not load gdi32.dll dynamically
|
||||
#cmakedefine _GLFW_NO_DLOAD_GDI32 1
|
||||
// Define this to 1 to not load winmm.dll dynamically
|
||||
#cmakedefine _GLFW_NO_DLOAD_WINMM 1
|
||||
|
||||
// The GLFW version as used by glfwGetVersionString
|
||||
#define _GLFW_VERSION_FULL "@GLFW_VERSION_FULL@"
|
||||
|
||||
|
||||
+1
-1
@@ -167,7 +167,7 @@ void _glfwInputKey(_GLFWwindow* window, int key, int action)
|
||||
return;
|
||||
|
||||
// Register key action
|
||||
if(action == GLFW_RELEASE && window->stickyKeys)
|
||||
if (action == GLFW_RELEASE && window->stickyKeys)
|
||||
window->key[key] = GLFW_STICK;
|
||||
else
|
||||
{
|
||||
|
||||
@@ -7,7 +7,7 @@ Name: GLFW
|
||||
Description: A portable library for OpenGL, window and input
|
||||
Version: 3.0.0
|
||||
URL: http://www.glfw.org/
|
||||
Requires.private: gl x11 @GLFW_PKGLIBS@
|
||||
Requires.private: @GLFW_PKG_DEPS@
|
||||
Libs: -L${libdir} -lglfw
|
||||
Libs.private: @GLFW_LIBRARIES@
|
||||
Libs.private: @GLFW_PKG_LIBS@
|
||||
Cflags: -I${includedir}
|
||||
|
||||
+2
-2
@@ -31,7 +31,7 @@
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
#if defined(GLFW_BUILD_DLL)
|
||||
#if defined(_GLFW_BUILD_DLL)
|
||||
|
||||
//========================================================================
|
||||
// GLFW DLL entry point
|
||||
@@ -45,5 +45,5 @@ BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#endif // GLFW_BUILD_DLL
|
||||
#endif // _GLFW_BUILD_DLL
|
||||
|
||||
|
||||
+3
-3
@@ -200,7 +200,7 @@ int _glfwPlatformInit(void)
|
||||
// as possible in the hope of still being the foreground process)
|
||||
SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0,
|
||||
&_glfwLibrary.Win32.foregroundLockTimeout, 0);
|
||||
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, (LPVOID) 0,
|
||||
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, UIntToPtr(0),
|
||||
SPIF_SENDCHANGE);
|
||||
|
||||
if (!initLibraries())
|
||||
@@ -246,7 +246,7 @@ int _glfwPlatformTerminate(void)
|
||||
|
||||
// Restore previous FOREGROUNDLOCKTIMEOUT system setting
|
||||
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0,
|
||||
(LPVOID) _glfwLibrary.Win32.foregroundLockTimeout,
|
||||
UIntToPtr(_glfwLibrary.Win32.foregroundLockTimeout),
|
||||
SPIF_SENDCHANGE);
|
||||
|
||||
return GL_TRUE;
|
||||
@@ -271,7 +271,7 @@ const char* _glfwPlatformGetVersionString(void)
|
||||
#else
|
||||
" (unknown compiler)"
|
||||
#endif
|
||||
#if defined(GLFW_BUILD_DLL)
|
||||
#if defined(_GLFW_BUILD_DLL)
|
||||
" DLL"
|
||||
#endif
|
||||
#if !defined(_GLFW_NO_DLOAD_GDI32)
|
||||
|
||||
@@ -51,7 +51,9 @@
|
||||
#endif
|
||||
|
||||
// GLFW requires Windows XP
|
||||
#ifndef WINVER
|
||||
#define WINVER 0x0501
|
||||
#endif
|
||||
|
||||
#include <windows.h>
|
||||
#include <mmsystem.h>
|
||||
|
||||
+2
-45
@@ -34,30 +34,6 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Convert BPP to RGB bits based on "best guess"
|
||||
//========================================================================
|
||||
|
||||
static void bpp2rgb(int bpp, int* r, int* g, int* b)
|
||||
{
|
||||
int delta;
|
||||
|
||||
// We assume that by 32 they really meant 24
|
||||
if (bpp == 32)
|
||||
bpp = 24;
|
||||
|
||||
// Convert "bits per pixel" to red, green & blue sizes
|
||||
|
||||
*r = *g = *b = bpp / 3;
|
||||
delta = bpp - (*r * 3);
|
||||
if (delta >= 1)
|
||||
*g = *g + 1;
|
||||
|
||||
if (delta == 2)
|
||||
*r = *r + 1;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Enable/disable minimize/restore animations
|
||||
//========================================================================
|
||||
@@ -1441,6 +1417,7 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
|
||||
GLboolean recreateContext = GL_FALSE;
|
||||
|
||||
window->Win32.desiredRefreshRate = wndconfig->refreshRate;
|
||||
window->resizable = wndconfig->resizable;
|
||||
|
||||
if (!_glfwLibrary.Win32.classAtom)
|
||||
{
|
||||
@@ -1599,29 +1576,10 @@ void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title)
|
||||
|
||||
void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
|
||||
{
|
||||
//int bpp, refresh;
|
||||
int newMode = 0;
|
||||
GLboolean sizeChanged = GL_FALSE;
|
||||
|
||||
if (window->mode == GLFW_FULLSCREEN)
|
||||
{
|
||||
// Get some info about the current mode
|
||||
|
||||
DEVMODE dm;
|
||||
|
||||
dm.dmSize = sizeof(DEVMODE);
|
||||
//if (EnumDisplaySettings(NULL, window->Win32.modeID, &dm))
|
||||
//{
|
||||
// We need to keep BPP the same for the OpenGL context to keep working
|
||||
//bpp = dm.dmBitsPerPel;
|
||||
|
||||
// Get closest match for target video mode
|
||||
//refresh = window->Win32.desiredRefreshRate;
|
||||
//newMode = _glfwGetClosestVideoModeBPP(&width, &height, &bpp, &refresh);
|
||||
//}
|
||||
//else
|
||||
//newMode = window->Win32.modeID;
|
||||
|
||||
if (width > window->width || height > window->height)
|
||||
{
|
||||
// The new video mode is larger than the current one, so we resize
|
||||
@@ -1633,8 +1591,7 @@ void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
|
||||
sizeChanged = GL_TRUE;
|
||||
}
|
||||
|
||||
//if (newMode != window->Win32.modeID)
|
||||
//_glfwSetVideoModeMODE(newMode);
|
||||
// TODO: Change video mode
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -323,7 +323,7 @@ struct _glfwResolution
|
||||
int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
|
||||
{
|
||||
int count, k, l, r, g, b, rgba, gl;
|
||||
int depth, screen;
|
||||
int depth, screen = DefaultScreen(_glfwLibrary.X11.display);
|
||||
XVisualInfo* vislist;
|
||||
XVisualInfo dummy;
|
||||
int viscount, rgbcount, rescount;
|
||||
@@ -372,6 +372,8 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
|
||||
}
|
||||
}
|
||||
|
||||
XFree(vislist);
|
||||
|
||||
rescount = 0;
|
||||
resarray = NULL;
|
||||
|
||||
@@ -457,8 +459,6 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
|
||||
}
|
||||
}
|
||||
|
||||
XFree(vislist);
|
||||
|
||||
free(resarray);
|
||||
free(rgbarray);
|
||||
|
||||
|
||||
+11
-2
@@ -79,7 +79,11 @@ static int keyCodeToGLFWKeyCode(int keyCode)
|
||||
// Note: This way we always force "NumLock = ON", which is intentional
|
||||
// since the returned key code should correspond to a physical
|
||||
// location.
|
||||
#if defined(_GLFW_HAS_XKB)
|
||||
keySym = XkbKeycodeToKeysym(_glfwLibrary.X11.display, keyCode, 1, 0);
|
||||
#else
|
||||
keySym = XKeycodeToKeysym(_glfwLibrary.X11.display, keyCode, 1);
|
||||
#endif
|
||||
switch (keySym)
|
||||
{
|
||||
case XK_KP_0: return GLFW_KEY_KP_0;
|
||||
@@ -102,7 +106,12 @@ static int keyCodeToGLFWKeyCode(int keyCode)
|
||||
// Now try pimary keysym for function keys (non-printable keys). These
|
||||
// should not be layout dependent (i.e. US layout and international
|
||||
// layouts should give the same result).
|
||||
#if defined(_GLFW_HAS_XKB)
|
||||
keySym = XkbKeycodeToKeysym(_glfwLibrary.X11.display, keyCode, 0, 0);
|
||||
#else
|
||||
keySym = XKeycodeToKeysym(_glfwLibrary.X11.display, keyCode, 0);
|
||||
#endif
|
||||
|
||||
switch (keySym)
|
||||
{
|
||||
case XK_Escape: return GLFW_KEY_ESCAPE;
|
||||
@@ -476,8 +485,8 @@ static void initGammaRamp(void)
|
||||
// RandR gamma support is only available with version 1.2 and above
|
||||
if (_glfwLibrary.X11.RandR.available &&
|
||||
(_glfwLibrary.X11.RandR.majorVersion > 1 ||
|
||||
_glfwLibrary.X11.RandR.majorVersion == 1 &&
|
||||
_glfwLibrary.X11.RandR.minorVersion >= 2))
|
||||
(_glfwLibrary.X11.RandR.majorVersion == 1 &&
|
||||
_glfwLibrary.X11.RandR.minorVersion >= 2)))
|
||||
{
|
||||
// FIXME: Assumes that all monitors have the same size gamma tables
|
||||
// This is reasonable as I suspect the that if they did differ, it
|
||||
|
||||
+3
-2
@@ -30,6 +30,7 @@
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
|
||||
|
||||
@@ -39,7 +40,7 @@
|
||||
|
||||
static uint64_t getRawTime(void)
|
||||
{
|
||||
#if defined(_POSIX_TIMERS) && defined(_POSIX_MONOTONIC_CLOCK)
|
||||
#if defined(CLOCK_MONOTONIC)
|
||||
if (_glfwLibrary.X11.timer.monotonic)
|
||||
{
|
||||
struct timespec ts;
|
||||
@@ -64,7 +65,7 @@ static uint64_t getRawTime(void)
|
||||
|
||||
void _glfwInitTimer(void)
|
||||
{
|
||||
#if defined(_POSIX_TIMERS) && defined(_POSIX_MONOTONIC_CLOCK)
|
||||
#if defined(CLOCK_MONOTONIC)
|
||||
struct timespec ts;
|
||||
|
||||
if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0)
|
||||
|
||||
Reference in New Issue
Block a user