From c9820b2ba50cacc5fbeeb6a9c71f5e544bd45dee Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 26 Mar 2012 15:20:31 +0200 Subject: [PATCH 1/4] Fixed issues found with static analysis. --- src/cocoa_joystick.m | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/cocoa_joystick.m b/src/cocoa_joystick.m index 45b3be0f..c0268e44 100644 --- a/src/cocoa_joystick.m +++ b/src/cocoa_joystick.m @@ -336,7 +336,12 @@ void _glfwInitJoysticks(void) result = IOMasterPort(bootstrap_port, &masterPort); hidMatchDictionary = IOServiceMatching(kIOHIDDeviceKey); if (kIOReturnSuccess != result || !hidMatchDictionary) + { + if (hidMatchDictionary) + CFRelease(hidMatchDictionary); + return; + } result = IOServiceGetMatchingServices(masterPort, hidMatchDictionary, @@ -370,19 +375,27 @@ void _glfwInitJoysticks(void) /* Check device type */ refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDPrimaryUsagePageKey)); if (refCF) + { CFNumberGetValue(refCF, kCFNumberLongType, &usagePage); + if (usagePage != kHIDPage_GenericDesktop) + { + /* We are not interested in this device */ + continue; + } + } refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDPrimaryUsageKey)); if (refCF) - CFNumberGetValue(refCF, kCFNumberLongType, &usage); - - if ((usagePage != kHIDPage_GenericDesktop) || - (usage != kHIDUsage_GD_Joystick && - usage != kHIDUsage_GD_GamePad && - usage != kHIDUsage_GD_MultiAxisController)) { - /* We don't interested in this device */ - continue; + CFNumberGetValue(refCF, kCFNumberLongType, &usage); + + if ((usage != kHIDUsage_GD_Joystick && + usage != kHIDUsage_GD_GamePad && + usage != kHIDUsage_GD_MultiAxisController)) + { + /* We are not interested in this device */ + continue; + } } _glfwJoystick* joystick = &_glfwJoysticks[deviceCounter]; From a12b395442f8c1a7f0d0acfdcca9b1560e1bdb54 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 26 Mar 2012 15:21:13 +0200 Subject: [PATCH 2/4] Added headers to project. --- src/CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 26471f93..ae72cda7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,10 +3,12 @@ include_directories(${GLFW_SOURCE_DIR}/src ${GLFW_BINARY_DIR}/src ${glfw_INCLUDE_DIRS}) +set(common_HEADERS ${GLFW_SOURCE_DIR}/include/GL/glfw3.h internal.h) set(common_SOURCES error.c fullscreen.c gamma.c init.c input.c joystick.c opengl.c time.c window.c) if (_GLFW_COCOA_NSGL) + set(glfw_HEADERS ${common_HEADERS} cocoa_platform.h) set(glfw_SOURCES ${common_SOURCES} cocoa_fullscreen.m cocoa_gamma.c cocoa_init.m cocoa_input.m cocoa_joystick.m cocoa_opengl.m cocoa_time.c cocoa_window.m) @@ -14,18 +16,20 @@ if (_GLFW_COCOA_NSGL) # For some reason, CMake doesn't know about .m set_source_files_properties(${glfw_SOURCES} PROPERTIES LANGUAGE C) elseif (_GLFW_WIN32_WGL) + set(glfw_HEADERS ${common_HEADERS} win32_platform.h) set(glfw_SOURCES ${common_SOURCES} win32_fullscreen.c win32_gamma.c win32_init.c win32_input.c win32_joystick.c win32_opengl.c win32_time.c win32_window.c win32_dllmain.c) elseif (_GLFW_X11_GLX) + set(glfw_HEADERS ${common_HEADERS} x11_platform.h) set(glfw_SOURCES ${common_SOURCES} x11_fullscreen.c x11_gamma.c x11_init.c x11_input.c x11_joystick.c x11_keysym2unicode.c x11_opengl.c x11_time.c x11_window.c) endif() -add_library(glfw ${glfw_SOURCES}) +add_library(glfw ${glfw_SOURCES} ${glfw_HEADERS}) if (BUILD_SHARED_LIBS) From d40a3d1617c9a04e436208dc3ea692e1947b0e5f Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 26 Mar 2012 15:21:41 +0200 Subject: [PATCH 3/4] Renamed Cocoa window object member. --- src/cocoa_platform.h | 2 +- src/cocoa_window.m | 52 ++++++++++++++++++++++---------------------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/cocoa_platform.h b/src/cocoa_platform.h index b70fb184..801b4c88 100644 --- a/src/cocoa_platform.h +++ b/src/cocoa_platform.h @@ -72,7 +72,7 @@ typedef struct _GLFWcontextNSGL //------------------------------------------------------------------------ typedef struct _GLFWwindowNS { - id window; + id object; id delegate; unsigned int modifierFlags; double fracScrollX; diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 5cd7ee3e..3f3dbc4a 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -69,7 +69,7 @@ [window->NSGL.context update]; NSRect contentRect = - [window->NS.window contentRectForFrameRect:[window->NS.window frame]]; + [window->NS.object contentRectForFrameRect:[window->NS.object frame]]; _glfwInputWindowSize(window, contentRect.size.width, contentRect.size.height); } @@ -79,7 +79,7 @@ [window->NSGL.context update]; NSRect contentRect = - [window->NS.window contentRectForFrameRect:[window->NS.window frame]]; + [window->NS.object contentRectForFrameRect:[window->NS.object frame]]; CGPoint mainScreenOrigin = CGDisplayBounds(CGMainDisplayID()).origin; double mainScreenHeight = CGDisplayBounds(CGMainDisplayID()).size.height; @@ -360,7 +360,7 @@ static int convertMacKeyCode(unsigned int macKeyCode) NSPoint p = [event locationInWindow]; // Cocoa coordinate system has origin at lower left - p.y = [[window->NS.window contentView] bounds].size.height - p.y; + p.y = [[window->NS.object contentView] bounds].size.height - p.y; _glfwInputCursorMotion(window, p.x, p.y); } @@ -674,25 +674,25 @@ static GLboolean createWindow(_GLFWwindow* window, else styleMask = NSBorderlessWindowMask; - window->NS.window = [[NSWindow alloc] + window->NS.object = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, window->width, window->height) styleMask:styleMask backing:NSBackingStoreBuffered defer:NO]; - if (window->NS.window == nil) + if (window->NS.object == nil) { _glfwSetError(GLFW_PLATFORM_ERROR, "Cocoa/NSOpenGL: Failed to create window"); return GL_FALSE; } - [window->NS.window setTitle:[NSString stringWithUTF8String:wndconfig->title]]; - [window->NS.window setContentView:[[GLFWContentView alloc] + [window->NS.object setTitle:[NSString stringWithUTF8String:wndconfig->title]]; + [window->NS.object setContentView:[[GLFWContentView alloc] initWithGlfwWindow:window]]; - [window->NS.window setDelegate:window->NS.delegate]; - [window->NS.window setAcceptsMouseMovedEvents:YES]; - [window->NS.window center]; + [window->NS.object setDelegate:window->NS.delegate]; + [window->NS.object setAcceptsMouseMovedEvents:YES]; + [window->NS.object center]; return GL_TRUE; } @@ -906,8 +906,8 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window, if (!createContext(window, wndconfig, fbconfig)) return GL_FALSE; - [window->NS.window makeKeyAndOrderFront:nil]; - [window->NSGL.context setView:[window->NS.window contentView]]; + [window->NS.object makeKeyAndOrderFront:nil]; + [window->NSGL.context setView:[window->NS.object contentView]]; if (wndconfig->mode == GLFW_FULLSCREEN) { @@ -921,7 +921,7 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window, return GL_FALSE; } - [[window->NS.window contentView] enterFullScreenMode:[NSScreen mainScreen] + [[window->NS.object contentView] enterFullScreenMode:[NSScreen mainScreen] withOptions:nil]; } @@ -943,11 +943,11 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window, void _glfwPlatformCloseWindow(_GLFWwindow* window) { - [window->NS.window orderOut:nil]; + [window->NS.object orderOut:nil]; if (window->mode == GLFW_FULLSCREEN) { - [[window->NS.window contentView] exitFullScreenModeWithOptions:nil]; + [[window->NS.object contentView] exitFullScreenModeWithOptions:nil]; _glfwRestoreVideoMode(); } @@ -959,12 +959,12 @@ void _glfwPlatformCloseWindow(_GLFWwindow* window) [window->NSGL.context release]; window->NSGL.context = nil; - [window->NS.window setDelegate:nil]; + [window->NS.object setDelegate:nil]; [window->NS.delegate release]; window->NS.delegate = nil; - [window->NS.window close]; - window->NS.window = nil; + [window->NS.object close]; + window->NS.object = nil; // TODO: Probably more cleanup } @@ -976,7 +976,7 @@ void _glfwPlatformCloseWindow(_GLFWwindow* window) void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char *title) { - [window->NS.window setTitle:[NSString stringWithUTF8String:title]]; + [window->NS.object setTitle:[NSString stringWithUTF8String:title]]; } @@ -986,7 +986,7 @@ void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char *title) void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height) { - [window->NS.window setContentSize:NSMakeSize(width, height)]; + [window->NS.object setContentSize:NSMakeSize(width, height)]; } @@ -997,16 +997,16 @@ void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height) void _glfwPlatformSetWindowPos(_GLFWwindow* window, int x, int y) { NSRect contentRect = - [window->NS.window contentRectForFrameRect:[window->NS.window frame]]; + [window->NS.object contentRectForFrameRect:[window->NS.object frame]]; // We assume here that the client code wants to position the window within the // screen the window currently occupies - NSRect screenRect = [[window->NS.window screen] visibleFrame]; + NSRect screenRect = [[window->NS.object screen] visibleFrame]; contentRect.origin = NSMakePoint(screenRect.origin.x + x, screenRect.origin.y + screenRect.size.height - y - contentRect.size.height); - [window->NS.window setFrame:[window->NS.window frameRectForContentRect:contentRect] + [window->NS.object setFrame:[window->NS.object frameRectForContentRect:contentRect] display:YES]; } @@ -1017,7 +1017,7 @@ void _glfwPlatformSetWindowPos(_GLFWwindow* window, int x, int y) void _glfwPlatformIconifyWindow(_GLFWwindow* window) { - [window->NS.window miniaturize:nil]; + [window->NS.object miniaturize:nil]; } @@ -1027,7 +1027,7 @@ void _glfwPlatformIconifyWindow(_GLFWwindow* window) void _glfwPlatformRestoreWindow(_GLFWwindow* window) { - [window->NS.window deminiaturize:nil]; + [window->NS.object deminiaturize:nil]; } @@ -1168,7 +1168,7 @@ void _glfwPlatformSetMouseCursorPos(_GLFWwindow* window, int x, int y) // "global coordinates" are upside down from CG's... NSPoint localPoint = NSMakePoint(x, y); - NSPoint globalPoint = [window->NS.window convertBaseToScreen:localPoint]; + NSPoint globalPoint = [window->NS.object convertBaseToScreen:localPoint]; CGPoint mainScreenOrigin = CGDisplayBounds(CGMainDisplayID()).origin; double mainScreenHeight = CGDisplayBounds(CGMainDisplayID()).size.height; CGPoint targetPoint = CGPointMake(globalPoint.x - mainScreenOrigin.x, From 77c9baab3556f351806378ab294967bb0999a788 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 26 Mar 2012 15:29:01 +0200 Subject: [PATCH 4/4] Fixed issues found with static analysis. --- src/cocoa_platform.h | 1 + src/cocoa_window.m | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/cocoa_platform.h b/src/cocoa_platform.h index 801b4c88..67154190 100644 --- a/src/cocoa_platform.h +++ b/src/cocoa_platform.h @@ -74,6 +74,7 @@ typedef struct _GLFWwindowNS { id object; id delegate; + id view; unsigned int modifierFlags; double fracScrollX; double fracScrollY; diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 3f3dbc4a..e3b79706 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -687,9 +687,10 @@ static GLboolean createWindow(_GLFWwindow* window, return GL_FALSE; } + window->NS.view = [[GLFWContentView alloc] initWithGlfwWindow:window]; + [window->NS.object setTitle:[NSString stringWithUTF8String:wndconfig->title]]; - [window->NS.object setContentView:[[GLFWContentView alloc] - initWithGlfwWindow:window]]; + [window->NS.object setContentView:window->NS.view]; [window->NS.object setDelegate:window->NS.delegate]; [window->NS.object setAcceptsMouseMovedEvents:YES]; [window->NS.object center]; @@ -963,6 +964,9 @@ void _glfwPlatformCloseWindow(_GLFWwindow* window) [window->NS.delegate release]; window->NS.delegate = nil; + [window->NS.view release]; + window->NS.view = nil; + [window->NS.object close]; window->NS.object = nil;