1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-11-23 10:48:51 -05:00

Renamed global struct and substructs.

Renamed _glfwLibrary to _glfw and made all substructs lower-case, making
global variable names easier to read and type.  Partially inspired by the
internal naming conventions of glwt.
This commit is contained in:
Camilla Berglund 2013-01-02 01:40:42 +01:00
parent 45459d5a34
commit b72a97d531
39 changed files with 1017 additions and 1054 deletions

View File

@ -74,9 +74,9 @@ const char* _glfwPlatformGetClipboardString(_GLFWwindow* window)
return NULL; return NULL;
} }
free(_glfwLibrary.NS.clipboardString); free(_glfw.ns.clipboardString);
_glfwLibrary.NS.clipboardString = strdup([object UTF8String]); _glfw.ns.clipboardString = strdup([object UTF8String]);
return _glfwLibrary.NS.clipboardString; return _glfw.ns.clipboardString;
} }

View File

@ -52,7 +52,7 @@ void _glfwPlatformGetGammaRamp(GLFWgammaramp* ramp)
CGGammaValue blue[GLFW_GAMMA_RAMP_SIZE]; CGGammaValue blue[GLFW_GAMMA_RAMP_SIZE];
// For now, don't support anything that is not GLFW_GAMMA_RAMP_SIZE // For now, don't support anything that is not GLFW_GAMMA_RAMP_SIZE
if (_glfwLibrary.originalRampSize != GLFW_GAMMA_RAMP_SIZE) if (_glfw.originalRampSize != GLFW_GAMMA_RAMP_SIZE)
return; return;
CGGetDisplayTransferByTable(CGMainDisplayID(), GLFW_GAMMA_RAMP_SIZE, red, green, blue, CGGetDisplayTransferByTable(CGMainDisplayID(), GLFW_GAMMA_RAMP_SIZE, red, green, blue,
@ -80,7 +80,7 @@ void _glfwPlatformSetGammaRamp(const GLFWgammaramp* ramp)
CGGammaValue blue[GLFW_GAMMA_RAMP_SIZE]; CGGammaValue blue[GLFW_GAMMA_RAMP_SIZE];
// For now, don't support anything that is not GLFW_GAMMA_RAMP_SIZE // For now, don't support anything that is not GLFW_GAMMA_RAMP_SIZE
if (_glfwLibrary.originalRampSize != GLFW_GAMMA_RAMP_SIZE) if (_glfw.originalRampSize != GLFW_GAMMA_RAMP_SIZE)
return; return;
// Convert to float & take the difference of the original gamma and // Convert to float & take the difference of the original gamma and

View File

@ -79,11 +79,11 @@ static void changeToResourcesDirectory(void)
int _glfwPlatformInit(void) int _glfwPlatformInit(void)
{ {
_glfwLibrary.NS.autoreleasePool = [[NSAutoreleasePool alloc] init]; _glfw.ns.autoreleasePool = [[NSAutoreleasePool alloc] init];
_glfwLibrary.NSGL.framework = _glfw.nsgl.framework =
CFBundleGetBundleWithIdentifier(CFSTR("com.apple.opengl")); CFBundleGetBundleWithIdentifier(CFSTR("com.apple.opengl"));
if (_glfwLibrary.NSGL.framework == NULL) if (_glfw.nsgl.framework == NULL)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,
"NSGL: Failed to locate OpenGL framework"); "NSGL: Failed to locate OpenGL framework");
@ -93,9 +93,9 @@ int _glfwPlatformInit(void)
changeToResourcesDirectory(); changeToResourcesDirectory();
// Save the original gamma ramp // Save the original gamma ramp
_glfwLibrary.originalRampSize = CGDisplayGammaTableCapacity(CGMainDisplayID()); _glfw.originalRampSize = CGDisplayGammaTableCapacity(CGMainDisplayID());
_glfwPlatformGetGammaRamp(&_glfwLibrary.originalRamp); _glfwPlatformGetGammaRamp(&_glfw.originalRamp);
_glfwLibrary.currentRamp = _glfwLibrary.originalRamp; _glfw.currentRamp = _glfw.originalRamp;
_glfwInitTimer(); _glfwInitTimer();
@ -104,12 +104,11 @@ int _glfwPlatformInit(void)
if (!_glfwInitOpenGL()) if (!_glfwInitOpenGL())
return GL_FALSE; return GL_FALSE;
_glfwLibrary.NS.eventSource = CGEventSourceCreate(kCGEventSourceStateHIDSystemState); _glfw.ns.eventSource = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
if (!_glfwLibrary.NS.eventSource) if (!_glfw.ns.eventSource)
return GL_FALSE; return GL_FALSE;
CGEventSourceSetLocalEventsSuppressionInterval(_glfwLibrary.NS.eventSource, CGEventSourceSetLocalEventsSuppressionInterval(_glfw.ns.eventSource, 0.0);
0.0);
return GL_TRUE; return GL_TRUE;
} }
@ -123,22 +122,22 @@ void _glfwPlatformTerminate(void)
{ {
// TODO: Probably other cleanup // TODO: Probably other cleanup
if (_glfwLibrary.NS.eventSource) if (_glfw.ns.eventSource)
{ {
CFRelease(_glfwLibrary.NS.eventSource); CFRelease(_glfw.ns.eventSource);
_glfwLibrary.NS.eventSource = NULL; _glfw.ns.eventSource = NULL;
} }
// Restore the original gamma ramp // Restore the original gamma ramp
if (_glfwLibrary.rampChanged) if (_glfw.rampChanged)
_glfwPlatformSetGammaRamp(&_glfwLibrary.originalRamp); _glfwPlatformSetGammaRamp(&_glfw.originalRamp);
[NSApp setDelegate:nil]; [NSApp setDelegate:nil];
[_glfwLibrary.NS.delegate release]; [_glfw.ns.delegate release];
_glfwLibrary.NS.delegate = nil; _glfw.ns.delegate = nil;
[_glfwLibrary.NS.autoreleasePool release]; [_glfw.ns.autoreleasePool release];
_glfwLibrary.NS.autoreleasePool = nil; _glfw.ns.autoreleasePool = nil;
_glfwTerminateJoysticks(); _glfwTerminateJoysticks();

View File

@ -190,7 +190,7 @@ GLboolean _glfwSetVideoMode(int* width, int* height, int* bpp)
return GL_FALSE; return GL_FALSE;
} }
_glfwLibrary.NS.previousMode = CGDisplayCopyDisplayMode(CGMainDisplayID()); _glfw.ns.previousMode = CGDisplayCopyDisplayMode(CGMainDisplayID());
CGDisplayCapture(CGMainDisplayID()); CGDisplayCapture(CGMainDisplayID());
CGDisplaySetDisplayMode(CGMainDisplayID(), bestMode, NULL); CGDisplaySetDisplayMode(CGMainDisplayID(), bestMode, NULL);
@ -206,10 +206,7 @@ GLboolean _glfwSetVideoMode(int* width, int* height, int* bpp)
void _glfwRestoreVideoMode(void) void _glfwRestoreVideoMode(void)
{ {
CGDisplaySetDisplayMode(CGMainDisplayID(), CGDisplaySetDisplayMode(CGMainDisplayID(), _glfw.ns.previousMode, NULL);
_glfwLibrary.NS.previousMode,
NULL);
CGDisplayRelease(CGMainDisplayID()); CGDisplayRelease(CGMainDisplayID());
} }
@ -256,7 +253,7 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
size.width, size.height, size.width, size.height,
bounds.origin.x, bounds.origin.y); bounds.origin.x, bounds.origin.y);
monitors[found]->NS.displayID = displays[i]; monitors[found]->ns.displayID = displays[i];
found++; found++;
} }
@ -286,7 +283,7 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found)
CFIndex count, i; CFIndex count, i;
GLFWvidmode* result; GLFWvidmode* result;
modes = CGDisplayCopyAllDisplayModes(monitor->NS.displayID, NULL); modes = CGDisplayCopyAllDisplayModes(monitor->ns.displayID, NULL);
count = CFArrayGetCount(modes); count = CFArrayGetCount(modes);
result = (GLFWvidmode*) malloc(sizeof(GLFWvidmode) * count); result = (GLFWvidmode*) malloc(sizeof(GLFWvidmode) * count);
@ -317,7 +314,7 @@ void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode *mode)
{ {
CGDisplayModeRef displayMode; CGDisplayModeRef displayMode;
displayMode = CGDisplayCopyDisplayMode(monitor->NS.displayID); displayMode = CGDisplayCopyDisplayMode(monitor->ns.displayID);
*mode = vidmodeFromCGDisplayMode(displayMode); *mode = vidmodeFromCGDisplayMode(displayMode);
CGDisplayModeRelease(displayMode); CGDisplayModeRelease(displayMode);
} }

View File

@ -51,7 +51,7 @@ GLFWAPI id glfwGetCocoaWindow(GLFWwindow handle)
return 0; return 0;
} }
return window->NS.object; return window->ns.object;
} }
@ -69,6 +69,6 @@ GLFWAPI id glfwGetNSGLContext(GLFWwindow handle)
return NULL; return NULL;
} }
return window->NSGL.context; return window->nsgl.context;
} }

View File

@ -46,9 +46,9 @@ typedef void* id;
#error "No supported context creation API selected" #error "No supported context creation API selected"
#endif #endif
#define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowNS NS #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowNS ns
#define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryNS NS #define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryNS ns
#define _GLFW_PLATFORM_MONITOR_STATE _GLFWmonitorNS NS #define _GLFW_PLATFORM_MONITOR_STATE _GLFWmonitorNS ns
//======================================================================== //========================================================================

View File

@ -55,8 +55,8 @@ void _glfwInitTimer(void)
mach_timebase_info_data_t info; mach_timebase_info_data_t info;
mach_timebase_info(&info); mach_timebase_info(&info);
_glfwLibrary.NS.timer.resolution = (double) info.numer / (info.denom * 1.0e9); _glfw.ns.timer.resolution = (double) info.numer / (info.denom * 1.0e9);
_glfwLibrary.NS.timer.base = getRawTime(); _glfw.ns.timer.base = getRawTime();
} }
@ -70,8 +70,8 @@ void _glfwInitTimer(void)
double _glfwPlatformGetTime(void) double _glfwPlatformGetTime(void)
{ {
return (double) (getRawTime() - _glfwLibrary.NS.timer.base) * return (double) (getRawTime() - _glfw.ns.timer.base) *
_glfwLibrary.NS.timer.resolution; _glfw.ns.timer.resolution;
} }
@ -81,7 +81,7 @@ double _glfwPlatformGetTime(void)
void _glfwPlatformSetTime(double time) void _glfwPlatformSetTime(double time)
{ {
_glfwLibrary.NS.timer.base = getRawTime() - _glfw.ns.timer.base = getRawTime() -
(uint64_t) (time / _glfwLibrary.NS.timer.resolution); (uint64_t) (time / _glfw.ns.timer.resolution);
} }

View File

@ -65,20 +65,20 @@
- (void)windowDidResize:(NSNotification *)notification - (void)windowDidResize:(NSNotification *)notification
{ {
[window->NSGL.context update]; [window->nsgl.context update];
NSRect contentRect = NSRect contentRect =
[window->NS.object contentRectForFrameRect:[window->NS.object frame]]; [window->ns.object contentRectForFrameRect:[window->ns.object frame]];
_glfwInputWindowSize(window, contentRect.size.width, contentRect.size.height); _glfwInputWindowSize(window, contentRect.size.width, contentRect.size.height);
} }
- (void)windowDidMove:(NSNotification *)notification - (void)windowDidMove:(NSNotification *)notification
{ {
[window->NSGL.context update]; [window->nsgl.context update];
NSRect contentRect = NSRect contentRect =
[window->NS.object contentRectForFrameRect:[window->NS.object frame]]; [window->ns.object contentRectForFrameRect:[window->ns.object frame]];
CGPoint mainScreenOrigin = CGDisplayBounds(CGMainDisplayID()).origin; CGPoint mainScreenOrigin = CGDisplayBounds(CGMainDisplayID()).origin;
double mainScreenHeight = CGDisplayBounds(CGMainDisplayID()).size.height; double mainScreenHeight = CGDisplayBounds(CGMainDisplayID()).size.height;
@ -125,7 +125,7 @@
{ {
_GLFWwindow* window; _GLFWwindow* window;
for (window = _glfwLibrary.windowListHead; window; window = window->next) for (window = _glfw.windowListHead; window; window = window->next)
_glfwInputWindowCloseRequest(window); _glfwInputWindowCloseRequest(window);
return NSTerminateCancel; return NSTerminateCancel;
@ -135,7 +135,7 @@
{ {
_GLFWwindow* window; _GLFWwindow* window;
for (window = _glfwLibrary.windowListHead; window; window = window->next) for (window = _glfw.windowListHead; window; window = window->next)
_glfwInputWindowVisibility(window, GL_FALSE); _glfwInputWindowVisibility(window, GL_FALSE);
} }
@ -143,9 +143,9 @@
{ {
_GLFWwindow* window; _GLFWwindow* window;
for (window = _glfwLibrary.windowListHead; window; window = window->next) for (window = _glfw.windowListHead; window; window = window->next)
{ {
if ([window->NS.object isVisible]) if ([window->ns.object isVisible])
_glfwInputWindowVisibility(window, GL_TRUE); _glfwInputWindowVisibility(window, GL_TRUE);
} }
} }
@ -474,12 +474,12 @@ static int convertMacKeyCode(unsigned int macKeyCode)
unsigned int newModifierFlags = unsigned int newModifierFlags =
[event modifierFlags] | NSDeviceIndependentModifierFlagsMask; [event modifierFlags] | NSDeviceIndependentModifierFlagsMask;
if (newModifierFlags > window->NS.modifierFlags) if (newModifierFlags > window->ns.modifierFlags)
mode = GLFW_PRESS; mode = GLFW_PRESS;
else else
mode = GLFW_RELEASE; mode = GLFW_RELEASE;
window->NS.modifierFlags = newModifierFlags; window->ns.modifierFlags = newModifierFlags;
key = convertMacKeyCode([event keyCode]); key = convertMacKeyCode([event keyCode]);
if (key != -1) if (key != -1)
@ -684,28 +684,28 @@ static GLboolean createWindow(_GLFWwindow* window,
styleMask |= NSResizableWindowMask; styleMask |= NSResizableWindowMask;
} }
window->NS.object = [[NSWindow alloc] window->ns.object = [[NSWindow alloc]
initWithContentRect:NSMakeRect(wndconfig->positionX, wndconfig->positionY, window->width, window->height) initWithContentRect:NSMakeRect(wndconfig->positionX, wndconfig->positionY, window->width, window->height)
styleMask:styleMask styleMask:styleMask
backing:NSBackingStoreBuffered backing:NSBackingStoreBuffered
defer:NO]; defer:NO];
if (window->NS.object == nil) if (window->ns.object == nil)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, "Cocoa: Failed to create window"); _glfwInputError(GLFW_PLATFORM_ERROR, "Cocoa: Failed to create window");
return GL_FALSE; return GL_FALSE;
} }
window->NS.view = [[GLFWContentView alloc] initWithGlfwWindow:window]; window->ns.view = [[GLFWContentView alloc] initWithGlfwWindow:window];
[window->NS.object setTitle:[NSString stringWithUTF8String:wndconfig->title]]; [window->ns.object setTitle:[NSString stringWithUTF8String:wndconfig->title]];
[window->NS.object setContentView:window->NS.view]; [window->ns.object setContentView:window->ns.view];
[window->NS.object setDelegate:window->NS.delegate]; [window->ns.object setDelegate:window->ns.delegate];
[window->NS.object setAcceptsMouseMovedEvents:YES]; [window->ns.object setAcceptsMouseMovedEvents:YES];
[window->NS.object center]; [window->ns.object center];
if ([window->NS.object respondsToSelector:@selector(setRestorable:)]) if ([window->ns.object respondsToSelector:@selector(setRestorable:)])
[window->NS.object setRestorable:NO]; [window->ns.object setRestorable:NO];
return GL_TRUE; return GL_TRUE;
} }
@ -729,21 +729,21 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
// There can only be one application delegate, but we allocate it the // There can only be one application delegate, but we allocate it the
// first time a window is created to keep all window code in this file // first time a window is created to keep all window code in this file
if (_glfwLibrary.NS.delegate == nil) if (_glfw.ns.delegate == nil)
{ {
_glfwLibrary.NS.delegate = [[GLFWApplicationDelegate alloc] init]; _glfw.ns.delegate = [[GLFWApplicationDelegate alloc] init];
if (_glfwLibrary.NS.delegate == nil) if (_glfw.ns.delegate == nil)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,
"Cocoa: Failed to create application delegate"); "Cocoa: Failed to create application delegate");
return GL_FALSE; return GL_FALSE;
} }
[NSApp setDelegate:_glfwLibrary.NS.delegate]; [NSApp setDelegate:_glfw.ns.delegate];
} }
window->NS.delegate = [[GLFWWindowDelegate alloc] initWithGlfwWindow:window]; window->ns.delegate = [[GLFWWindowDelegate alloc] initWithGlfwWindow:window];
if (window->NS.delegate == nil) if (window->ns.delegate == nil)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,
"Cocoa: Failed to create window delegate"); "Cocoa: Failed to create window delegate");
@ -766,7 +766,7 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
if (!_glfwCreateContext(window, wndconfig, fbconfig)) if (!_glfwCreateContext(window, wndconfig, fbconfig))
return GL_FALSE; return GL_FALSE;
[window->NSGL.context setView:[window->NS.object contentView]]; [window->nsgl.context setView:[window->ns.object contentView]];
if (wndconfig->monitor) if (wndconfig->monitor)
{ {
@ -776,7 +776,7 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
return GL_FALSE; return GL_FALSE;
_glfwPlatformShowWindow(window); _glfwPlatformShowWindow(window);
[[window->NS.object contentView] enterFullScreenMode:[NSScreen mainScreen] [[window->ns.object contentView] enterFullScreenMode:[NSScreen mainScreen]
withOptions:nil]; withOptions:nil];
} }
@ -794,26 +794,26 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
void _glfwPlatformDestroyWindow(_GLFWwindow* window) void _glfwPlatformDestroyWindow(_GLFWwindow* window)
{ {
[window->NS.object orderOut:nil]; [window->ns.object orderOut:nil];
if (window->monitor) if (window->monitor)
{ {
[[window->NS.object contentView] exitFullScreenModeWithOptions:nil]; [[window->ns.object contentView] exitFullScreenModeWithOptions:nil];
_glfwRestoreVideoMode(); _glfwRestoreVideoMode();
} }
_glfwDestroyContext(window); _glfwDestroyContext(window);
[window->NS.object setDelegate:nil]; [window->ns.object setDelegate:nil];
[window->NS.delegate release]; [window->ns.delegate release];
window->NS.delegate = nil; window->ns.delegate = nil;
[window->NS.view release]; [window->ns.view release];
window->NS.view = nil; window->ns.view = nil;
[window->NS.object close]; [window->ns.object close];
window->NS.object = nil; window->ns.object = nil;
// TODO: Probably more cleanup // TODO: Probably more cleanup
} }
@ -825,7 +825,7 @@ void _glfwPlatformDestroyWindow(_GLFWwindow* window)
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char *title) void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char *title)
{ {
[window->NS.object setTitle:[NSString stringWithUTF8String:title]]; [window->ns.object setTitle:[NSString stringWithUTF8String:title]];
} }
@ -835,7 +835,7 @@ void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char *title)
void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height) void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
{ {
[window->NS.object setContentSize:NSMakeSize(width, height)]; [window->ns.object setContentSize:NSMakeSize(width, height)];
} }
@ -845,7 +845,7 @@ void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
void _glfwPlatformIconifyWindow(_GLFWwindow* window) void _glfwPlatformIconifyWindow(_GLFWwindow* window)
{ {
[window->NS.object miniaturize:nil]; [window->ns.object miniaturize:nil];
} }
@ -855,7 +855,7 @@ void _glfwPlatformIconifyWindow(_GLFWwindow* window)
void _glfwPlatformRestoreWindow(_GLFWwindow* window) void _glfwPlatformRestoreWindow(_GLFWwindow* window)
{ {
[window->NS.object deminiaturize:nil]; [window->ns.object deminiaturize:nil];
} }
@ -865,7 +865,7 @@ void _glfwPlatformRestoreWindow(_GLFWwindow* window)
void _glfwPlatformShowWindow(_GLFWwindow* window) void _glfwPlatformShowWindow(_GLFWwindow* window)
{ {
[window->NS.object makeKeyAndOrderFront:nil]; [window->ns.object makeKeyAndOrderFront:nil];
_glfwInputWindowVisibility(window, GL_TRUE); _glfwInputWindowVisibility(window, GL_TRUE);
} }
@ -876,7 +876,7 @@ void _glfwPlatformShowWindow(_GLFWwindow* window)
void _glfwPlatformHideWindow(_GLFWwindow* window) void _glfwPlatformHideWindow(_GLFWwindow* window)
{ {
[window->NS.object orderOut:nil]; [window->ns.object orderOut:nil];
_glfwInputWindowVisibility(window, GL_FALSE); _glfwInputWindowVisibility(window, GL_FALSE);
} }
@ -899,8 +899,8 @@ void _glfwPlatformPollEvents(void)
[NSApp sendEvent:event]; [NSApp sendEvent:event];
} }
[_glfwLibrary.NS.autoreleasePool drain]; [_glfw.ns.autoreleasePool drain];
_glfwLibrary.NS.autoreleasePool = [[NSAutoreleasePool alloc] init]; _glfw.ns.autoreleasePool = [[NSAutoreleasePool alloc] init];
} }
@ -937,7 +937,7 @@ void _glfwPlatformSetCursorPos(_GLFWwindow* window, int x, int y)
else else
{ {
NSPoint localPoint = NSMakePoint(x, window->height - y - 1); NSPoint localPoint = NSMakePoint(x, window->height - y - 1);
NSPoint globalPoint = [window->NS.object convertBaseToScreen:localPoint]; NSPoint globalPoint = [window->ns.object convertBaseToScreen:localPoint];
CGPoint mainScreenOrigin = CGDisplayBounds(CGMainDisplayID()).origin; CGPoint mainScreenOrigin = CGDisplayBounds(CGMainDisplayID()).origin;
double mainScreenHeight = CGDisplayBounds(CGMainDisplayID()).size.height; double mainScreenHeight = CGDisplayBounds(CGMainDisplayID()).size.height;
CGPoint targetPoint = CGPointMake(globalPoint.x - mainScreenOrigin.x, CGPoint targetPoint = CGPointMake(globalPoint.x - mainScreenOrigin.x,

View File

@ -59,7 +59,7 @@ static _GLFW_TLS _GLFWwindow* _glfwCurrentWindow = NULL;
static int getConfigAttrib(EGLConfig config, int attrib) static int getConfigAttrib(EGLConfig config, int attrib)
{ {
int value; int value;
eglGetConfigAttrib(_glfwLibrary.EGL.display, config, attrib, &value); eglGetConfigAttrib(_glfw.egl.display, config, attrib, &value);
return value; return value;
} }
@ -78,7 +78,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window,
*found = 0; *found = 0;
eglGetConfigs(_glfwLibrary.EGL.display, NULL, 0, &count); eglGetConfigs(_glfw.egl.display, NULL, 0, &count);
configs = (EGLConfig*) malloc(sizeof(EGLConfig) * count); configs = (EGLConfig*) malloc(sizeof(EGLConfig) * count);
if (!configs) if (!configs)
@ -87,7 +87,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window,
return NULL; return NULL;
} }
eglGetConfigs(_glfwLibrary.EGL.display, configs, count, &count); eglGetConfigs(_glfw.egl.display, configs, count, &count);
if (!count) if (!count)
{ {
free(configs); free(configs);
@ -190,7 +190,7 @@ static int createContext(_GLFWwindow* window,
EGLContext share = NULL; EGLContext share = NULL;
if (wndconfig->share) if (wndconfig->share)
share = wndconfig->share->EGL.context; share = wndconfig->share->egl.context;
// Retrieve the previously selected EGLConfig // Retrieve the previously selected EGLConfig
{ {
@ -199,7 +199,7 @@ static int createContext(_GLFWwindow* window,
setEGLattrib(EGL_CONFIG_ID, fbconfigID); setEGLattrib(EGL_CONFIG_ID, fbconfigID);
setEGLattrib(EGL_NONE, EGL_NONE); setEGLattrib(EGL_NONE, EGL_NONE);
eglChooseConfig(_glfwLibrary.EGL.display, attribs, &config, 1, &count); eglChooseConfig(_glfw.egl.display, attribs, &config, 1, &count);
if (!count) if (!count)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,
@ -215,10 +215,10 @@ static int createContext(_GLFWwindow* window,
EGLint redBits, greenBits, blueBits, alphaBits, visualID = 0; EGLint redBits, greenBits, blueBits, alphaBits, visualID = 0;
XVisualInfo info; XVisualInfo info;
eglGetConfigAttrib(_glfwLibrary.EGL.display, config, eglGetConfigAttrib(_glfw.egl.display, config,
EGL_NATIVE_VISUAL_ID, &visualID); EGL_NATIVE_VISUAL_ID, &visualID);
info.screen = _glfwLibrary.X11.screen; info.screen = _glfw.x11.screen;
mask = VisualScreenMask; mask = VisualScreenMask;
if (visualID) if (visualID)
@ -232,23 +232,23 @@ static int createContext(_GLFWwindow* window,
// some EGL drivers don't implement the EGL_NATIVE_VISUAL_ID // some EGL drivers don't implement the EGL_NATIVE_VISUAL_ID
// attribute, so attempt to find the closest match. // attribute, so attempt to find the closest match.
eglGetConfigAttrib(_glfwLibrary.EGL.display, config, eglGetConfigAttrib(_glfw.egl.display, config,
EGL_RED_SIZE, &redBits); EGL_RED_SIZE, &redBits);
eglGetConfigAttrib(_glfwLibrary.EGL.display, config, eglGetConfigAttrib(_glfw.egl.display, config,
EGL_GREEN_SIZE, &greenBits); EGL_GREEN_SIZE, &greenBits);
eglGetConfigAttrib(_glfwLibrary.EGL.display, config, eglGetConfigAttrib(_glfw.egl.display, config,
EGL_BLUE_SIZE, &blueBits); EGL_BLUE_SIZE, &blueBits);
eglGetConfigAttrib(_glfwLibrary.EGL.display, config, eglGetConfigAttrib(_glfw.egl.display, config,
EGL_ALPHA_SIZE, &alphaBits); EGL_ALPHA_SIZE, &alphaBits);
info.depth = redBits + greenBits + blueBits + alphaBits; info.depth = redBits + greenBits + blueBits + alphaBits;
mask |= VisualDepthMask; mask |= VisualDepthMask;
} }
window->EGL.visual = XGetVisualInfo(_glfwLibrary.X11.display, window->egl.visual = XGetVisualInfo(_glfw.x11.display,
mask, &info, &count); mask, &info, &count);
if (window->EGL.visual == NULL) if (window->egl.visual == NULL)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,
"EGL: Failed to retrieve visual for EGLConfig"); "EGL: Failed to retrieve visual for EGLConfig");
@ -275,7 +275,7 @@ static int createContext(_GLFWwindow* window,
} }
} }
if (_glfwLibrary.EGL.KHR_create_context) if (_glfw.egl.KHR_create_context)
{ {
int index = 0, mask = 0, flags = 0, strategy = 0; int index = 0, mask = 0, flags = 0, strategy = 0;
@ -330,10 +330,10 @@ static int createContext(_GLFWwindow* window,
setEGLattrib(EGL_NONE, EGL_NONE); setEGLattrib(EGL_NONE, EGL_NONE);
} }
window->EGL.context = eglCreateContext(_glfwLibrary.EGL.display, window->egl.context = eglCreateContext(_glfw.egl.display,
config, share, attribs); config, share, attribs);
if (window->EGL.context == EGL_NO_CONTEXT) if (window->egl.context == EGL_NO_CONTEXT)
{ {
// TODO: Handle all the various error codes here // TODO: Handle all the various error codes here
@ -341,7 +341,7 @@ static int createContext(_GLFWwindow* window,
return GL_FALSE; return GL_FALSE;
} }
window->EGL.config = config; window->egl.config = config;
return GL_TRUE; return GL_TRUE;
} }
@ -372,35 +372,35 @@ int _glfwInitOpenGL(void)
for (i = 0; libEGL_names[i] != NULL; i++) for (i = 0; libEGL_names[i] != NULL; i++)
{ {
_glfwLibrary.EGL.libEGL = dlopen(libEGL_names[i], RTLD_LAZY | RTLD_GLOBAL); _glfw.egl.libEGL = dlopen(libEGL_names[i], RTLD_LAZY | RTLD_GLOBAL);
if (_glfwLibrary.EGL.libEGL) if (_glfw.egl.libEGL)
break; break;
} }
if (!_glfwLibrary.EGL.libEGL) if (!_glfw.egl.libEGL)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, "EGL: Failed to find libEGL"); _glfwInputError(GLFW_PLATFORM_ERROR, "EGL: Failed to find libEGL");
return GL_FALSE; return GL_FALSE;
} }
#endif #endif
_glfwLibrary.EGL.display = eglGetDisplay(_GLFW_EGL_NATIVE_DISPLAY); _glfw.egl.display = eglGetDisplay(_GLFW_EGL_NATIVE_DISPLAY);
if (_glfwLibrary.EGL.display == EGL_NO_DISPLAY) if (_glfw.egl.display == EGL_NO_DISPLAY)
{ {
_glfwInputError(GLFW_API_UNAVAILABLE, "EGL: Failed to get EGL display"); _glfwInputError(GLFW_API_UNAVAILABLE, "EGL: Failed to get EGL display");
return GL_FALSE; return GL_FALSE;
} }
if (!eglInitialize(_glfwLibrary.EGL.display, if (!eglInitialize(_glfw.egl.display,
&_glfwLibrary.EGL.majorVersion, &_glfw.egl.versionMajor,
&_glfwLibrary.EGL.minorVersion)) &_glfw.egl.versionMinor))
{ {
_glfwInputError(GLFW_API_UNAVAILABLE, "EGL: Failed to initialize EGL"); _glfwInputError(GLFW_API_UNAVAILABLE, "EGL: Failed to initialize EGL");
return GL_FALSE; return GL_FALSE;
} }
if (_glfwPlatformExtensionSupported("EGL_KHR_create_context")) if (_glfwPlatformExtensionSupported("EGL_KHR_create_context"))
_glfwLibrary.EGL.KHR_create_context = GL_TRUE; _glfw.egl.KHR_create_context = GL_TRUE;
return GL_TRUE; return GL_TRUE;
} }
@ -413,14 +413,14 @@ int _glfwInitOpenGL(void)
void _glfwTerminateOpenGL(void) void _glfwTerminateOpenGL(void)
{ {
#ifdef _GLFW_DLOPEN_LIBEGL #ifdef _GLFW_DLOPEN_LIBEGL
if (_glfwLibrary.EGL.libEGL != NULL) if (_glfw.egl.libEGL != NULL)
{ {
dlclose(_glfwLibrary.EGL.libEGL); dlclose(_glfw.egl.libEGL);
_glfwLibrary.EGL.libEGL = NULL; _glfw.egl.libEGL = NULL;
} }
#endif #endif
eglTerminate(_glfwLibrary.EGL.display); eglTerminate(_glfw.egl.display);
} }
@ -472,22 +472,22 @@ int _glfwCreateContext(_GLFWwindow* window,
void _glfwDestroyContext(_GLFWwindow* window) void _glfwDestroyContext(_GLFWwindow* window)
{ {
if (window->EGL.visual) if (window->egl.visual)
{ {
XFree(window->EGL.visual); XFree(window->egl.visual);
window->EGL.visual = NULL; window->egl.visual = NULL;
} }
if (window->EGL.surface) if (window->egl.surface)
{ {
eglDestroySurface(_glfwLibrary.EGL.display, window->EGL.surface); eglDestroySurface(_glfw.egl.display, window->egl.surface);
window->EGL.surface = EGL_NO_SURFACE; window->egl.surface = EGL_NO_SURFACE;
} }
if (window->EGL.context) if (window->egl.context)
{ {
eglDestroyContext(_glfwLibrary.EGL.display, window->EGL.context); eglDestroyContext(_glfw.egl.display, window->egl.context);
window->EGL.context = EGL_NO_CONTEXT; window->egl.context = EGL_NO_CONTEXT;
} }
} }
@ -516,27 +516,27 @@ void _glfwPlatformMakeContextCurrent(_GLFWwindow* window)
{ {
if (window) if (window)
{ {
if (window->EGL.surface == EGL_NO_SURFACE) if (window->egl.surface == EGL_NO_SURFACE)
{ {
window->EGL.surface = eglCreateWindowSurface(_glfwLibrary.EGL.display, window->egl.surface = eglCreateWindowSurface(_glfw.egl.display,
window->EGL.config, window->egl.config,
_GLFW_EGL_NATIVE_WINDOW, _GLFW_EGL_NATIVE_WINDOW,
NULL); NULL);
if (window->EGL.surface == EGL_NO_SURFACE) if (window->egl.surface == EGL_NO_SURFACE)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,
"EGL: Failed to create window surface"); "EGL: Failed to create window surface");
} }
} }
eglMakeCurrent(_glfwLibrary.EGL.display, eglMakeCurrent(_glfw.egl.display,
window->EGL.surface, window->egl.surface,
window->EGL.surface, window->egl.surface,
window->EGL.context); window->egl.context);
} }
else else
{ {
eglMakeCurrent(_glfwLibrary.EGL.display, eglMakeCurrent(_glfw.egl.display,
EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
} }
@ -560,7 +560,7 @@ _GLFWwindow* _glfwPlatformGetCurrentContext(void)
void _glfwPlatformSwapBuffers(_GLFWwindow* window) void _glfwPlatformSwapBuffers(_GLFWwindow* window)
{ {
eglSwapBuffers(_glfwLibrary.EGL.display, window->EGL.surface); eglSwapBuffers(_glfw.egl.display, window->egl.surface);
} }
@ -570,7 +570,7 @@ void _glfwPlatformSwapBuffers(_GLFWwindow* window)
void _glfwPlatformSwapInterval(int interval) void _glfwPlatformSwapInterval(int interval)
{ {
eglSwapInterval(_glfwLibrary.EGL.display, interval); eglSwapInterval(_glfw.egl.display, interval);
} }
@ -582,7 +582,7 @@ int _glfwPlatformExtensionSupported(const char* extension)
{ {
const char* extensions; const char* extensions;
extensions = eglQueryString(_glfwLibrary.EGL.display, EGL_EXTENSIONS); extensions = eglQueryString(_glfw.egl.display, EGL_EXTENSIONS);
if (extensions != NULL) if (extensions != NULL)
{ {
if (_glfwStringInExtensionString(extension, (unsigned char*) extensions)) if (_glfwStringInExtensionString(extension, (unsigned char*) extensions))

View File

@ -48,14 +48,14 @@
#if defined(_GLFW_HAS_EGLGETPROCADDRESS) #if defined(_GLFW_HAS_EGLGETPROCADDRESS)
#define _glfw_eglGetProcAddress(x) eglGetProcAddress(x) #define _glfw_eglGetProcAddress(x) eglGetProcAddress(x)
#elif defined(_GLFW_HAS_DLOPEN) #elif defined(_GLFW_HAS_DLOPEN)
#define _glfw_eglGetProcAddress(x) dlsym(_glfwLibrary.EGL.libEGL, x) #define _glfw_eglGetProcAddress(x) dlsym(_glfw.egl.libEGL, x)
#define _GLFW_DLOPEN_LIBEGL #define _GLFW_DLOPEN_LIBEGL
#else #else
#error "No OpenGL entry point retrieval mechanism was enabled" #error "No OpenGL entry point retrieval mechanism was enabled"
#endif #endif
#define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextEGL EGL #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextEGL egl
#define _GLFW_PLATFORM_LIBRARY_OPENGL_STATE _GLFWlibraryEGL EGL #define _GLFW_PLATFORM_LIBRARY_OPENGL_STATE _GLFWlibraryEGL egl
//======================================================================== //========================================================================
@ -83,7 +83,7 @@ typedef struct _GLFWcontextEGL
typedef struct _GLFWlibraryEGL typedef struct _GLFWlibraryEGL
{ {
EGLDisplay display; EGLDisplay display;
EGLint majorVersion, minorVersion; EGLint versionMajor, versionMinor;
GLboolean KHR_create_context; GLboolean KHR_create_context;

View File

@ -95,7 +95,7 @@ GLFWAPI void glfwGetGammaRamp(GLFWgammaramp* ramp)
return; return;
} }
*ramp = _glfwLibrary.currentRamp; *ramp = _glfw.currentRamp;
} }
@ -112,7 +112,7 @@ GLFWAPI void glfwSetGammaRamp(const GLFWgammaramp* ramp)
} }
_glfwPlatformSetGammaRamp(ramp); _glfwPlatformSetGammaRamp(ramp);
_glfwLibrary.currentRamp = *ramp; _glfw.currentRamp = *ramp;
_glfwLibrary.rampChanged = GL_TRUE; _glfw.rampChanged = GL_TRUE;
} }

View File

@ -74,13 +74,13 @@ static int getFBConfigAttrib(_GLFWwindow* window, GLXFBConfig fbconfig, int attr
{ {
int value; int value;
if (_glfwLibrary.GLX.SGIX_fbconfig) if (_glfw.glx.SGIX_fbconfig)
{ {
_glfwLibrary.GLX.GetFBConfigAttribSGIX(_glfwLibrary.X11.display, _glfw.glx.GetFBConfigAttribSGIX(_glfw.x11.display,
fbconfig, attrib, &value); fbconfig, attrib, &value);
} }
else else
glXGetFBConfigAttrib(_glfwLibrary.X11.display, fbconfig, attrib, &value); glXGetFBConfigAttrib(_glfw.x11.display, fbconfig, attrib, &value);
return value; return value;
} }
@ -100,9 +100,9 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
*found = 0; *found = 0;
if (_glfwLibrary.GLX.majorVersion == 1 && _glfwLibrary.GLX.minorVersion < 3) if (_glfw.glx.versionMajor == 1 && _glfw.glx.versionMinor < 3)
{ {
if (!_glfwLibrary.GLX.SGIX_fbconfig) if (!_glfw.glx.SGIX_fbconfig)
{ {
_glfwInputError(GLFW_API_UNAVAILABLE, _glfwInputError(GLFW_API_UNAVAILABLE,
"GLX: GLXFBConfig support not found"); "GLX: GLXFBConfig support not found");
@ -110,7 +110,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
} }
} }
vendor = glXGetClientString(_glfwLibrary.X11.display, GLX_VENDOR); vendor = glXGetClientString(_glfw.x11.display, GLX_VENDOR);
if (strcmp(vendor, "Chromium") == 0) if (strcmp(vendor, "Chromium") == 0)
{ {
@ -119,12 +119,12 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
trustWindowBit = GL_FALSE; trustWindowBit = GL_FALSE;
} }
if (_glfwLibrary.GLX.SGIX_fbconfig) if (_glfw.glx.SGIX_fbconfig)
{ {
fbconfigs = _glfwLibrary.GLX.ChooseFBConfigSGIX(_glfwLibrary.X11.display, fbconfigs = _glfw.glx.ChooseFBConfigSGIX(_glfw.x11.display,
_glfwLibrary.X11.screen, _glfw.x11.screen,
NULL, NULL,
&count); &count);
if (!count) if (!count)
{ {
_glfwInputError(GLFW_API_UNAVAILABLE, _glfwInputError(GLFW_API_UNAVAILABLE,
@ -134,9 +134,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
} }
else else
{ {
fbconfigs = glXGetFBConfigs(_glfwLibrary.X11.display, fbconfigs = glXGetFBConfigs(_glfw.x11.display, _glfw.x11.screen, &count);
_glfwLibrary.X11.screen,
&count);
if (!count) if (!count)
{ {
_glfwInputError(GLFW_API_UNAVAILABLE, _glfwInputError(GLFW_API_UNAVAILABLE,
@ -196,12 +194,12 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
f->auxBuffers = getFBConfigAttrib(window, fbconfigs[i], GLX_AUX_BUFFERS); f->auxBuffers = getFBConfigAttrib(window, fbconfigs[i], GLX_AUX_BUFFERS);
f->stereo = getFBConfigAttrib(window, fbconfigs[i], GLX_STEREO); f->stereo = getFBConfigAttrib(window, fbconfigs[i], GLX_STEREO);
if (_glfwLibrary.GLX.ARB_multisample) if (_glfw.glx.ARB_multisample)
f->samples = getFBConfigAttrib(window, fbconfigs[i], GLX_SAMPLES); f->samples = getFBConfigAttrib(window, fbconfigs[i], GLX_SAMPLES);
else else
f->samples = 0; f->samples = 0;
if (_glfwLibrary.GLX.ARB_framebuffer_sRGB) if (_glfw.glx.ARB_framebuffer_sRGB)
f->sRGB = getFBConfigAttrib(window, fbconfigs[i], GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB); f->sRGB = getFBConfigAttrib(window, fbconfigs[i], GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB);
else else
f->sRGB = GL_FALSE; f->sRGB = GL_FALSE;
@ -238,18 +236,18 @@ static void createLegacyContext(_GLFWwindow* window,
GLXFBConfig fbconfig, GLXFBConfig fbconfig,
GLXContext share) GLXContext share)
{ {
if (_glfwLibrary.GLX.SGIX_fbconfig) if (_glfw.glx.SGIX_fbconfig)
{ {
window->GLX.context = window->glx.context =
_glfwLibrary.GLX.CreateContextWithConfigSGIX(_glfwLibrary.X11.display, _glfw.glx.CreateContextWithConfigSGIX(_glfw.x11.display,
fbconfig, fbconfig,
GLX_RGBA_TYPE, GLX_RGBA_TYPE,
share, share,
True); True);
} }
else else
{ {
window->GLX.context = glXCreateNewContext(_glfwLibrary.X11.display, window->glx.context = glXCreateNewContext(_glfw.x11.display,
fbconfig, fbconfig,
GLX_RGBA_TYPE, GLX_RGBA_TYPE,
share, share,
@ -275,7 +273,7 @@ static int createContext(_GLFWwindow* window,
GLXContext share = NULL; GLXContext share = NULL;
if (wndconfig->share) if (wndconfig->share)
share = wndconfig->share->GLX.context; share = wndconfig->share->glx.context;
// Retrieve the previously selected GLXFBConfig // Retrieve the previously selected GLXFBConfig
{ {
@ -284,18 +282,17 @@ static int createContext(_GLFWwindow* window,
setGLXattrib(GLX_FBCONFIG_ID, (int) fbconfigID); setGLXattrib(GLX_FBCONFIG_ID, (int) fbconfigID);
setGLXattrib(None, None); setGLXattrib(None, None);
if (_glfwLibrary.GLX.SGIX_fbconfig) if (_glfw.glx.SGIX_fbconfig)
{ {
fbconfig = fbconfig = _glfw.glx.ChooseFBConfigSGIX(_glfw.x11.display,
_glfwLibrary.GLX.ChooseFBConfigSGIX(_glfwLibrary.X11.display, _glfw.x11.screen,
_glfwLibrary.X11.screen,
attribs, attribs,
&dummy); &dummy);
} }
else else
{ {
fbconfig = glXChooseFBConfig(_glfwLibrary.X11.display, fbconfig = glXChooseFBConfig(_glfw.x11.display,
_glfwLibrary.X11.screen, _glfw.x11.screen,
attribs, attribs,
&dummy); &dummy);
} }
@ -309,19 +306,18 @@ static int createContext(_GLFWwindow* window,
} }
// Retrieve the corresponding visual // Retrieve the corresponding visual
if (_glfwLibrary.GLX.SGIX_fbconfig) if (_glfw.glx.SGIX_fbconfig)
{ {
window->GLX.visual = window->glx.visual =
_glfwLibrary.GLX.GetVisualFromFBConfigSGIX(_glfwLibrary.X11.display, _glfw.glx.GetVisualFromFBConfigSGIX(_glfw.x11.display, *fbconfig);
*fbconfig);
} }
else else
{ {
window->GLX.visual = glXGetVisualFromFBConfig(_glfwLibrary.X11.display, window->glx.visual = glXGetVisualFromFBConfig(_glfw.x11.display,
*fbconfig); *fbconfig);
} }
if (window->GLX.visual == NULL) if (window->glx.visual == NULL)
{ {
XFree(fbconfig); XFree(fbconfig);
@ -332,9 +328,9 @@ static int createContext(_GLFWwindow* window,
if (wndconfig->clientAPI == GLFW_OPENGL_ES_API) if (wndconfig->clientAPI == GLFW_OPENGL_ES_API)
{ {
if (!_glfwLibrary.GLX.ARB_create_context || if (!_glfw.glx.ARB_create_context ||
!_glfwLibrary.GLX.ARB_create_context_profile || !_glfw.glx.ARB_create_context_profile ||
!_glfwLibrary.GLX.EXT_create_context_es2_profile) !_glfw.glx.EXT_create_context_es2_profile)
{ {
_glfwInputError(GLFW_VERSION_UNAVAILABLE, _glfwInputError(GLFW_VERSION_UNAVAILABLE,
"GLX: OpenGL ES requested but " "GLX: OpenGL ES requested but "
@ -345,7 +341,7 @@ static int createContext(_GLFWwindow* window,
if (wndconfig->glForward) if (wndconfig->glForward)
{ {
if (!_glfwLibrary.GLX.ARB_create_context) if (!_glfw.glx.ARB_create_context)
{ {
_glfwInputError(GLFW_VERSION_UNAVAILABLE, _glfwInputError(GLFW_VERSION_UNAVAILABLE,
"GLX: Forward compatibility requested but " "GLX: Forward compatibility requested but "
@ -356,8 +352,8 @@ static int createContext(_GLFWwindow* window,
if (wndconfig->glProfile) if (wndconfig->glProfile)
{ {
if (!_glfwLibrary.GLX.ARB_create_context || if (!_glfw.glx.ARB_create_context ||
!_glfwLibrary.GLX.ARB_create_context_profile) !_glfw.glx.ARB_create_context_profile)
{ {
_glfwInputError(GLFW_VERSION_UNAVAILABLE, _glfwInputError(GLFW_VERSION_UNAVAILABLE,
"GLX: An OpenGL profile requested but " "GLX: An OpenGL profile requested but "
@ -366,7 +362,7 @@ static int createContext(_GLFWwindow* window,
} }
} }
if (_glfwLibrary.GLX.ARB_create_context) if (_glfw.glx.ARB_create_context)
{ {
int index = 0, mask = 0, flags = 0, strategy = 0; int index = 0, mask = 0, flags = 0, strategy = 0;
@ -391,7 +387,7 @@ static int createContext(_GLFWwindow* window,
if (wndconfig->glRobustness != GLFW_NO_ROBUSTNESS) if (wndconfig->glRobustness != GLFW_NO_ROBUSTNESS)
{ {
if (_glfwLibrary.GLX.ARB_create_context_robustness) if (_glfw.glx.ARB_create_context_robustness)
{ {
if (wndconfig->glRobustness == GLFW_NO_RESET_NOTIFICATION) if (wndconfig->glRobustness == GLFW_NO_RESET_NOTIFICATION)
strategy = GLX_NO_RESET_NOTIFICATION_ARB; strategy = GLX_NO_RESET_NOTIFICATION_ARB;
@ -430,22 +426,22 @@ static int createContext(_GLFWwindow* window,
_glfwErrorCode = Success; _glfwErrorCode = Success;
XSetErrorHandler(errorHandler); XSetErrorHandler(errorHandler);
window->GLX.context = window->glx.context =
_glfwLibrary.GLX.CreateContextAttribsARB(_glfwLibrary.X11.display, _glfw.glx.CreateContextAttribsARB(_glfw.x11.display,
*fbconfig, *fbconfig,
share, share,
True, True,
attribs); attribs);
// We are done, so unset the error handler again (see above) // We are done, so unset the error handler again (see above)
XSetErrorHandler(NULL); XSetErrorHandler(NULL);
if (window->GLX.context == NULL) if (window->glx.context == NULL)
{ {
// HACK: This is a fallback for the broken Mesa implementation of // HACK: This is a fallback for the broken Mesa implementation of
// GLX_ARB_create_context_profile, which fails default 1.0 context // GLX_ARB_create_context_profile, which fails default 1.0 context
// creation with a GLXBadProfileARB error in violation of the spec // creation with a GLXBadProfileARB error in violation of the spec
if (_glfwErrorCode == _glfwLibrary.GLX.errorBase + GLXBadProfileARB && if (_glfwErrorCode == _glfw.glx.errorBase + GLXBadProfileARB &&
wndconfig->clientAPI == GLFW_OPENGL_API && wndconfig->clientAPI == GLFW_OPENGL_API &&
wndconfig->glProfile == GLFW_OPENGL_NO_PROFILE && wndconfig->glProfile == GLFW_OPENGL_NO_PROFILE &&
wndconfig->glForward == GL_FALSE) wndconfig->glForward == GL_FALSE)
@ -459,7 +455,7 @@ static int createContext(_GLFWwindow* window,
XFree(fbconfig); XFree(fbconfig);
if (window->GLX.context == NULL) if (window->glx.context == NULL)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, "GLX: Failed to create context"); _glfwInputError(GLFW_PLATFORM_ERROR, "GLX: Failed to create context");
return GL_FALSE; return GL_FALSE;
@ -494,12 +490,12 @@ int _glfwInitOpenGL(void)
for (i = 0; libGL_names[i] != NULL; i++) for (i = 0; libGL_names[i] != NULL; i++)
{ {
_glfwLibrary.GLX.libGL = dlopen(libGL_names[i], RTLD_LAZY | RTLD_GLOBAL); _glfw.glx.libGL = dlopen(libGL_names[i], RTLD_LAZY | RTLD_GLOBAL);
if (_glfwLibrary.GLX.libGL) if (_glfw.glx.libGL)
break; break;
} }
if (!_glfwLibrary.GLX.libGL) if (!_glfw.glx.libGL)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, "GLX: Failed to find libGL"); _glfwInputError(GLFW_PLATFORM_ERROR, "GLX: Failed to find libGL");
return GL_FALSE; return GL_FALSE;
@ -507,17 +503,17 @@ int _glfwInitOpenGL(void)
#endif #endif
// Check if GLX is supported on this display // Check if GLX is supported on this display
if (!glXQueryExtension(_glfwLibrary.X11.display, if (!glXQueryExtension(_glfw.x11.display,
&_glfwLibrary.GLX.errorBase, &_glfw.glx.errorBase,
&_glfwLibrary.GLX.eventBase)) &_glfw.glx.eventBase))
{ {
_glfwInputError(GLFW_API_UNAVAILABLE, "GLX: GLX support not found"); _glfwInputError(GLFW_API_UNAVAILABLE, "GLX: GLX support not found");
return GL_FALSE; return GL_FALSE;
} }
if (!glXQueryVersion(_glfwLibrary.X11.display, if (!glXQueryVersion(_glfw.x11.display,
&_glfwLibrary.GLX.majorVersion, &_glfw.glx.versionMajor,
&_glfwLibrary.GLX.minorVersion)) &_glfw.glx.versionMinor))
{ {
_glfwInputError(GLFW_API_UNAVAILABLE, _glfwInputError(GLFW_API_UNAVAILABLE,
"GLX: Failed to query GLX version"); "GLX: Failed to query GLX version");
@ -526,74 +522,74 @@ int _glfwInitOpenGL(void)
if (_glfwPlatformExtensionSupported("GLX_EXT_swap_control")) if (_glfwPlatformExtensionSupported("GLX_EXT_swap_control"))
{ {
_glfwLibrary.GLX.SwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC) _glfw.glx.SwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC)
_glfwPlatformGetProcAddress("glXSwapIntervalEXT"); _glfwPlatformGetProcAddress("glXSwapIntervalEXT");
if (_glfwLibrary.GLX.SwapIntervalEXT) if (_glfw.glx.SwapIntervalEXT)
_glfwLibrary.GLX.EXT_swap_control = GL_TRUE; _glfw.glx.EXT_swap_control = GL_TRUE;
} }
if (_glfwPlatformExtensionSupported("GLX_SGI_swap_control")) if (_glfwPlatformExtensionSupported("GLX_SGI_swap_control"))
{ {
_glfwLibrary.GLX.SwapIntervalSGI = (PFNGLXSWAPINTERVALSGIPROC) _glfw.glx.SwapIntervalSGI = (PFNGLXSWAPINTERVALSGIPROC)
_glfwPlatformGetProcAddress("glXSwapIntervalSGI"); _glfwPlatformGetProcAddress("glXSwapIntervalSGI");
if (_glfwLibrary.GLX.SwapIntervalSGI) if (_glfw.glx.SwapIntervalSGI)
_glfwLibrary.GLX.SGI_swap_control = GL_TRUE; _glfw.glx.SGI_swap_control = GL_TRUE;
} }
if (_glfwPlatformExtensionSupported("GLX_MESA_swap_control")) if (_glfwPlatformExtensionSupported("GLX_MESA_swap_control"))
{ {
_glfwLibrary.GLX.SwapIntervalMESA = (PFNGLXSWAPINTERVALMESAPROC) _glfw.glx.SwapIntervalMESA = (PFNGLXSWAPINTERVALMESAPROC)
_glfwPlatformGetProcAddress("glXSwapIntervalMESA"); _glfwPlatformGetProcAddress("glXSwapIntervalMESA");
if (_glfwLibrary.GLX.SwapIntervalMESA) if (_glfw.glx.SwapIntervalMESA)
_glfwLibrary.GLX.MESA_swap_control = GL_TRUE; _glfw.glx.MESA_swap_control = GL_TRUE;
} }
if (_glfwPlatformExtensionSupported("GLX_SGIX_fbconfig")) if (_glfwPlatformExtensionSupported("GLX_SGIX_fbconfig"))
{ {
_glfwLibrary.GLX.GetFBConfigAttribSGIX = (PFNGLXGETFBCONFIGATTRIBSGIXPROC) _glfw.glx.GetFBConfigAttribSGIX = (PFNGLXGETFBCONFIGATTRIBSGIXPROC)
_glfwPlatformGetProcAddress("glXGetFBConfigAttribSGIX"); _glfwPlatformGetProcAddress("glXGetFBConfigAttribSGIX");
_glfwLibrary.GLX.ChooseFBConfigSGIX = (PFNGLXCHOOSEFBCONFIGSGIXPROC) _glfw.glx.ChooseFBConfigSGIX = (PFNGLXCHOOSEFBCONFIGSGIXPROC)
_glfwPlatformGetProcAddress("glXChooseFBConfigSGIX"); _glfwPlatformGetProcAddress("glXChooseFBConfigSGIX");
_glfwLibrary.GLX.CreateContextWithConfigSGIX = (PFNGLXCREATECONTEXTWITHCONFIGSGIXPROC) _glfw.glx.CreateContextWithConfigSGIX = (PFNGLXCREATECONTEXTWITHCONFIGSGIXPROC)
_glfwPlatformGetProcAddress("glXCreateContextWithConfigSGIX"); _glfwPlatformGetProcAddress("glXCreateContextWithConfigSGIX");
_glfwLibrary.GLX.GetVisualFromFBConfigSGIX = (PFNGLXGETVISUALFROMFBCONFIGSGIXPROC) _glfw.glx.GetVisualFromFBConfigSGIX = (PFNGLXGETVISUALFROMFBCONFIGSGIXPROC)
_glfwPlatformGetProcAddress("glXGetVisualFromFBConfigSGIX"); _glfwPlatformGetProcAddress("glXGetVisualFromFBConfigSGIX");
if (_glfwLibrary.GLX.GetFBConfigAttribSGIX && if (_glfw.glx.GetFBConfigAttribSGIX &&
_glfwLibrary.GLX.ChooseFBConfigSGIX && _glfw.glx.ChooseFBConfigSGIX &&
_glfwLibrary.GLX.CreateContextWithConfigSGIX && _glfw.glx.CreateContextWithConfigSGIX &&
_glfwLibrary.GLX.GetVisualFromFBConfigSGIX) _glfw.glx.GetVisualFromFBConfigSGIX)
{ {
_glfwLibrary.GLX.SGIX_fbconfig = GL_TRUE; _glfw.glx.SGIX_fbconfig = GL_TRUE;
} }
} }
if (_glfwPlatformExtensionSupported("GLX_ARB_multisample")) if (_glfwPlatformExtensionSupported("GLX_ARB_multisample"))
_glfwLibrary.GLX.ARB_multisample = GL_TRUE; _glfw.glx.ARB_multisample = GL_TRUE;
if (_glfwPlatformExtensionSupported("GLX_ARB_framebuffer_sRGB")) if (_glfwPlatformExtensionSupported("GLX_ARB_framebuffer_sRGB"))
_glfwLibrary.GLX.ARB_framebuffer_sRGB = GL_TRUE; _glfw.glx.ARB_framebuffer_sRGB = GL_TRUE;
if (_glfwPlatformExtensionSupported("GLX_ARB_create_context")) if (_glfwPlatformExtensionSupported("GLX_ARB_create_context"))
{ {
_glfwLibrary.GLX.CreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC) _glfw.glx.CreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC)
_glfwPlatformGetProcAddress("glXCreateContextAttribsARB"); _glfwPlatformGetProcAddress("glXCreateContextAttribsARB");
if (_glfwLibrary.GLX.CreateContextAttribsARB) if (_glfw.glx.CreateContextAttribsARB)
_glfwLibrary.GLX.ARB_create_context = GL_TRUE; _glfw.glx.ARB_create_context = GL_TRUE;
} }
if (_glfwPlatformExtensionSupported("GLX_ARB_create_context_robustness")) if (_glfwPlatformExtensionSupported("GLX_ARB_create_context_robustness"))
_glfwLibrary.GLX.ARB_create_context_robustness = GL_TRUE; _glfw.glx.ARB_create_context_robustness = GL_TRUE;
if (_glfwPlatformExtensionSupported("GLX_ARB_create_context_profile")) if (_glfwPlatformExtensionSupported("GLX_ARB_create_context_profile"))
_glfwLibrary.GLX.ARB_create_context_profile = GL_TRUE; _glfw.glx.ARB_create_context_profile = GL_TRUE;
if (_glfwPlatformExtensionSupported("GLX_EXT_create_context_es2_profile")) if (_glfwPlatformExtensionSupported("GLX_EXT_create_context_es2_profile"))
_glfwLibrary.GLX.EXT_create_context_es2_profile = GL_TRUE; _glfw.glx.EXT_create_context_es2_profile = GL_TRUE;
return GL_TRUE; return GL_TRUE;
} }
@ -607,10 +603,10 @@ void _glfwTerminateOpenGL(void)
{ {
// Unload libGL.so if necessary // Unload libGL.so if necessary
#ifdef _GLFW_DLOPEN_LIBGL #ifdef _GLFW_DLOPEN_LIBGL
if (_glfwLibrary.GLX.libGL != NULL) if (_glfw.glx.libGL != NULL)
{ {
dlclose(_glfwLibrary.GLX.libGL); dlclose(_glfw.glx.libGL);
_glfwLibrary.GLX.libGL = NULL; _glfw.glx.libGL = NULL;
} }
#endif #endif
} }
@ -660,16 +656,16 @@ int _glfwCreateContext(_GLFWwindow* window,
void _glfwDestroyContext(_GLFWwindow* window) void _glfwDestroyContext(_GLFWwindow* window)
{ {
if (window->GLX.visual) if (window->glx.visual)
{ {
XFree(window->GLX.visual); XFree(window->glx.visual);
window->GLX.visual = NULL; window->glx.visual = NULL;
} }
if (window->GLX.context) if (window->glx.context)
{ {
glXDestroyContext(_glfwLibrary.X11.display, window->GLX.context); glXDestroyContext(_glfw.x11.display, window->glx.context);
window->GLX.context = NULL; window->glx.context = NULL;
} }
} }
@ -686,12 +682,12 @@ void _glfwPlatformMakeContextCurrent(_GLFWwindow* window)
{ {
if (window) if (window)
{ {
glXMakeCurrent(_glfwLibrary.X11.display, glXMakeCurrent(_glfw.x11.display,
window->X11.handle, window->x11.handle,
window->GLX.context); window->glx.context);
} }
else else
glXMakeCurrent(_glfwLibrary.X11.display, None, NULL); glXMakeCurrent(_glfw.x11.display, None, NULL);
_glfwCurrentWindow = window; _glfwCurrentWindow = window;
} }
@ -713,7 +709,7 @@ _GLFWwindow* _glfwPlatformGetCurrentContext(void)
void _glfwPlatformSwapBuffers(_GLFWwindow* window) void _glfwPlatformSwapBuffers(_GLFWwindow* window)
{ {
glXSwapBuffers(_glfwLibrary.X11.display, window->X11.handle); glXSwapBuffers(_glfw.x11.display, window->x11.handle);
} }
@ -725,18 +721,18 @@ void _glfwPlatformSwapInterval(int interval)
{ {
_GLFWwindow* window = _glfwCurrentWindow; _GLFWwindow* window = _glfwCurrentWindow;
if (_glfwLibrary.GLX.EXT_swap_control) if (_glfw.glx.EXT_swap_control)
{ {
_glfwLibrary.GLX.SwapIntervalEXT(_glfwLibrary.X11.display, _glfw.glx.SwapIntervalEXT(_glfw.x11.display,
window->X11.handle, window->x11.handle,
interval); interval);
} }
else if (_glfwLibrary.GLX.MESA_swap_control) else if (_glfw.glx.MESA_swap_control)
_glfwLibrary.GLX.SwapIntervalMESA(interval); _glfw.glx.SwapIntervalMESA(interval);
else if (_glfwLibrary.GLX.SGI_swap_control) else if (_glfw.glx.SGI_swap_control)
{ {
if (interval > 0) if (interval > 0)
_glfwLibrary.GLX.SwapIntervalSGI(interval); _glfw.glx.SwapIntervalSGI(interval);
} }
} }
@ -750,8 +746,8 @@ int _glfwPlatformExtensionSupported(const char* extension)
const GLubyte* extensions; const GLubyte* extensions;
// Get list of GLX extensions // Get list of GLX extensions
extensions = (const GLubyte*) glXQueryExtensionsString(_glfwLibrary.X11.display, extensions = (const GLubyte*) glXQueryExtensionsString(_glfw.x11.display,
_glfwLibrary.X11.screen); _glfw.x11.screen);
if (extensions != NULL) if (extensions != NULL)
{ {
if (_glfwStringInExtensionString(extension, extensions)) if (_glfwStringInExtensionString(extension, extensions))

View File

@ -54,14 +54,14 @@
#elif defined(_GLFW_HAS_GLXGETPROCADDRESSEXT) #elif defined(_GLFW_HAS_GLXGETPROCADDRESSEXT)
#define _glfw_glXGetProcAddress(x) glXGetProcAddressEXT(x) #define _glfw_glXGetProcAddress(x) glXGetProcAddressEXT(x)
#elif defined(_GLFW_HAS_DLOPEN) #elif defined(_GLFW_HAS_DLOPEN)
#define _glfw_glXGetProcAddress(x) dlsym(_glfwLibrary.GLX.libGL, x) #define _glfw_glXGetProcAddress(x) dlsym(_glfw.glx.libGL, x)
#define _GLFW_DLOPEN_LIBGL #define _GLFW_DLOPEN_LIBGL
#else #else
#error "No OpenGL entry point retrieval mechanism was enabled" #error "No OpenGL entry point retrieval mechanism was enabled"
#endif #endif
#define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextGLX GLX #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextGLX glx
#define _GLFW_PLATFORM_LIBRARY_OPENGL_STATE _GLFWlibraryGLX GLX #define _GLFW_PLATFORM_LIBRARY_OPENGL_STATE _GLFWlibraryGLX glx
#ifndef GLX_MESA_swap_control #ifndef GLX_MESA_swap_control
typedef int (*PFNGLXSWAPINTERVALMESAPROC)(int); typedef int (*PFNGLXSWAPINTERVALMESAPROC)(int);
@ -89,7 +89,7 @@ typedef struct _GLFWcontextGLX
typedef struct _GLFWlibraryGLX typedef struct _GLFWlibraryGLX
{ {
// Server-side GLX version // Server-side GLX version
int majorVersion, minorVersion; int versionMajor, versionMinor;
int eventBase; int eventBase;
int errorBase; int errorBase;

View File

@ -47,13 +47,13 @@ GLboolean _glfwInitialized = GL_FALSE;
// This should only be touched after a call to glfwInit that has not been // This should only be touched after a call to glfwInit that has not been
// followed by a call to glfwTerminate // followed by a call to glfwTerminate
//------------------------------------------------------------------------ //------------------------------------------------------------------------
_GLFWlibrary _glfwLibrary; _GLFWlibrary _glfw;
//------------------------------------------------------------------------ //------------------------------------------------------------------------
// The current error callback // The current error callback
// This is outside of _glfwLibrary so it can be initialized and usable // This is outside of _glfw so it can be initialized and usable before
// before glfwInit is called, which lets that function report errors // glfwInit is called, which lets that function report errors
//------------------------------------------------------------------------ //------------------------------------------------------------------------
static GLFWerrorfun _glfwErrorCallback = NULL; static GLFWerrorfun _glfwErrorCallback = NULL;
@ -142,7 +142,7 @@ GLFWAPI int glfwInit(void)
if (_glfwInitialized) if (_glfwInitialized)
return GL_TRUE; return GL_TRUE;
memset(&_glfwLibrary, 0, sizeof(_glfwLibrary)); memset(&_glfw, 0, sizeof(_glfw));
if (!_glfwPlatformInit()) if (!_glfwPlatformInit())
{ {
@ -150,8 +150,8 @@ GLFWAPI int glfwInit(void)
return GL_FALSE; return GL_FALSE;
} }
_glfwLibrary.monitors = _glfwPlatformGetMonitors(&_glfwLibrary.monitorCount); _glfw.monitors = _glfwPlatformGetMonitors(&_glfw.monitorCount);
if (!_glfwLibrary.monitors) if (!_glfw.monitors)
{ {
_glfwPlatformTerminate(); _glfwPlatformTerminate();
return GL_FALSE; return GL_FALSE;
@ -176,8 +176,8 @@ GLFWAPI void glfwTerminate(void)
return; return;
// Close all remaining windows // Close all remaining windows
while (_glfwLibrary.windowListHead) while (_glfw.windowListHead)
glfwDestroyWindow(_glfwLibrary.windowListHead); glfwDestroyWindow(_glfw.windowListHead);
_glfwDestroyMonitors(); _glfwDestroyMonitors();

View File

@ -406,7 +406,7 @@ GLFWAPI void glfwSetCursorPos(GLFWwindow handle, int xpos, int ypos)
return; return;
} }
if (_glfwLibrary.focusedWindow != window) if (_glfw.focusedWindow != window)
return; return;
// Don't do anything if the cursor position did not change // Don't do anything if the cursor position did not change

View File

@ -275,7 +275,7 @@ struct _GLFWlibrary
// These are exported from and documented in init.c // These are exported from and documented in init.c
//------------------------------------------------------------------------ //------------------------------------------------------------------------
extern GLboolean _glfwInitialized; extern GLboolean _glfwInitialized;
extern _GLFWlibrary _glfwLibrary; extern _GLFWlibrary _glfw;
//======================================================================== //========================================================================

View File

@ -132,12 +132,12 @@ void _glfwInputMonitorChange(void)
for (i = 0; i < monitorCount; i++) for (i = 0; i < monitorCount; i++)
{ {
for (j = 0; j < _glfwLibrary.monitorCount; j++) for (j = 0; j < _glfw.monitorCount; j++)
{ {
if (_glfwLibrary.monitors[j] == NULL) if (_glfw.monitors[j] == NULL)
continue; continue;
if (strcmp(monitors[i]->name, _glfwLibrary.monitors[j]->name) == 0) if (strcmp(monitors[i]->name, _glfw.monitors[j]->name) == 0)
{ {
// This monitor was connected before, so re-use the existing // This monitor was connected before, so re-use the existing
// monitor object to preserve its address and user pointer // monitor object to preserve its address and user pointer
@ -145,40 +145,40 @@ void _glfwInputMonitorChange(void)
// TODO: Transfer monitor properties // TODO: Transfer monitor properties
_glfwDestroyMonitor(monitors[i]); _glfwDestroyMonitor(monitors[i]);
monitors[i] = _glfwLibrary.monitors[j]; monitors[i] = _glfw.monitors[j];
_glfwLibrary.monitors[j] = NULL; _glfw.monitors[j] = NULL;
break; break;
} }
} }
if (j == _glfwLibrary.monitorCount) if (j == _glfw.monitorCount)
{ {
// This monitor was not connected before // This monitor was not connected before
_glfwLibrary.monitorCallback(monitors[i], GLFW_CONNECTED); _glfw.monitorCallback(monitors[i], GLFW_CONNECTED);
} }
} }
for (i = 0; i < _glfwLibrary.monitorCount; i++) for (i = 0; i < _glfw.monitorCount; i++)
{ {
_GLFWwindow* window; _GLFWwindow* window;
if (_glfwLibrary.monitors[i] == NULL) if (_glfw.monitors[i] == NULL)
continue; continue;
// This monitor is no longer connected // This monitor is no longer connected
_glfwLibrary.monitorCallback(_glfwLibrary.monitors[i], GLFW_DISCONNECTED); _glfw.monitorCallback(_glfw.monitors[i], GLFW_DISCONNECTED);
for (window = _glfwLibrary.windowListHead; window; window = window->next) for (window = _glfw.windowListHead; window; window = window->next)
{ {
if (window->monitor == _glfwLibrary.monitors[i]) if (window->monitor == _glfw.monitors[i])
window->monitor = NULL; window->monitor = NULL;
} }
} }
_glfwDestroyMonitors(); _glfwDestroyMonitors();
_glfwLibrary.monitors = monitors; _glfw.monitors = monitors;
_glfwLibrary.monitorCount = monitorCount; _glfw.monitorCount = monitorCount;
} }
@ -190,12 +190,12 @@ void _glfwDestroyMonitors(void)
{ {
int i; int i;
for (i = 0; i < _glfwLibrary.monitorCount; i++) for (i = 0; i < _glfw.monitorCount; i++)
_glfwDestroyMonitor(_glfwLibrary.monitors[i]); _glfwDestroyMonitor(_glfw.monitors[i]);
free(_glfwLibrary.monitors); free(_glfw.monitors);
_glfwLibrary.monitors = NULL; _glfw.monitors = NULL;
_glfwLibrary.monitorCount = 0; _glfw.monitorCount = 0;
} }
@ -294,8 +294,8 @@ GLFWAPI const GLFWmonitor* glfwGetMonitors(int* count)
return NULL; return NULL;
} }
*count = _glfwLibrary.monitorCount; *count = _glfw.monitorCount;
return (GLFWmonitor*) _glfwLibrary.monitors; return (GLFWmonitor*) _glfw.monitors;
} }
@ -314,11 +314,11 @@ GLFWAPI GLFWmonitor glfwGetPrimaryMonitor(void)
return NULL; return NULL;
} }
for (i = 0; i < _glfwLibrary.monitorCount; i++) for (i = 0; i < _glfw.monitorCount; i++)
{ {
if (_glfwLibrary.monitors[i]->primary) if (_glfw.monitors[i]->primary)
{ {
handle = _glfwLibrary.monitors[i]; handle = _glfw.monitors[i];
break; break;
} }
} }
@ -409,7 +409,7 @@ GLFWAPI void glfwSetMonitorCallback(GLFWmonitorfun cbfun)
return; return;
} }
_glfwLibrary.monitorCallback = cbfun; _glfw.monitorCallback = cbfun;
} }

View File

@ -201,9 +201,9 @@ int _glfwCreateContext(_GLFWwindow* window,
#undef ADD_ATTR #undef ADD_ATTR
#undef ADD_ATTR2 #undef ADD_ATTR2
window->NSGL.pixelFormat = window->nsgl.pixelFormat =
[[NSOpenGLPixelFormat alloc] initWithAttributes:attributes]; [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
if (window->NSGL.pixelFormat == nil) if (window->nsgl.pixelFormat == nil)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,
"NSOpenGL: Failed to create OpenGL pixel format"); "NSOpenGL: Failed to create OpenGL pixel format");
@ -213,12 +213,12 @@ int _glfwCreateContext(_GLFWwindow* window,
NSOpenGLContext* share = NULL; NSOpenGLContext* share = NULL;
if (wndconfig->share) if (wndconfig->share)
share = wndconfig->share->NSGL.context; share = wndconfig->share->nsgl.context;
window->NSGL.context = window->nsgl.context =
[[NSOpenGLContext alloc] initWithFormat:window->NSGL.pixelFormat [[NSOpenGLContext alloc] initWithFormat:window->nsgl.pixelFormat
shareContext:share]; shareContext:share];
if (window->NSGL.context == nil) if (window->nsgl.context == nil)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,
"NSOpenGL: Failed to create OpenGL context"); "NSOpenGL: Failed to create OpenGL context");
@ -235,11 +235,11 @@ int _glfwCreateContext(_GLFWwindow* window,
void _glfwDestroyContext(_GLFWwindow* window) void _glfwDestroyContext(_GLFWwindow* window)
{ {
[window->NSGL.pixelFormat release]; [window->nsgl.pixelFormat release];
window->NSGL.pixelFormat = nil; window->nsgl.pixelFormat = nil;
[window->NSGL.context release]; [window->nsgl.context release];
window->NSGL.context = nil; window->nsgl.context = nil;
} }
@ -254,7 +254,7 @@ void _glfwDestroyContext(_GLFWwindow* window)
void _glfwPlatformMakeContextCurrent(_GLFWwindow* window) void _glfwPlatformMakeContextCurrent(_GLFWwindow* window)
{ {
if (window) if (window)
[window->NSGL.context makeCurrentContext]; [window->nsgl.context makeCurrentContext];
else else
[NSOpenGLContext clearCurrentContext]; [NSOpenGLContext clearCurrentContext];
@ -279,7 +279,7 @@ _GLFWwindow* _glfwPlatformGetCurrentContext(void)
void _glfwPlatformSwapBuffers(_GLFWwindow* window) void _glfwPlatformSwapBuffers(_GLFWwindow* window)
{ {
// ARP appears to be unnecessary, but this is future-proof // ARP appears to be unnecessary, but this is future-proof
[window->NSGL.context flushBuffer]; [window->nsgl.context flushBuffer];
} }
@ -292,7 +292,7 @@ void _glfwPlatformSwapInterval(int interval)
_GLFWwindow* window = _glfwPlatformGetCurrentContext(); _GLFWwindow* window = _glfwPlatformGetCurrentContext();
GLint sync = interval; GLint sync = interval;
[window->NSGL.context setValues:&sync forParameter:NSOpenGLCPSwapInterval]; [window->nsgl.context setValues:&sync forParameter:NSOpenGLCPSwapInterval];
} }
@ -317,7 +317,7 @@ GLFWglproc _glfwPlatformGetProcAddress(const char* procname)
procname, procname,
kCFStringEncodingASCII); kCFStringEncodingASCII);
GLFWglproc symbol = CFBundleGetFunctionPointerForName(_glfwLibrary.NSGL.framework, GLFWglproc symbol = CFBundleGetFunctionPointerForName(_glfw.nsgl.framework,
symbolName); symbolName);
CFRelease(symbolName); CFRelease(symbolName);

View File

@ -31,8 +31,8 @@
#define _nsgl_platform_h_ #define _nsgl_platform_h_
#define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextNSGL NSGL #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextNSGL nsgl
#define _GLFW_PLATFORM_LIBRARY_OPENGL_STATE _GLFWlibraryNSGL NSGL #define _GLFW_PLATFORM_LIBRARY_OPENGL_STATE _GLFWlibraryNSGL nsgl
//======================================================================== //========================================================================

View File

@ -63,83 +63,83 @@ static _GLFW_TLS _GLFWwindow* _glfwCurrentWindow = NULL;
static void initWGLExtensions(_GLFWwindow* window) static void initWGLExtensions(_GLFWwindow* window)
{ {
// This needs to include every function pointer loaded below // This needs to include every function pointer loaded below
window->WGL.SwapIntervalEXT = NULL; window->wgl.SwapIntervalEXT = NULL;
window->WGL.GetPixelFormatAttribivARB = NULL; window->wgl.GetPixelFormatAttribivARB = NULL;
window->WGL.GetExtensionsStringARB = NULL; window->wgl.GetExtensionsStringARB = NULL;
window->WGL.GetExtensionsStringEXT = NULL; window->wgl.GetExtensionsStringEXT = NULL;
window->WGL.CreateContextAttribsARB = NULL; window->wgl.CreateContextAttribsARB = NULL;
// This needs to include every extension used below except for // This needs to include every extension used below except for
// WGL_ARB_extensions_string and WGL_EXT_extensions_string // WGL_ARB_extensions_string and WGL_EXT_extensions_string
window->WGL.ARB_multisample = GL_FALSE; window->wgl.ARB_multisample = GL_FALSE;
window->WGL.ARB_framebuffer_sRGB = GL_FALSE; window->wgl.ARB_framebuffer_sRGB = GL_FALSE;
window->WGL.ARB_create_context = GL_FALSE; window->wgl.ARB_create_context = GL_FALSE;
window->WGL.ARB_create_context_profile = GL_FALSE; window->wgl.ARB_create_context_profile = GL_FALSE;
window->WGL.EXT_create_context_es2_profile = GL_FALSE; window->wgl.EXT_create_context_es2_profile = GL_FALSE;
window->WGL.ARB_create_context_robustness = GL_FALSE; window->wgl.ARB_create_context_robustness = GL_FALSE;
window->WGL.EXT_swap_control = GL_FALSE; window->wgl.EXT_swap_control = GL_FALSE;
window->WGL.ARB_pixel_format = GL_FALSE; window->wgl.ARB_pixel_format = GL_FALSE;
window->WGL.GetExtensionsStringEXT = (PFNWGLGETEXTENSIONSSTRINGEXTPROC) window->wgl.GetExtensionsStringEXT = (PFNWGLGETEXTENSIONSSTRINGEXTPROC)
wglGetProcAddress("wglGetExtensionsStringEXT"); wglGetProcAddress("wglGetExtensionsStringEXT");
if (!window->WGL.GetExtensionsStringEXT) if (!window->wgl.GetExtensionsStringEXT)
{ {
window->WGL.GetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC) window->wgl.GetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)
wglGetProcAddress("wglGetExtensionsStringARB"); wglGetProcAddress("wglGetExtensionsStringARB");
if (!window->WGL.GetExtensionsStringARB) if (!window->wgl.GetExtensionsStringARB)
return; return;
} }
if (_glfwPlatformExtensionSupported("WGL_ARB_multisample")) if (_glfwPlatformExtensionSupported("WGL_ARB_multisample"))
window->WGL.ARB_multisample = GL_TRUE; window->wgl.ARB_multisample = GL_TRUE;
if (_glfwPlatformExtensionSupported("WGL_ARB_framebuffer_sRGB")) if (_glfwPlatformExtensionSupported("WGL_ARB_framebuffer_sRGB"))
window->WGL.ARB_framebuffer_sRGB = GL_TRUE; window->wgl.ARB_framebuffer_sRGB = GL_TRUE;
if (_glfwPlatformExtensionSupported("WGL_ARB_create_context")) if (_glfwPlatformExtensionSupported("WGL_ARB_create_context"))
{ {
window->WGL.CreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC) window->wgl.CreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)
wglGetProcAddress("wglCreateContextAttribsARB"); wglGetProcAddress("wglCreateContextAttribsARB");
if (window->WGL.CreateContextAttribsARB) if (window->wgl.CreateContextAttribsARB)
window->WGL.ARB_create_context = GL_TRUE; window->wgl.ARB_create_context = GL_TRUE;
} }
if (window->WGL.ARB_create_context) if (window->wgl.ARB_create_context)
{ {
if (_glfwPlatformExtensionSupported("WGL_ARB_create_context_profile")) if (_glfwPlatformExtensionSupported("WGL_ARB_create_context_profile"))
window->WGL.ARB_create_context_profile = GL_TRUE; window->wgl.ARB_create_context_profile = GL_TRUE;
} }
if (window->WGL.ARB_create_context && if (window->wgl.ARB_create_context &&
window->WGL.ARB_create_context_profile) window->wgl.ARB_create_context_profile)
{ {
if (_glfwPlatformExtensionSupported("WGL_EXT_create_context_es2_profile")) if (_glfwPlatformExtensionSupported("WGL_EXT_create_context_es2_profile"))
window->WGL.EXT_create_context_es2_profile = GL_TRUE; window->wgl.EXT_create_context_es2_profile = GL_TRUE;
} }
if (window->WGL.ARB_create_context) if (window->wgl.ARB_create_context)
{ {
if (_glfwPlatformExtensionSupported("WGL_ARB_create_context_robustness")) if (_glfwPlatformExtensionSupported("WGL_ARB_create_context_robustness"))
window->WGL.ARB_create_context_robustness = GL_TRUE; window->wgl.ARB_create_context_robustness = GL_TRUE;
} }
if (_glfwPlatformExtensionSupported("WGL_EXT_swap_control")) if (_glfwPlatformExtensionSupported("WGL_EXT_swap_control"))
{ {
window->WGL.SwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC) window->wgl.SwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)
wglGetProcAddress("wglSwapIntervalEXT"); wglGetProcAddress("wglSwapIntervalEXT");
if (window->WGL.SwapIntervalEXT) if (window->wgl.SwapIntervalEXT)
window->WGL.EXT_swap_control = GL_TRUE; window->wgl.EXT_swap_control = GL_TRUE;
} }
if (_glfwPlatformExtensionSupported("WGL_ARB_pixel_format")) if (_glfwPlatformExtensionSupported("WGL_ARB_pixel_format"))
{ {
window->WGL.GetPixelFormatAttribivARB = (PFNWGLGETPIXELFORMATATTRIBIVARBPROC) window->wgl.GetPixelFormatAttribivARB = (PFNWGLGETPIXELFORMATATTRIBIVARBPROC)
wglGetProcAddress("wglGetPixelFormatAttribivARB"); wglGetProcAddress("wglGetPixelFormatAttribivARB");
if (window->WGL.GetPixelFormatAttribivARB) if (window->wgl.GetPixelFormatAttribivARB)
window->WGL.ARB_pixel_format = GL_TRUE; window->wgl.ARB_pixel_format = GL_TRUE;
} }
} }
@ -153,7 +153,7 @@ static int getPixelFormatAttrib(_GLFWwindow* window, int pixelFormat, int attrib
{ {
int value = 0; int value = 0;
if (!window->WGL.GetPixelFormatAttribivARB(window->WGL.DC, if (!window->wgl.GetPixelFormatAttribivARB(window->wgl.dc,
pixelFormat, pixelFormat,
0, 1, &attrib, &value)) 0, 1, &attrib, &value))
{ {
@ -177,7 +177,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
*found = 0; *found = 0;
if (window->WGL.ARB_pixel_format) if (window->wgl.ARB_pixel_format)
{ {
available = getPixelFormatAttrib(window, available = getPixelFormatAttrib(window,
1, 1,
@ -185,7 +185,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
} }
else else
{ {
available = DescribePixelFormat(window->WGL.DC, available = DescribePixelFormat(window->wgl.dc,
1, 1,
sizeof(PIXELFORMATDESCRIPTOR), sizeof(PIXELFORMATDESCRIPTOR),
NULL); NULL);
@ -208,7 +208,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
{ {
_GLFWfbconfig* f = fbconfigs + *found; _GLFWfbconfig* f = fbconfigs + *found;
if (window->WGL.ARB_pixel_format) if (window->wgl.ARB_pixel_format)
{ {
// Get pixel format attributes through WGL_ARB_pixel_format // Get pixel format attributes through WGL_ARB_pixel_format
if (!getPixelFormatAttrib(window, i, WGL_SUPPORT_OPENGL_ARB) || if (!getPixelFormatAttrib(window, i, WGL_SUPPORT_OPENGL_ARB) ||
@ -246,12 +246,12 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
f->auxBuffers = getPixelFormatAttrib(window, i, WGL_AUX_BUFFERS_ARB); f->auxBuffers = getPixelFormatAttrib(window, i, WGL_AUX_BUFFERS_ARB);
f->stereo = getPixelFormatAttrib(window, i, WGL_STEREO_ARB); f->stereo = getPixelFormatAttrib(window, i, WGL_STEREO_ARB);
if (window->WGL.ARB_multisample) if (window->wgl.ARB_multisample)
f->samples = getPixelFormatAttrib(window, i, WGL_SAMPLES_ARB); f->samples = getPixelFormatAttrib(window, i, WGL_SAMPLES_ARB);
else else
f->samples = 0; f->samples = 0;
if (window->WGL.ARB_framebuffer_sRGB) if (window->wgl.ARB_framebuffer_sRGB)
f->sRGB = getPixelFormatAttrib(window, i, WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB); f->sRGB = getPixelFormatAttrib(window, i, WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB);
else else
f->sRGB = GL_FALSE; f->sRGB = GL_FALSE;
@ -260,7 +260,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
{ {
// Get pixel format attributes through old-fashioned PFDs // Get pixel format attributes through old-fashioned PFDs
if (!DescribePixelFormat(window->WGL.DC, if (!DescribePixelFormat(window->wgl.dc,
i, i,
sizeof(PIXELFORMATDESCRIPTOR), sizeof(PIXELFORMATDESCRIPTOR),
&pfd)) &pfd))
@ -342,9 +342,9 @@ static GLboolean createContext(_GLFWwindow* window,
HGLRC share = NULL; HGLRC share = NULL;
if (wndconfig->share) if (wndconfig->share)
share = wndconfig->share->WGL.context; share = wndconfig->share->wgl.context;
if (!DescribePixelFormat(window->WGL.DC, pixelFormat, sizeof(pfd), &pfd)) if (!DescribePixelFormat(window->wgl.dc, pixelFormat, sizeof(pfd), &pfd))
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,
"Win32: Failed to retrieve PFD for selected pixel " "Win32: Failed to retrieve PFD for selected pixel "
@ -352,14 +352,14 @@ static GLboolean createContext(_GLFWwindow* window,
return GL_FALSE; return GL_FALSE;
} }
if (!SetPixelFormat(window->WGL.DC, pixelFormat, &pfd)) if (!SetPixelFormat(window->wgl.dc, pixelFormat, &pfd))
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,
"Win32: Failed to set selected pixel format"); "Win32: Failed to set selected pixel format");
return GL_FALSE; return GL_FALSE;
} }
if (window->WGL.ARB_create_context) if (window->wgl.ARB_create_context)
{ {
int index = 0, mask = 0, flags = 0, strategy = 0; int index = 0, mask = 0, flags = 0, strategy = 0;
@ -384,7 +384,7 @@ static GLboolean createContext(_GLFWwindow* window,
if (wndconfig->glRobustness) if (wndconfig->glRobustness)
{ {
if (window->WGL.ARB_create_context_robustness) if (window->wgl.ARB_create_context_robustness)
{ {
if (wndconfig->glRobustness == GLFW_NO_RESET_NOTIFICATION) if (wndconfig->glRobustness == GLFW_NO_RESET_NOTIFICATION)
strategy = WGL_NO_RESET_NOTIFICATION_ARB; strategy = WGL_NO_RESET_NOTIFICATION_ARB;
@ -412,10 +412,10 @@ static GLboolean createContext(_GLFWwindow* window,
setWGLattrib(0, 0); setWGLattrib(0, 0);
window->WGL.context = window->WGL.CreateContextAttribsARB(window->WGL.DC, window->wgl.context = window->wgl.CreateContextAttribsARB(window->wgl.dc,
share, share,
attribs); attribs);
if (!window->WGL.context) if (!window->wgl.context)
{ {
_glfwInputError(GLFW_VERSION_UNAVAILABLE, _glfwInputError(GLFW_VERSION_UNAVAILABLE,
"WGL: Failed to create OpenGL context"); "WGL: Failed to create OpenGL context");
@ -424,8 +424,8 @@ static GLboolean createContext(_GLFWwindow* window,
} }
else else
{ {
window->WGL.context = wglCreateContext(window->WGL.DC); window->wgl.context = wglCreateContext(window->wgl.dc);
if (!window->WGL.context) if (!window->wgl.context)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,
"WGL: Failed to create OpenGL context"); "WGL: Failed to create OpenGL context");
@ -434,7 +434,7 @@ static GLboolean createContext(_GLFWwindow* window,
if (share) if (share)
{ {
if (!wglShareLists(share, window->WGL.context)) if (!wglShareLists(share, window->wgl.context))
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,
"WGL: Failed to enable sharing with specified " "WGL: Failed to enable sharing with specified "
@ -467,8 +467,8 @@ int _glfwCreateContext(_GLFWwindow* window,
{ {
_GLFWfbconfig closest; _GLFWfbconfig closest;
window->WGL.DC = GetDC(window->Win32.handle); window->wgl.dc = GetDC(window->win32.handle);
if (!window->WGL.DC) if (!window->wgl.dc)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,
"Win32: Failed to retrieve DC for window"); "Win32: Failed to retrieve DC for window");
@ -509,16 +509,16 @@ int _glfwCreateContext(_GLFWwindow* window,
void _glfwDestroyContext(_GLFWwindow* window) void _glfwDestroyContext(_GLFWwindow* window)
{ {
if (window->WGL.context) if (window->wgl.context)
{ {
wglDeleteContext(window->WGL.context); wglDeleteContext(window->wgl.context);
window->WGL.context = NULL; window->wgl.context = NULL;
} }
if (window->WGL.DC) if (window->wgl.dc)
{ {
ReleaseDC(window->Win32.handle, window->WGL.DC); ReleaseDC(window->win32.handle, window->wgl.dc);
window->WGL.DC = NULL; window->wgl.dc = NULL;
} }
} }
@ -537,7 +537,7 @@ int _glfwAnalyzeContext(const _GLFWwindow* window,
{ {
if (wndconfig->glForward) if (wndconfig->glForward)
{ {
if (!window->WGL.ARB_create_context) if (!window->wgl.ARB_create_context)
{ {
_glfwInputError(GLFW_VERSION_UNAVAILABLE, _glfwInputError(GLFW_VERSION_UNAVAILABLE,
"WGL: A forward compatible OpenGL context " "WGL: A forward compatible OpenGL context "
@ -551,7 +551,7 @@ int _glfwAnalyzeContext(const _GLFWwindow* window,
if (wndconfig->glProfile) if (wndconfig->glProfile)
{ {
if (!window->WGL.ARB_create_context_profile) if (!window->wgl.ARB_create_context_profile)
{ {
_glfwInputError(GLFW_VERSION_UNAVAILABLE, _glfwInputError(GLFW_VERSION_UNAVAILABLE,
"WGL: OpenGL profile requested but " "WGL: OpenGL profile requested but "
@ -564,9 +564,9 @@ int _glfwAnalyzeContext(const _GLFWwindow* window,
} }
else else
{ {
if (!window->WGL.ARB_create_context || if (!window->wgl.ARB_create_context ||
!window->WGL.ARB_create_context_profile || !window->wgl.ARB_create_context_profile ||
!window->WGL.EXT_create_context_es2_profile) !window->wgl.EXT_create_context_es2_profile)
{ {
_glfwInputError(GLFW_VERSION_UNAVAILABLE, _glfwInputError(GLFW_VERSION_UNAVAILABLE,
"WGL: OpenGL ES requested but " "WGL: OpenGL ES requested but "
@ -579,13 +579,13 @@ int _glfwAnalyzeContext(const _GLFWwindow* window,
if (wndconfig->glMajor != 1 || wndconfig->glMinor != 0) if (wndconfig->glMajor != 1 || wndconfig->glMinor != 0)
{ {
if (window->WGL.ARB_create_context) if (window->wgl.ARB_create_context)
required = GL_TRUE; required = GL_TRUE;
} }
if (wndconfig->glDebug) if (wndconfig->glDebug)
{ {
if (window->WGL.ARB_create_context) if (window->wgl.ARB_create_context)
required = GL_TRUE; required = GL_TRUE;
} }
@ -594,7 +594,7 @@ int _glfwAnalyzeContext(const _GLFWwindow* window,
// We want FSAA, but can we get it? // We want FSAA, but can we get it?
// FSAA is not a hard constraint, so otherwise we just don't care // FSAA is not a hard constraint, so otherwise we just don't care
if (window->WGL.ARB_multisample && window->WGL.ARB_pixel_format) if (window->wgl.ARB_multisample && window->wgl.ARB_pixel_format)
{ {
// We appear to have both the extension and the means to ask for it // We appear to have both the extension and the means to ask for it
required = GL_TRUE; required = GL_TRUE;
@ -619,7 +619,7 @@ int _glfwAnalyzeContext(const _GLFWwindow* window,
void _glfwPlatformMakeContextCurrent(_GLFWwindow* window) void _glfwPlatformMakeContextCurrent(_GLFWwindow* window)
{ {
if (window) if (window)
wglMakeCurrent(window->WGL.DC, window->WGL.context); wglMakeCurrent(window->wgl.dc, window->wgl.context);
else else
wglMakeCurrent(NULL, NULL); wglMakeCurrent(NULL, NULL);
@ -643,7 +643,7 @@ _GLFWwindow* _glfwPlatformGetCurrentContext(void)
void _glfwPlatformSwapBuffers(_GLFWwindow* window) void _glfwPlatformSwapBuffers(_GLFWwindow* window)
{ {
SwapBuffers(window->WGL.DC); SwapBuffers(window->wgl.dc);
} }
@ -655,8 +655,8 @@ void _glfwPlatformSwapInterval(int interval)
{ {
_GLFWwindow* window = _glfwCurrentWindow; _GLFWwindow* window = _glfwCurrentWindow;
if (window->WGL.EXT_swap_control) if (window->wgl.EXT_swap_control)
window->WGL.SwapIntervalEXT(interval); window->wgl.SwapIntervalEXT(interval);
} }
@ -670,9 +670,9 @@ int _glfwPlatformExtensionSupported(const char* extension)
_GLFWwindow* window = _glfwCurrentWindow; _GLFWwindow* window = _glfwCurrentWindow;
if (window->WGL.GetExtensionsStringEXT != NULL) if (window->wgl.GetExtensionsStringEXT != NULL)
{ {
extensions = (GLubyte*) window->WGL.GetExtensionsStringEXT(); extensions = (GLubyte*) window->wgl.GetExtensionsStringEXT();
if (extensions != NULL) if (extensions != NULL)
{ {
if (_glfwStringInExtensionString(extension, extensions)) if (_glfwStringInExtensionString(extension, extensions))
@ -680,9 +680,9 @@ int _glfwPlatformExtensionSupported(const char* extension)
} }
} }
if (window->WGL.GetExtensionsStringARB != NULL) if (window->wgl.GetExtensionsStringARB != NULL)
{ {
extensions = (GLubyte*) window->WGL.GetExtensionsStringARB(window->WGL.DC); extensions = (GLubyte*) window->wgl.GetExtensionsStringARB(window->wgl.dc);
if (extensions != NULL) if (extensions != NULL)
{ {
if (_glfwStringInExtensionString(extension, extensions)) if (_glfwStringInExtensionString(extension, extensions))

View File

@ -37,8 +37,8 @@
#include "../support/GL/wglext.h" #include "../support/GL/wglext.h"
#define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextWGL WGL #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextWGL wgl
#define _GLFW_PLATFORM_LIBRARY_OPENGL_STATE _GLFWlibraryWGL WGL #define _GLFW_PLATFORM_LIBRARY_OPENGL_STATE _GLFWlibraryWGL wgl
//======================================================================== //========================================================================
@ -51,7 +51,7 @@
typedef struct _GLFWcontextWGL typedef struct _GLFWcontextWGL
{ {
// Platform specific window resources // Platform specific window resources
HDC DC; // Private GDI device context HDC dc; // Private GDI device context
HGLRC context; // Permanent rendering context HGLRC context; // Permanent rendering context
// Platform specific extensions (context specific) // Platform specific extensions (context specific)

View File

@ -73,7 +73,7 @@ void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string)
memcpy(GlobalLock(stringHandle), wideString, wideSize); memcpy(GlobalLock(stringHandle), wideString, wideSize);
GlobalUnlock(stringHandle); GlobalUnlock(stringHandle);
if (!OpenClipboard(window->Win32.handle)) if (!OpenClipboard(window->win32.handle))
{ {
GlobalFree(stringHandle); GlobalFree(stringHandle);
free(wideString); free(wideString);
@ -104,7 +104,7 @@ const char* _glfwPlatformGetClipboardString(_GLFWwindow* window)
return NULL; return NULL;
} }
if (!OpenClipboard(window->Win32.handle)) if (!OpenClipboard(window->win32.handle))
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, "Win32: Failed to open clipboard"); _glfwInputError(GLFW_PLATFORM_ERROR, "Win32: Failed to open clipboard");
return NULL; return NULL;
@ -120,20 +120,20 @@ const char* _glfwPlatformGetClipboardString(_GLFWwindow* window)
return NULL; return NULL;
} }
free(_glfwLibrary.Win32.clipboardString); free(_glfw.win32.clipboardString);
_glfwLibrary.Win32.clipboardString = _glfw.win32.clipboardString =
_glfwCreateUTF8FromWideString(GlobalLock(stringHandle)); _glfwCreateUTF8FromWideString(GlobalLock(stringHandle));
GlobalUnlock(stringHandle); GlobalUnlock(stringHandle);
CloseClipboard(); CloseClipboard();
if (!_glfwLibrary.Win32.clipboardString) if (!_glfw.win32.clipboardString)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,
"Win32: Failed to convert wide string to UTF-8"); "Win32: Failed to convert wide string to UTF-8");
return NULL; return NULL;
} }
return _glfwLibrary.Win32.clipboardString; return _glfw.win32.clipboardString;
} }

View File

@ -60,23 +60,23 @@ static GLboolean initLibraries(void)
#ifndef _GLFW_NO_DLOAD_WINMM #ifndef _GLFW_NO_DLOAD_WINMM
// winmm.dll (for joystick and timer support) // winmm.dll (for joystick and timer support)
_glfwLibrary.Win32.winmm.instance = LoadLibrary(L"winmm.dll"); _glfw.win32.winmm.instance = LoadLibrary(L"winmm.dll");
if (!_glfwLibrary.Win32.winmm.instance) if (!_glfw.win32.winmm.instance)
return GL_FALSE; return GL_FALSE;
_glfwLibrary.Win32.winmm.joyGetDevCaps = (JOYGETDEVCAPS_T) _glfw.win32.winmm.joyGetDevCaps = (JOYGETDEVCAPS_T)
GetProcAddress(_glfwLibrary.Win32.winmm.instance, "joyGetDevCapsW"); GetProcAddress(_glfw.win32.winmm.instance, "joyGetDevCapsW");
_glfwLibrary.Win32.winmm.joyGetPos = (JOYGETPOS_T) _glfw.win32.winmm.joyGetPos = (JOYGETPOS_T)
GetProcAddress(_glfwLibrary.Win32.winmm.instance, "joyGetPos"); GetProcAddress(_glfw.win32.winmm.instance, "joyGetPos");
_glfwLibrary.Win32.winmm.joyGetPosEx = (JOYGETPOSEX_T) _glfw.win32.winmm.joyGetPosEx = (JOYGETPOSEX_T)
GetProcAddress(_glfwLibrary.Win32.winmm.instance, "joyGetPosEx"); GetProcAddress(_glfw.win32.winmm.instance, "joyGetPosEx");
_glfwLibrary.Win32.winmm.timeGetTime = (TIMEGETTIME_T) _glfw.win32.winmm.timeGetTime = (TIMEGETTIME_T)
GetProcAddress(_glfwLibrary.Win32.winmm.instance, "timeGetTime"); GetProcAddress(_glfw.win32.winmm.instance, "timeGetTime");
if (!_glfwLibrary.Win32.winmm.joyGetDevCaps || if (!_glfw.win32.winmm.joyGetDevCaps ||
!_glfwLibrary.Win32.winmm.joyGetPos || !_glfw.win32.winmm.joyGetPos ||
!_glfwLibrary.Win32.winmm.joyGetPosEx || !_glfw.win32.winmm.joyGetPosEx ||
!_glfwLibrary.Win32.winmm.timeGetTime) !_glfw.win32.winmm.timeGetTime)
{ {
return GL_FALSE; return GL_FALSE;
} }
@ -93,10 +93,10 @@ static GLboolean initLibraries(void)
static void freeLibraries(void) static void freeLibraries(void)
{ {
#ifndef _GLFW_NO_DLOAD_WINMM #ifndef _GLFW_NO_DLOAD_WINMM
if (_glfwLibrary.Win32.winmm.instance != NULL) if (_glfw.win32.winmm.instance != NULL)
{ {
FreeLibrary(_glfwLibrary.Win32.winmm.instance); FreeLibrary(_glfw.win32.winmm.instance);
_glfwLibrary.Win32.winmm.instance = NULL; _glfw.win32.winmm.instance = NULL;
} }
#endif // _GLFW_NO_DLOAD_WINMM #endif // _GLFW_NO_DLOAD_WINMM
} }
@ -170,7 +170,7 @@ int _glfwPlatformInit(void)
// with the FOREGROUNDLOCKTIMEOUT system setting (we do this as early // with the FOREGROUNDLOCKTIMEOUT system setting (we do this as early
// as possible in the hope of still being the foreground process) // as possible in the hope of still being the foreground process)
SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0, SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0,
&_glfwLibrary.Win32.foregroundLockTimeout, 0); &_glfw.win32.foregroundLockTimeout, 0);
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, UIntToPtr(0), SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, UIntToPtr(0),
SPIF_SENDCHANGE); SPIF_SENDCHANGE);
@ -183,12 +183,12 @@ int _glfwPlatformInit(void)
_control87(MCW_EM, MCW_EM); _control87(MCW_EM, MCW_EM);
#endif #endif
_glfwLibrary.Win32.instance = GetModuleHandle(NULL); _glfw.win32.instance = GetModuleHandle(NULL);
// Save the original gamma ramp // Save the original gamma ramp
_glfwLibrary.originalRampSize = 256; _glfw.originalRampSize = 256;
_glfwPlatformGetGammaRamp(&_glfwLibrary.originalRamp); _glfwPlatformGetGammaRamp(&_glfw.originalRamp);
_glfwLibrary.currentRamp = _glfwLibrary.originalRamp; _glfw.currentRamp = _glfw.originalRamp;
_glfwInitTimer(); _glfwInitTimer();
@ -203,13 +203,13 @@ int _glfwPlatformInit(void)
void _glfwPlatformTerminate(void) void _glfwPlatformTerminate(void)
{ {
// Restore the original gamma ramp // Restore the original gamma ramp
if (_glfwLibrary.rampChanged) if (_glfw.rampChanged)
_glfwPlatformSetGammaRamp(&_glfwLibrary.originalRamp); _glfwPlatformSetGammaRamp(&_glfw.originalRamp);
if (_glfwLibrary.Win32.classAtom) if (_glfw.win32.classAtom)
{ {
UnregisterClass(_GLFW_WNDCLASSNAME, _glfwLibrary.Win32.instance); UnregisterClass(_GLFW_WNDCLASSNAME, _glfw.win32.instance);
_glfwLibrary.Win32.classAtom = 0; _glfw.win32.classAtom = 0;
} }
// TODO: Remove keyboard hook // TODO: Remove keyboard hook
@ -218,7 +218,7 @@ void _glfwPlatformTerminate(void)
// Restore previous FOREGROUNDLOCKTIMEOUT system setting // Restore previous FOREGROUNDLOCKTIMEOUT system setting
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0,
UIntToPtr(_glfwLibrary.Win32.foregroundLockTimeout), UIntToPtr(_glfw.win32.foregroundLockTimeout),
SPIF_SENDCHANGE); SPIF_SENDCHANGE);
} }

View File

@ -235,9 +235,9 @@ const char* _glfwPlatformGetJoystickName(int joy)
_glfw_joyGetDevCaps(i, &jc, sizeof(JOYCAPS)); _glfw_joyGetDevCaps(i, &jc, sizeof(JOYCAPS));
free(_glfwLibrary.Win32.joyNames[i]); free(_glfw.win32.joyNames[i]);
_glfwLibrary.Win32.joyNames[i] = _glfwCreateUTF8FromWideString(jc.szPname); _glfw.win32.joyNames[i] = _glfwCreateUTF8FromWideString(jc.szPname);
return _glfwLibrary.Win32.joyNames[i]; return _glfw.win32.joyNames[i];
} }

View File

@ -243,7 +243,7 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
return NULL; return NULL;
} }
monitors[found]->Win32.name = _wcsdup(adapter.DeviceName); monitors[found]->win32.name = _wcsdup(adapter.DeviceName);
found++; found++;
} }
@ -258,7 +258,7 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
void _glfwPlatformDestroyMonitor(_GLFWmonitor* monitor) void _glfwPlatformDestroyMonitor(_GLFWmonitor* monitor)
{ {
free(monitor->Win32.name); free(monitor->win32.name);
} }
@ -282,7 +282,7 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found)
ZeroMemory(&dm, sizeof(DEVMODE)); ZeroMemory(&dm, sizeof(DEVMODE));
dm.dmSize = sizeof(DEVMODE); dm.dmSize = sizeof(DEVMODE);
if (!EnumDisplaySettings(monitor->Win32.name, modeIndex, &dm)) if (!EnumDisplaySettings(monitor->win32.name, modeIndex, &dm))
break; break;
modeIndex++; modeIndex++;
@ -352,7 +352,7 @@ void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode)
ZeroMemory(&dm, sizeof(DEVMODE)); ZeroMemory(&dm, sizeof(DEVMODE));
dm.dmSize = sizeof(DEVMODE); dm.dmSize = sizeof(DEVMODE);
EnumDisplaySettings(monitor->Win32.name, ENUM_REGISTRY_SETTINGS, &dm); EnumDisplaySettings(monitor->win32.name, ENUM_REGISTRY_SETTINGS, &dm);
mode->width = dm.dmPelsWidth; mode->width = dm.dmPelsWidth;
mode->height = dm.dmPelsHeight; mode->height = dm.dmPelsHeight;

View File

@ -1,4 +1,4 @@
//======================================================================== _glfw
// GLFW - An OpenGL library // GLFW - An OpenGL library
// Platform: Win32/WGL // Platform: Win32/WGL
// API version: 3.0 // API version: 3.0
@ -51,7 +51,7 @@ GLFWAPI HWND glfwGetWin32Window(GLFWwindow handle)
return NULL; return NULL;
} }
return window->Win32.handle; return window->win32.handle;
} }

View File

@ -89,10 +89,10 @@ typedef DWORD (WINAPI * TIMEGETTIME_T) (void);
// winmm.dll shortcuts // winmm.dll shortcuts
#ifndef _GLFW_NO_DLOAD_WINMM #ifndef _GLFW_NO_DLOAD_WINMM
#define _glfw_joyGetDevCaps _glfwLibrary.Win32.winmm.joyGetDevCaps #define _glfw_joyGetDevCaps _glfw.win32.winmm.joyGetDevCaps
#define _glfw_joyGetPos _glfwLibrary.Win32.winmm.joyGetPos #define _glfw_joyGetPos _glfw.win32.winmm.joyGetPos
#define _glfw_joyGetPosEx _glfwLibrary.Win32.winmm.joyGetPosEx #define _glfw_joyGetPosEx _glfw.win32.winmm.joyGetPosEx
#define _glfw_timeGetTime _glfwLibrary.Win32.winmm.timeGetTime #define _glfw_timeGetTime _glfw.win32.winmm.timeGetTime
#else #else
#define _glfw_joyGetDevCaps joyGetDevCaps #define _glfw_joyGetDevCaps joyGetDevCaps
#define _glfw_joyGetPos joyGetPos #define _glfw_joyGetPos joyGetPos
@ -113,16 +113,16 @@ typedef DWORD (WINAPI * TIMEGETTIME_T) (void);
#if defined(_GLFW_WGL) #if defined(_GLFW_WGL)
#include "wgl_platform.h" #include "wgl_platform.h"
#elif defined(_GLFW_EGL) #elif defined(_GLFW_EGL)
#define _GLFW_EGL_NATIVE_WINDOW window->Win32.handle #define _GLFW_EGL_NATIVE_WINDOW window->win32.handle
#define _GLFW_EGL_NATIVE_DISPLAY NULL #define _GLFW_EGL_NATIVE_DISPLAY NULL
#include "egl_platform.h" #include "egl_platform.h"
#else #else
#error "No supported context creation API selected" #error "No supported context creation API selected"
#endif #endif
#define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowWin32 Win32 #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowWin32 win32
#define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryWin32 Win32 #define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryWin32 win32
#define _GLFW_PLATFORM_MONITOR_STATE _GLFWmonitorWin32 Win32 #define _GLFW_PLATFORM_MONITOR_STATE _GLFWmonitorWin32 win32
//======================================================================== //========================================================================

View File

@ -45,15 +45,15 @@ void _glfwInitTimer(void)
if (QueryPerformanceFrequency((LARGE_INTEGER*) &freq)) if (QueryPerformanceFrequency((LARGE_INTEGER*) &freq))
{ {
_glfwLibrary.Win32.timer.hasPC = GL_TRUE; _glfw.win32.timer.hasPC = GL_TRUE;
_glfwLibrary.Win32.timer.resolution = 1.0 / (double) freq; _glfw.win32.timer.resolution = 1.0 / (double) freq;
QueryPerformanceCounter((LARGE_INTEGER*) &_glfwLibrary.Win32.timer.t0_64); QueryPerformanceCounter((LARGE_INTEGER*) &_glfw.win32.timer.t0_64);
} }
else else
{ {
_glfwLibrary.Win32.timer.hasPC = GL_FALSE; _glfw.win32.timer.hasPC = GL_FALSE;
_glfwLibrary.Win32.timer.resolution = 0.001; // winmm resolution is 1 ms _glfw.win32.timer.resolution = 0.001; // winmm resolution is 1 ms
_glfwLibrary.Win32.timer.t0_32 = _glfw_timeGetTime(); _glfw.win32.timer.t0_32 = _glfw_timeGetTime();
} }
} }
@ -71,15 +71,15 @@ double _glfwPlatformGetTime(void)
double t; double t;
__int64 t_64; __int64 t_64;
if (_glfwLibrary.Win32.timer.hasPC) if (_glfw.win32.timer.hasPC)
{ {
QueryPerformanceCounter((LARGE_INTEGER*) &t_64); QueryPerformanceCounter((LARGE_INTEGER*) &t_64);
t = (double)(t_64 - _glfwLibrary.Win32.timer.t0_64); t = (double)(t_64 - _glfw.win32.timer.t0_64);
} }
else else
t = (double)(_glfw_timeGetTime() - _glfwLibrary.Win32.timer.t0_32); t = (double)(_glfw_timeGetTime() - _glfw.win32.timer.t0_32);
return t * _glfwLibrary.Win32.timer.resolution; return t * _glfw.win32.timer.resolution;
} }
@ -91,12 +91,12 @@ void _glfwPlatformSetTime(double t)
{ {
__int64 t_64; __int64 t_64;
if (_glfwLibrary.Win32.timer.hasPC) if (_glfw.win32.timer.hasPC)
{ {
QueryPerformanceCounter((LARGE_INTEGER*) &t_64); QueryPerformanceCounter((LARGE_INTEGER*) &t_64);
_glfwLibrary.Win32.timer.t0_64 = t_64 - (__int64) (t / _glfwLibrary.Win32.timer.resolution); _glfw.win32.timer.t0_64 = t_64 - (__int64) (t / _glfw.win32.timer.resolution);
} }
else else
_glfwLibrary.Win32.timer.t0_32 = _glfw_timeGetTime() - (int)(t * 1000.0); _glfw.win32.timer.t0_32 = _glfw_timeGetTime() - (int)(t * 1000.0);
} }

View File

@ -55,11 +55,11 @@ static void captureCursor(_GLFWwindow* window)
ShowCursor(FALSE); ShowCursor(FALSE);
// Clip cursor to the window // Clip cursor to the window
if (GetWindowRect(window->Win32.handle, &ClipWindowRect)) if (GetWindowRect(window->win32.handle, &ClipWindowRect))
ClipCursor(&ClipWindowRect); ClipCursor(&ClipWindowRect);
// Capture cursor to user window // Capture cursor to user window
SetCapture(window->Win32.handle); SetCapture(window->win32.handle);
} }
@ -340,7 +340,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
focused = FALSE; focused = FALSE;
} }
if (!focused && _glfwLibrary.focusedWindow == window) if (!focused && _glfw.focusedWindow == window)
{ {
// The window was defocused (or iconified, see above) // The window was defocused (or iconified, see above)
@ -356,14 +356,14 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
_glfwPlatformIconifyWindow(window); _glfwPlatformIconifyWindow(window);
} }
if (_glfwLibrary.Win32.monitor.modeChanged) if (_glfw.win32.monitor.modeChanged)
{ {
_glfwRestoreVideoMode(); _glfwRestoreVideoMode();
_glfwLibrary.Win32.monitor.modeChanged = GL_FALSE; _glfw.win32.monitor.modeChanged = GL_FALSE;
} }
} }
} }
else if (focused && _glfwLibrary.focusedWindow != window) else if (focused && _glfw.focusedWindow != window)
{ {
// The window was focused // The window was focused
@ -372,14 +372,14 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
if (window->monitor) if (window->monitor)
{ {
if (!_glfwLibrary.Win32.monitor.modeChanged) if (!_glfw.win32.monitor.modeChanged)
{ {
_glfwSetVideoMode(&_glfwLibrary.Win32.monitor.width, _glfwSetVideoMode(&_glfw.win32.monitor.width,
&_glfwLibrary.Win32.monitor.height, &_glfw.win32.monitor.height,
&_glfwLibrary.Win32.monitor.bitsPerPixel, &_glfw.win32.monitor.bitsPerPixel,
GL_TRUE); GL_TRUE);
_glfwLibrary.Win32.monitor.modeChanged = GL_TRUE; _glfw.win32.monitor.modeChanged = GL_TRUE;
} }
} }
} }
@ -535,18 +535,18 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
newCursorX = GET_X_LPARAM(lParam); newCursorX = GET_X_LPARAM(lParam);
newCursorY = GET_Y_LPARAM(lParam); newCursorY = GET_Y_LPARAM(lParam);
if (newCursorX != window->Win32.oldCursorX || if (newCursorX != window->win32.oldCursorX ||
newCursorY != window->Win32.oldCursorY) newCursorY != window->win32.oldCursorY)
{ {
int x, y; int x, y;
if (window->cursorMode == GLFW_CURSOR_CAPTURED) if (window->cursorMode == GLFW_CURSOR_CAPTURED)
{ {
if (_glfwLibrary.focusedWindow != window) if (_glfw.focusedWindow != window)
return 0; return 0;
x = newCursorX - window->Win32.oldCursorX; x = newCursorX - window->win32.oldCursorX;
y = newCursorY - window->Win32.oldCursorY; y = newCursorY - window->win32.oldCursorY;
} }
else else
{ {
@ -554,23 +554,23 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
y = newCursorY; y = newCursorY;
} }
window->Win32.oldCursorX = newCursorX; window->win32.oldCursorX = newCursorX;
window->Win32.oldCursorY = newCursorY; window->win32.oldCursorY = newCursorY;
window->Win32.cursorCentered = GL_FALSE; window->win32.cursorCentered = GL_FALSE;
_glfwInputCursorMotion(window, x, y); _glfwInputCursorMotion(window, x, y);
} }
if (!window->Win32.cursorInside) if (!window->win32.cursorInside)
{ {
TRACKMOUSEEVENT tme; TRACKMOUSEEVENT tme;
ZeroMemory(&tme, sizeof(tme)); ZeroMemory(&tme, sizeof(tme));
tme.cbSize = sizeof(tme); tme.cbSize = sizeof(tme);
tme.dwFlags = TME_LEAVE; tme.dwFlags = TME_LEAVE;
tme.hwndTrack = window->Win32.handle; tme.hwndTrack = window->win32.handle;
TrackMouseEvent(&tme); TrackMouseEvent(&tme);
window->Win32.cursorInside = GL_TRUE; window->win32.cursorInside = GL_TRUE;
_glfwInputCursorEnter(window, GL_TRUE); _glfwInputCursorEnter(window, GL_TRUE);
} }
@ -579,7 +579,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
case WM_MOUSELEAVE: case WM_MOUSELEAVE:
{ {
window->Win32.cursorInside = GL_FALSE; window->win32.cursorInside = GL_FALSE;
_glfwInputCursorEnter(window, GL_FALSE); _glfwInputCursorEnter(window, GL_FALSE);
return 0; return 0;
} }
@ -604,7 +604,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
if (window->cursorMode == GLFW_CURSOR_CAPTURED) if (window->cursorMode == GLFW_CURSOR_CAPTURED)
{ {
RECT ClipWindowRect; RECT ClipWindowRect;
if (GetWindowRect(window->Win32.handle, &ClipWindowRect)) if (GetWindowRect(window->win32.handle, &ClipWindowRect))
ClipCursor(&ClipWindowRect); ClipCursor(&ClipWindowRect);
} }
@ -618,7 +618,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
if (window->cursorMode == GLFW_CURSOR_CAPTURED) if (window->cursorMode == GLFW_CURSOR_CAPTURED)
{ {
RECT ClipWindowRect; RECT ClipWindowRect;
if (GetWindowRect(window->Win32.handle, &ClipWindowRect)) if (GetWindowRect(window->win32.handle, &ClipWindowRect))
ClipCursor(&ClipWindowRect); ClipCursor(&ClipWindowRect);
} }
@ -673,7 +673,7 @@ static void getFullWindowSize(_GLFWwindow* window,
rect.bottom = (long) clientHeight - 1; rect.bottom = (long) clientHeight - 1;
// Adjust according to window styles // Adjust according to window styles
AdjustWindowRectEx(&rect, window->Win32.dwStyle, FALSE, window->Win32.dwExStyle); AdjustWindowRectEx(&rect, window->win32.dwStyle, FALSE, window->win32.dwExStyle);
// Calculate width and height of full window // Calculate width and height of full window
*fullWidth = rect.right - rect.left + 1; *fullWidth = rect.right - rect.left + 1;
@ -695,14 +695,14 @@ static ATOM registerWindowClass(void)
wc.lpfnWndProc = (WNDPROC) windowProc; // Message handler wc.lpfnWndProc = (WNDPROC) windowProc; // Message handler
wc.cbClsExtra = 0; // No extra class data wc.cbClsExtra = 0; // No extra class data
wc.cbWndExtra = sizeof(void*) + sizeof(int); // Make room for one pointer wc.cbWndExtra = sizeof(void*) + sizeof(int); // Make room for one pointer
wc.hInstance = _glfwLibrary.Win32.instance; // Set instance wc.hInstance = _glfw.win32.instance; // Set instance
wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Load arrow pointer wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Load arrow pointer
wc.hbrBackground = NULL; // No background wc.hbrBackground = NULL; // No background
wc.lpszMenuName = NULL; // No menu wc.lpszMenuName = NULL; // No menu
wc.lpszClassName = _GLFW_WNDCLASSNAME; // Set class name wc.lpszClassName = _GLFW_WNDCLASSNAME; // Set class name
// Load user-provided icon if available // Load user-provided icon if available
wc.hIcon = LoadIcon(_glfwLibrary.Win32.instance, L"GLFW_ICON"); wc.hIcon = LoadIcon(_glfw.win32.instance, L"GLFW_ICON");
if (!wc.hIcon) if (!wc.hIcon)
{ {
// Load default icon // Load default icon
@ -747,9 +747,9 @@ static int createWindow(_GLFWwindow* window,
// (SetForegroundWindow doesn't work properly under // (SetForegroundWindow doesn't work properly under
// Win98/ME/2K/.NET/+) // Win98/ME/2K/.NET/+)
/* /*
if (_glfwLibrary.Sys.WinVer != _GLFW_WIN_95 && if (_glfw.Sys.WinVer != _GLFW_WIN_95 &&
_glfwLibrary.Sys.WinVer != _GLFW_WIN_NT4 && _glfw.Sys.WinVer != _GLFW_WIN_NT4 &&
_glfwLibrary.Sys.WinVer != _GLFW_WIN_XP) _glfw.Sys.WinVer != _GLFW_WIN_XP)
{ {
dwStyle |= WS_MINIMIZE; dwStyle |= WS_MINIMIZE;
} }
@ -767,8 +767,8 @@ static int createWindow(_GLFWwindow* window,
} }
// Remember window styles (used by getFullWindowSize) // Remember window styles (used by getFullWindowSize)
window->Win32.dwStyle = dwStyle; window->win32.dwStyle = dwStyle;
window->Win32.dwExStyle = dwExStyle; window->win32.dwExStyle = dwExStyle;
// Adjust window size for frame and title bar // Adjust window size for frame and title bar
getFullWindowSize(window, window->width, window->height, &fullWidth, &fullHeight); getFullWindowSize(window, window->width, window->height, &fullWidth, &fullHeight);
@ -798,19 +798,19 @@ static int createWindow(_GLFWwindow* window,
return GL_FALSE; return GL_FALSE;
} }
window->Win32.handle = CreateWindowEx(window->Win32.dwExStyle, window->win32.handle = CreateWindowEx(window->win32.dwExStyle,
_GLFW_WNDCLASSNAME, _GLFW_WNDCLASSNAME,
wideTitle, wideTitle,
window->Win32.dwStyle, window->win32.dwStyle,
positionX, positionY, positionX, positionY,
fullWidth, // Decorated window width fullWidth, // Decorated window width
fullHeight, // Decorated window height fullHeight, // Decorated window height
NULL, // No parent window NULL, // No parent window
NULL, // No menu NULL, // No menu
_glfwLibrary.Win32.instance, _glfw.win32.instance,
window); // Pass GLFW window to WM_CREATE window); // Pass GLFW window to WM_CREATE
if (!window->Win32.handle) if (!window->win32.handle)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, "Win32: Failed to create window"); _glfwInputError(GLFW_PLATFORM_ERROR, "Win32: Failed to create window");
return GL_FALSE; return GL_FALSE;
@ -820,9 +820,9 @@ static int createWindow(_GLFWwindow* window,
// Initialize cursor position data // Initialize cursor position data
GetCursorPos(&pos); GetCursorPos(&pos);
ScreenToClient(window->Win32.handle, &pos); ScreenToClient(window->win32.handle, &pos);
window->Win32.oldCursorX = window->cursorPosX = pos.x; window->win32.oldCursorX = window->cursorPosX = pos.x;
window->Win32.oldCursorY = window->cursorPosY = pos.y; window->win32.oldCursorY = window->cursorPosY = pos.y;
if (!_glfwCreateContext(window, wndconfig, fbconfig)) if (!_glfwCreateContext(window, wndconfig, fbconfig))
return GL_FALSE; return GL_FALSE;
@ -841,13 +841,13 @@ static void destroyWindow(_GLFWwindow* window)
// This is duplicated from glfwDestroyWindow // This is duplicated from glfwDestroyWindow
// TODO: Stop duplicating code // TODO: Stop duplicating code
if (window == _glfwLibrary.focusedWindow) if (window == _glfw.focusedWindow)
_glfwLibrary.focusedWindow = NULL; _glfw.focusedWindow = NULL;
if (window->Win32.handle) if (window->win32.handle)
{ {
DestroyWindow(window->Win32.handle); DestroyWindow(window->win32.handle);
window->Win32.handle = NULL; window->win32.handle = NULL;
} }
} }
@ -867,10 +867,10 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
{ {
int status; int status;
if (!_glfwLibrary.Win32.classAtom) if (!_glfw.win32.classAtom)
{ {
_glfwLibrary.Win32.classAtom = registerWindowClass(); _glfw.win32.classAtom = registerWindowClass();
if (!_glfwLibrary.Win32.classAtom) if (!_glfw.win32.classAtom)
return GL_FALSE; return GL_FALSE;
} }
@ -880,16 +880,16 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
if (bpp < 15 || bpp >= 24) if (bpp < 15 || bpp >= 24)
bpp = 32; bpp = 32;
_glfwLibrary.Win32.monitor.width = window->width; _glfw.win32.monitor.width = window->width;
_glfwLibrary.Win32.monitor.height = window->height; _glfw.win32.monitor.height = window->height;
_glfwLibrary.Win32.monitor.bitsPerPixel = bpp; _glfw.win32.monitor.bitsPerPixel = bpp;
_glfwSetVideoMode(&_glfwLibrary.Win32.monitor.width, _glfwSetVideoMode(&_glfw.win32.monitor.width,
&_glfwLibrary.Win32.monitor.height, &_glfw.win32.monitor.height,
&_glfwLibrary.Win32.monitor.bitsPerPixel, &_glfw.win32.monitor.bitsPerPixel,
GL_FALSE); GL_FALSE);
_glfwLibrary.Win32.monitor.modeChanged = GL_TRUE; _glfw.win32.monitor.modeChanged = GL_TRUE;
} }
if (!createWindow(window, wndconfig, fbconfig)) if (!createWindow(window, wndconfig, fbconfig))
@ -935,7 +935,7 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
{ {
// Place the window above all topmost windows // Place the window above all topmost windows
_glfwPlatformShowWindow(window); _glfwPlatformShowWindow(window);
SetWindowPos(window->Win32.handle, HWND_TOPMOST, 0,0,0,0, SetWindowPos(window->win32.handle, HWND_TOPMOST, 0,0,0,0,
SWP_NOMOVE | SWP_NOSIZE); SWP_NOMOVE | SWP_NOSIZE);
} }
@ -953,10 +953,10 @@ void _glfwPlatformDestroyWindow(_GLFWwindow* window)
if (window->monitor) if (window->monitor)
{ {
if (_glfwLibrary.Win32.monitor.modeChanged) if (_glfw.win32.monitor.modeChanged)
{ {
_glfwRestoreVideoMode(); _glfwRestoreVideoMode();
_glfwLibrary.Win32.monitor.modeChanged = GL_FALSE; _glfw.win32.monitor.modeChanged = GL_FALSE;
} }
} }
} }
@ -976,7 +976,7 @@ void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title)
return; return;
} }
SetWindowText(window->Win32.handle, wideTitle); SetWindowText(window->win32.handle, wideTitle);
free(wideTitle); free(wideTitle);
} }
@ -998,7 +998,7 @@ void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
// the window before switch modes to avoid exposing whatever is // the window before switch modes to avoid exposing whatever is
// underneath // underneath
SetWindowPos(window->Win32.handle, HWND_TOP, 0, 0, width, height, SetWindowPos(window->win32.handle, HWND_TOP, 0, 0, width, height,
SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOZORDER); SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOZORDER);
sizeChanged = GL_TRUE; sizeChanged = GL_TRUE;
} }
@ -1015,7 +1015,7 @@ void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
// Set window size (if we haven't already) // Set window size (if we haven't already)
if (!sizeChanged) if (!sizeChanged)
{ {
SetWindowPos(window->Win32.handle, HWND_TOP, 0, 0, width, height, SetWindowPos(window->win32.handle, HWND_TOP, 0, 0, width, height,
SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOZORDER); SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOZORDER);
} }
} }
@ -1027,7 +1027,7 @@ void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
void _glfwPlatformIconifyWindow(_GLFWwindow* window) void _glfwPlatformIconifyWindow(_GLFWwindow* window)
{ {
ShowWindow(window->Win32.handle, SW_MINIMIZE); ShowWindow(window->win32.handle, SW_MINIMIZE);
} }
@ -1037,7 +1037,7 @@ void _glfwPlatformIconifyWindow(_GLFWwindow* window)
void _glfwPlatformRestoreWindow(_GLFWwindow* window) void _glfwPlatformRestoreWindow(_GLFWwindow* window)
{ {
ShowWindow(window->Win32.handle, SW_RESTORE); ShowWindow(window->win32.handle, SW_RESTORE);
} }
@ -1047,10 +1047,10 @@ void _glfwPlatformRestoreWindow(_GLFWwindow* window)
void _glfwPlatformShowWindow(_GLFWwindow* window) void _glfwPlatformShowWindow(_GLFWwindow* window)
{ {
ShowWindow(window->Win32.handle, SW_SHOWNORMAL); ShowWindow(window->win32.handle, SW_SHOWNORMAL);
BringWindowToTop(window->Win32.handle); BringWindowToTop(window->win32.handle);
SetForegroundWindow(window->Win32.handle); SetForegroundWindow(window->win32.handle);
SetFocus(window->Win32.handle); SetFocus(window->win32.handle);
} }
@ -1060,7 +1060,7 @@ void _glfwPlatformShowWindow(_GLFWwindow* window)
void _glfwPlatformHideWindow(_GLFWwindow* window) void _glfwPlatformHideWindow(_GLFWwindow* window)
{ {
ShowWindow(window->Win32.handle, SW_HIDE); ShowWindow(window->win32.handle, SW_HIDE);
} }
@ -1073,17 +1073,17 @@ void _glfwPlatformPollEvents(void)
MSG msg; MSG msg;
_GLFWwindow* window; _GLFWwindow* window;
window = _glfwLibrary.focusedWindow; window = _glfw.focusedWindow;
if (window) if (window)
{ {
window->Win32.cursorCentered = GL_FALSE; window->win32.cursorCentered = GL_FALSE;
window->Win32.oldCursorX = window->width / 2; window->win32.oldCursorX = window->width / 2;
window->Win32.oldCursorY = window->height / 2; window->win32.oldCursorY = window->height / 2;
} }
else else
{ {
//window->Win32.oldCursorX = window->cursorPosX; //window->win32.oldCursorX = window->cursorPosX;
//window->Win32.oldCursorY = window->cursorPosY; //window->win32.oldCursorY = window->cursorPosY;
} }
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
@ -1092,7 +1092,7 @@ void _glfwPlatformPollEvents(void)
{ {
// Treat WM_QUIT as a close on all windows // Treat WM_QUIT as a close on all windows
window = _glfwLibrary.windowListHead; window = _glfw.windowListHead;
while (window) while (window)
{ {
_glfwInputWindowCloseRequest(window); _glfwInputWindowCloseRequest(window);
@ -1109,7 +1109,7 @@ void _glfwPlatformPollEvents(void)
// LSHIFT/RSHIFT fixup (keys tend to "stick" without this fix) // LSHIFT/RSHIFT fixup (keys tend to "stick" without this fix)
// This is the only async event handling in GLFW, but it solves some // This is the only async event handling in GLFW, but it solves some
// nasty problems. // nasty problems.
window = _glfwLibrary.focusedWindow; window = _glfw.focusedWindow;
if (window) if (window)
{ {
int lshift_down, rshift_down; int lshift_down, rshift_down;
@ -1128,16 +1128,16 @@ void _glfwPlatformPollEvents(void)
} }
// Did the cursor move in an focused window that has captured the cursor // Did the cursor move in an focused window that has captured the cursor
window = _glfwLibrary.focusedWindow; window = _glfw.focusedWindow;
if (window) if (window)
{ {
if (window->cursorMode == GLFW_CURSOR_CAPTURED && if (window->cursorMode == GLFW_CURSOR_CAPTURED &&
!window->Win32.cursorCentered) !window->win32.cursorCentered)
{ {
_glfwPlatformSetCursorPos(window, _glfwPlatformSetCursorPos(window,
window->width / 2, window->width / 2,
window->height / 2); window->height / 2);
window->Win32.cursorCentered = GL_TRUE; window->win32.cursorCentered = GL_TRUE;
} }
} }
} }
@ -1166,7 +1166,7 @@ void _glfwPlatformSetCursorPos(_GLFWwindow* window, int x, int y)
// Convert client coordinates to screen coordinates // Convert client coordinates to screen coordinates
pos.x = x; pos.x = x;
pos.y = y; pos.y = y;
ClientToScreen(window->Win32.handle, &pos); ClientToScreen(window->win32.handle, &pos);
SetCursorPos(pos.x, pos.y); SetCursorPos(pos.x, pos.y);
} }

View File

@ -56,7 +56,7 @@ static void clearScrollOffsets(void)
{ {
_GLFWwindow* window; _GLFWwindow* window;
for (window = _glfwLibrary.windowListHead; window; window = window->next) for (window = _glfw.windowListHead; window; window = window->next)
{ {
window->scrollX = 0; window->scrollX = 0;
window->scrollY = 0; window->scrollY = 0;
@ -76,9 +76,9 @@ void _glfwInputWindowFocus(_GLFWwindow* window, GLboolean focused)
{ {
if (focused) if (focused)
{ {
if (_glfwLibrary.focusedWindow != window) if (_glfw.focusedWindow != window)
{ {
_glfwLibrary.focusedWindow = window; _glfw.focusedWindow = window;
if (window->windowFocusCallback) if (window->windowFocusCallback)
window->windowFocusCallback(window, focused); window->windowFocusCallback(window, focused);
@ -86,7 +86,7 @@ void _glfwInputWindowFocus(_GLFWwindow* window, GLboolean focused)
} }
else else
{ {
if (_glfwLibrary.focusedWindow == window) if (_glfw.focusedWindow == window)
{ {
int i; int i;
@ -104,7 +104,7 @@ void _glfwInputWindowFocus(_GLFWwindow* window, GLboolean focused)
_glfwInputMouseClick(window, i, GLFW_RELEASE); _glfwInputMouseClick(window, i, GLFW_RELEASE);
} }
_glfwLibrary.focusedWindow = NULL; _glfw.focusedWindow = NULL;
if (window->windowFocusCallback) if (window->windowFocusCallback)
window->windowFocusCallback(window, focused); window->windowFocusCallback(window, focused);
@ -225,34 +225,34 @@ GLFWAPI GLFWwindow glfwCreateWindow(int width, int height,
// window hints should be cleared after each call even if it fails // window hints should be cleared after each call even if it fails
// Set up desired framebuffer config // Set up desired framebuffer config
fbconfig.redBits = Max(_glfwLibrary.hints.redBits, 0); fbconfig.redBits = Max(_glfw.hints.redBits, 0);
fbconfig.greenBits = Max(_glfwLibrary.hints.greenBits, 0); fbconfig.greenBits = Max(_glfw.hints.greenBits, 0);
fbconfig.blueBits = Max(_glfwLibrary.hints.blueBits, 0); fbconfig.blueBits = Max(_glfw.hints.blueBits, 0);
fbconfig.alphaBits = Max(_glfwLibrary.hints.alphaBits, 0); fbconfig.alphaBits = Max(_glfw.hints.alphaBits, 0);
fbconfig.depthBits = Max(_glfwLibrary.hints.depthBits, 0); fbconfig.depthBits = Max(_glfw.hints.depthBits, 0);
fbconfig.stencilBits = Max(_glfwLibrary.hints.stencilBits, 0); fbconfig.stencilBits = Max(_glfw.hints.stencilBits, 0);
fbconfig.accumRedBits = Max(_glfwLibrary.hints.accumRedBits, 0); fbconfig.accumRedBits = Max(_glfw.hints.accumRedBits, 0);
fbconfig.accumGreenBits = Max(_glfwLibrary.hints.accumGreenBits, 0); fbconfig.accumGreenBits = Max(_glfw.hints.accumGreenBits, 0);
fbconfig.accumBlueBits = Max(_glfwLibrary.hints.accumBlueBits, 0); fbconfig.accumBlueBits = Max(_glfw.hints.accumBlueBits, 0);
fbconfig.accumAlphaBits = Max(_glfwLibrary.hints.accumAlphaBits, 0); fbconfig.accumAlphaBits = Max(_glfw.hints.accumAlphaBits, 0);
fbconfig.auxBuffers = Max(_glfwLibrary.hints.auxBuffers, 0); fbconfig.auxBuffers = Max(_glfw.hints.auxBuffers, 0);
fbconfig.stereo = _glfwLibrary.hints.stereo ? GL_TRUE : GL_FALSE; fbconfig.stereo = _glfw.hints.stereo ? GL_TRUE : GL_FALSE;
fbconfig.samples = Max(_glfwLibrary.hints.samples, 0); fbconfig.samples = Max(_glfw.hints.samples, 0);
fbconfig.sRGB = _glfwLibrary.hints.sRGB ? GL_TRUE : GL_FALSE; fbconfig.sRGB = _glfw.hints.sRGB ? GL_TRUE : GL_FALSE;
// Set up desired window config // Set up desired window config
wndconfig.title = title; wndconfig.title = title;
wndconfig.resizable = _glfwLibrary.hints.resizable ? GL_TRUE : GL_FALSE; wndconfig.resizable = _glfw.hints.resizable ? GL_TRUE : GL_FALSE;
wndconfig.visible = _glfwLibrary.hints.visible ? GL_TRUE : GL_FALSE; wndconfig.visible = _glfw.hints.visible ? GL_TRUE : GL_FALSE;
wndconfig.positionX = _glfwLibrary.hints.positionX; wndconfig.positionX = _glfw.hints.positionX;
wndconfig.positionY = _glfwLibrary.hints.positionY; wndconfig.positionY = _glfw.hints.positionY;
wndconfig.clientAPI = _glfwLibrary.hints.clientAPI; wndconfig.clientAPI = _glfw.hints.clientAPI;
wndconfig.glMajor = _glfwLibrary.hints.glMajor; wndconfig.glMajor = _glfw.hints.glMajor;
wndconfig.glMinor = _glfwLibrary.hints.glMinor; wndconfig.glMinor = _glfw.hints.glMinor;
wndconfig.glForward = _glfwLibrary.hints.glForward ? GL_TRUE : GL_FALSE; wndconfig.glForward = _glfw.hints.glForward ? GL_TRUE : GL_FALSE;
wndconfig.glDebug = _glfwLibrary.hints.glDebug ? GL_TRUE : GL_FALSE; wndconfig.glDebug = _glfw.hints.glDebug ? GL_TRUE : GL_FALSE;
wndconfig.glProfile = _glfwLibrary.hints.glProfile; wndconfig.glProfile = _glfw.hints.glProfile;
wndconfig.glRobustness = _glfwLibrary.hints.glRobustness; wndconfig.glRobustness = _glfw.hints.glRobustness;
wndconfig.monitor = (_GLFWmonitor*) monitor; wndconfig.monitor = (_GLFWmonitor*) monitor;
wndconfig.share = (_GLFWwindow*) share; wndconfig.share = (_GLFWwindow*) share;
@ -276,8 +276,8 @@ GLFWAPI GLFWwindow glfwCreateWindow(int width, int height,
return NULL; return NULL;
} }
window->next = _glfwLibrary.windowListHead; window->next = _glfw.windowListHead;
_glfwLibrary.windowListHead = window; _glfw.windowListHead = window;
// Remember window settings // Remember window settings
window->width = width; window->width = width;
@ -344,27 +344,27 @@ void glfwDefaultWindowHints(void)
return; return;
} }
memset(&_glfwLibrary.hints, 0, sizeof(_glfwLibrary.hints)); memset(&_glfw.hints, 0, sizeof(_glfw.hints));
// The default is OpenGL with minimum version 1.0 // The default is OpenGL with minimum version 1.0
_glfwLibrary.hints.clientAPI = GLFW_OPENGL_API; _glfw.hints.clientAPI = GLFW_OPENGL_API;
_glfwLibrary.hints.glMajor = 1; _glfw.hints.glMajor = 1;
_glfwLibrary.hints.glMinor = 0; _glfw.hints.glMinor = 0;
// The default is to show the window and allow window resizing // The default is to show the window and allow window resizing
_glfwLibrary.hints.resizable = GL_TRUE; _glfw.hints.resizable = GL_TRUE;
_glfwLibrary.hints.visible = GL_TRUE; _glfw.hints.visible = GL_TRUE;
// The default window position is the upper left corner of the screen // The default window position is the upper left corner of the screen
_glfwLibrary.hints.positionX = 0; _glfw.hints.positionX = 0;
_glfwLibrary.hints.positionY = 0; _glfw.hints.positionY = 0;
// The default is 24 bits of color, 24 bits of depth and 8 bits of stencil // The default is 24 bits of color, 24 bits of depth and 8 bits of stencil
_glfwLibrary.hints.redBits = 8; _glfw.hints.redBits = 8;
_glfwLibrary.hints.greenBits = 8; _glfw.hints.greenBits = 8;
_glfwLibrary.hints.blueBits = 8; _glfw.hints.blueBits = 8;
_glfwLibrary.hints.depthBits = 24; _glfw.hints.depthBits = 24;
_glfwLibrary.hints.stencilBits = 8; _glfw.hints.stencilBits = 8;
} }
@ -383,79 +383,79 @@ GLFWAPI void glfwWindowHint(int target, int hint)
switch (target) switch (target)
{ {
case GLFW_RED_BITS: case GLFW_RED_BITS:
_glfwLibrary.hints.redBits = hint; _glfw.hints.redBits = hint;
break; break;
case GLFW_GREEN_BITS: case GLFW_GREEN_BITS:
_glfwLibrary.hints.greenBits = hint; _glfw.hints.greenBits = hint;
break; break;
case GLFW_BLUE_BITS: case GLFW_BLUE_BITS:
_glfwLibrary.hints.blueBits = hint; _glfw.hints.blueBits = hint;
break; break;
case GLFW_ALPHA_BITS: case GLFW_ALPHA_BITS:
_glfwLibrary.hints.alphaBits = hint; _glfw.hints.alphaBits = hint;
break; break;
case GLFW_DEPTH_BITS: case GLFW_DEPTH_BITS:
_glfwLibrary.hints.depthBits = hint; _glfw.hints.depthBits = hint;
break; break;
case GLFW_STENCIL_BITS: case GLFW_STENCIL_BITS:
_glfwLibrary.hints.stencilBits = hint; _glfw.hints.stencilBits = hint;
break; break;
case GLFW_ACCUM_RED_BITS: case GLFW_ACCUM_RED_BITS:
_glfwLibrary.hints.accumRedBits = hint; _glfw.hints.accumRedBits = hint;
break; break;
case GLFW_ACCUM_GREEN_BITS: case GLFW_ACCUM_GREEN_BITS:
_glfwLibrary.hints.accumGreenBits = hint; _glfw.hints.accumGreenBits = hint;
break; break;
case GLFW_ACCUM_BLUE_BITS: case GLFW_ACCUM_BLUE_BITS:
_glfwLibrary.hints.accumBlueBits = hint; _glfw.hints.accumBlueBits = hint;
break; break;
case GLFW_ACCUM_ALPHA_BITS: case GLFW_ACCUM_ALPHA_BITS:
_glfwLibrary.hints.accumAlphaBits = hint; _glfw.hints.accumAlphaBits = hint;
break; break;
case GLFW_AUX_BUFFERS: case GLFW_AUX_BUFFERS:
_glfwLibrary.hints.auxBuffers = hint; _glfw.hints.auxBuffers = hint;
break; break;
case GLFW_STEREO: case GLFW_STEREO:
_glfwLibrary.hints.stereo = hint; _glfw.hints.stereo = hint;
break; break;
case GLFW_RESIZABLE: case GLFW_RESIZABLE:
_glfwLibrary.hints.resizable = hint; _glfw.hints.resizable = hint;
break; break;
case GLFW_VISIBLE: case GLFW_VISIBLE:
_glfwLibrary.hints.visible = hint; _glfw.hints.visible = hint;
break; break;
case GLFW_POSITION_X: case GLFW_POSITION_X:
_glfwLibrary.hints.positionX = hint; _glfw.hints.positionX = hint;
break; break;
case GLFW_POSITION_Y: case GLFW_POSITION_Y:
_glfwLibrary.hints.positionY = hint; _glfw.hints.positionY = hint;
break; break;
case GLFW_SAMPLES: case GLFW_SAMPLES:
_glfwLibrary.hints.samples = hint; _glfw.hints.samples = hint;
break; break;
case GLFW_SRGB_CAPABLE: case GLFW_SRGB_CAPABLE:
_glfwLibrary.hints.sRGB = hint; _glfw.hints.sRGB = hint;
break; break;
case GLFW_CLIENT_API: case GLFW_CLIENT_API:
_glfwLibrary.hints.clientAPI = hint; _glfw.hints.clientAPI = hint;
break; break;
case GLFW_CONTEXT_VERSION_MAJOR: case GLFW_CONTEXT_VERSION_MAJOR:
_glfwLibrary.hints.glMajor = hint; _glfw.hints.glMajor = hint;
break; break;
case GLFW_CONTEXT_VERSION_MINOR: case GLFW_CONTEXT_VERSION_MINOR:
_glfwLibrary.hints.glMinor = hint; _glfw.hints.glMinor = hint;
break; break;
case GLFW_CONTEXT_ROBUSTNESS: case GLFW_CONTEXT_ROBUSTNESS:
_glfwLibrary.hints.glRobustness = hint; _glfw.hints.glRobustness = hint;
break; break;
case GLFW_OPENGL_FORWARD_COMPAT: case GLFW_OPENGL_FORWARD_COMPAT:
_glfwLibrary.hints.glForward = hint; _glfw.hints.glForward = hint;
break; break;
case GLFW_OPENGL_DEBUG_CONTEXT: case GLFW_OPENGL_DEBUG_CONTEXT:
_glfwLibrary.hints.glDebug = hint; _glfw.hints.glDebug = hint;
break; break;
case GLFW_OPENGL_PROFILE: case GLFW_OPENGL_PROFILE:
_glfwLibrary.hints.glProfile = hint; _glfw.hints.glProfile = hint;
break; break;
default: default:
_glfwInputError(GLFW_INVALID_ENUM, NULL); _glfwInputError(GLFW_INVALID_ENUM, NULL);
@ -502,14 +502,14 @@ GLFWAPI void glfwDestroyWindow(GLFWwindow handle)
_glfwPlatformMakeContextCurrent(NULL); _glfwPlatformMakeContextCurrent(NULL);
// Clear the focused window pointer if this is the focused window // Clear the focused window pointer if this is the focused window
if (window == _glfwLibrary.focusedWindow) if (window == _glfw.focusedWindow)
_glfwLibrary.focusedWindow = NULL; _glfw.focusedWindow = NULL;
_glfwPlatformDestroyWindow(window); _glfwPlatformDestroyWindow(window);
// Unlink window from global linked list // Unlink window from global linked list
{ {
_GLFWwindow** prev = &_glfwLibrary.windowListHead; _GLFWwindow** prev = &_glfw.windowListHead;
while (*prev != window) while (*prev != window)
prev = &((*prev)->next); prev = &((*prev)->next);
@ -690,7 +690,7 @@ GLFWAPI int glfwGetWindowParam(GLFWwindow handle, int param)
switch (param) switch (param)
{ {
case GLFW_FOCUSED: case GLFW_FOCUSED:
return window == _glfwLibrary.focusedWindow; return window == _glfw.focusedWindow;
case GLFW_ICONIFIED: case GLFW_ICONIFIED:
return window->iconified; return window->iconified;
case GLFW_SHOULD_CLOSE: case GLFW_SHOULD_CLOSE:

View File

@ -53,7 +53,7 @@ GLboolean _glfwReadSelection(XSelectionEvent* request)
if (request->property == None) if (request->property == None)
return GL_FALSE; return GL_FALSE;
XGetWindowProperty(_glfwLibrary.X11.display, XGetWindowProperty(_glfw.x11.display,
request->requestor, request->requestor,
request->property, request->property,
0, LONG_MAX, 0, LONG_MAX,
@ -68,8 +68,8 @@ GLboolean _glfwReadSelection(XSelectionEvent* request)
if (actualType == None) if (actualType == None)
return GL_FALSE; return GL_FALSE;
free(_glfwLibrary.X11.selection.string); free(_glfw.x11.selection.string);
_glfwLibrary.X11.selection.string = strdup(data); _glfw.x11.selection.string = strdup(data);
XFree(data); XFree(data);
return GL_TRUE; return GL_TRUE;
@ -86,19 +86,19 @@ Atom _glfwWriteSelection(XSelectionRequestEvent* request)
Atom property = request->property; Atom property = request->property;
if (property == None) if (property == None)
property = _glfwLibrary.X11.selection.property; property = _glfw.x11.selection.property;
if (request->target == _glfwLibrary.X11.selection.targets) if (request->target == _glfw.x11.selection.targets)
{ {
// The list of supported targets was requested // The list of supported targets was requested
XChangeProperty(_glfwLibrary.X11.display, XChangeProperty(_glfw.x11.display,
request->requestor, request->requestor,
property, property,
XA_ATOM, XA_ATOM,
32, 32,
PropModeReplace, PropModeReplace,
(unsigned char*) _glfwLibrary.X11.selection.formats, (unsigned char*) _glfw.x11.selection.formats,
_GLFW_CLIPBOARD_FORMAT_COUNT); _GLFW_CLIPBOARD_FORMAT_COUNT);
return property; return property;
@ -106,18 +106,18 @@ Atom _glfwWriteSelection(XSelectionRequestEvent* request)
for (i = 0; i < _GLFW_CLIPBOARD_FORMAT_COUNT; i++) for (i = 0; i < _GLFW_CLIPBOARD_FORMAT_COUNT; i++)
{ {
if (request->target == _glfwLibrary.X11.selection.formats[i]) if (request->target == _glfw.x11.selection.formats[i])
{ {
// The requested target is one we support // The requested target is one we support
XChangeProperty(_glfwLibrary.X11.display, XChangeProperty(_glfw.x11.display,
request->requestor, request->requestor,
property, property,
request->target, request->target,
8, 8,
PropModeReplace, PropModeReplace,
(unsigned char*) _glfwLibrary.X11.selection.string, (unsigned char*) _glfw.x11.selection.string,
strlen(_glfwLibrary.X11.selection.string)); strlen(_glfw.x11.selection.string));
return property; return property;
} }
@ -138,13 +138,13 @@ Atom _glfwWriteSelection(XSelectionRequestEvent* request)
void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string) void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string)
{ {
// Store the new string in preparation for a selection request event // Store the new string in preparation for a selection request event
free(_glfwLibrary.X11.selection.string); free(_glfw.x11.selection.string);
_glfwLibrary.X11.selection.string = strdup(string); _glfw.x11.selection.string = strdup(string);
// Set the specified window as owner of the selection // Set the specified window as owner of the selection
XSetSelectionOwner(_glfwLibrary.X11.display, XSetSelectionOwner(_glfw.x11.display,
_glfwLibrary.X11.selection.atom, _glfw.x11.selection.atom,
window->X11.handle, CurrentTime); window->x11.handle, CurrentTime);
} }
@ -156,36 +156,35 @@ const char* _glfwPlatformGetClipboardString(_GLFWwindow* window)
{ {
int i; int i;
_glfwLibrary.X11.selection.status = _GLFW_CONVERSION_INACTIVE; _glfw.x11.selection.status = _GLFW_CONVERSION_INACTIVE;
for (i = 0; i < _GLFW_CLIPBOARD_FORMAT_COUNT; i++) for (i = 0; i < _GLFW_CLIPBOARD_FORMAT_COUNT; i++)
{ {
// Request conversion to the selected format // Request conversion to the selected format
_glfwLibrary.X11.selection.target = _glfw.x11.selection.target = _glfw.x11.selection.formats[i];
_glfwLibrary.X11.selection.formats[i];
XConvertSelection(_glfwLibrary.X11.display, XConvertSelection(_glfw.x11.display,
_glfwLibrary.X11.selection.atom, _glfw.x11.selection.atom,
_glfwLibrary.X11.selection.target, _glfw.x11.selection.target,
_glfwLibrary.X11.selection.property, _glfw.x11.selection.property,
window->X11.handle, CurrentTime); window->x11.handle, CurrentTime);
// Process the resulting SelectionNotify event // Process the resulting SelectionNotify event
XSync(_glfwLibrary.X11.display, False); XSync(_glfw.x11.display, False);
while (_glfwLibrary.X11.selection.status == _GLFW_CONVERSION_INACTIVE) while (_glfw.x11.selection.status == _GLFW_CONVERSION_INACTIVE)
_glfwPlatformWaitEvents(); _glfwPlatformWaitEvents();
if (_glfwLibrary.X11.selection.status == _GLFW_CONVERSION_SUCCEEDED) if (_glfw.x11.selection.status == _GLFW_CONVERSION_SUCCEEDED)
break; break;
} }
if (_glfwLibrary.X11.selection.status == _GLFW_CONVERSION_FAILED) if (_glfw.x11.selection.status == _GLFW_CONVERSION_FAILED)
{ {
_glfwInputError(GLFW_FORMAT_UNAVAILABLE, _glfwInputError(GLFW_FORMAT_UNAVAILABLE,
"X11: Failed to convert selection to string"); "X11: Failed to convert selection to string");
return NULL; return NULL;
} }
return _glfwLibrary.X11.selection.string; return _glfw.x11.selection.string;
} }

View File

@ -45,25 +45,25 @@ void _glfwInitGammaRamp(void)
{ {
#ifdef _GLFW_HAS_XRANDR #ifdef _GLFW_HAS_XRANDR
// RandR gamma support is only available with version 1.2 and above // RandR gamma support is only available with version 1.2 and above
if (_glfwLibrary.X11.RandR.available && if (_glfw.x11.randr.available &&
(_glfwLibrary.X11.RandR.majorVersion > 1 || (_glfw.x11.randr.versionMajor > 1 ||
(_glfwLibrary.X11.RandR.majorVersion == 1 && (_glfw.x11.randr.versionMajor == 1 &&
_glfwLibrary.X11.RandR.minorVersion >= 2))) _glfw.x11.randr.versionMinor >= 2)))
{ {
// FIXME: Assumes that all monitors have the same size gamma tables // FIXME: Assumes that all monitors have the same size gamma tables
// This is reasonable as I suspect the that if they did differ, it // This is reasonable as I suspect the that if they did differ, it
// would imply that setting the gamma size to an arbitary size is // would imply that setting the gamma size to an arbitary size is
// possible as well. // possible as well.
XRRScreenResources* rr = XRRGetScreenResources(_glfwLibrary.X11.display, XRRScreenResources* rr = XRRGetScreenResources(_glfw.x11.display,
_glfwLibrary.X11.root); _glfw.x11.root);
_glfwLibrary.originalRampSize = XRRGetCrtcGammaSize(_glfwLibrary.X11.display, _glfw.originalRampSize = XRRGetCrtcGammaSize(_glfw.x11.display,
rr->crtcs[0]); rr->crtcs[0]);
if (_glfwLibrary.originalRampSize == 0) if (_glfw.originalRampSize == 0)
{ {
// This is probably older Nvidia RandR with broken gamma support // This is probably older Nvidia RandR with broken gamma support
// Flag it as useless and try Xf86VidMode below, if available // Flag it as useless and try Xf86VidMode below, if available
_glfwLibrary.X11.RandR.gammaBroken = GL_TRUE; _glfw.x11.randr.gammaBroken = GL_TRUE;
} }
XRRFreeScreenResources(rr); XRRFreeScreenResources(rr);
@ -71,21 +71,20 @@ void _glfwInitGammaRamp(void)
#endif /*_GLFW_HAS_XRANDR*/ #endif /*_GLFW_HAS_XRANDR*/
#if defined(_GLFW_HAS_XF86VIDMODE) #if defined(_GLFW_HAS_XF86VIDMODE)
if (_glfwLibrary.X11.VidMode.available && if (_glfw.x11.vidmode.available && !_glfw.originalRampSize)
!_glfwLibrary.originalRampSize)
{ {
// Get the gamma size using XF86VidMode // Get the gamma size using XF86VidMode
XF86VidModeGetGammaRampSize(_glfwLibrary.X11.display, XF86VidModeGetGammaRampSize(_glfw.x11.display,
_glfwLibrary.X11.screen, _glfw.x11.screen,
&_glfwLibrary.originalRampSize); &_glfw.originalRampSize);
} }
#endif /*_GLFW_HAS_XF86VIDMODE*/ #endif /*_GLFW_HAS_XF86VIDMODE*/
if (_glfwLibrary.originalRampSize) if (_glfw.originalRampSize)
{ {
// Save the original gamma ramp // Save the original gamma ramp
_glfwPlatformGetGammaRamp(&_glfwLibrary.originalRamp); _glfwPlatformGetGammaRamp(&_glfw.originalRamp);
_glfwLibrary.currentRamp = _glfwLibrary.originalRamp; _glfw.currentRamp = _glfw.originalRamp;
} }
} }
@ -96,8 +95,8 @@ void _glfwInitGammaRamp(void)
void _glfwTerminateGammaRamp(void) void _glfwTerminateGammaRamp(void)
{ {
if (_glfwLibrary.originalRampSize && _glfwLibrary.rampChanged) if (_glfw.originalRampSize && _glfw.rampChanged)
_glfwPlatformSetGammaRamp(&_glfwLibrary.originalRamp); _glfwPlatformSetGammaRamp(&_glfw.originalRamp);
} }
@ -112,7 +111,7 @@ void _glfwTerminateGammaRamp(void)
void _glfwPlatformGetGammaRamp(GLFWgammaramp* ramp) void _glfwPlatformGetGammaRamp(GLFWgammaramp* ramp)
{ {
// For now, don't support anything that is not GLFW_GAMMA_RAMP_SIZE // For now, don't support anything that is not GLFW_GAMMA_RAMP_SIZE
if (_glfwLibrary.originalRampSize != GLFW_GAMMA_RAMP_SIZE) if (_glfw.originalRampSize != GLFW_GAMMA_RAMP_SIZE)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,
"X11: Failed to get gamma ramp due to size " "X11: Failed to get gamma ramp due to size "
@ -120,16 +119,15 @@ void _glfwPlatformGetGammaRamp(GLFWgammaramp* ramp)
return; return;
} }
if (_glfwLibrary.X11.RandR.available && if (_glfw.x11.randr.available && !_glfw.x11.randr.gammaBroken)
!_glfwLibrary.X11.RandR.gammaBroken)
{ {
#if defined (_GLFW_HAS_XRANDR) #if defined (_GLFW_HAS_XRANDR)
size_t size = GLFW_GAMMA_RAMP_SIZE * sizeof(unsigned short); size_t size = GLFW_GAMMA_RAMP_SIZE * sizeof(unsigned short);
XRRScreenResources* rr = XRRGetScreenResources(_glfwLibrary.X11.display, XRRScreenResources* rr = XRRGetScreenResources(_glfw.x11.display,
_glfwLibrary.X11.root); _glfw.x11.root);
XRRCrtcGamma* gamma = XRRGetCrtcGamma(_glfwLibrary.X11.display, XRRCrtcGamma* gamma = XRRGetCrtcGamma(_glfw.x11.display,
rr->crtcs[0]); rr->crtcs[0]);
// TODO: Handle case of original ramp size having a size other than 256 // TODO: Handle case of original ramp size having a size other than 256
@ -142,11 +140,11 @@ void _glfwPlatformGetGammaRamp(GLFWgammaramp* ramp)
XRRFreeScreenResources(rr); XRRFreeScreenResources(rr);
#endif /*_GLFW_HAS_XRANDR*/ #endif /*_GLFW_HAS_XRANDR*/
} }
else if (_glfwLibrary.X11.VidMode.available) else if (_glfw.x11.vidmode.available)
{ {
#if defined (_GLFW_HAS_XF86VIDMODE) #if defined (_GLFW_HAS_XF86VIDMODE)
XF86VidModeGetGammaRamp(_glfwLibrary.X11.display, XF86VidModeGetGammaRamp(_glfw.x11.display,
_glfwLibrary.X11.screen, _glfw.x11.screen,
GLFW_GAMMA_RAMP_SIZE, GLFW_GAMMA_RAMP_SIZE,
ramp->red, ramp->red,
ramp->green, ramp->green,
@ -163,7 +161,7 @@ void _glfwPlatformGetGammaRamp(GLFWgammaramp* ramp)
void _glfwPlatformSetGammaRamp(const GLFWgammaramp* ramp) void _glfwPlatformSetGammaRamp(const GLFWgammaramp* ramp)
{ {
// For now, don't support anything that is not GLFW_GAMMA_RAMP_SIZE // For now, don't support anything that is not GLFW_GAMMA_RAMP_SIZE
if (_glfwLibrary.originalRampSize != GLFW_GAMMA_RAMP_SIZE) if (_glfw.originalRampSize != GLFW_GAMMA_RAMP_SIZE)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,
"X11: Failed to set gamma ramp due to size " "X11: Failed to set gamma ramp due to size "
@ -171,15 +169,14 @@ void _glfwPlatformSetGammaRamp(const GLFWgammaramp* ramp)
return; return;
} }
if (_glfwLibrary.X11.RandR.available && if (_glfw.x11.randr.available && !_glfw.x11.randr.gammaBroken)
!_glfwLibrary.X11.RandR.gammaBroken)
{ {
#if defined (_GLFW_HAS_XRANDR) #if defined (_GLFW_HAS_XRANDR)
int i; int i;
size_t size = GLFW_GAMMA_RAMP_SIZE * sizeof(unsigned short); size_t size = GLFW_GAMMA_RAMP_SIZE * sizeof(unsigned short);
XRRScreenResources* rr = XRRGetScreenResources(_glfwLibrary.X11.display, XRRScreenResources* rr = XRRGetScreenResources(_glfw.x11.display,
_glfwLibrary.X11.root); _glfw.x11.root);
// Update gamma per monitor // Update gamma per monitor
for (i = 0; i < rr->ncrtc; i++) for (i = 0; i < rr->ncrtc; i++)
@ -190,18 +187,18 @@ void _glfwPlatformSetGammaRamp(const GLFWgammaramp* ramp)
memcpy(gamma->green, ramp->green, size); memcpy(gamma->green, ramp->green, size);
memcpy(gamma->blue, ramp->blue, size); memcpy(gamma->blue, ramp->blue, size);
XRRSetCrtcGamma(_glfwLibrary.X11.display, rr->crtcs[i], gamma); XRRSetCrtcGamma(_glfw.x11.display, rr->crtcs[i], gamma);
XRRFreeGamma(gamma); XRRFreeGamma(gamma);
} }
XRRFreeScreenResources(rr); XRRFreeScreenResources(rr);
#endif /*_GLFW_HAS_XRANDR*/ #endif /*_GLFW_HAS_XRANDR*/
} }
else if (_glfwLibrary.X11.VidMode.available) else if (_glfw.x11.vidmode.available)
{ {
#if defined (_GLFW_HAS_XF86VIDMODE) #if defined (_GLFW_HAS_XF86VIDMODE)
XF86VidModeSetGammaRamp(_glfwLibrary.X11.display, XF86VidModeSetGammaRamp(_glfw.x11.display,
_glfwLibrary.X11.screen, _glfw.x11.screen,
GLFW_GAMMA_RAMP_SIZE, GLFW_GAMMA_RAMP_SIZE,
(unsigned short*) ramp->red, (unsigned short*) ramp->red,
(unsigned short*) ramp->green, (unsigned short*) ramp->green,

View File

@ -52,9 +52,9 @@ static int keyCodeToGLFWKeyCode(int keyCode)
// since the returned key code should correspond to a physical // since the returned key code should correspond to a physical
// location. // location.
#if defined(_GLFW_HAS_XKB) #if defined(_GLFW_HAS_XKB)
keySym = XkbKeycodeToKeysym(_glfwLibrary.X11.display, keyCode, 1, 0); keySym = XkbKeycodeToKeysym(_glfw.x11.display, keyCode, 1, 0);
#else #else
keySym = XKeycodeToKeysym(_glfwLibrary.X11.display, keyCode, 1); keySym = XKeycodeToKeysym(_glfw.x11.display, keyCode, 1);
#endif #endif
switch (keySym) switch (keySym)
{ {
@ -79,9 +79,9 @@ static int keyCodeToGLFWKeyCode(int keyCode)
// should not be layout dependent (i.e. US layout and international // should not be layout dependent (i.e. US layout and international
// layouts should give the same result). // layouts should give the same result).
#if defined(_GLFW_HAS_XKB) #if defined(_GLFW_HAS_XKB)
keySym = XkbKeycodeToKeysym(_glfwLibrary.X11.display, keyCode, 0, 0); keySym = XkbKeycodeToKeysym(_glfw.x11.display, keyCode, 0, 0);
#else #else
keySym = XKeycodeToKeysym(_glfwLibrary.X11.display, keyCode, 0); keySym = XKeycodeToKeysym(_glfw.x11.display, keyCode, 0);
#endif #endif
switch (keySym) switch (keySym)
@ -234,19 +234,19 @@ static void updateKeyCodeLUT(void)
// Clear the LUT // Clear the LUT
for (keyCode = 0; keyCode < 256; keyCode++) for (keyCode = 0; keyCode < 256; keyCode++)
_glfwLibrary.X11.keyCodeLUT[keyCode] = -1; _glfw.x11.keyCodeLUT[keyCode] = -1;
#if defined(_GLFW_HAS_XKB) #if defined(_GLFW_HAS_XKB)
// If the Xkb extension is available, use it to determine physical key // If the Xkb extension is available, use it to determine physical key
// locations independently of the current keyboard layout // locations independently of the current keyboard layout
if (_glfwLibrary.X11.Xkb.available) if (_glfw.x11.xkb.available)
{ {
int i, keyCodeGLFW; int i, keyCodeGLFW;
char name[XkbKeyNameLength + 1]; char name[XkbKeyNameLength + 1];
XkbDescPtr descr; XkbDescPtr descr;
// Get keyboard description // Get keyboard description
descr = XkbGetKeyboard(_glfwLibrary.X11.display, descr = XkbGetKeyboard(_glfw.x11.display,
XkbAllComponentsMask, XkbAllComponentsMask,
XkbUseCoreKbd); XkbUseCoreKbd);
@ -315,7 +315,7 @@ static void updateKeyCodeLUT(void)
// Update the key code LUT // Update the key code LUT
if ((keyCode >= 0) && (keyCode < 256)) if ((keyCode >= 0) && (keyCode < 256))
_glfwLibrary.X11.keyCodeLUT[keyCode] = keyCodeGLFW; _glfw.x11.keyCodeLUT[keyCode] = keyCodeGLFW;
} }
// Free the keyboard description // Free the keyboard description
@ -327,11 +327,8 @@ static void updateKeyCodeLUT(void)
// lookups // lookups
for (keyCode = 0; keyCode < 256; keyCode++) for (keyCode = 0; keyCode < 256; keyCode++)
{ {
if (_glfwLibrary.X11.keyCodeLUT[keyCode] < 0) if (_glfw.x11.keyCodeLUT[keyCode] < 0)
{ _glfw.x11.keyCodeLUT[keyCode] = keyCodeToGLFWKeyCode(keyCode);
_glfwLibrary.X11.keyCodeLUT[keyCode] =
keyCodeToGLFWKeyCode(keyCode);
}
} }
} }
@ -350,7 +347,7 @@ static unsigned long getWindowProperty(Window window,
int actualFormat; int actualFormat;
unsigned long itemCount, bytesAfter; unsigned long itemCount, bytesAfter;
XGetWindowProperty(_glfwLibrary.X11.display, XGetWindowProperty(_glfw.x11.display,
window, window,
property, property,
0, 0,
@ -378,7 +375,7 @@ static Atom getSupportedAtom(Atom* supportedAtoms,
unsigned long atomCount, unsigned long atomCount,
const char* atomName) const char* atomName)
{ {
Atom atom = XInternAtom(_glfwLibrary.X11.display, atomName, True); Atom atom = XInternAtom(_glfw.x11.display, atomName, True);
if (atom != None) if (atom != None)
{ {
unsigned long i; unsigned long i;
@ -405,14 +402,14 @@ static void initEWMH(void)
// First we need a couple of atoms, which should already be there // First we need a couple of atoms, which should already be there
Atom supportingWmCheck = Atom supportingWmCheck =
XInternAtom(_glfwLibrary.X11.display, "_NET_SUPPORTING_WM_CHECK", True); XInternAtom(_glfw.x11.display, "_NET_SUPPORTING_WM_CHECK", True);
Atom wmSupported = Atom wmSupported =
XInternAtom(_glfwLibrary.X11.display, "_NET_SUPPORTED", True); XInternAtom(_glfw.x11.display, "_NET_SUPPORTED", True);
if (supportingWmCheck == None || wmSupported == None) if (supportingWmCheck == None || wmSupported == None)
return; return;
// Then we look for the _NET_SUPPORTING_WM_CHECK property of the root window // Then we look for the _NET_SUPPORTING_WM_CHECK property of the root window
if (getWindowProperty(_glfwLibrary.X11.root, if (getWindowProperty(_glfw.x11.root,
supportingWmCheck, supportingWmCheck,
XA_WINDOW, XA_WINDOW,
(unsigned char**) &windowFromRoot) != 1) (unsigned char**) &windowFromRoot) != 1)
@ -451,34 +448,34 @@ static void initEWMH(void)
// Now we need to check the _NET_SUPPORTED property of the root window // Now we need to check the _NET_SUPPORTED property of the root window
// It should be a list of supported WM protocol and state atoms // It should be a list of supported WM protocol and state atoms
atomCount = getWindowProperty(_glfwLibrary.X11.root, atomCount = getWindowProperty(_glfw.x11.root,
wmSupported, wmSupported,
XA_ATOM, XA_ATOM,
(unsigned char**) &supportedAtoms); (unsigned char**) &supportedAtoms);
// See which of the atoms we support that are supported by the WM // See which of the atoms we support that are supported by the WM
_glfwLibrary.X11.wmState = _glfw.x11.wmState =
getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_STATE"); getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_STATE");
_glfwLibrary.X11.wmStateFullscreen = _glfw.x11.wmStateFullscreen =
getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_STATE_FULLSCREEN"); getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_STATE_FULLSCREEN");
_glfwLibrary.X11.wmName = _glfw.x11.wmName =
getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_NAME"); getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_NAME");
_glfwLibrary.X11.wmIconName = _glfw.x11.wmIconName =
getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_ICON_NAME"); getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_ICON_NAME");
_glfwLibrary.X11.wmPing = _glfw.x11.wmPing =
getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_PING"); getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_PING");
_glfwLibrary.X11.wmActiveWindow = _glfw.x11.wmActiveWindow =
getSupportedAtom(supportedAtoms, atomCount, "_NET_ACTIVE_WINDOW"); getSupportedAtom(supportedAtoms, atomCount, "_NET_ACTIVE_WINDOW");
XFree(supportedAtoms); XFree(supportedAtoms);
_glfwLibrary.X11.hasEWMH = GL_TRUE; _glfw.x11.hasEWMH = GL_TRUE;
} }
@ -488,8 +485,8 @@ static void initEWMH(void)
static GLboolean initDisplay(void) static GLboolean initDisplay(void)
{ {
_glfwLibrary.X11.display = XOpenDisplay(NULL); _glfw.x11.display = XOpenDisplay(NULL);
if (!_glfwLibrary.X11.display) if (!_glfw.x11.display)
{ {
_glfwInputError(GLFW_API_UNAVAILABLE, "X11: Failed to open X display"); _glfwInputError(GLFW_API_UNAVAILABLE, "X11: Failed to open X display");
return GL_FALSE; return GL_FALSE;
@ -497,32 +494,31 @@ static GLboolean initDisplay(void)
// As the API currently doesn't understand multiple display devices, we hard-code // As the API currently doesn't understand multiple display devices, we hard-code
// this choice and hope for the best // this choice and hope for the best
_glfwLibrary.X11.screen = DefaultScreen(_glfwLibrary.X11.display); _glfw.x11.screen = DefaultScreen(_glfw.x11.display);
_glfwLibrary.X11.root = RootWindow(_glfwLibrary.X11.display, _glfw.x11.root = RootWindow(_glfw.x11.display, _glfw.x11.screen);
_glfwLibrary.X11.screen);
// Check for XF86VidMode extension // Check for XF86VidMode extension
#ifdef _GLFW_HAS_XF86VIDMODE #ifdef _GLFW_HAS_XF86VIDMODE
_glfwLibrary.X11.VidMode.available = _glfw.x11.vidmode.available =
XF86VidModeQueryExtension(_glfwLibrary.X11.display, XF86VidModeQueryExtension(_glfw.x11.display,
&_glfwLibrary.X11.VidMode.eventBase, &_glfw.x11.vidmode.eventBase,
&_glfwLibrary.X11.VidMode.errorBase); &_glfw.x11.vidmode.errorBase);
#else #else
_glfwLibrary.X11.VidMode.available = GL_FALSE; _glfw.x11.vidmode.available = GL_FALSE;
#endif /*_GLFW_HAS_XF86VIDMODE*/ #endif /*_GLFW_HAS_XF86VIDMODE*/
// Check for XRandR extension // Check for XRandR extension
#ifdef _GLFW_HAS_XRANDR #ifdef _GLFW_HAS_XRANDR
_glfwLibrary.X11.RandR.available = _glfw.x11.randr.available =
XRRQueryExtension(_glfwLibrary.X11.display, XRRQueryExtension(_glfw.x11.display,
&_glfwLibrary.X11.RandR.eventBase, &_glfw.x11.randr.eventBase,
&_glfwLibrary.X11.RandR.errorBase); &_glfw.x11.randr.errorBase);
if (_glfwLibrary.X11.RandR.available) if (_glfw.x11.randr.available)
{ {
if (!XRRQueryVersion(_glfwLibrary.X11.display, if (!XRRQueryVersion(_glfw.x11.display,
&_glfwLibrary.X11.RandR.majorVersion, &_glfw.x11.randr.versionMajor,
&_glfwLibrary.X11.RandR.minorVersion)) &_glfw.x11.randr.versionMinor))
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,
"X11: Failed to query RandR version"); "X11: Failed to query RandR version");
@ -530,22 +526,22 @@ static GLboolean initDisplay(void)
} }
} }
#else #else
_glfwLibrary.X11.RandR.available = GL_FALSE; _glfw.x11.randr.available = GL_FALSE;
#endif /*_GLFW_HAS_XRANDR*/ #endif /*_GLFW_HAS_XRANDR*/
// Check if Xkb is supported on this display // Check if Xkb is supported on this display
#if defined(_GLFW_HAS_XKB) #if defined(_GLFW_HAS_XKB)
_glfwLibrary.X11.Xkb.majorVersion = 1; _glfw.x11.xkb.versionMajor = 1;
_glfwLibrary.X11.Xkb.minorVersion = 0; _glfw.x11.xkb.versionMinor = 0;
_glfwLibrary.X11.Xkb.available = _glfw.x11.xkb.available =
XkbQueryExtension(_glfwLibrary.X11.display, XkbQueryExtension(_glfw.x11.display,
&_glfwLibrary.X11.Xkb.majorOpcode, &_glfw.x11.xkb.majorOpcode,
&_glfwLibrary.X11.Xkb.eventBase, &_glfw.x11.xkb.eventBase,
&_glfwLibrary.X11.Xkb.errorBase, &_glfw.x11.xkb.errorBase,
&_glfwLibrary.X11.Xkb.majorVersion, &_glfw.x11.xkb.versionMajor,
&_glfwLibrary.X11.Xkb.minorVersion); &_glfw.x11.xkb.versionMinor);
#else #else
_glfwLibrary.X11.Xkb.available = GL_FALSE; _glfw.x11.xkb.available = GL_FALSE;
#endif /* _GLFW_HAS_XKB */ #endif /* _GLFW_HAS_XKB */
// Update the key code LUT // Update the key code LUT
@ -554,24 +550,24 @@ static GLboolean initDisplay(void)
updateKeyCodeLUT(); updateKeyCodeLUT();
// Find or create selection property atom // Find or create selection property atom
_glfwLibrary.X11.selection.property = _glfw.x11.selection.property =
XInternAtom(_glfwLibrary.X11.display, "GLFW_SELECTION", False); XInternAtom(_glfw.x11.display, "GLFW_SELECTION", False);
// Find or create clipboard atom // Find or create clipboard atom
_glfwLibrary.X11.selection.atom = _glfw.x11.selection.atom =
XInternAtom(_glfwLibrary.X11.display, "CLIPBOARD", False); XInternAtom(_glfw.x11.display, "CLIPBOARD", False);
// Find or create selection target atoms // Find or create selection target atoms
_glfwLibrary.X11.selection.formats[_GLFW_CLIPBOARD_FORMAT_UTF8] = _glfw.x11.selection.formats[_GLFW_CLIPBOARD_FORMAT_UTF8] =
XInternAtom(_glfwLibrary.X11.display, "UTF8_STRING", False); XInternAtom(_glfw.x11.display, "UTF8_STRING", False);
_glfwLibrary.X11.selection.formats[_GLFW_CLIPBOARD_FORMAT_COMPOUND] = _glfw.x11.selection.formats[_GLFW_CLIPBOARD_FORMAT_COMPOUND] =
XInternAtom(_glfwLibrary.X11.display, "COMPOUND_STRING", False); XInternAtom(_glfw.x11.display, "COMPOUND_STRING", False);
_glfwLibrary.X11.selection.formats[_GLFW_CLIPBOARD_FORMAT_STRING] = _glfw.x11.selection.formats[_GLFW_CLIPBOARD_FORMAT_STRING] =
XA_STRING; XA_STRING;
_glfwLibrary.X11.selection.targets = XInternAtom(_glfwLibrary.X11.display, _glfw.x11.selection.targets = XInternAtom(_glfw.x11.display,
"TARGETS", "TARGETS",
False); False);
return GL_TRUE; return GL_TRUE;
} }
@ -591,20 +587,18 @@ static Cursor createNULLCursor(void)
// TODO: Add error checks // TODO: Add error checks
cursormask = XCreatePixmap(_glfwLibrary.X11.display, cursormask = XCreatePixmap(_glfw.x11.display, _glfw.x11.root, 1, 1, 1);
_glfwLibrary.X11.root,
1, 1, 1);
xgc.function = GXclear; xgc.function = GXclear;
gc = XCreateGC(_glfwLibrary.X11.display, cursormask, GCFunction, &xgc); gc = XCreateGC(_glfw.x11.display, cursormask, GCFunction, &xgc);
XFillRectangle(_glfwLibrary.X11.display, cursormask, gc, 0, 0, 1, 1); XFillRectangle(_glfw.x11.display, cursormask, gc, 0, 0, 1, 1);
col.pixel = 0; col.pixel = 0;
col.red = 0; col.red = 0;
col.flags = 4; col.flags = 4;
cursor = XCreatePixmapCursor(_glfwLibrary.X11.display, cursor = XCreatePixmapCursor(_glfw.x11.display,
cursormask, cursormask, cursormask, cursormask,
&col, &col, 0, 0); &col, &col, 0, 0);
XFreePixmap(_glfwLibrary.X11.display, cursormask); XFreePixmap(_glfw.x11.display, cursormask);
XFreeGC(_glfwLibrary.X11.display, gc); XFreeGC(_glfw.x11.display, gc);
return cursor; return cursor;
} }
@ -616,10 +610,10 @@ static Cursor createNULLCursor(void)
static void terminateDisplay(void) static void terminateDisplay(void)
{ {
if (_glfwLibrary.X11.display) if (_glfw.x11.display)
{ {
XCloseDisplay(_glfwLibrary.X11.display); XCloseDisplay(_glfw.x11.display);
_glfwLibrary.X11.display = NULL; _glfw.x11.display = NULL;
} }
} }
@ -646,7 +640,7 @@ int _glfwPlatformInit(void)
initEWMH(); initEWMH();
_glfwLibrary.X11.cursor = createNULLCursor(); _glfw.x11.cursor = createNULLCursor();
if (!_glfwInitJoysticks()) if (!_glfwInitJoysticks())
return GL_FALSE; return GL_FALSE;
@ -664,10 +658,10 @@ int _glfwPlatformInit(void)
void _glfwPlatformTerminate(void) void _glfwPlatformTerminate(void)
{ {
if (_glfwLibrary.X11.cursor) if (_glfw.x11.cursor)
{ {
XFreeCursor(_glfwLibrary.X11.display, _glfwLibrary.X11.cursor); XFreeCursor(_glfw.x11.display, _glfw.x11.cursor);
_glfwLibrary.X11.cursor = (Cursor) 0; _glfw.x11.cursor = (Cursor) 0;
} }
_glfwTerminateGammaRamp(); _glfwTerminateGammaRamp();
@ -679,8 +673,8 @@ void _glfwPlatformTerminate(void)
terminateDisplay(); terminateDisplay();
// Free clipboard memory // Free clipboard memory
if (_glfwLibrary.X11.selection.string) if (_glfw.x11.selection.string)
free(_glfwLibrary.X11.selection.string); free(_glfw.x11.selection.string);
} }

View File

@ -60,7 +60,7 @@ static int openJoystickDevice(int joy, const char* path)
if (fd == -1) if (fd == -1)
return GL_FALSE; return GL_FALSE;
_glfwLibrary.X11.joystick[joy].fd = fd; _glfw.x11.joystick[joy].fd = fd;
// Verify that the joystick driver version is at least 1.0 // Verify that the joystick driver version is at least 1.0
ioctl(fd, JSIOCGVERSION, &version); ioctl(fd, JSIOCGVERSION, &version);
@ -74,17 +74,16 @@ static int openJoystickDevice(int joy, const char* path)
if (ioctl(fd, JSIOCGNAME(sizeof(name)), name) < 0) if (ioctl(fd, JSIOCGNAME(sizeof(name)), name) < 0)
strncpy(name, "Unknown", sizeof(name)); strncpy(name, "Unknown", sizeof(name));
_glfwLibrary.X11.joystick[joy].name = strdup(name); _glfw.x11.joystick[joy].name = strdup(name);
ioctl(fd, JSIOCGAXES, &numAxes); ioctl(fd, JSIOCGAXES, &numAxes);
_glfwLibrary.X11.joystick[joy].numAxes = (int) numAxes; _glfw.x11.joystick[joy].numAxes = (int) numAxes;
ioctl(fd, JSIOCGBUTTONS, &numButtons); ioctl(fd, JSIOCGBUTTONS, &numButtons);
_glfwLibrary.X11.joystick[joy].numButtons = (int) numButtons; _glfw.x11.joystick[joy].numButtons = (int) numButtons;
_glfwLibrary.X11.joystick[joy].axis = _glfw.x11.joystick[joy].axis = (float*) malloc(sizeof(float) * numAxes);
(float*) malloc(sizeof(float) * numAxes); if (_glfw.x11.joystick[joy].axis == NULL)
if (_glfwLibrary.X11.joystick[joy].axis == NULL)
{ {
close(fd); close(fd);
@ -92,18 +91,17 @@ static int openJoystickDevice(int joy, const char* path)
return GL_FALSE; return GL_FALSE;
} }
_glfwLibrary.X11.joystick[joy].button = _glfw.x11.joystick[joy].button = (unsigned char*) malloc(numButtons);
(unsigned char*) malloc(sizeof(char) * numButtons); if (_glfw.x11.joystick[joy].button == NULL)
if (_glfwLibrary.X11.joystick[joy].button == NULL)
{ {
free(_glfwLibrary.X11.joystick[joy].axis); free(_glfw.x11.joystick[joy].axis);
close(fd); close(fd);
_glfwInputError(GLFW_OUT_OF_MEMORY, NULL); _glfwInputError(GLFW_OUT_OF_MEMORY, NULL);
return GL_FALSE; return GL_FALSE;
} }
_glfwLibrary.X11.joystick[joy].present = GL_TRUE; _glfw.x11.joystick[joy].present = GL_TRUE;
#endif // __linux__ #endif // __linux__
return GL_TRUE; return GL_TRUE;
@ -123,17 +121,17 @@ static void pollJoystickEvents(void)
for (i = 0; i <= GLFW_JOYSTICK_LAST; i++) for (i = 0; i <= GLFW_JOYSTICK_LAST; i++)
{ {
if (!_glfwLibrary.X11.joystick[i].present) if (!_glfw.x11.joystick[i].present)
continue; continue;
// Read all queued events (non-blocking) // Read all queued events (non-blocking)
for (;;) for (;;)
{ {
errno = 0; errno = 0;
result = read(_glfwLibrary.X11.joystick[i].fd, &e, sizeof(e)); result = read(_glfw.x11.joystick[i].fd, &e, sizeof(e));
if (errno == ENODEV) if (errno == ENODEV)
_glfwLibrary.X11.joystick[i].present = GL_FALSE; _glfw.x11.joystick[i].present = GL_FALSE;
if (result == -1) if (result == -1)
break; break;
@ -144,21 +142,21 @@ static void pollJoystickEvents(void)
switch (e.type) switch (e.type)
{ {
case JS_EVENT_AXIS: case JS_EVENT_AXIS:
_glfwLibrary.X11.joystick[i].axis[e.number] = _glfw.x11.joystick[i].axis[e.number] =
(float) e.value / 32767.0f; (float) e.value / 32767.0f;
// We need to change the sign for the Y axes, so that // We need to change the sign for the Y axes, so that
// positive = up/forward, according to the GLFW spec. // positive = up/forward, according to the GLFW spec.
if (e.number & 1) if (e.number & 1)
{ {
_glfwLibrary.X11.joystick[i].axis[e.number] = _glfw.x11.joystick[i].axis[e.number] =
-_glfwLibrary.X11.joystick[i].axis[e.number]; -_glfw.x11.joystick[i].axis[e.number];
} }
break; break;
case JS_EVENT_BUTTON: case JS_EVENT_BUTTON:
_glfwLibrary.X11.joystick[i].button[e.number] = _glfw.x11.joystick[i].button[e.number] =
e.value ? GLFW_PRESS : GLFW_RELEASE; e.value ? GLFW_PRESS : GLFW_RELEASE;
break; break;
@ -239,14 +237,14 @@ void _glfwTerminateJoysticks(void)
for (i = 0; i <= GLFW_JOYSTICK_LAST; i++) for (i = 0; i <= GLFW_JOYSTICK_LAST; i++)
{ {
if (_glfwLibrary.X11.joystick[i].present) if (_glfw.x11.joystick[i].present)
{ {
close(_glfwLibrary.X11.joystick[i].fd); close(_glfw.x11.joystick[i].fd);
free(_glfwLibrary.X11.joystick[i].axis); free(_glfw.x11.joystick[i].axis);
free(_glfwLibrary.X11.joystick[i].button); free(_glfw.x11.joystick[i].button);
free(_glfwLibrary.X11.joystick[i].name); free(_glfw.x11.joystick[i].name);
_glfwLibrary.X11.joystick[i].present = GL_FALSE; _glfw.x11.joystick[i].present = GL_FALSE;
} }
} }
#endif // __linux__ #endif // __linux__
@ -265,7 +263,7 @@ int _glfwPlatformGetJoystickParam(int joy, int param)
{ {
pollJoystickEvents(); pollJoystickEvents();
if (!_glfwLibrary.X11.joystick[joy].present) if (!_glfw.x11.joystick[joy].present)
return 0; return 0;
switch (param) switch (param)
@ -274,10 +272,10 @@ int _glfwPlatformGetJoystickParam(int joy, int param)
return GL_TRUE; return GL_TRUE;
case GLFW_AXES: case GLFW_AXES:
return _glfwLibrary.X11.joystick[joy].numAxes; return _glfw.x11.joystick[joy].numAxes;
case GLFW_BUTTONS: case GLFW_BUTTONS:
return _glfwLibrary.X11.joystick[joy].numButtons; return _glfw.x11.joystick[joy].numButtons;
default: default:
_glfwInputError(GLFW_INVALID_ENUM, NULL); _glfwInputError(GLFW_INVALID_ENUM, NULL);
@ -297,14 +295,14 @@ int _glfwPlatformGetJoystickAxes(int joy, float* axes, int numAxes)
pollJoystickEvents(); pollJoystickEvents();
if (!_glfwLibrary.X11.joystick[joy].present) if (!_glfw.x11.joystick[joy].present)
return 0; return 0;
if (_glfwLibrary.X11.joystick[joy].numAxes < numAxes) if (_glfw.x11.joystick[joy].numAxes < numAxes)
numAxes = _glfwLibrary.X11.joystick[joy].numAxes; numAxes = _glfw.x11.joystick[joy].numAxes;
for (i = 0; i < numAxes; i++) for (i = 0; i < numAxes; i++)
axes[i] = _glfwLibrary.X11.joystick[joy].axis[i]; axes[i] = _glfw.x11.joystick[joy].axis[i];
return numAxes; return numAxes;
} }
@ -321,14 +319,14 @@ int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons,
pollJoystickEvents(); pollJoystickEvents();
if (!_glfwLibrary.X11.joystick[joy].present) if (!_glfw.x11.joystick[joy].present)
return 0; return 0;
if (_glfwLibrary.X11.joystick[joy].numButtons < numButtons) if (_glfw.x11.joystick[joy].numButtons < numButtons)
numButtons = _glfwLibrary.X11.joystick[joy].numButtons; numButtons = _glfw.x11.joystick[joy].numButtons;
for (i = 0; i < numButtons; i++) for (i = 0; i < numButtons; i++)
buttons[i] = _glfwLibrary.X11.joystick[joy].button[i]; buttons[i] = _glfw.x11.joystick[joy].button[i];
return numButtons; return numButtons;
} }
@ -340,9 +338,9 @@ int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons,
const char* _glfwPlatformGetJoystickName(int joy) const char* _glfwPlatformGetJoystickName(int joy)
{ {
if (!_glfwLibrary.X11.joystick[joy].present) if (!_glfw.x11.joystick[joy].present)
return NULL; return NULL;
return _glfwLibrary.X11.joystick[joy].name; return _glfw.x11.joystick[joy].name;
} }

View File

@ -47,14 +47,14 @@ int _glfwGetClosestVideoMode(int* width, int* height)
{ {
int i, match, bestmatch; int i, match, bestmatch;
if (_glfwLibrary.X11.RandR.available) if (_glfw.x11.randr.available)
{ {
#if defined(_GLFW_HAS_XRANDR) #if defined(_GLFW_HAS_XRANDR)
int sizecount, bestsize; int sizecount, bestsize;
XRRScreenConfiguration* sc; XRRScreenConfiguration* sc;
XRRScreenSize* sizelist; XRRScreenSize* sizelist;
sc = XRRGetScreenInfo(_glfwLibrary.X11.display, _glfwLibrary.X11.root); sc = XRRGetScreenInfo(_glfw.x11.display, _glfw.x11.root);
sizelist = XRRConfigSizes(sc, &sizecount); sizelist = XRRConfigSizes(sc, &sizecount);
@ -89,8 +89,8 @@ int _glfwGetClosestVideoMode(int* width, int* height)
} }
// Default: Simply use the screen resolution // Default: Simply use the screen resolution
*width = DisplayWidth(_glfwLibrary.X11.display, _glfwLibrary.X11.screen); *width = DisplayWidth(_glfw.x11.display, _glfw.x11.screen);
*height = DisplayHeight(_glfwLibrary.X11.display, _glfwLibrary.X11.screen); *height = DisplayHeight(_glfw.x11.display, _glfw.x11.screen);
return 0; return 0;
} }
@ -102,28 +102,28 @@ int _glfwGetClosestVideoMode(int* width, int* height)
void _glfwSetVideoModeMODE(int mode) void _glfwSetVideoModeMODE(int mode)
{ {
if (_glfwLibrary.X11.RandR.available) if (_glfw.x11.randr.available)
{ {
#if defined(_GLFW_HAS_XRANDR) #if defined(_GLFW_HAS_XRANDR)
XRRScreenConfiguration* sc; XRRScreenConfiguration* sc;
Window root; Window root;
root = _glfwLibrary.X11.root; root = _glfw.x11.root;
sc = XRRGetScreenInfo(_glfwLibrary.X11.display, root); sc = XRRGetScreenInfo(_glfw.x11.display, root);
// Remember old size and flag that we have changed the mode // Remember old size and flag that we have changed the mode
if (!_glfwLibrary.X11.FS.modeChanged) if (!_glfw.x11.fs.modeChanged)
{ {
_glfwLibrary.X11.FS.oldSizeID = XRRConfigCurrentConfiguration(sc, &_glfwLibrary.X11.FS.oldRotation); _glfw.x11.fs.oldSizeID = XRRConfigCurrentConfiguration(sc, &_glfw.x11.fs.oldRotation);
_glfwLibrary.X11.FS.oldWidth = DisplayWidth(_glfwLibrary.X11.display, _glfw.x11.fs.oldWidth = DisplayWidth(_glfw.x11.display,
_glfwLibrary.X11.screen); _glfw.x11.screen);
_glfwLibrary.X11.FS.oldHeight = DisplayHeight(_glfwLibrary.X11.display, _glfw.x11.fs.oldHeight = DisplayHeight(_glfw.x11.display,
_glfwLibrary.X11.screen); _glfw.x11.screen);
_glfwLibrary.X11.FS.modeChanged = GL_TRUE; _glfw.x11.fs.modeChanged = GL_TRUE;
} }
XRRSetScreenConfig(_glfwLibrary.X11.display, XRRSetScreenConfig(_glfw.x11.display,
sc, sc,
root, root,
mode, mode,
@ -158,23 +158,22 @@ void _glfwSetVideoMode(int* width, int* height)
void _glfwRestoreVideoMode(void) void _glfwRestoreVideoMode(void)
{ {
if (_glfwLibrary.X11.FS.modeChanged) if (_glfw.x11.fs.modeChanged)
{ {
if (_glfwLibrary.X11.RandR.available) if (_glfw.x11.randr.available)
{ {
#if defined(_GLFW_HAS_XRANDR) #if defined(_GLFW_HAS_XRANDR)
XRRScreenConfiguration* sc; XRRScreenConfiguration* sc;
if (_glfwLibrary.X11.RandR.available) if (_glfw.x11.randr.available)
{ {
sc = XRRGetScreenInfo(_glfwLibrary.X11.display, sc = XRRGetScreenInfo(_glfw.x11.display, _glfw.x11.root);
_glfwLibrary.X11.root);
XRRSetScreenConfig(_glfwLibrary.X11.display, XRRSetScreenConfig(_glfw.x11.display,
sc, sc,
_glfwLibrary.X11.root, _glfw.x11.root,
_glfwLibrary.X11.FS.oldSizeID, _glfw.x11.fs.oldSizeID,
_glfwLibrary.X11.FS.oldRotation, _glfw.x11.fs.oldRotation,
CurrentTime); CurrentTime);
XRRFreeScreenConfigInfo(sc); XRRFreeScreenConfigInfo(sc);
@ -182,7 +181,7 @@ void _glfwRestoreVideoMode(void)
#endif /*_GLFW_HAS_XRANDR*/ #endif /*_GLFW_HAS_XRANDR*/
} }
_glfwLibrary.X11.FS.modeChanged = GL_FALSE; _glfw.x11.fs.modeChanged = GL_FALSE;
} }
} }
@ -201,18 +200,16 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
int found = 0; int found = 0;
_GLFWmonitor** monitors = NULL; _GLFWmonitor** monitors = NULL;
if (_glfwLibrary.X11.RandR.available) if (_glfw.x11.randr.available)
{ {
#if defined (_GLFW_HAS_XRANDR) #if defined (_GLFW_HAS_XRANDR)
int i; int i;
RROutput primary; RROutput primary;
XRRScreenResources* sr; XRRScreenResources* sr;
sr = XRRGetScreenResources(_glfwLibrary.X11.display, sr = XRRGetScreenResources(_glfw.x11.display, _glfw.x11.root);
_glfwLibrary.X11.root);
primary = XRRGetOutputPrimary(_glfwLibrary.X11.display, primary = XRRGetOutputPrimary(_glfw.x11.display, _glfw.x11.root);
_glfwLibrary.X11.root);
monitors = (_GLFWmonitor**) calloc(sr->noutput, sizeof(_GLFWmonitor*)); monitors = (_GLFWmonitor**) calloc(sr->noutput, sizeof(_GLFWmonitor*));
if (!monitors) if (!monitors)
@ -229,7 +226,7 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
XRRCrtcInfo* ci; XRRCrtcInfo* ci;
int physicalWidth, physicalHeight; int physicalWidth, physicalHeight;
oi = XRRGetOutputInfo(_glfwLibrary.X11.display, sr, sr->outputs[i]); oi = XRRGetOutputInfo(_glfw.x11.display, sr, sr->outputs[i]);
if (oi->connection != RR_Connected) if (oi->connection != RR_Connected)
{ {
XRRFreeOutputInfo(oi); XRRFreeOutputInfo(oi);
@ -243,13 +240,13 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
} }
else else
{ {
physicalWidth = DisplayWidthMM(_glfwLibrary.X11.display, physicalWidth = DisplayWidthMM(_glfw.x11.display,
_glfwLibrary.X11.screen); _glfw.x11.screen);
physicalHeight = DisplayHeightMM(_glfwLibrary.X11.display, physicalHeight = DisplayHeightMM(_glfw.x11.display,
_glfwLibrary.X11.screen); _glfw.x11.screen);
} }
ci = XRRGetCrtcInfo(_glfwLibrary.X11.display, sr, oi->crtc); ci = XRRGetCrtcInfo(_glfw.x11.display, sr, oi->crtc);
monitors[found] = _glfwCreateMonitor(oi->name, monitors[found] = _glfwCreateMonitor(oi->name,
sr->outputs[i] == primary, sr->outputs[i] == primary,
@ -265,7 +262,7 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
} }
// This is retained until the monitor object is destroyed // This is retained until the monitor object is destroyed
monitors[found]->X11.output = oi; monitors[found]->x11.output = oi;
found++; found++;
} }
#endif /*_GLFW_HAS_XRANDR*/ #endif /*_GLFW_HAS_XRANDR*/
@ -282,10 +279,10 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
void _glfwPlatformDestroyMonitor(_GLFWmonitor* monitor) void _glfwPlatformDestroyMonitor(_GLFWmonitor* monitor)
{ {
if (_glfwLibrary.X11.RandR.available) if (_glfw.x11.randr.available)
{ {
#if defined (_GLFW_HAS_XRANDR) #if defined (_GLFW_HAS_XRANDR)
XRRFreeOutputInfo(monitor->X11.output); XRRFreeOutputInfo(monitor->x11.output);
#endif /*_GLFW_HAS_XRANDR*/ #endif /*_GLFW_HAS_XRANDR*/
} }
} }
@ -300,21 +297,20 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found)
GLFWvidmode* result; GLFWvidmode* result;
int depth, r, g, b; int depth, r, g, b;
depth = DefaultDepth(_glfwLibrary.X11.display, _glfwLibrary.X11.screen); depth = DefaultDepth(_glfw.x11.display, _glfw.x11.screen);
_glfwSplitBPP(depth, &r, &g, &b); _glfwSplitBPP(depth, &r, &g, &b);
*found = 0; *found = 0;
// Build array of available resolutions // Build array of available resolutions
if (_glfwLibrary.X11.RandR.available) if (_glfw.x11.randr.available)
{ {
#if defined(_GLFW_HAS_XRANDR) #if defined(_GLFW_HAS_XRANDR)
XRRScreenResources* sr; XRRScreenResources* sr;
int i, j, count = monitor->X11.output->nmode; int i, j, count = monitor->x11.output->nmode;
sr = XRRGetScreenResources(_glfwLibrary.X11.display, sr = XRRGetScreenResources(_glfw.x11.display, _glfw.x11.root);
_glfwLibrary.X11.root);
result = (GLFWvidmode*) malloc(sizeof(GLFWvidmode) * count); result = (GLFWvidmode*) malloc(sizeof(GLFWvidmode) * count);
if (!result) if (!result)
@ -329,7 +325,7 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found)
for (j = 0; j < sr->nmode; j++) for (j = 0; j < sr->nmode; j++)
{ {
if (sr->modes[j].id == monitor->X11.output->modes[i]) if (sr->modes[j].id == monitor->x11.output->modes[i])
break; break;
} }
@ -377,10 +373,8 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found)
return NULL; return NULL;
} }
result[0].width = DisplayWidth(_glfwLibrary.X11.display, result[0].width = DisplayWidth(_glfw.x11.display, _glfw.x11.screen);
_glfwLibrary.X11.screen); result[0].height = DisplayHeight(_glfw.x11.display, _glfw.x11.screen);
result[0].height = DisplayHeight(_glfwLibrary.X11.display,
_glfwLibrary.X11.screen);
result[0].redBits = r; result[0].redBits = r;
result[0].greenBits = g; result[0].greenBits = g;
result[0].blueBits = b; result[0].blueBits = b;
@ -396,14 +390,13 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found)
void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode) void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode)
{ {
if (_glfwLibrary.X11.RandR.available) if (_glfw.x11.randr.available)
{ {
#if defined (_GLFW_HAS_XRANDR) #if defined (_GLFW_HAS_XRANDR)
XRRScreenResources* sr; XRRScreenResources* sr;
XRRCrtcInfo* ci; XRRCrtcInfo* ci;
sr = XRRGetScreenResources(_glfwLibrary.X11.display, sr = XRRGetScreenResources(_glfw.x11.display, _glfw.x11.root);
_glfwLibrary.X11.root);
if (!sr) if (!sr)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,
@ -411,8 +404,7 @@ void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode)
return; return;
} }
ci = XRRGetCrtcInfo(_glfwLibrary.X11.display, ci = XRRGetCrtcInfo(_glfw.x11.display, sr, monitor->x11.output->crtc);
sr, monitor->X11.output->crtc);
if (!ci) if (!ci)
{ {
XRRFreeScreenResources(sr); XRRFreeScreenResources(sr);
@ -431,14 +423,11 @@ void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode)
} }
else else
{ {
mode->width = DisplayWidth(_glfwLibrary.X11.display, mode->width = DisplayWidth(_glfw.x11.display, _glfw.x11.screen);
_glfwLibrary.X11.screen); mode->height = DisplayHeight(_glfw.x11.display, _glfw.x11.screen);
mode->height = DisplayHeight(_glfwLibrary.X11.display,
_glfwLibrary.X11.screen);
} }
_glfwSplitBPP(DefaultDepth(_glfwLibrary.X11.display, _glfwSplitBPP(DefaultDepth(_glfw.x11.display, _glfw.x11.screen),
_glfwLibrary.X11.screen),
&mode->redBits, &mode->greenBits, &mode->blueBits); &mode->redBits, &mode->greenBits, &mode->blueBits);
} }

View File

@ -43,7 +43,7 @@
GLFWAPI Display* glfwGetX11Display(void) GLFWAPI Display* glfwGetX11Display(void)
{ {
return _glfwLibrary.X11.display; return _glfw.x11.display;
} }
@ -61,7 +61,7 @@ GLFWAPI Window glfwGetX11Window(GLFWwindow handle)
return 0; return 0;
} }
return window->X11.handle; return window->x11.handle;
} }
@ -79,6 +79,6 @@ GLFWAPI GLXContext glfwGetGLXContext(GLFWwindow handle)
return NULL; return NULL;
} }
return window->GLX.context; return window->glx.context;
} }

View File

@ -54,20 +54,20 @@
#endif #endif
#if defined(_GLFW_GLX) #if defined(_GLFW_GLX)
#define _GLFW_X11_CONTEXT_VISUAL window->GLX.visual #define _GLFW_X11_CONTEXT_VISUAL window->glx.visual
#include "glx_platform.h" #include "glx_platform.h"
#elif defined(_GLFW_EGL) #elif defined(_GLFW_EGL)
#define _GLFW_X11_CONTEXT_VISUAL window->EGL.visual #define _GLFW_X11_CONTEXT_VISUAL window->egl.visual
#define _GLFW_EGL_NATIVE_WINDOW window->X11.handle #define _GLFW_EGL_NATIVE_WINDOW window->x11.handle
#define _GLFW_EGL_NATIVE_DISPLAY _glfwLibrary.X11.display #define _GLFW_EGL_NATIVE_DISPLAY _glfw.x11.display
#include "egl_platform.h" #include "egl_platform.h"
#else #else
#error "No supported context creation API selected" #error "No supported context creation API selected"
#endif #endif
#define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowX11 X11 #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowX11 x11
#define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryX11 X11 #define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryX11 x11
#define _GLFW_PLATFORM_MONITOR_STATE _GLFWmonitorX11 X11 #define _GLFW_PLATFORM_MONITOR_STATE _GLFWmonitorX11 x11
// Clipboard format atom indices // Clipboard format atom indices
#define _GLFW_CLIPBOARD_FORMAT_UTF8 0 #define _GLFW_CLIPBOARD_FORMAT_UTF8 0
@ -141,25 +141,25 @@ typedef struct _GLFWlibraryX11
GLboolean available; GLboolean available;
int eventBase; int eventBase;
int errorBase; int errorBase;
} VidMode; } vidmode;
struct { struct {
GLboolean available; GLboolean available;
int eventBase; int eventBase;
int errorBase; int errorBase;
int majorVersion; int versionMajor;
int minorVersion; int versionMinor;
GLboolean gammaBroken; GLboolean gammaBroken;
} RandR; } randr;
struct { struct {
GLboolean available; GLboolean available;
int majorOpcode; int majorOpcode;
int eventBase; int eventBase;
int errorBase; int errorBase;
int majorVersion; int versionMajor;
int minorVersion; int versionMinor;
} Xkb; } xkb;
// Key code LUT (mapping X11 key codes to GLFW key codes) // Key code LUT (mapping X11 key codes to GLFW key codes)
int keyCodeLUT[256]; int keyCodeLUT[256];
@ -185,7 +185,7 @@ typedef struct _GLFWlibraryX11
#if defined(_GLFW_HAS_XF86VIDMODE) #if defined(_GLFW_HAS_XF86VIDMODE)
XF86VidModeModeInfo oldMode; XF86VidModeModeInfo oldMode;
#endif /*_GLFW_HAS_XF86VIDMODE*/ #endif /*_GLFW_HAS_XF86VIDMODE*/
} FS; } fs;
// Timer data // Timer data
struct { struct {

View File

@ -41,7 +41,7 @@
static uint64_t getRawTime(void) static uint64_t getRawTime(void)
{ {
#if defined(CLOCK_MONOTONIC) #if defined(CLOCK_MONOTONIC)
if (_glfwLibrary.X11.timer.monotonic) if (_glfw.x11.timer.monotonic)
{ {
struct timespec ts; struct timespec ts;
@ -70,16 +70,16 @@ void _glfwInitTimer(void)
if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0)
{ {
_glfwLibrary.X11.timer.monotonic = GL_TRUE; _glfw.x11.timer.monotonic = GL_TRUE;
_glfwLibrary.X11.timer.resolution = 1e-9; _glfw.x11.timer.resolution = 1e-9;
} }
else else
#endif #endif
{ {
_glfwLibrary.X11.timer.resolution = 1e-6; _glfw.x11.timer.resolution = 1e-6;
} }
_glfwLibrary.X11.timer.base = getRawTime(); _glfw.x11.timer.base = getRawTime();
} }
@ -93,8 +93,8 @@ void _glfwInitTimer(void)
double _glfwPlatformGetTime(void) double _glfwPlatformGetTime(void)
{ {
return (double) (getRawTime() - _glfwLibrary.X11.timer.base) * return (double) (getRawTime() - _glfw.x11.timer.base) *
_glfwLibrary.X11.timer.resolution; _glfw.x11.timer.resolution;
} }
@ -104,7 +104,7 @@ double _glfwPlatformGetTime(void)
void _glfwPlatformSetTime(double time) void _glfwPlatformSetTime(double time)
{ {
_glfwLibrary.X11.timer.base = getRawTime() - _glfw.x11.timer.base = getRawTime() -
(uint64_t) (time / _glfwLibrary.X11.timer.resolution); (uint64_t) (time / _glfw.x11.timer.resolution);
} }

View File

@ -54,7 +54,7 @@ static int translateKey(int keycode)
{ {
// Use the pre-filled LUT (see updateKeyCodeLUT() in x11_init.c) // Use the pre-filled LUT (see updateKeyCodeLUT() in x11_init.c)
if ((keycode >= 0) && (keycode < 256)) if ((keycode >= 0) && (keycode < 256))
return _glfwLibrary.X11.keyCodeLUT[keycode]; return _glfw.x11.keyCodeLUT[keycode];
else else
return -1; return -1;
} }
@ -91,8 +91,8 @@ static GLboolean createWindow(_GLFWwindow* window,
// Create one based on the visual used by the current context // Create one based on the visual used by the current context
// TODO: Decouple this from context creation // TODO: Decouple this from context creation
window->X11.colormap = XCreateColormap(_glfwLibrary.X11.display, window->x11.colormap = XCreateColormap(_glfw.x11.display,
_glfwLibrary.X11.root, _glfw.x11.root,
visual->visual, visual->visual,
AllocNone); AllocNone);
@ -100,7 +100,7 @@ static GLboolean createWindow(_GLFWwindow* window,
{ {
wamask = CWBorderPixel | CWColormap | CWEventMask; wamask = CWBorderPixel | CWColormap | CWEventMask;
wa.colormap = window->X11.colormap; wa.colormap = window->x11.colormap;
wa.border_pixel = 0; wa.border_pixel = 0;
wa.event_mask = StructureNotifyMask | KeyPressMask | KeyReleaseMask | wa.event_mask = StructureNotifyMask | KeyPressMask | KeyReleaseMask |
PointerMotionMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | ButtonPressMask | ButtonReleaseMask |
@ -112,13 +112,13 @@ static GLboolean createWindow(_GLFWwindow* window,
// The /only/ reason for setting the background pixel here is that // The /only/ reason for setting the background pixel here is that
// otherwise our window won't get any decorations on systems using // otherwise our window won't get any decorations on systems using
// certain versions of Compiz on Intel hardware // certain versions of Compiz on Intel hardware
wa.background_pixel = BlackPixel(_glfwLibrary.X11.display, wa.background_pixel = BlackPixel(_glfw.x11.display,
_glfwLibrary.X11.screen); _glfw.x11.screen);
wamask |= CWBackPixel; wamask |= CWBackPixel;
} }
window->X11.handle = XCreateWindow(_glfwLibrary.X11.display, window->x11.handle = XCreateWindow(_glfw.x11.display,
_glfwLibrary.X11.root, _glfw.x11.root,
wndconfig->positionX, wndconfig->positionY, wndconfig->positionX, wndconfig->positionY,
window->width, window->height, window->width, window->height,
0, // Border width 0, // Border width
@ -128,7 +128,7 @@ static GLboolean createWindow(_GLFWwindow* window,
wamask, wamask,
&wa); &wa);
if (!window->X11.handle) if (!window->x11.handle)
{ {
// TODO: Handle all the various error codes here and translate them // TODO: Handle all the various error codes here and translate them
// to GLFW errors // to GLFW errors
@ -139,12 +139,12 @@ static GLboolean createWindow(_GLFWwindow* window,
// Request a window position to be set once the window is shown // Request a window position to be set once the window is shown
// (see _glfwPlatformShowWindow) // (see _glfwPlatformShowWindow)
window->X11.windowPosSet = GL_FALSE; window->x11.windowPosSet = GL_FALSE;
window->X11.positionX = wndconfig->positionX; window->x11.positionX = wndconfig->positionX;
window->X11.positionY = wndconfig->positionY; window->x11.positionY = wndconfig->positionY;
} }
if (window->monitor && !_glfwLibrary.X11.hasEWMH) if (window->monitor && !_glfw.x11.hasEWMH)
{ {
// This is the butcher's way of removing window decorations // This is the butcher's way of removing window decorations
// Setting the override-redirect attribute on a window makes the window // Setting the override-redirect attribute on a window makes the window
@ -156,18 +156,18 @@ static GLboolean createWindow(_GLFWwindow* window,
XSetWindowAttributes attributes; XSetWindowAttributes attributes;
attributes.override_redirect = True; attributes.override_redirect = True;
XChangeWindowAttributes(_glfwLibrary.X11.display, XChangeWindowAttributes(_glfw.x11.display,
window->X11.handle, window->x11.handle,
CWOverrideRedirect, CWOverrideRedirect,
&attributes); &attributes);
window->X11.overrideRedirect = GL_TRUE; window->x11.overrideRedirect = GL_TRUE;
} }
// Find or create the protocol atom for window close notifications // Find or create the protocol atom for window close notifications
_glfwLibrary.X11.wmDeleteWindow = XInternAtom(_glfwLibrary.X11.display, _glfw.x11.wmDeleteWindow = XInternAtom(_glfw.x11.display,
"WM_DELETE_WINDOW", "WM_DELETE_WINDOW",
False); False);
// Declare the WM protocols supported by GLFW // Declare the WM protocols supported by GLFW
{ {
@ -176,18 +176,18 @@ static GLboolean createWindow(_GLFWwindow* window,
// The WM_DELETE_WINDOW ICCCM protocol // The WM_DELETE_WINDOW ICCCM protocol
// Basic window close notification protocol // Basic window close notification protocol
if (_glfwLibrary.X11.wmDeleteWindow != None) if (_glfw.x11.wmDeleteWindow != None)
protocols[count++] = _glfwLibrary.X11.wmDeleteWindow; protocols[count++] = _glfw.x11.wmDeleteWindow;
// The _NET_WM_PING EWMH protocol // The _NET_WM_PING EWMH protocol
// Tells the WM to ping the GLFW window and flag the application as // Tells the WM to ping the GLFW window and flag the application as
// unresponsive if the WM doesn't get a reply within a few seconds // unresponsive if the WM doesn't get a reply within a few seconds
if (_glfwLibrary.X11.wmPing != None) if (_glfw.x11.wmPing != None)
protocols[count++] = _glfwLibrary.X11.wmPing; protocols[count++] = _glfw.x11.wmPing;
if (count > 0) if (count > 0)
{ {
XSetWMProtocols(_glfwLibrary.X11.display, window->X11.handle, XSetWMProtocols(_glfw.x11.display, window->x11.handle,
protocols, count); protocols, count);
} }
} }
@ -205,7 +205,7 @@ static GLboolean createWindow(_GLFWwindow* window,
hints->flags = StateHint; hints->flags = StateHint;
hints->initial_state = NormalState; hints->initial_state = NormalState;
XSetWMHints(_glfwLibrary.X11.display, window->X11.handle, hints); XSetWMHints(_glfw.x11.display, window->x11.handle, hints);
XFree(hints); XFree(hints);
} }
@ -235,7 +235,7 @@ static GLboolean createWindow(_GLFWwindow* window,
hints->min_height = hints->max_height = window->height; hints->min_height = hints->max_height = window->height;
} }
XSetWMNormalHints(_glfwLibrary.X11.display, window->X11.handle, hints); XSetWMNormalHints(_glfw.x11.display, window->x11.handle, hints);
XFree(hints); XFree(hints);
} }
@ -254,18 +254,16 @@ static void hideCursor(_GLFWwindow* window)
// Un-grab cursor (in windowed mode only; in fullscreen mode we still // Un-grab cursor (in windowed mode only; in fullscreen mode we still
// want the cursor grabbed in order to confine the cursor to the window // want the cursor grabbed in order to confine the cursor to the window
// area) // area)
if (window->X11.cursorGrabbed && window->monitor == NULL) if (window->x11.cursorGrabbed && window->monitor == NULL)
{ {
XUngrabPointer(_glfwLibrary.X11.display, CurrentTime); XUngrabPointer(_glfw.x11.display, CurrentTime);
window->X11.cursorGrabbed = GL_FALSE; window->x11.cursorGrabbed = GL_FALSE;
} }
if (!window->X11.cursorHidden) if (!window->x11.cursorHidden)
{ {
XDefineCursor(_glfwLibrary.X11.display, XDefineCursor(_glfw.x11.display, window->x11.handle, _glfw.x11.cursor);
window->X11.handle, window->x11.cursorHidden = GL_TRUE;
_glfwLibrary.X11.cursor);
window->X11.cursorHidden = GL_TRUE;
} }
} }
@ -278,16 +276,16 @@ static void captureCursor(_GLFWwindow* window)
{ {
hideCursor(window); hideCursor(window);
if (!window->X11.cursorGrabbed) if (!window->x11.cursorGrabbed)
{ {
if (XGrabPointer(_glfwLibrary.X11.display, window->X11.handle, True, if (XGrabPointer(_glfw.x11.display, window->x11.handle, True,
ButtonPressMask | ButtonReleaseMask | ButtonPressMask | ButtonReleaseMask |
PointerMotionMask, GrabModeAsync, GrabModeAsync, PointerMotionMask, GrabModeAsync, GrabModeAsync,
window->X11.handle, None, CurrentTime) == window->x11.handle, None, CurrentTime) ==
GrabSuccess) GrabSuccess)
{ {
window->X11.cursorGrabbed = GL_TRUE; window->x11.cursorGrabbed = GL_TRUE;
window->X11.cursorCentered = GL_FALSE; window->x11.cursorCentered = GL_FALSE;
} }
} }
} }
@ -302,17 +300,17 @@ static void showCursor(_GLFWwindow* window)
// Un-grab cursor (in windowed mode only; in fullscreen mode we still // Un-grab cursor (in windowed mode only; in fullscreen mode we still
// want the cursor grabbed in order to confine the cursor to the window // want the cursor grabbed in order to confine the cursor to the window
// area) // area)
if (window->X11.cursorGrabbed && window->monitor == NULL) if (window->x11.cursorGrabbed && window->monitor == NULL)
{ {
XUngrabPointer(_glfwLibrary.X11.display, CurrentTime); XUngrabPointer(_glfw.x11.display, CurrentTime);
window->X11.cursorGrabbed = GL_FALSE; window->x11.cursorGrabbed = GL_FALSE;
} }
// Show cursor // Show cursor
if (window->X11.cursorHidden) if (window->x11.cursorHidden)
{ {
XUndefineCursor(_glfwLibrary.X11.display, window->X11.handle); XUndefineCursor(_glfw.x11.display, window->x11.handle);
window->X11.cursorHidden = GL_FALSE; window->x11.cursorHidden = GL_FALSE;
} }
} }
@ -323,29 +321,29 @@ static void showCursor(_GLFWwindow* window)
static void enterFullscreenMode(_GLFWwindow* window) static void enterFullscreenMode(_GLFWwindow* window)
{ {
if (!_glfwLibrary.X11.saver.changed) if (!_glfw.x11.saver.changed)
{ {
// Remember old screen saver settings // Remember old screen saver settings
XGetScreenSaver(_glfwLibrary.X11.display, XGetScreenSaver(_glfw.x11.display,
&_glfwLibrary.X11.saver.timeout, &_glfw.x11.saver.timeout,
&_glfwLibrary.X11.saver.interval, &_glfw.x11.saver.interval,
&_glfwLibrary.X11.saver.blanking, &_glfw.x11.saver.blanking,
&_glfwLibrary.X11.saver.exposure); &_glfw.x11.saver.exposure);
// Disable screen saver // Disable screen saver
XSetScreenSaver(_glfwLibrary.X11.display, 0, 0, DontPreferBlanking, XSetScreenSaver(_glfw.x11.display, 0, 0, DontPreferBlanking,
DefaultExposures); DefaultExposures);
_glfwLibrary.X11.saver.changed = GL_TRUE; _glfw.x11.saver.changed = GL_TRUE;
} }
_glfwSetVideoMode(&window->width, &window->height); _glfwSetVideoMode(&window->width, &window->height);
if (_glfwLibrary.X11.hasEWMH && if (_glfw.x11.hasEWMH &&
_glfwLibrary.X11.wmState != None && _glfw.x11.wmState != None &&
_glfwLibrary.X11.wmStateFullscreen != None) _glfw.x11.wmStateFullscreen != None)
{ {
if (_glfwLibrary.X11.wmActiveWindow != None) if (_glfw.x11.wmActiveWindow != None)
{ {
// Ask the window manager to raise and focus the GLFW window // Ask the window manager to raise and focus the GLFW window
// Only focused windows with the _NET_WM_STATE_FULLSCREEN state end // Only focused windows with the _NET_WM_STATE_FULLSCREEN state end
@ -355,14 +353,14 @@ static void enterFullscreenMode(_GLFWwindow* window)
memset(&event, 0, sizeof(event)); memset(&event, 0, sizeof(event));
event.type = ClientMessage; event.type = ClientMessage;
event.xclient.window = window->X11.handle; event.xclient.window = window->x11.handle;
event.xclient.format = 32; // Data is 32-bit longs event.xclient.format = 32; // Data is 32-bit longs
event.xclient.message_type = _glfwLibrary.X11.wmActiveWindow; event.xclient.message_type = _glfw.x11.wmActiveWindow;
event.xclient.data.l[0] = 1; // Sender is a normal application event.xclient.data.l[0] = 1; // Sender is a normal application
event.xclient.data.l[1] = 0; // We don't really know the timestamp event.xclient.data.l[1] = 0; // We don't really know the timestamp
XSendEvent(_glfwLibrary.X11.display, XSendEvent(_glfw.x11.display,
_glfwLibrary.X11.root, _glfw.x11.root,
False, False,
SubstructureNotifyMask | SubstructureRedirectMask, SubstructureNotifyMask | SubstructureRedirectMask,
&event); &event);
@ -376,38 +374,38 @@ static void enterFullscreenMode(_GLFWwindow* window)
memset(&event, 0, sizeof(event)); memset(&event, 0, sizeof(event));
event.type = ClientMessage; event.type = ClientMessage;
event.xclient.window = window->X11.handle; event.xclient.window = window->x11.handle;
event.xclient.format = 32; // Data is 32-bit longs event.xclient.format = 32; // Data is 32-bit longs
event.xclient.message_type = _glfwLibrary.X11.wmState; event.xclient.message_type = _glfw.x11.wmState;
event.xclient.data.l[0] = _NET_WM_STATE_ADD; event.xclient.data.l[0] = _NET_WM_STATE_ADD;
event.xclient.data.l[1] = _glfwLibrary.X11.wmStateFullscreen; event.xclient.data.l[1] = _glfw.x11.wmStateFullscreen;
event.xclient.data.l[2] = 0; // No secondary property event.xclient.data.l[2] = 0; // No secondary property
event.xclient.data.l[3] = 1; // Sender is a normal application event.xclient.data.l[3] = 1; // Sender is a normal application
XSendEvent(_glfwLibrary.X11.display, XSendEvent(_glfw.x11.display,
_glfwLibrary.X11.root, _glfw.x11.root,
False, False,
SubstructureNotifyMask | SubstructureRedirectMask, SubstructureNotifyMask | SubstructureRedirectMask,
&event); &event);
} }
else if (window->X11.overrideRedirect) else if (window->x11.overrideRedirect)
{ {
// In override-redirect mode we have divorced ourselves from the // In override-redirect mode we have divorced ourselves from the
// window manager, so we need to do everything manually // window manager, so we need to do everything manually
XRaiseWindow(_glfwLibrary.X11.display, window->X11.handle); XRaiseWindow(_glfw.x11.display, window->x11.handle);
XSetInputFocus(_glfwLibrary.X11.display, window->X11.handle, XSetInputFocus(_glfw.x11.display, window->x11.handle,
RevertToParent, CurrentTime); RevertToParent, CurrentTime);
XMoveWindow(_glfwLibrary.X11.display, window->X11.handle, 0, 0); XMoveWindow(_glfw.x11.display, window->x11.handle, 0, 0);
XResizeWindow(_glfwLibrary.X11.display, window->X11.handle, XResizeWindow(_glfw.x11.display, window->x11.handle,
window->width, window->height); window->width, window->height);
} }
// HACK: Try to get window inside viewport (for virtual displays) by moving // HACK: Try to get window inside viewport (for virtual displays) by moving
// the cursor to the upper left corner (and then to the center) // the cursor to the upper left corner (and then to the center)
// This hack should be harmless on saner systems as well // This hack should be harmless on saner systems as well
XWarpPointer(_glfwLibrary.X11.display, None, window->X11.handle, 0,0,0,0, 0,0); XWarpPointer(_glfw.x11.display, None, window->x11.handle, 0,0,0,0, 0,0);
XWarpPointer(_glfwLibrary.X11.display, None, window->X11.handle, 0,0,0,0, XWarpPointer(_glfw.x11.display, None, window->x11.handle, 0,0,0,0,
window->width / 2, window->height / 2); window->width / 2, window->height / 2);
} }
@ -420,21 +418,21 @@ static void leaveFullscreenMode(_GLFWwindow* window)
{ {
_glfwRestoreVideoMode(); _glfwRestoreVideoMode();
if (_glfwLibrary.X11.saver.changed) if (_glfw.x11.saver.changed)
{ {
// Restore old screen saver settings // Restore old screen saver settings
XSetScreenSaver(_glfwLibrary.X11.display, XSetScreenSaver(_glfw.x11.display,
_glfwLibrary.X11.saver.timeout, _glfw.x11.saver.timeout,
_glfwLibrary.X11.saver.interval, _glfw.x11.saver.interval,
_glfwLibrary.X11.saver.blanking, _glfw.x11.saver.blanking,
_glfwLibrary.X11.saver.exposure); _glfw.x11.saver.exposure);
_glfwLibrary.X11.saver.changed = GL_FALSE; _glfw.x11.saver.changed = GL_FALSE;
} }
if (_glfwLibrary.X11.hasEWMH && if (_glfw.x11.hasEWMH &&
_glfwLibrary.X11.wmState != None && _glfw.x11.wmState != None &&
_glfwLibrary.X11.wmStateFullscreen != None) _glfw.x11.wmStateFullscreen != None)
{ {
// Ask the window manager to make the GLFW window a normal window // Ask the window manager to make the GLFW window a normal window
// Normal windows usually have frames and other decorations // Normal windows usually have frames and other decorations
@ -443,16 +441,16 @@ static void leaveFullscreenMode(_GLFWwindow* window)
memset(&event, 0, sizeof(event)); memset(&event, 0, sizeof(event));
event.type = ClientMessage; event.type = ClientMessage;
event.xclient.window = window->X11.handle; event.xclient.window = window->x11.handle;
event.xclient.format = 32; // Data is 32-bit longs event.xclient.format = 32; // Data is 32-bit longs
event.xclient.message_type = _glfwLibrary.X11.wmState; event.xclient.message_type = _glfw.x11.wmState;
event.xclient.data.l[0] = _NET_WM_STATE_REMOVE; event.xclient.data.l[0] = _NET_WM_STATE_REMOVE;
event.xclient.data.l[1] = _glfwLibrary.X11.wmStateFullscreen; event.xclient.data.l[1] = _glfw.x11.wmStateFullscreen;
event.xclient.data.l[2] = 0; // No secondary property event.xclient.data.l[2] = 0; // No secondary property
event.xclient.data.l[3] = 1; // Sender is a normal application event.xclient.data.l[3] = 1; // Sender is a normal application
XSendEvent(_glfwLibrary.X11.display, XSendEvent(_glfw.x11.display,
_glfwLibrary.X11.root, _glfw.x11.root,
False, False,
SubstructureNotifyMask | SubstructureRedirectMask, SubstructureNotifyMask | SubstructureRedirectMask,
&event); &event);
@ -468,9 +466,9 @@ static _GLFWwindow* findWindow(Window handle)
{ {
_GLFWwindow* window; _GLFWwindow* window;
for (window = _glfwLibrary.windowListHead; window; window = window->next) for (window = _glfw.windowListHead; window; window = window->next)
{ {
if (window->X11.handle == handle) if (window->x11.handle == handle)
return window; return window;
} }
@ -511,10 +509,10 @@ static void processEvent(XEvent *event)
// will get KeyRelease/KeyPress pairs with similar or identical // will get KeyRelease/KeyPress pairs with similar or identical
// time stamps. User selected key repeat filtering is handled in // time stamps. User selected key repeat filtering is handled in
// _glfwInputKey/_glfwInputChar. // _glfwInputKey/_glfwInputChar.
if (XEventsQueued(_glfwLibrary.X11.display, QueuedAfterReading)) if (XEventsQueued(_glfw.x11.display, QueuedAfterReading))
{ {
XEvent nextEvent; XEvent nextEvent;
XPeekEvent(_glfwLibrary.X11.display, &nextEvent); XPeekEvent(_glfw.x11.display, &nextEvent);
if (nextEvent.type == KeyPress && if (nextEvent.type == KeyPress &&
nextEvent.xkey.window == event->xkey.window && nextEvent.xkey.window == event->xkey.window &&
@ -629,8 +627,8 @@ static void processEvent(XEvent *event)
if (window == NULL) if (window == NULL)
return; return;
if (event->xmotion.x != window->X11.cursorPosX || if (event->xmotion.x != window->x11.cursorPosX ||
event->xmotion.y != window->X11.cursorPosY) event->xmotion.y != window->x11.cursorPosY)
{ {
// The cursor was moved by something other than GLFW // The cursor was moved by something other than GLFW
@ -638,11 +636,11 @@ static void processEvent(XEvent *event)
if (window->cursorMode == GLFW_CURSOR_CAPTURED) if (window->cursorMode == GLFW_CURSOR_CAPTURED)
{ {
if (_glfwLibrary.focusedWindow != window) if (_glfw.focusedWindow != window)
break; break;
x = event->xmotion.x - window->X11.cursorPosX; x = event->xmotion.x - window->x11.cursorPosX;
y = event->xmotion.y - window->X11.cursorPosY; y = event->xmotion.y - window->x11.cursorPosY;
} }
else else
{ {
@ -650,9 +648,9 @@ static void processEvent(XEvent *event)
y = event->xmotion.y; y = event->xmotion.y;
} }
window->X11.cursorPosX = event->xmotion.x; window->x11.cursorPosX = event->xmotion.x;
window->X11.cursorPosY = event->xmotion.y; window->x11.cursorPosY = event->xmotion.y;
window->X11.cursorCentered = GL_FALSE; window->x11.cursorCentered = GL_FALSE;
_glfwInputCursorMotion(window, x, y); _glfwInputCursorMotion(window, x, y);
} }
@ -685,21 +683,21 @@ static void processEvent(XEvent *event)
if (window == NULL) if (window == NULL)
return; return;
if ((Atom) event->xclient.data.l[0] == _glfwLibrary.X11.wmDeleteWindow) if ((Atom) event->xclient.data.l[0] == _glfw.x11.wmDeleteWindow)
{ {
// The window manager was asked to close the window, for example by // The window manager was asked to close the window, for example by
// the user pressing a 'close' window decoration button // the user pressing a 'close' window decoration button
_glfwInputWindowCloseRequest(window); _glfwInputWindowCloseRequest(window);
} }
else if (_glfwLibrary.X11.wmPing != None && else if (_glfw.x11.wmPing != None &&
(Atom) event->xclient.data.l[0] == _glfwLibrary.X11.wmPing) (Atom) event->xclient.data.l[0] == _glfw.x11.wmPing)
{ {
// The window manager is pinging the application to ensure it's // The window manager is pinging the application to ensure it's
// still responding to events // still responding to events
event->xclient.window = _glfwLibrary.X11.root; event->xclient.window = _glfw.x11.root;
XSendEvent(_glfwLibrary.X11.display, XSendEvent(_glfw.x11.display,
event->xclient.window, event->xclient.window,
False, False,
SubstructureNotifyMask | SubstructureRedirectMask, SubstructureNotifyMask | SubstructureRedirectMask,
@ -778,8 +776,8 @@ static void processEvent(XEvent *event)
{ {
// The ownership of the selection was lost // The ownership of the selection was lost
free(_glfwLibrary.X11.selection.string); free(_glfw.x11.selection.string);
_glfwLibrary.X11.selection.string = NULL; _glfw.x11.selection.string = NULL;
break; break;
} }
@ -790,9 +788,9 @@ static void processEvent(XEvent *event)
XSelectionEvent* request = &event->xselection; XSelectionEvent* request = &event->xselection;
if (_glfwReadSelection(request)) if (_glfwReadSelection(request))
_glfwLibrary.X11.selection.status = _GLFW_CONVERSION_SUCCEEDED; _glfw.x11.selection.status = _GLFW_CONVERSION_SUCCEEDED;
else else
_glfwLibrary.X11.selection.status = _GLFW_CONVERSION_FAILED; _glfw.x11.selection.status = _GLFW_CONVERSION_FAILED;
break; break;
} }
@ -814,7 +812,7 @@ static void processEvent(XEvent *event)
response.xselection.target = request->target; response.xselection.target = request->target;
response.xselection.time = request->time; response.xselection.time = request->time;
XSendEvent(_glfwLibrary.X11.display, XSendEvent(_glfw.x11.display,
request->requestor, request->requestor,
False, 0, &response); False, 0, &response);
break; break;
@ -826,7 +824,7 @@ static void processEvent(XEvent *event)
default: default:
{ {
#if defined(_GLFW_HAS_XRANDR) #if defined(_GLFW_HAS_XRANDR)
switch (event->type - _glfwLibrary.X11.RandR.eventBase) switch (event->type - _glfw.x11.randr.eventBase)
{ {
case RRScreenChangeNotify: case RRScreenChangeNotify:
{ {
@ -862,10 +860,10 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
#if defined(_GLFW_HAS_XRANDR) #if defined(_GLFW_HAS_XRANDR)
// Request screen change notifications // Request screen change notifications
if (_glfwLibrary.X11.RandR.available) if (_glfw.x11.randr.available)
{ {
XRRSelectInput(_glfwLibrary.X11.display, XRRSelectInput(_glfw.x11.display,
window->X11.handle, window->x11.handle,
RRScreenChangeNotifyMask); RRScreenChangeNotifyMask);
} }
#endif /*_GLFW_HAS_XRANDR*/ #endif /*_GLFW_HAS_XRANDR*/
@ -882,8 +880,8 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
int windowX, windowY, rootX, rootY; int windowX, windowY, rootX, rootY;
unsigned int mask; unsigned int mask;
XQueryPointer(_glfwLibrary.X11.display, XQueryPointer(_glfw.x11.display,
window->X11.handle, window->x11.handle,
&cursorRoot, &cursorRoot,
&cursorWindow, &cursorWindow,
&rootX, &rootY, &rootX, &rootY,
@ -911,17 +909,17 @@ void _glfwPlatformDestroyWindow(_GLFWwindow* window)
_glfwDestroyContext(window); _glfwDestroyContext(window);
if (window->X11.handle) if (window->x11.handle)
{ {
XUnmapWindow(_glfwLibrary.X11.display, window->X11.handle); XUnmapWindow(_glfw.x11.display, window->x11.handle);
XDestroyWindow(_glfwLibrary.X11.display, window->X11.handle); XDestroyWindow(_glfw.x11.display, window->x11.handle);
window->X11.handle = (Window) 0; window->x11.handle = (Window) 0;
} }
if (window->X11.colormap) if (window->x11.colormap)
{ {
XFreeColormap(_glfwLibrary.X11.display, window->X11.colormap); XFreeColormap(_glfw.x11.display, window->x11.colormap);
window->X11.colormap = (Colormap) 0; window->x11.colormap = (Colormap) 0;
} }
} }
@ -932,36 +930,36 @@ void _glfwPlatformDestroyWindow(_GLFWwindow* window)
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title) void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title)
{ {
Atom type = XInternAtom(_glfwLibrary.X11.display, "UTF8_STRING", False); Atom type = XInternAtom(_glfw.x11.display, "UTF8_STRING", False);
#if defined(X_HAVE_UTF8_STRING) #if defined(X_HAVE_UTF8_STRING)
Xutf8SetWMProperties(_glfwLibrary.X11.display, Xutf8SetWMProperties(_glfw.x11.display,
window->X11.handle, window->x11.handle,
title, title, title, title,
NULL, 0, NULL, 0,
NULL, NULL, NULL); NULL, NULL, NULL);
#else #else
// This may be a slightly better fallback than using XStoreName and // This may be a slightly better fallback than using XStoreName and
// XSetIconName, which always store their arguments using STRING // XSetIconName, which always store their arguments using STRING
XmbSetWMProperties(_glfwLibrary.X11.display, XmbSetWMProperties(_glfw.x11.display,
window->X11.handle, window->x11.handle,
title, title, title, title,
NULL, 0, NULL, 0,
NULL, NULL, NULL); NULL, NULL, NULL);
#endif #endif
if (_glfwLibrary.X11.wmName != None) if (_glfw.x11.wmName != None)
{ {
XChangeProperty(_glfwLibrary.X11.display, window->X11.handle, XChangeProperty(_glfw.x11.display, window->x11.handle,
_glfwLibrary.X11.wmName, type, 8, _glfw.x11.wmName, type, 8,
PropModeReplace, PropModeReplace,
(unsigned char*) title, strlen(title)); (unsigned char*) title, strlen(title));
} }
if (_glfwLibrary.X11.wmIconName != None) if (_glfw.x11.wmIconName != None)
{ {
XChangeProperty(_glfwLibrary.X11.display, window->X11.handle, XChangeProperty(_glfw.x11.display, window->x11.handle,
_glfwLibrary.X11.wmIconName, type, 8, _glfw.x11.wmIconName, type, 8,
PropModeReplace, PropModeReplace,
(unsigned char*) title, strlen(title)); (unsigned char*) title, strlen(title));
} }
@ -992,7 +990,7 @@ void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
hints->min_width = hints->max_width = width; hints->min_width = hints->max_width = width;
hints->min_height = hints->max_height = height; hints->min_height = hints->max_height = height;
XSetWMNormalHints(_glfwLibrary.X11.display, window->X11.handle, hints); XSetWMNormalHints(_glfw.x11.display, window->x11.handle, hints);
XFree(hints); XFree(hints);
} }
@ -1001,9 +999,7 @@ void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
// Change window size before changing fullscreen mode? // Change window size before changing fullscreen mode?
if (width > window->width) if (width > window->width)
{ {
XResizeWindow(_glfwLibrary.X11.display, XResizeWindow(_glfw.x11.display, window->x11.handle, width, height);
window->X11.handle,
width, height);
sizeChanged = GL_TRUE; sizeChanged = GL_TRUE;
} }
@ -1012,7 +1008,7 @@ void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
// Set window size (if not already changed) // Set window size (if not already changed)
if (!sizeChanged) if (!sizeChanged)
XResizeWindow(_glfwLibrary.X11.display, window->X11.handle, width, height); XResizeWindow(_glfw.x11.display, window->x11.handle, width, height);
} }
@ -1022,16 +1018,14 @@ void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
void _glfwPlatformIconifyWindow(_GLFWwindow* window) void _glfwPlatformIconifyWindow(_GLFWwindow* window)
{ {
if (window->X11.overrideRedirect) if (window->x11.overrideRedirect)
{ {
// Override-redirect windows cannot be iconified or restored, as those // Override-redirect windows cannot be iconified or restored, as those
// tasks are performed by the window manager // tasks are performed by the window manager
return; return;
} }
XIconifyWindow(_glfwLibrary.X11.display, XIconifyWindow(_glfw.x11.display, window->x11.handle, _glfw.x11.screen);
window->X11.handle,
_glfwLibrary.X11.screen);
} }
@ -1041,14 +1035,14 @@ void _glfwPlatformIconifyWindow(_GLFWwindow* window)
void _glfwPlatformRestoreWindow(_GLFWwindow* window) void _glfwPlatformRestoreWindow(_GLFWwindow* window)
{ {
if (window->X11.overrideRedirect) if (window->x11.overrideRedirect)
{ {
// Override-redirect windows cannot be iconified or restored, as those // Override-redirect windows cannot be iconified or restored, as those
// tasks are performed by the window manager // tasks are performed by the window manager
return; return;
} }
XMapWindow(_glfwLibrary.X11.display, window->X11.handle); XMapWindow(_glfw.x11.display, window->x11.handle);
} }
@ -1058,16 +1052,16 @@ void _glfwPlatformRestoreWindow(_GLFWwindow* window)
void _glfwPlatformShowWindow(_GLFWwindow* window) void _glfwPlatformShowWindow(_GLFWwindow* window)
{ {
XMapRaised(_glfwLibrary.X11.display, window->X11.handle); XMapRaised(_glfw.x11.display, window->x11.handle);
XFlush(_glfwLibrary.X11.display); XFlush(_glfw.x11.display);
// Set the window position the first time the window is shown // Set the window position the first time the window is shown
// Note: XMoveWindow has no effect before the window has been mapped. // Note: XMoveWindow has no effect before the window has been mapped.
if (!window->X11.windowPosSet) if (!window->x11.windowPosSet)
{ {
XMoveWindow(_glfwLibrary.X11.display, window->X11.handle, XMoveWindow(_glfw.x11.display, window->x11.handle,
window->X11.positionX, window->X11.positionY); window->x11.positionX, window->x11.positionY);
window->X11.windowPosSet = GL_TRUE; window->x11.windowPosSet = GL_TRUE;
} }
} }
@ -1078,8 +1072,8 @@ void _glfwPlatformShowWindow(_GLFWwindow* window)
void _glfwPlatformHideWindow(_GLFWwindow* window) void _glfwPlatformHideWindow(_GLFWwindow* window)
{ {
XUnmapWindow(_glfwLibrary.X11.display, window->X11.handle); XUnmapWindow(_glfw.x11.display, window->x11.handle);
XFlush(_glfwLibrary.X11.display); XFlush(_glfw.x11.display);
} }
@ -1091,8 +1085,8 @@ void _glfwPlatformPollEvents(void)
{ {
XEvent event; XEvent event;
while (XCheckMaskEvent(_glfwLibrary.X11.display, ~0, &event) || while (XCheckMaskEvent(_glfw.x11.display, ~0, &event) ||
XCheckTypedEvent(_glfwLibrary.X11.display, ClientMessage, &event)) XCheckTypedEvent(_glfw.x11.display, ClientMessage, &event))
{ {
processEvent(&event); processEvent(&event);
} }
@ -1101,21 +1095,21 @@ void _glfwPlatformPollEvents(void)
// captured the cursor (because then it needs to be re-centered) // captured the cursor (because then it needs to be re-centered)
_GLFWwindow* window; _GLFWwindow* window;
window = _glfwLibrary.focusedWindow; window = _glfw.focusedWindow;
if (window) if (window)
{ {
if (window->cursorMode == GLFW_CURSOR_CAPTURED && if (window->cursorMode == GLFW_CURSOR_CAPTURED &&
!window->X11.cursorCentered) !window->x11.cursorCentered)
{ {
_glfwPlatformSetCursorPos(window, _glfwPlatformSetCursorPos(window,
window->width / 2, window->width / 2,
window->height / 2); window->height / 2);
window->X11.cursorCentered = GL_TRUE; window->x11.cursorCentered = GL_TRUE;
// NOTE: This is a temporary fix. It works as long as you use // NOTE: This is a temporary fix. It works as long as you use
// offsets accumulated over the course of a frame, instead of // offsets accumulated over the course of a frame, instead of
// performing the necessary actions per callback call. // performing the necessary actions per callback call.
XFlush( _glfwLibrary.X11.display ); XFlush(_glfw.x11.display);
} }
} }
} }
@ -1130,12 +1124,12 @@ void _glfwPlatformWaitEvents(void)
int fd; int fd;
fd_set fds; fd_set fds;
fd = ConnectionNumber(_glfwLibrary.X11.display); fd = ConnectionNumber(_glfw.x11.display);
FD_ZERO(&fds); FD_ZERO(&fds);
FD_SET(fd, &fds); FD_SET(fd, &fds);
XFlush(_glfwLibrary.X11.display); XFlush(_glfw.x11.display);
if (select(fd + 1, &fds, NULL, NULL, NULL) > 0) if (select(fd + 1, &fds, NULL, NULL, NULL) > 0)
_glfwPlatformPollEvents(); _glfwPlatformPollEvents();
@ -1149,10 +1143,10 @@ void _glfwPlatformWaitEvents(void)
void _glfwPlatformSetCursorPos(_GLFWwindow* window, int x, int y) void _glfwPlatformSetCursorPos(_GLFWwindow* window, int x, int y)
{ {
// Store the new position so it can be recognized later // Store the new position so it can be recognized later
window->X11.cursorPosX = x; window->x11.cursorPosX = x;
window->X11.cursorPosY = y; window->x11.cursorPosY = y;
XWarpPointer(_glfwLibrary.X11.display, None, window->X11.handle, 0,0,0,0, x, y); XWarpPointer(_glfw.x11.display, None, window->x11.handle, 0,0,0,0, x, y);
} }