diff --git a/CMakeLists.txt b/CMakeLists.txt index f116fc68..1b3c9aeb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -356,13 +356,15 @@ if (_GLFW_COCOA AND _GLFW_NSGL) find_library(COCOA_FRAMEWORK Cocoa) find_library(IOKIT_FRAMEWORK IOKit) find_library(CORE_FOUNDATION_FRAMEWORK CoreFoundation) + find_library(CORE_VIDEO_FRAMEWORK CoreVideo) list(APPEND glfw_LIBRARIES ${COCOA_FRAMEWORK} ${OPENGL_gl_LIBRARY} ${IOKIT_FRAMEWORK} - ${CORE_FOUNDATION_FRAMEWORK}) + ${CORE_FOUNDATION_FRAMEWORK} + ${CORE_VIDEO_FRAMEWORK}) set(GLFW_PKG_DEPS "") - set(GLFW_PKG_LIBS "-framework Cocoa -framework OpenGL -framework IOKit -framework CoreFoundation") + set(GLFW_PKG_LIBS "-framework Cocoa -framework OpenGL -framework IOKit -framework CoreFoundation -framework CoreVideo") endif() #-------------------------------------------------------------------- diff --git a/README.md b/README.md index c44e924c..1eaa9b42 100644 --- a/README.md +++ b/README.md @@ -223,6 +223,7 @@ See the [GLFW documentation](http://www.glfw.org/docs/latest/). with Xcode 5 - [Cocoa] Bugfix: The cursor remained visible if moved onto client area after having been set to hidden outside it + - [Cocoa] Bugfix: The refresh rate was zero for all modes of certain monitors - [X11] Added setting of the `WM_CLASS` property to the initial window title @@ -309,6 +310,7 @@ skills. - Matt Sealey - SephiRok - Steve Sexton + - Systemcluster - Dmitri Shuralyov - Daniel Skorupski - Bradley Smith diff --git a/docs/build.dox b/docs/build.dox index eda5ddb2..d793b112 100644 --- a/docs/build.dox +++ b/docs/build.dox @@ -189,7 +189,7 @@ If you are using the dynamic library version of GLFW, simply add it to the project dependencies. If you are using the static library version of GLFW, add it and the Cocoa, -OpenGL and IOKit frameworks to the project as dependencies. +OpenGL, IOKit and CoreVideo frameworks to the project as dependencies. @subsection build_link_osx With command-line on OS X @@ -198,7 +198,7 @@ If you do not wish to use pkg-config, you need to add the required frameworks and libraries to your command-line using the `-l` and `-framework` switches, i.e.: - cc -o myprog myprog.c -lglfw -framework Cocoa -framework OpenGL -framework IOKit + cc -o myprog myprog.c -lglfw -framework Cocoa -framework OpenGL -framework IOKit -framework CoreVideo Note that you do not add the `.framework` extension to a framework when adding it from the command-line. diff --git a/src/cocoa_monitor.m b/src/cocoa_monitor.m index e7aec2b1..83402803 100644 --- a/src/cocoa_monitor.m +++ b/src/cocoa_monitor.m @@ -31,6 +31,8 @@ #include #include +#include +#include // Get the name of the specified display @@ -94,13 +96,21 @@ static GLboolean modeIsGood(CGDisplayModeRef mode) // Convert Core Graphics display mode to GLFW video mode // -static GLFWvidmode vidmodeFromCGDisplayMode(CGDisplayModeRef mode) +static GLFWvidmode vidmodeFromCGDisplayMode(CGDisplayModeRef mode, + CVDisplayLinkRef link) { GLFWvidmode result; result.width = (int) CGDisplayModeGetWidth(mode); result.height = (int) CGDisplayModeGetHeight(mode); result.refreshRate = (int) CGDisplayModeGetRefreshRate(mode); + if (result.refreshRate == 0) + { + const CVTime time = CVDisplayLinkGetNominalOutputVideoRefreshPeriod(link); + if (!(time.flags & kCVTimeIsIndefinite)) + result.refreshRate = (int) (time.timeScale / (double) time.timeValue); + } + CFStringRef format = CGDisplayModeCopyPixelEncoding(mode); if (CFStringCompare(format, CFSTR(IO16BitDirectPixels), 0) == 0) @@ -334,6 +344,9 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found) CFArrayRef modes; CFIndex count, i; GLFWvidmode* result; + CVDisplayLinkRef link; + + CVDisplayLinkCreateWithCGDisplay(monitor->ns.displayID, &link); modes = CGDisplayCopyAllDisplayModes(monitor->ns.displayID, NULL); count = CFArrayGetCount(modes); @@ -348,21 +361,28 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found) mode = (CGDisplayModeRef) CFArrayGetValueAtIndex(modes, i); if (modeIsGood(mode)) { - result[*found] = vidmodeFromCGDisplayMode(mode); + result[*found] = vidmodeFromCGDisplayMode(mode, link); (*found)++; } } CFRelease(modes); + + CVDisplayLinkRelease(link); return result; } void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode *mode) { CGDisplayModeRef displayMode; + CVDisplayLinkRef link; + + CVDisplayLinkCreateWithCGDisplay(monitor->ns.displayID, &link); displayMode = CGDisplayCopyDisplayMode(monitor->ns.displayID); - *mode = vidmodeFromCGDisplayMode(displayMode); + *mode = vidmodeFromCGDisplayMode(displayMode, link); CGDisplayModeRelease(displayMode); + + CVDisplayLinkRelease(link); }