Skip to content

Commit ebe3039

Browse files
committed
Display (macOS): fix zero refresh rate on some monitors
1 parent 4c7d479 commit ebe3039

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Bugfixes:
44

55
* Fix builds on s390x (@jonathanspw, #402)
6+
* Fix zero refresh rate on some monitors (macOS)
67

78
# 1.9.0
89

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,7 @@ if(APPLE)
666666
PRIVATE "-framework OpenCL"
667667
PRIVATE "-framework Cocoa"
668668
PRIVATE "-framework CoreWLAN"
669+
PRIVATE "-framework CoreVideo"
669670
PRIVATE "-weak_framework MediaRemote -F /System/Library/PrivateFrameworks"
670671
PRIVATE "-weak_framework DisplayServices -F /System/Library/PrivateFrameworks"
671672
)

src/detection/displayserver/displayserver_apple.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <string.h>
77
#include <assert.h>
88
#include <CoreGraphics/CGDirectDisplay.h>
9+
#include <CoreVideo/CVDisplayLink.h>
910

1011
static void detectDisplays(FFDisplayServerResult* ds)
1112
{
@@ -20,10 +21,25 @@ static void detectDisplays(FFDisplayServerResult* ds)
2021
CGDisplayModeRef mode = CGDisplayCopyDisplayMode(screen);
2122
if(mode)
2223
{
24+
//https://github.com/glfw/glfw/commit/aab08712dd8142b642e2042e7b7ba563acd07a45
25+
double refreshRate = CGDisplayModeGetRefreshRate(mode);
26+
27+
if (refreshRate == 0)
28+
{
29+
CVDisplayLinkRef link;
30+
if(CVDisplayLinkCreateWithCGDisplay(screen, &link) == kCVReturnSuccess)
31+
{
32+
const CVTime time = CVDisplayLinkGetNominalOutputVideoRefreshPeriod(link);
33+
if (!(time.flags & kCVTimeIsIndefinite))
34+
refreshRate = time.timeScale / (double) time.timeValue + 0.5; //59.97...
35+
CVDisplayLinkRelease(link);
36+
}
37+
}
38+
2339
ffdsAppendDisplay(ds,
2440
(uint32_t)CGDisplayModeGetPixelWidth(mode),
2541
(uint32_t)CGDisplayModeGetPixelHeight(mode),
26-
(uint32_t)CGDisplayModeGetRefreshRate(mode),
42+
(uint32_t)refreshRate,
2743
(uint32_t)CGDisplayModeGetWidth(mode),
2844
(uint32_t)CGDisplayModeGetHeight(mode)
2945
);

0 commit comments

Comments
 (0)