mirror of
https://github.com/glfw/glfw.git
synced 2026-09-18 22:55:46 +00:00
Merge branch 'master' into cursor-enter-leave
This commit is contained in:
+20
-19
@@ -1,43 +1,43 @@
|
||||
|
||||
if(UNIX)
|
||||
if(_GLFW_HAS_XRANDR)
|
||||
if (_GLFW_HAS_XRANDR)
|
||||
set(GLFW_PKGLIBS "${GLFW_PKGLIBS} xrandr")
|
||||
endif(_GLFW_HAS_XRANDR)
|
||||
if(_GLFW_HAS_XF86VIDMODE)
|
||||
endif()
|
||||
if (_GLFW_HAS_XF86VIDMODE)
|
||||
set(GLFW_PKGLIBS "${GLFW_PKGLIBS} xxf86vm")
|
||||
endif(_GLFW_HAS_XF86VIDMODE)
|
||||
endif()
|
||||
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)
|
||||
endif()
|
||||
|
||||
include_directories(${GLFW_SOURCE_DIR}/src
|
||||
${GLFW_BINARY_DIR}/src
|
||||
${GLFW_INCLUDE_DIR})
|
||||
|
||||
set(common_SOURCES enable.c error.c fullscreen.c gamma.c init.c input.c
|
||||
set(common_SOURCES 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_enable.m cocoa_fullscreen.m
|
||||
cocoa_gamma.m cocoa_init.m cocoa_joystick.m
|
||||
cocoa_opengl.m cocoa_time.m cocoa_window.m)
|
||||
set(libglfw_SOURCES ${common_SOURCES} 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_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)
|
||||
elseif(_GLFW_X11_GLX)
|
||||
set(libglfw_SOURCES ${common_SOURCES} x11_enable.c x11_fullscreen.c
|
||||
x11_gamma.c x11_init.c x11_joystick.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_opengl.c x11_time.c
|
||||
x11_window.c)
|
||||
else()
|
||||
message(FATAL_ERROR "No supported platform was selected")
|
||||
endif(_GLFW_COCOA_NSGL)
|
||||
endif()
|
||||
|
||||
add_library(libglfwStatic STATIC ${libglfw_SOURCES})
|
||||
add_library(libglfwShared SHARED ${libglfw_SOURCES})
|
||||
@@ -47,22 +47,23 @@ set_target_properties(libglfwStatic libglfwShared PROPERTIES
|
||||
OUTPUT_NAME glfw)
|
||||
|
||||
if(WIN32)
|
||||
target_link_libraries(libglfwShared winmm)
|
||||
# The GLFW DLL needs a special compile-time macro and import library name
|
||||
set_target_properties(libglfwShared PROPERTIES
|
||||
DEFINE_SYMBOL GLFW_BUILD_DLL
|
||||
COMPILE_DEFINITIONS "GLFW_BUILD_DLL;_GLFW_NO_DLOAD_GDI32;_GLFW_NO_DLOAD_WINMM"
|
||||
PREFIX ""
|
||||
IMPORT_PREFIX ""
|
||||
IMPORT_SUFFIX "dll.lib")
|
||||
endif(WIN32)
|
||||
endif()
|
||||
|
||||
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)
|
||||
if (NOT CFLAGS)
|
||||
set(CFLAGS "")
|
||||
endif(NOT CFLAGS)
|
||||
endif()
|
||||
set_target_properties(libglfwShared PROPERTIES COMPILE_FLAGS "${CFLAGS} -fno-common")
|
||||
endif(APPLE)
|
||||
endif()
|
||||
|
||||
install(TARGETS libglfwStatic libglfwShared 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
|
||||
//========================================================================
|
||||
|
||||
@@ -32,6 +32,8 @@
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <ApplicationServices/ApplicationServices.h>
|
||||
|
||||
|
||||
//************************************************************************
|
||||
//**** GLFW internal functions ****
|
||||
+42
-155
@@ -27,162 +27,45 @@
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
// Needed for _NSGetProgname
|
||||
#include <crt_externs.h>
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
//========================================================================
|
||||
// GLFW application class
|
||||
// Change to our application bundle's resources directory, if present
|
||||
//========================================================================
|
||||
|
||||
@interface GLFWApplication : NSApplication
|
||||
@end
|
||||
|
||||
@implementation GLFWApplication
|
||||
|
||||
// From http://cocoadev.com/index.pl?GameKeyboardHandlingAlmost
|
||||
// This works around an AppKit bug, where key up events while holding
|
||||
// down the command key don't get sent to the key window.
|
||||
- (void)sendEvent:(NSEvent *)event
|
||||
static void changeToResourcesDirectory(void)
|
||||
{
|
||||
if ([event type] == NSKeyUp && ([event modifierFlags] & NSCommandKeyMask))
|
||||
[[self keyWindow] sendEvent:event];
|
||||
else
|
||||
[super sendEvent:event];
|
||||
}
|
||||
char resourcesPath[MAXPATHLEN];
|
||||
|
||||
@end
|
||||
CFBundleRef bundle = CFBundleGetMainBundle();
|
||||
if (!bundle)
|
||||
return;
|
||||
|
||||
CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(bundle);
|
||||
|
||||
// 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
|
||||
|
||||
// Keys to search for as potential application names
|
||||
NSString* GLFWNameKeys[] =
|
||||
{
|
||||
@"CFBundleDisplayName",
|
||||
@"CFBundleName",
|
||||
@"CFBundleExecutable",
|
||||
};
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Try to figure out what the calling application is called
|
||||
//========================================================================
|
||||
static NSString* findAppName(void)
|
||||
{
|
||||
unsigned int i;
|
||||
NSDictionary* infoDictionary = [[NSBundle mainBundle] infoDictionary];
|
||||
|
||||
for (i = 0; i < sizeof(GLFWNameKeys) / sizeof(GLFWNameKeys[0]); i++)
|
||||
CFStringRef last = CFURLCopyLastPathComponent(resourcesURL);
|
||||
if (CFStringCompare(CFSTR("Resources"), last, 0) != kCFCompareEqualTo)
|
||||
{
|
||||
id name = [infoDictionary objectForKey:GLFWNameKeys[i]];
|
||||
if (name &&
|
||||
[name isKindOfClass:[NSString class]] &&
|
||||
![@"" isEqualToString:name])
|
||||
{
|
||||
return name;
|
||||
}
|
||||
CFRelease(last);
|
||||
CFRelease(resourcesURL);
|
||||
return;
|
||||
}
|
||||
|
||||
// If we get here, we're unbundled
|
||||
if (!_glfwLibrary.NS.unbundled)
|
||||
CFRelease(last);
|
||||
|
||||
if (!CFURLGetFileSystemRepresentation(resourcesURL,
|
||||
true,
|
||||
(UInt8*) resourcesPath,
|
||||
MAXPATHLEN))
|
||||
{
|
||||
// Could do this only if we discover we're unbundled, but it should
|
||||
// do no harm...
|
||||
ProcessSerialNumber psn = { 0, kCurrentProcess };
|
||||
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
|
||||
|
||||
// Having the app in front of the terminal window is also generally
|
||||
// handy. There is an NSApplication API to do this, but...
|
||||
SetFrontProcess(&psn);
|
||||
|
||||
_glfwLibrary.NS.unbundled = GL_TRUE;
|
||||
CFRelease(resourcesURL);
|
||||
return;
|
||||
}
|
||||
|
||||
char** progname = _NSGetProgname();
|
||||
if (progname && *progname)
|
||||
{
|
||||
// TODO: UTF-8?
|
||||
return [NSString stringWithUTF8String:*progname];
|
||||
}
|
||||
CFRelease(resourcesURL);
|
||||
|
||||
// Really shouldn't get here
|
||||
return @"GLFW Application";
|
||||
}
|
||||
|
||||
//========================================================================
|
||||
// Set up the menu bar (manually)
|
||||
// This is nasty, nasty stuff -- calls to undocumented semi-private APIs that
|
||||
// could go away at any moment, lots of stuff that really should be
|
||||
// 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)
|
||||
{
|
||||
NSString* appName = findAppName();
|
||||
|
||||
NSMenu* bar = [[NSMenu alloc] init];
|
||||
[NSApp setMainMenu:bar];
|
||||
|
||||
NSMenuItem* appMenuItem =
|
||||
[bar addItemWithTitle:@"" action:NULL keyEquivalent:@""];
|
||||
NSMenu* appMenu = [[NSMenu alloc] init];
|
||||
[appMenuItem setSubmenu:appMenu];
|
||||
|
||||
[appMenu addItemWithTitle:[NSString stringWithFormat:@"About %@", appName]
|
||||
action:@selector(orderFrontStandardAboutPanel:)
|
||||
keyEquivalent:@""];
|
||||
[appMenu addItem:[NSMenuItem separatorItem]];
|
||||
NSMenu* servicesMenu = [[NSMenu alloc] init];
|
||||
[NSApp setServicesMenu:servicesMenu];
|
||||
[[appMenu addItemWithTitle:@"Services"
|
||||
action:NULL
|
||||
keyEquivalent:@""] setSubmenu:servicesMenu];
|
||||
[appMenu addItem:[NSMenuItem separatorItem]];
|
||||
[appMenu addItemWithTitle:[NSString stringWithFormat:@"Hide %@", appName]
|
||||
action:@selector(hide:)
|
||||
keyEquivalent:@"h"];
|
||||
[[appMenu addItemWithTitle:@"Hide Others"
|
||||
action:@selector(hideOtherApplications:)
|
||||
keyEquivalent:@"h"]
|
||||
setKeyEquivalentModifierMask:NSAlternateKeyMask | NSCommandKeyMask];
|
||||
[appMenu addItemWithTitle:@"Show All"
|
||||
action:@selector(unhideAllApplications:)
|
||||
keyEquivalent:@""];
|
||||
[appMenu addItem:[NSMenuItem separatorItem]];
|
||||
[appMenu addItemWithTitle:[NSString stringWithFormat:@"Quit %@", appName]
|
||||
action:@selector(terminate:)
|
||||
keyEquivalent:@"q"];
|
||||
|
||||
NSMenuItem* windowMenuItem =
|
||||
[bar addItemWithTitle:@"" action:NULL keyEquivalent:@""];
|
||||
NSMenu* windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
|
||||
[NSApp setWindowsMenu:windowMenu];
|
||||
[windowMenuItem setSubmenu:windowMenu];
|
||||
|
||||
[windowMenu addItemWithTitle:@"Miniaturize"
|
||||
action:@selector(performMiniaturize:)
|
||||
keyEquivalent:@"m"];
|
||||
[windowMenu addItemWithTitle:@"Zoom"
|
||||
action:@selector(performZoom:)
|
||||
keyEquivalent:@""];
|
||||
[windowMenu addItem:[NSMenuItem separatorItem]];
|
||||
[windowMenu addItemWithTitle:@"Bring All to Front"
|
||||
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];
|
||||
chdir(resourcesPath);
|
||||
}
|
||||
|
||||
|
||||
@@ -198,9 +81,6 @@ int _glfwPlatformInit(void)
|
||||
{
|
||||
_glfwLibrary.NS.autoreleasePool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
// Implicitly create shared NSApplication instance
|
||||
[GLFWApplication sharedApplication];
|
||||
|
||||
_glfwLibrary.NS.OpenGLFramework =
|
||||
CFBundleGetBundleWithIdentifier(CFSTR("com.apple.opengl"));
|
||||
if (_glfwLibrary.NS.OpenGLFramework == NULL)
|
||||
@@ -210,31 +90,30 @@ int _glfwPlatformInit(void)
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
NSString* resourcePath = [[NSBundle mainBundle] resourcePath];
|
||||
changeToResourcesDirectory();
|
||||
|
||||
if (access([resourcePath cStringUsingEncoding:NSUTF8StringEncoding], R_OK) == 0)
|
||||
chdir([resourcePath cStringUsingEncoding:NSUTF8StringEncoding]);
|
||||
|
||||
// Setting up menu bar must go exactly here else weirdness ensues
|
||||
setUpMenuBar();
|
||||
|
||||
[NSApp finishLaunching];
|
||||
|
||||
_glfwPlatformSetTime(0.0);
|
||||
|
||||
_glfwLibrary.NS.desktopMode =
|
||||
(NSDictionary*) CGDisplayCurrentMode(CGMainDisplayID());
|
||||
_glfwLibrary.NS.desktopMode = CGDisplayCopyDisplayMode(CGMainDisplayID());
|
||||
|
||||
// Save the original gamma ramp
|
||||
_glfwLibrary.originalRampSize = CGDisplayGammaTableCapacity(CGMainDisplayID());
|
||||
_glfwPlatformGetGammaRamp(&_glfwLibrary.originalRamp);
|
||||
_glfwLibrary.currentRamp = _glfwLibrary.originalRamp;
|
||||
|
||||
_glfwInitTimer();
|
||||
|
||||
_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
|
||||
//========================================================================
|
||||
@@ -243,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;
|
||||
|
||||
+26
-16
@@ -152,7 +152,7 @@ static void addJoystickElement(_glfwJoystick* joystick, CFTypeRef refElement)
|
||||
long number;
|
||||
CFTypeRef refType;
|
||||
|
||||
_glfwJoystickElement* element = (_glfwJoystickElement*) _glfwMalloc(sizeof(_glfwJoystickElement));
|
||||
_glfwJoystickElement* element = (_glfwJoystickElement*) malloc(sizeof(_glfwJoystickElement));
|
||||
|
||||
CFArrayAppendValue(elementsArray, element);
|
||||
|
||||
@@ -232,33 +232,35 @@ 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);
|
||||
_glfwFree(axes);
|
||||
free(axes);
|
||||
}
|
||||
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);
|
||||
_glfwFree(button);
|
||||
free(button);
|
||||
}
|
||||
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);
|
||||
_glfwFree(hat);
|
||||
free(hat);
|
||||
}
|
||||
CFArrayRemoveAllValues(joystick->hats);
|
||||
joystick->hats = 0;
|
||||
@@ -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;
|
||||
@@ -568,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
|
||||
//========================================================================
|
||||
|
||||
+14
-6
@@ -37,6 +37,7 @@
|
||||
#if defined(__OBJC__)
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#else
|
||||
#include <ApplicationServices/ApplicationServices.h>
|
||||
typedef void* id;
|
||||
#endif
|
||||
|
||||
@@ -85,15 +86,16 @@ typedef struct _GLFWwindowNS
|
||||
typedef struct _GLFWlibraryNS
|
||||
{
|
||||
struct {
|
||||
double t0;
|
||||
double base;
|
||||
double resolution;
|
||||
} timer;
|
||||
|
||||
// dlopen handle for dynamically loading OpenGL extension entry points
|
||||
void* OpenGLFramework;
|
||||
GLboolean unbundled;
|
||||
id desktopMode;
|
||||
id delegate;
|
||||
id autoreleasePool;
|
||||
void* OpenGLFramework;
|
||||
CGDisplayModeRef desktopMode;
|
||||
CGEventSourceRef eventSource;
|
||||
id delegate;
|
||||
id autoreleasePool;
|
||||
} _GLFWlibraryNS;
|
||||
|
||||
|
||||
@@ -101,9 +103,15 @@ typedef struct _GLFWlibraryNS
|
||||
// Prototypes for platform specific internal functions
|
||||
//========================================================================
|
||||
|
||||
// Time
|
||||
void _glfwInitTimer(void);
|
||||
|
||||
// Joystick input
|
||||
void _glfwInitJoysticks(void);
|
||||
void _glfwTerminateJoysticks(void);
|
||||
|
||||
// Fullscreen
|
||||
GLboolean _glfwSetVideoMode(int* width, int* height, int* bpp, int* refreshRate);
|
||||
void _glfwRestoreVideoMode(void);
|
||||
|
||||
#endif // _platform_h_
|
||||
|
||||
@@ -29,6 +29,36 @@
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
#include <mach/mach_time.h>
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Return raw time
|
||||
//========================================================================
|
||||
|
||||
static uint64_t getRawTime(void)
|
||||
{
|
||||
return mach_absolute_time();
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
////// GLFW internal API //////
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//========================================================================
|
||||
// Initialise timer
|
||||
//========================================================================
|
||||
|
||||
void _glfwInitTimer(void)
|
||||
{
|
||||
mach_timebase_info_data_t info;
|
||||
mach_timebase_info(&info);
|
||||
|
||||
_glfwLibrary.NS.timer.resolution = (double) info.numer / (info.denom * 1.0e9);
|
||||
_glfwLibrary.NS.timer.base = getRawTime();
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
////// GLFW platform API //////
|
||||
@@ -40,17 +70,18 @@
|
||||
|
||||
double _glfwPlatformGetTime(void)
|
||||
{
|
||||
return [NSDate timeIntervalSinceReferenceDate] -
|
||||
_glfwLibrary.NS.timer.t0;
|
||||
return (double) (getRawTime() - _glfwLibrary.NS.timer.base) *
|
||||
_glfwLibrary.NS.timer.resolution;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Set timer value in seconds
|
||||
//========================================================================
|
||||
|
||||
void _glfwPlatformSetTime(double time)
|
||||
{
|
||||
_glfwLibrary.NS.timer.t0 =
|
||||
[NSDate timeIntervalSinceReferenceDate] - time;
|
||||
_glfwLibrary.NS.timer.base = getRawTime() -
|
||||
(uint64_t) (time / _glfwLibrary.NS.timer.resolution);
|
||||
}
|
||||
|
||||
+507
-307
@@ -29,6 +29,9 @@
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
// Needed for _NSGetProgname
|
||||
#include <crt_externs.h>
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Delegate for window related notifications
|
||||
@@ -109,6 +112,7 @@
|
||||
|
||||
@end
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Delegate for application related notifications
|
||||
//========================================================================
|
||||
@@ -130,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 */ -1,
|
||||
/* 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_GRAVE_ACCENT,
|
||||
/* 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
|
||||
@@ -273,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
|
||||
//========================================================================
|
||||
@@ -385,15 +388,15 @@ 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)
|
||||
{
|
||||
if (!window->sysKeysDisabled)
|
||||
if (window->systemKeys)
|
||||
[super keyDown:event];
|
||||
}
|
||||
else
|
||||
@@ -409,7 +412,7 @@ static int convertMacKeyCode(unsigned int macKeyCode)
|
||||
|
||||
- (void)flagsChanged:(NSEvent *)event
|
||||
{
|
||||
int mode;
|
||||
int mode, key;
|
||||
unsigned int newModifierFlags =
|
||||
[event modifierFlags] | NSDeviceIndependentModifierFlagsMask;
|
||||
|
||||
@@ -419,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
|
||||
@@ -444,19 +450,229 @@ static int convertMacKeyCode(unsigned int macKeyCode)
|
||||
@end
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
////// GLFW platform API //////
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//========================================================================
|
||||
// Here is where the window is created, and the OpenGL rendering context is
|
||||
// created
|
||||
// GLFW application class
|
||||
//========================================================================
|
||||
|
||||
int _glfwPlatformOpenWindow(_GLFWwindow* window,
|
||||
const _GLFWwndconfig *wndconfig,
|
||||
const _GLFWfbconfig *fbconfig)
|
||||
@interface GLFWApplication : NSApplication
|
||||
@end
|
||||
|
||||
@implementation GLFWApplication
|
||||
|
||||
// From http://cocoadev.com/index.pl?GameKeyboardHandlingAlmost
|
||||
// This works around an AppKit bug, where key up events while holding
|
||||
// down the command key don't get sent to the key window.
|
||||
- (void)sendEvent:(NSEvent *)event
|
||||
{
|
||||
if ([event type] == NSKeyUp && ([event modifierFlags] & NSCommandKeyMask))
|
||||
[[self keyWindow] sendEvent:event];
|
||||
else
|
||||
[super sendEvent:event];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Try to figure out what the calling application is called
|
||||
//========================================================================
|
||||
|
||||
static NSString* findAppName(void)
|
||||
{
|
||||
unsigned int i;
|
||||
NSDictionary* infoDictionary = [[NSBundle mainBundle] infoDictionary];
|
||||
|
||||
// Keys to search for as potential application names
|
||||
NSString* GLFWNameKeys[] =
|
||||
{
|
||||
@"CFBundleDisplayName",
|
||||
@"CFBundleName",
|
||||
@"CFBundleExecutable",
|
||||
};
|
||||
|
||||
for (i = 0; i < sizeof(GLFWNameKeys) / sizeof(GLFWNameKeys[0]); i++)
|
||||
{
|
||||
id name = [infoDictionary objectForKey:GLFWNameKeys[i]];
|
||||
if (name &&
|
||||
[name isKindOfClass:[NSString class]] &&
|
||||
![@"" isEqualToString:name])
|
||||
{
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
// If we get here, we're unbundled
|
||||
ProcessSerialNumber psn = { 0, kCurrentProcess };
|
||||
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
|
||||
|
||||
// Having the app in front of the terminal window is also generally
|
||||
// handy. There is an NSApplication API to do this, but...
|
||||
SetFrontProcess(&psn);
|
||||
|
||||
char** progname = _NSGetProgname();
|
||||
if (progname && *progname)
|
||||
{
|
||||
// TODO: UTF-8?
|
||||
return [NSString stringWithUTF8String:*progname];
|
||||
}
|
||||
|
||||
// Really shouldn't get here
|
||||
return @"GLFW Application";
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Set up the menu bar (manually)
|
||||
// This is nasty, nasty stuff -- calls to undocumented semi-private APIs that
|
||||
// could go away at any moment, lots of stuff that really should be
|
||||
// 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 createMenuBar(void)
|
||||
{
|
||||
NSString* appName = findAppName();
|
||||
|
||||
NSMenu* bar = [[NSMenu alloc] init];
|
||||
[NSApp setMainMenu:bar];
|
||||
|
||||
NSMenuItem* appMenuItem =
|
||||
[bar addItemWithTitle:@"" action:NULL keyEquivalent:@""];
|
||||
NSMenu* appMenu = [[NSMenu alloc] init];
|
||||
[appMenuItem setSubmenu:appMenu];
|
||||
|
||||
[appMenu addItemWithTitle:[NSString stringWithFormat:@"About %@", appName]
|
||||
action:@selector(orderFrontStandardAboutPanel:)
|
||||
keyEquivalent:@""];
|
||||
[appMenu addItem:[NSMenuItem separatorItem]];
|
||||
NSMenu* servicesMenu = [[NSMenu alloc] init];
|
||||
[NSApp setServicesMenu:servicesMenu];
|
||||
[[appMenu addItemWithTitle:@"Services"
|
||||
action:NULL
|
||||
keyEquivalent:@""] setSubmenu:servicesMenu];
|
||||
[appMenu addItem:[NSMenuItem separatorItem]];
|
||||
[appMenu addItemWithTitle:[NSString stringWithFormat:@"Hide %@", appName]
|
||||
action:@selector(hide:)
|
||||
keyEquivalent:@"h"];
|
||||
[[appMenu addItemWithTitle:@"Hide Others"
|
||||
action:@selector(hideOtherApplications:)
|
||||
keyEquivalent:@"h"]
|
||||
setKeyEquivalentModifierMask:NSAlternateKeyMask | NSCommandKeyMask];
|
||||
[appMenu addItemWithTitle:@"Show All"
|
||||
action:@selector(unhideAllApplications:)
|
||||
keyEquivalent:@""];
|
||||
[appMenu addItem:[NSMenuItem separatorItem]];
|
||||
[appMenu addItemWithTitle:[NSString stringWithFormat:@"Quit %@", appName]
|
||||
action:@selector(terminate:)
|
||||
keyEquivalent:@"q"];
|
||||
|
||||
NSMenuItem* windowMenuItem =
|
||||
[bar addItemWithTitle:@"" action:NULL keyEquivalent:@""];
|
||||
NSMenu* windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
|
||||
[NSApp setWindowsMenu:windowMenu];
|
||||
[windowMenuItem setSubmenu:windowMenu];
|
||||
|
||||
[windowMenu addItemWithTitle:@"Miniaturize"
|
||||
action:@selector(performMiniaturize:)
|
||||
keyEquivalent:@"m"];
|
||||
[windowMenu addItemWithTitle:@"Zoom"
|
||||
action:@selector(performZoom:)
|
||||
keyEquivalent:@""];
|
||||
[windowMenu addItem:[NSMenuItem separatorItem]];
|
||||
[windowMenu addItemWithTitle:@"Bring All to Front"
|
||||
action:@selector(arrangeInFront:)
|
||||
keyEquivalent:@""];
|
||||
|
||||
// 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 initializeAppKit(void)
|
||||
{
|
||||
if (NSApp)
|
||||
return GL_TRUE;
|
||||
|
||||
// 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
|
||||
createMenuBar();
|
||||
|
||||
[NSApp finishLaunching];
|
||||
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Create the Cocoa window
|
||||
//========================================================================
|
||||
|
||||
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 ||
|
||||
@@ -468,14 +684,23 @@ int _glfwPlatformOpenWindow(_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;
|
||||
}
|
||||
}
|
||||
@@ -499,6 +724,106 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
#define ADD_ATTR(x) { attributes[attributeCount++] = x; }
|
||||
#define ADD_ATTR2(x, y) { ADD_ATTR(x); ADD_ATTR(y); }
|
||||
|
||||
// Arbitrary array size here
|
||||
NSOpenGLPixelFormatAttribute attributes[24];
|
||||
|
||||
ADD_ATTR(NSOpenGLPFADoubleBuffer);
|
||||
|
||||
if (wndconfig->mode == GLFW_FULLSCREEN)
|
||||
{
|
||||
ADD_ATTR(NSOpenGLPFANoRecovery);
|
||||
ADD_ATTR2(NSOpenGLPFAScreenMask,
|
||||
CGDisplayIDToOpenGLDisplayMask(CGMainDisplayID()));
|
||||
}
|
||||
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
|
||||
if (wndconfig->glMajor > 2)
|
||||
ADD_ATTR2(NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core);
|
||||
#endif /*MAC_OS_X_VERSION_MAX_ALLOWED*/
|
||||
|
||||
ADD_ATTR2(NSOpenGLPFAColorSize, colorBits);
|
||||
|
||||
if (fbconfig->alphaBits > 0)
|
||||
ADD_ATTR2(NSOpenGLPFAAlphaSize, fbconfig->alphaBits);
|
||||
|
||||
if (fbconfig->depthBits > 0)
|
||||
ADD_ATTR2(NSOpenGLPFADepthSize, fbconfig->depthBits);
|
||||
|
||||
if (fbconfig->stencilBits > 0)
|
||||
ADD_ATTR2(NSOpenGLPFAStencilSize, fbconfig->stencilBits);
|
||||
|
||||
int accumBits = fbconfig->accumRedBits + fbconfig->accumGreenBits +
|
||||
fbconfig->accumBlueBits + fbconfig->accumAlphaBits;
|
||||
|
||||
if (accumBits > 0)
|
||||
ADD_ATTR2(NSOpenGLPFAAccumSize, accumBits);
|
||||
|
||||
if (fbconfig->auxBuffers > 0)
|
||||
ADD_ATTR2(NSOpenGLPFAAuxBuffers, fbconfig->auxBuffers);
|
||||
|
||||
if (fbconfig->stereo)
|
||||
ADD_ATTR(NSOpenGLPFAStereo);
|
||||
|
||||
if (fbconfig->samples > 0)
|
||||
{
|
||||
ADD_ATTR2(NSOpenGLPFASampleBuffers, 1);
|
||||
ADD_ATTR2(NSOpenGLPFASamples, fbconfig->samples);
|
||||
}
|
||||
|
||||
ADD_ATTR(0);
|
||||
|
||||
#undef ADD_ATTR
|
||||
#undef ADD_ATTR2
|
||||
|
||||
window->NSGL.pixelFormat =
|
||||
[[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
|
||||
if (window->NSGL.pixelFormat == nil)
|
||||
{
|
||||
_glfwSetError(GLFW_PLATFORM_ERROR,
|
||||
"Cocoa/NSOpenGL: Failed to create OpenGL pixel format");
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
NSOpenGLContext* share = NULL;
|
||||
|
||||
if (wndconfig->share)
|
||||
share = wndconfig->share->NSGL.context;
|
||||
|
||||
window->NSGL.context =
|
||||
[[NSOpenGLContext alloc] initWithFormat:window->NSGL.pixelFormat
|
||||
shareContext:share];
|
||||
if (window->NSGL.context == nil)
|
||||
{
|
||||
_glfwSetError(GLFW_PLATFORM_ERROR,
|
||||
"Cocoa/NSOpenGL: Failed to create OpenGL context");
|
||||
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)
|
||||
{
|
||||
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)
|
||||
@@ -530,157 +855,30 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
|
||||
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_ATTR2(x, y) { ADD_ATTR(x); ADD_ATTR(y); }
|
||||
|
||||
// Arbitrary array size here
|
||||
NSOpenGLPixelFormatAttribute attributes[24];
|
||||
|
||||
ADD_ATTR(NSOpenGLPFADoubleBuffer);
|
||||
|
||||
if (wndconfig->mode == GLFW_FULLSCREEN)
|
||||
{
|
||||
ADD_ATTR(NSOpenGLPFAFullScreen);
|
||||
ADD_ATTR(NSOpenGLPFANoRecovery);
|
||||
ADD_ATTR2(NSOpenGLPFAScreenMask,
|
||||
CGDisplayIDToOpenGLDisplayMask(CGMainDisplayID()));
|
||||
}
|
||||
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
|
||||
if (wndconfig->glMajor > 2)
|
||||
ADD_ATTR2(NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core);
|
||||
#endif /*MAC_OS_X_VERSION_MAX_ALLOWED*/
|
||||
|
||||
ADD_ATTR2(NSOpenGLPFAColorSize, colorBits);
|
||||
|
||||
if (fbconfig->alphaBits > 0)
|
||||
ADD_ATTR2(NSOpenGLPFAAlphaSize, fbconfig->alphaBits);
|
||||
|
||||
if (fbconfig->depthBits > 0)
|
||||
ADD_ATTR2(NSOpenGLPFADepthSize, fbconfig->depthBits);
|
||||
|
||||
if (fbconfig->stencilBits > 0)
|
||||
ADD_ATTR2(NSOpenGLPFAStencilSize, fbconfig->stencilBits);
|
||||
|
||||
int accumBits = fbconfig->accumRedBits + fbconfig->accumGreenBits +
|
||||
fbconfig->accumBlueBits + fbconfig->accumAlphaBits;
|
||||
|
||||
if (accumBits > 0)
|
||||
ADD_ATTR2(NSOpenGLPFAAccumSize, accumBits);
|
||||
|
||||
if (fbconfig->auxBuffers > 0)
|
||||
ADD_ATTR2(NSOpenGLPFAAuxBuffers, fbconfig->auxBuffers);
|
||||
|
||||
if (fbconfig->stereo)
|
||||
ADD_ATTR(NSOpenGLPFAStereo );
|
||||
|
||||
if (fbconfig->samples > 0)
|
||||
{
|
||||
ADD_ATTR2(NSOpenGLPFASampleBuffers, 1);
|
||||
ADD_ATTR2(NSOpenGLPFASamples, fbconfig->samples);
|
||||
}
|
||||
|
||||
ADD_ATTR(0);
|
||||
|
||||
#undef ADD_ATTR
|
||||
#undef ADD_ATTR2
|
||||
|
||||
window->NSGL.pixelFormat =
|
||||
[[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
|
||||
if (window->NSGL.pixelFormat == nil)
|
||||
{
|
||||
_glfwSetError(GLFW_PLATFORM_ERROR,
|
||||
"Cocoa/NSOpenGL: Failed to create pixel format");
|
||||
if (!createWindow(window, wndconfig))
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
NSOpenGLContext* share = NULL;
|
||||
|
||||
if (wndconfig->share)
|
||||
share = wndconfig->share->NSGL.context;
|
||||
|
||||
window->NSGL.context =
|
||||
[[NSOpenGLContext alloc] initWithFormat:window->NSGL.pixelFormat
|
||||
shareContext:share];
|
||||
if (window->NSGL.context == nil)
|
||||
{
|
||||
_glfwSetError(GLFW_PLATFORM_ERROR,
|
||||
"Cocoa/NSOpenGL: Failed to create OpenGL context");
|
||||
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)
|
||||
{
|
||||
// TODO: Make this work on pre-Leopard systems
|
||||
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];
|
||||
}
|
||||
@@ -709,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];
|
||||
@@ -731,16 +927,17 @@ void _glfwPlatformCloseWindow(_GLFWwindow* window)
|
||||
// TODO: Probably more cleanup
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Set the window title
|
||||
//========================================================================
|
||||
|
||||
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char *title)
|
||||
{
|
||||
[window->NS.window setTitle:[NSString stringWithCString:title
|
||||
encoding:NSISOLatin1StringEncoding]];
|
||||
[window->NS.window setTitle:[NSString stringWithUTF8String:title]];
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Set the window size
|
||||
//========================================================================
|
||||
@@ -750,6 +947,7 @@ void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
|
||||
[window->NS.window setContentSize:NSMakeSize(width, height)];
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Set the window position
|
||||
//========================================================================
|
||||
@@ -770,6 +968,7 @@ void _glfwPlatformSetWindowPos(_GLFWwindow* window, int x, int y)
|
||||
display:YES];
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Iconify the window
|
||||
//========================================================================
|
||||
@@ -779,6 +978,7 @@ void _glfwPlatformIconifyWindow(_GLFWwindow* window)
|
||||
[window->NS.window miniaturize:nil];
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Restore (un-iconify) the window
|
||||
//========================================================================
|
||||
@@ -788,6 +988,7 @@ void _glfwPlatformRestoreWindow(_GLFWwindow* window)
|
||||
[window->NS.window deminiaturize:nil];
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Write back window parameters into GLFW window structure
|
||||
//========================================================================
|
||||
@@ -862,6 +1063,7 @@ void _glfwPlatformRefreshWindowParams(void)
|
||||
window->glDebug = GL_FALSE;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Poll for new window and input events
|
||||
//========================================================================
|
||||
@@ -886,6 +1088,7 @@ void _glfwPlatformPollEvents(void)
|
||||
_glfwLibrary.NS.autoreleasePool = [[NSAutoreleasePool alloc] init];
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Wait for new window and input events
|
||||
//========================================================================
|
||||
@@ -904,6 +1107,7 @@ void _glfwPlatformWaitEvents( void )
|
||||
_glfwPlatformPollEvents();
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Set physical mouse cursor position
|
||||
//========================================================================
|
||||
@@ -921,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;
|
||||
@@ -936,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@"
|
||||
|
||||
|
||||
-192
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
-55
@@ -35,30 +35,6 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
////// GLFW internal API //////
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//========================================================================
|
||||
// Allocate memory using the allocator
|
||||
//========================================================================
|
||||
|
||||
void* _glfwMalloc(size_t size)
|
||||
{
|
||||
return _glfwLibrary.allocator.malloc(size);
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Free memory using the allocator
|
||||
//========================================================================
|
||||
|
||||
void _glfwFree(void* ptr)
|
||||
{
|
||||
_glfwLibrary.allocator.free(ptr);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
////// GLFW public API //////
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@@ -68,43 +44,12 @@ void _glfwFree(void* ptr)
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI int glfwInit(void)
|
||||
{
|
||||
return glfwInitWithModels(NULL, NULL);
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Initialize various GLFW state using custom model interfaces
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI int glfwInitWithModels(GLFWthreadmodel* threading, 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
|
||||
if (!allocator->malloc || !allocator->free)
|
||||
{
|
||||
_glfwSetError(GLFW_INVALID_VALUE, NULL);
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
_glfwLibrary.allocator = *allocator;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Use the libc malloc and free
|
||||
_glfwLibrary.allocator.malloc = malloc;
|
||||
_glfwLibrary.allocator.free = free;
|
||||
}
|
||||
|
||||
// Not all window hints have zero as their default value, so this
|
||||
// needs to be here despite the memset above
|
||||
_glfwSetDefaultWindowHints();
|
||||
|
||||
+191
-55
@@ -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;
|
||||
@@ -51,16 +167,16 @@ 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
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -161,6 +277,77 @@ void _glfwInputCursorEnter(_GLFWwindow* window, int entered)
|
||||
////// 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
|
||||
//========================================================================
|
||||
@@ -175,10 +362,8 @@ GLFWAPI int glfwGetKey(GLFWwindow handle, int key)
|
||||
return GLFW_RELEASE;
|
||||
}
|
||||
|
||||
// Is it a valid key?
|
||||
if (key < 0 || key > GLFW_KEY_LAST)
|
||||
{
|
||||
// TODO: Decide whether key is a value or enum
|
||||
_glfwSetError(GLFW_INVALID_ENUM,
|
||||
"glfwGetKey: The specified key is invalid");
|
||||
return GLFW_RELEASE;
|
||||
@@ -209,7 +394,6 @@ GLFWAPI int glfwGetMouseButton(GLFWwindow handle, int button)
|
||||
return GLFW_RELEASE;
|
||||
}
|
||||
|
||||
// Is it a valid mouse button?
|
||||
if (button < 0 || button > GLFW_MOUSE_BUTTON_LAST)
|
||||
{
|
||||
_glfwSetError(GLFW_INVALID_ENUM,
|
||||
@@ -242,7 +426,6 @@ GLFWAPI void glfwGetMousePos(GLFWwindow handle, int* xpos, int* ypos)
|
||||
return;
|
||||
}
|
||||
|
||||
// Return mouse position
|
||||
if (xpos != NULL)
|
||||
*xpos = window->cursorPosX;
|
||||
|
||||
@@ -311,51 +494,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
|
||||
//========================================================================
|
||||
@@ -416,7 +554,6 @@ GLFWAPI void glfwSetMousePosCallback(GLFWmouseposfun cbfun)
|
||||
return;
|
||||
}
|
||||
|
||||
// Set callback function
|
||||
_glfwLibrary.mousePosCallback = cbfun;
|
||||
|
||||
// Call the callback function to let the application know the current
|
||||
@@ -459,7 +596,6 @@ GLFWAPI void glfwSetScrollCallback(GLFWscrollfun cbfun)
|
||||
return;
|
||||
}
|
||||
|
||||
// Set callback function
|
||||
_glfwLibrary.scrollCallback = cbfun;
|
||||
}
|
||||
|
||||
|
||||
+10
-17
@@ -37,9 +37,9 @@
|
||||
//========================================================================
|
||||
|
||||
#if defined(_init_c_)
|
||||
#define GLFWGLOBAL
|
||||
#define GLFWGLOBAL
|
||||
#else
|
||||
#define GLFWGLOBAL extern
|
||||
#define GLFWGLOBAL extern
|
||||
#endif
|
||||
|
||||
|
||||
@@ -66,13 +66,13 @@
|
||||
#include "../support/GL/glext.h"
|
||||
|
||||
#if defined(_GLFW_COCOA_NSGL)
|
||||
#include "cocoa_platform.h"
|
||||
#include "cocoa_platform.h"
|
||||
#elif defined(_GLFW_WIN32_WGL)
|
||||
#include "win32_platform.h"
|
||||
#include "win32_platform.h"
|
||||
#elif defined(_GLFW_X11_GLX)
|
||||
#include "x11_platform.h"
|
||||
#include "x11_platform.h"
|
||||
#else
|
||||
#error "No supported platform selected"
|
||||
#error "No supported platform selected"
|
||||
#endif
|
||||
|
||||
typedef struct _GLFWhints _GLFWhints;
|
||||
@@ -183,7 +183,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;
|
||||
@@ -242,9 +242,6 @@ struct _GLFWlibrary
|
||||
GLFWkeyfun keyCallback;
|
||||
GLFWcharfun charCallback;
|
||||
|
||||
GLFWthreadmodel threading;
|
||||
GLFWallocator allocator;
|
||||
|
||||
GLFWgammaramp currentRamp;
|
||||
GLFWgammaramp originalRamp;
|
||||
int originalRampSize;
|
||||
@@ -277,7 +274,7 @@ int _glfwPlatformInit(void);
|
||||
int _glfwPlatformTerminate(void);
|
||||
const char* _glfwPlatformGetVersionString(void);
|
||||
|
||||
// Enable/Disable
|
||||
// Input
|
||||
void _glfwPlatformEnableSystemKeys(_GLFWwindow* window);
|
||||
void _glfwPlatformDisableSystemKeys(_GLFWwindow* window);
|
||||
|
||||
@@ -327,10 +324,6 @@ void _glfwPlatformCopyContext(_GLFWwindow* src, _GLFWwindow* dst, unsigned long
|
||||
// Prototypes for platform independent internal functions
|
||||
//========================================================================
|
||||
|
||||
// Memory management (init.c)
|
||||
void* _glfwMalloc(size_t size);
|
||||
void _glfwFree(void* ptr);
|
||||
|
||||
// Fullscren management (fullscreen.c)
|
||||
void _glfwSplitBPP(int bpp, int* red, int* green, int* blue);
|
||||
|
||||
@@ -340,14 +333,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);
|
||||
|
||||
+59
-5
@@ -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)
|
||||
@@ -131,6 +131,60 @@ static void freeLibraries(void)
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
////// GLFW internal API //////
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//========================================================================
|
||||
// Returns a wide string version of the specified UTF-8 string
|
||||
//========================================================================
|
||||
|
||||
WCHAR* _glfwCreateWideStringFromUTF8(const char* source)
|
||||
{
|
||||
WCHAR* target;
|
||||
int length;
|
||||
|
||||
length = MultiByteToWideChar(CP_UTF8, 0, source, -1, NULL, 0);
|
||||
if (!length)
|
||||
return NULL;
|
||||
|
||||
target = (WCHAR*) malloc(sizeof(WCHAR) * (length + 1));
|
||||
|
||||
if (!MultiByteToWideChar(CP_UTF8, 0, source, -1, target, length + 1))
|
||||
{
|
||||
free(target);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Returns a UTF-8 string version of the specified wide string
|
||||
//========================================================================
|
||||
|
||||
char* _glfwCreateUTF8FromWideString(const WCHAR* source)
|
||||
{
|
||||
char* target;
|
||||
int length;
|
||||
|
||||
length = WideCharToMultiByte(CP_UTF8, 0, source, -1, NULL, 0, NULL, NULL);
|
||||
if (!length)
|
||||
return NULL;
|
||||
|
||||
target = (char*) malloc(length + 1);
|
||||
|
||||
if (!WideCharToMultiByte(CP_UTF8, 0, source, -1, target, length + 1, NULL, NULL))
|
||||
{
|
||||
free(target);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
////// GLFW platform API //////
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
+59
-47
@@ -45,6 +45,14 @@
|
||||
// thinks it is the only one that gets to do so
|
||||
#undef APIENTRY
|
||||
|
||||
// GLFW on Windows is Unicode only and does not work in MBCS mode
|
||||
#ifndef UNICODE
|
||||
#define UNICODE
|
||||
#endif
|
||||
|
||||
// GLFW requires Windows XP
|
||||
#define WINVER 0x0501
|
||||
|
||||
#include <windows.h>
|
||||
#include <mmsystem.h>
|
||||
|
||||
@@ -61,10 +69,10 @@
|
||||
// Some old versions of w32api (used by MinGW and Cygwin) define
|
||||
// WH_KEYBOARD_LL without typedef:ing KBDLLHOOKSTRUCT (!)
|
||||
#if defined(__MINGW32__) || defined(__CYGWIN__)
|
||||
#include <w32api.h>
|
||||
#if defined(WH_KEYBOARD_LL) && (__W32API_MAJOR_VERSION == 1) && (__W32API_MINOR_VERSION <= 2)
|
||||
#undef WH_KEYBOARD_LL
|
||||
#endif
|
||||
#include <w32api.h>
|
||||
#if defined(WH_KEYBOARD_LL) && (__W32API_MAJOR_VERSION == 1) && (__W32API_MINOR_VERSION <= 2)
|
||||
#undef WH_KEYBOARD_LL
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
@@ -84,64 +92,64 @@ typedef struct tagKBDLLHOOKSTRUCT {
|
||||
#endif // WH_KEYBOARD_LL
|
||||
|
||||
#ifndef LLKHF_ALTDOWN
|
||||
#define LLKHF_ALTDOWN 0x00000020
|
||||
#define LLKHF_ALTDOWN 0x00000020
|
||||
#endif
|
||||
|
||||
#ifndef SPI_SETSCREENSAVERRUNNING
|
||||
#define SPI_SETSCREENSAVERRUNNING 97
|
||||
#define SPI_SETSCREENSAVERRUNNING 97
|
||||
#endif
|
||||
#ifndef SPI_GETANIMATION
|
||||
#define SPI_GETANIMATION 72
|
||||
#define SPI_GETANIMATION 72
|
||||
#endif
|
||||
#ifndef SPI_SETANIMATION
|
||||
#define SPI_SETANIMATION 73
|
||||
#define SPI_SETANIMATION 73
|
||||
#endif
|
||||
#ifndef SPI_GETFOREGROUNDLOCKTIMEOUT
|
||||
#define SPI_GETFOREGROUNDLOCKTIMEOUT 0x2000
|
||||
#define SPI_GETFOREGROUNDLOCKTIMEOUT 0x2000
|
||||
#endif
|
||||
#ifndef SPI_SETFOREGROUNDLOCKTIMEOUT
|
||||
#define SPI_SETFOREGROUNDLOCKTIMEOUT 0x2001
|
||||
#define SPI_SETFOREGROUNDLOCKTIMEOUT 0x2001
|
||||
#endif
|
||||
|
||||
#ifndef CDS_FULLSCREEN
|
||||
#define CDS_FULLSCREEN 4
|
||||
#define CDS_FULLSCREEN 4
|
||||
#endif
|
||||
|
||||
#ifndef PFD_GENERIC_ACCELERATED
|
||||
#define PFD_GENERIC_ACCELERATED 0x00001000
|
||||
#define PFD_GENERIC_ACCELERATED 0x00001000
|
||||
#endif
|
||||
#ifndef PFD_DEPTH_DONTCARE
|
||||
#define PFD_DEPTH_DONTCARE 0x20000000
|
||||
#define PFD_DEPTH_DONTCARE 0x20000000
|
||||
#endif
|
||||
|
||||
#ifndef ENUM_CURRENT_SETTINGS
|
||||
#define ENUM_CURRENT_SETTINGS -1
|
||||
#define ENUM_CURRENT_SETTINGS -1
|
||||
#endif
|
||||
#ifndef ENUM_REGISTRY_SETTINGS
|
||||
#define ENUM_REGISTRY_SETTINGS -2
|
||||
#define ENUM_REGISTRY_SETTINGS -2
|
||||
#endif
|
||||
|
||||
#ifndef WM_MOUSEWHEEL
|
||||
#define WM_MOUSEWHEEL 0x020A
|
||||
#define WM_MOUSEWHEEL 0x020A
|
||||
#endif
|
||||
#ifndef WHEEL_DELTA
|
||||
#define WHEEL_DELTA 120
|
||||
#define WHEEL_DELTA 120
|
||||
#endif
|
||||
#ifndef WM_MOUSEHWHEEL
|
||||
#define WM_MOUSEHWHEEL 0x020E
|
||||
#define WM_MOUSEHWHEEL 0x020E
|
||||
#endif
|
||||
|
||||
#ifndef WM_XBUTTONDOWN
|
||||
#define WM_XBUTTONDOWN 0x020B
|
||||
#define WM_XBUTTONDOWN 0x020B
|
||||
#endif
|
||||
#ifndef WM_XBUTTONUP
|
||||
#define WM_XBUTTONUP 0x020C
|
||||
#define WM_XBUTTONUP 0x020C
|
||||
#endif
|
||||
#ifndef XBUTTON1
|
||||
#define XBUTTON1 1
|
||||
#define XBUTTON1 1
|
||||
#endif
|
||||
#ifndef XBUTTON2
|
||||
#define XBUTTON2 2
|
||||
#define XBUTTON2 2
|
||||
#endif
|
||||
|
||||
|
||||
@@ -162,7 +170,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);
|
||||
@@ -171,40 +179,40 @@ typedef DWORD (WINAPI * TIMEGETTIME_T) (void);
|
||||
|
||||
// gdi32.dll shortcuts
|
||||
#ifndef _GLFW_NO_DLOAD_GDI32
|
||||
#define _glfw_ChoosePixelFormat _glfwLibrary.Win32.gdi.ChoosePixelFormat
|
||||
#define _glfw_DescribePixelFormat _glfwLibrary.Win32.gdi.DescribePixelFormat
|
||||
#define _glfw_GetPixelFormat _glfwLibrary.Win32.gdi.GetPixelFormat
|
||||
#define _glfw_SetPixelFormat _glfwLibrary.Win32.gdi.SetPixelFormat
|
||||
#define _glfw_SwapBuffers _glfwLibrary.Win32.gdi.SwapBuffers
|
||||
#define _glfw_GetDeviceGammaRamp _glfwLibrary.Win32.gdi.GetDeviceGammaRamp
|
||||
#define _glfw_SetDeviceGammaRamp _glfwLibrary.Win32.gdi.SetDeviceGammaRamp
|
||||
#define _glfw_ChoosePixelFormat _glfwLibrary.Win32.gdi.ChoosePixelFormat
|
||||
#define _glfw_DescribePixelFormat _glfwLibrary.Win32.gdi.DescribePixelFormat
|
||||
#define _glfw_GetPixelFormat _glfwLibrary.Win32.gdi.GetPixelFormat
|
||||
#define _glfw_SetPixelFormat _glfwLibrary.Win32.gdi.SetPixelFormat
|
||||
#define _glfw_SwapBuffers _glfwLibrary.Win32.gdi.SwapBuffers
|
||||
#define _glfw_GetDeviceGammaRamp _glfwLibrary.Win32.gdi.GetDeviceGammaRamp
|
||||
#define _glfw_SetDeviceGammaRamp _glfwLibrary.Win32.gdi.SetDeviceGammaRamp
|
||||
#else
|
||||
#define _glfw_ChoosePixelFormat ChoosePixelFormat
|
||||
#define _glfw_DescribePixelFormat DescribePixelFormat
|
||||
#define _glfw_GetPixelFormat GetPixelFormat
|
||||
#define _glfw_SetPixelFormat SetPixelFormat
|
||||
#define _glfw_SwapBuffers SwapBuffers
|
||||
#define _glfw_GetDeviceGammaRamp GetDeviceGammaRamp
|
||||
#define _glfw_SetDeviceGammaRamp SetDeviceGammaRamp
|
||||
#define _glfw_ChoosePixelFormat ChoosePixelFormat
|
||||
#define _glfw_DescribePixelFormat DescribePixelFormat
|
||||
#define _glfw_GetPixelFormat GetPixelFormat
|
||||
#define _glfw_SetPixelFormat SetPixelFormat
|
||||
#define _glfw_SwapBuffers SwapBuffers
|
||||
#define _glfw_GetDeviceGammaRamp GetDeviceGammaRamp
|
||||
#define _glfw_SetDeviceGammaRamp SetDeviceGammaRamp
|
||||
#endif // _GLFW_NO_DLOAD_GDI32
|
||||
|
||||
// winmm.dll shortcuts
|
||||
#ifndef _GLFW_NO_DLOAD_WINMM
|
||||
#define _glfw_joyGetDevCaps _glfwLibrary.Win32.winmm.joyGetDevCapsA
|
||||
#define _glfw_joyGetPos _glfwLibrary.Win32.winmm.joyGetPos
|
||||
#define _glfw_joyGetPosEx _glfwLibrary.Win32.winmm.joyGetPosEx
|
||||
#define _glfw_timeGetTime _glfwLibrary.Win32.winmm.timeGetTime
|
||||
#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_joyGetPos joyGetPos
|
||||
#define _glfw_joyGetPosEx joyGetPosEx
|
||||
#define _glfw_timeGetTime timeGetTime
|
||||
#define _glfw_joyGetDevCaps joyGetDevCaps
|
||||
#define _glfw_joyGetPos joyGetPos
|
||||
#define _glfw_joyGetPosEx joyGetPosEx
|
||||
#define _glfw_timeGetTime timeGetTime
|
||||
#endif // _GLFW_NO_DLOAD_WINMM
|
||||
|
||||
|
||||
// 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
|
||||
@@ -309,7 +317,7 @@ typedef struct _GLFWlibraryWin32
|
||||
// winmm.dll
|
||||
struct {
|
||||
HINSTANCE instance;
|
||||
JOYGETDEVCAPSA_T joyGetDevCapsA;
|
||||
JOYGETDEVCAPS_T joyGetDevCaps;
|
||||
JOYGETPOS_T joyGetPos;
|
||||
JOYGETPOSEX_T joyGetPosEx;
|
||||
TIMEGETTIME_T timeGetTime;
|
||||
@@ -323,6 +331,10 @@ typedef struct _GLFWlibraryWin32
|
||||
// Prototypes for platform specific internal functions
|
||||
//========================================================================
|
||||
|
||||
// Wide strings
|
||||
WCHAR* _glfwCreateWideStringFromUTF8(const char* source);
|
||||
char* _glfwCreateUTF8FromWideString(const WCHAR* source);
|
||||
|
||||
// Time
|
||||
void _glfwInitTimer(void);
|
||||
|
||||
|
||||
+30
-8
@@ -195,7 +195,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
result = (_GLFWfbconfig*) _glfwMalloc(sizeof(_GLFWfbconfig) * count);
|
||||
result = (_GLFWfbconfig*) malloc(sizeof(_GLFWfbconfig) * count);
|
||||
if (!result)
|
||||
{
|
||||
_glfwSetError(GLFW_OUT_OF_MEMORY,
|
||||
@@ -895,7 +895,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
||||
if (_glfwLibrary.charCallback)
|
||||
translateChar(window, (DWORD) wParam, (DWORD) lParam);
|
||||
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_KEYUP:
|
||||
@@ -910,7 +910,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
||||
else
|
||||
_glfwInputKey(window, translateKey(wParam, lParam), GLFW_RELEASE);
|
||||
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_LBUTTONDOWN:
|
||||
@@ -1220,7 +1220,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
|
||||
@@ -1257,13 +1257,13 @@ static int choosePixelFormat(_GLFWwindow* window, const _GLFWfbconfig* fbconfig)
|
||||
closest = _glfwChooseFBConfig(fbconfig, fbconfigs, fbcount);
|
||||
if (!closest)
|
||||
{
|
||||
_glfwFree(fbconfigs);
|
||||
free(fbconfigs);
|
||||
return 0;
|
||||
}
|
||||
|
||||
pixelFormat = (int) closest->platformID;
|
||||
|
||||
_glfwFree(fbconfigs);
|
||||
free(fbconfigs);
|
||||
fbconfigs = NULL;
|
||||
closest = NULL;
|
||||
|
||||
@@ -1283,6 +1283,7 @@ static int createWindow(_GLFWwindow* window,
|
||||
int pixelFormat, fullWidth, fullHeight;
|
||||
RECT wa;
|
||||
POINT pos;
|
||||
WCHAR* wideTitle;
|
||||
|
||||
// Set common window styles
|
||||
dwStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
|
||||
@@ -1331,9 +1332,17 @@ static int createWindow(_GLFWwindow* window,
|
||||
else
|
||||
SystemParametersInfo(SPI_GETWORKAREA, 0, &wa, 0);
|
||||
|
||||
wideTitle = _glfwCreateWideStringFromUTF8(wndconfig->title);
|
||||
if (!wideTitle)
|
||||
{
|
||||
_glfwSetError(GLFW_PLATFORM_ERROR,
|
||||
"glfwOpenWindow: Failed to convert title to wide string");
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
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
|
||||
@@ -1349,6 +1358,8 @@ static int createWindow(_GLFWwindow* window,
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
free(wideTitle);
|
||||
|
||||
window->WGL.DC = GetDC(window->Win32.handle);
|
||||
if (!window->WGL.DC)
|
||||
{
|
||||
@@ -1430,6 +1441,7 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
|
||||
GLboolean recreateContext = GL_FALSE;
|
||||
|
||||
window->Win32.desiredRefreshRate = wndconfig->refreshRate;
|
||||
window->resizable = wndconfig->resizable;
|
||||
|
||||
if (!_glfwLibrary.Win32.classAtom)
|
||||
{
|
||||
@@ -1568,7 +1580,17 @@ void _glfwPlatformCloseWindow(_GLFWwindow* window)
|
||||
|
||||
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title)
|
||||
{
|
||||
SetWindowText(window->Win32.handle, title);
|
||||
WCHAR* wideTitle = _glfwCreateWideStringFromUTF8(title);
|
||||
if (!wideTitle)
|
||||
{
|
||||
_glfwSetError(GLFW_PLATFORM_ERROR,
|
||||
"glfwSetWindowTitle: Failed to convert title to wide string");
|
||||
return;
|
||||
}
|
||||
|
||||
SetWindowText(window->Win32.handle, wideTitle);
|
||||
|
||||
free(wideTitle);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+4
-4
@@ -291,7 +291,7 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height,
|
||||
height = 480;
|
||||
}
|
||||
|
||||
window = (_GLFWwindow*) _glfwMalloc(sizeof(_GLFWwindow));
|
||||
window = (_GLFWwindow*) malloc(sizeof(_GLFWwindow));
|
||||
if (!window)
|
||||
{
|
||||
_glfwSetError(GLFW_OUT_OF_MEMORY,
|
||||
@@ -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
|
||||
@@ -491,7 +492,7 @@ GLFWAPI void glfwCloseWindow(GLFWwindow handle)
|
||||
*prev = window->next;
|
||||
}
|
||||
|
||||
_glfwFree(window);
|
||||
free(window);
|
||||
}
|
||||
|
||||
|
||||
@@ -654,7 +655,6 @@ GLFWAPI void glfwRestoreWindow(GLFWwindow handle)
|
||||
if (!window->iconified)
|
||||
return;
|
||||
|
||||
// Restore iconified window
|
||||
_glfwPlatformRestoreWindow(window);
|
||||
|
||||
if (window->mode == GLFW_FULLSCREEN)
|
||||
|
||||
@@ -339,7 +339,7 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
|
||||
return 0;
|
||||
}
|
||||
|
||||
rgbarray = (int*) _glfwMalloc(sizeof(int) * viscount);
|
||||
rgbarray = (int*) malloc(sizeof(int) * viscount);
|
||||
rgbcount = 0;
|
||||
|
||||
// Build RGB array
|
||||
@@ -372,6 +372,8 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
|
||||
}
|
||||
}
|
||||
|
||||
XFree(vislist);
|
||||
|
||||
rescount = 0;
|
||||
resarray = NULL;
|
||||
|
||||
@@ -387,7 +389,7 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
|
||||
sc = XRRGetScreenInfo(_glfwLibrary.X11.display, _glfwLibrary.X11.root);
|
||||
sizelist = XRRConfigSizes(sc, &sizecount);
|
||||
|
||||
resarray = (struct _glfwResolution*) _glfwMalloc(sizeof(struct _glfwResolution) * sizecount);
|
||||
resarray = (struct _glfwResolution*) malloc(sizeof(struct _glfwResolution) * sizecount);
|
||||
|
||||
for (k = 0; k < sizecount; k++)
|
||||
{
|
||||
@@ -407,7 +409,7 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
|
||||
|
||||
XF86VidModeGetAllModeLines(_glfwLibrary.X11.display, screen, &modecount, &modelist);
|
||||
|
||||
resarray = (struct _glfwResolution*) _glfwMalloc(sizeof(struct _glfwResolution) * modecount);
|
||||
resarray = (struct _glfwResolution*) malloc(sizeof(struct _glfwResolution) * modecount);
|
||||
|
||||
for (k = 0; k < modecount; k++)
|
||||
{
|
||||
@@ -436,7 +438,7 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
|
||||
if (!resarray)
|
||||
{
|
||||
rescount = 1;
|
||||
resarray = (struct _glfwResolution*) _glfwMalloc(sizeof(struct _glfwResolution) * rescount);
|
||||
resarray = (struct _glfwResolution*) malloc(sizeof(struct _glfwResolution) * rescount);
|
||||
|
||||
resarray[0].width = DisplayWidth(_glfwLibrary.X11.display, screen);
|
||||
resarray[0].height = DisplayHeight(_glfwLibrary.X11.display, screen);
|
||||
@@ -457,10 +459,8 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
|
||||
}
|
||||
}
|
||||
|
||||
XFree(vislist);
|
||||
|
||||
_glfwFree(resarray);
|
||||
_glfwFree(rgbarray);
|
||||
free(resarray);
|
||||
free(rgbarray);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
+1
-2
@@ -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
@@ -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>
|
||||
@@ -141,6 +134,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
|
||||
|
||||
+2
-2
@@ -39,7 +39,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 +64,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)
|
||||
|
||||
+42
-6
@@ -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");
|
||||
|
||||
@@ -310,7 +316,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
|
||||
}
|
||||
}
|
||||
|
||||
result = (_GLFWfbconfig*) _glfwMalloc(sizeof(_GLFWfbconfig) * count);
|
||||
result = (_GLFWfbconfig*) malloc(sizeof(_GLFWfbconfig) * count);
|
||||
if (!result)
|
||||
{
|
||||
_glfwSetError(GLFW_OUT_OF_MEMORY,
|
||||
@@ -1444,12 +1450,12 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
|
||||
result = _glfwChooseFBConfig(fbconfig, fbconfigs, fbcount);
|
||||
if (!result)
|
||||
{
|
||||
_glfwFree(fbconfigs);
|
||||
free(fbconfigs);
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
closest = *result;
|
||||
_glfwFree(fbconfigs);
|
||||
free(fbconfigs);
|
||||
}
|
||||
|
||||
if (!createContext(window, wndconfig, (GLXFBConfigID) closest.platformID))
|
||||
@@ -1544,9 +1550,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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user