Skip to content

Commit 21a3576

Browse files
committed
Display (macOS): detect maximum resolution & refresh rate
1 parent fa92900 commit 21a3576

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/detection/displayserver/displayserver_apple.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ static void detectDisplays(FFDisplayServerResult* ds)
6060
displayInfo = IODisplayCreateInfoDictionary(servicePort, kIODisplayOnlyPreferredName);
6161
}
6262
#endif
63+
6364
uint32_t physicalWidth = 0, physicalHeight = 0;
65+
uint32_t preferredWidth = 0, preferredHeight = 0;
66+
double preferredRefreshRate = 0;
67+
6468
if(displayInfo)
6569
{
6670
CFDictionaryRef productNames;
@@ -76,6 +80,32 @@ static void detectDisplays(FFDisplayServerResult* ds)
7680
if (edidLength >= 128)
7781
ffEdidGetPhysicalSize(edidData, &physicalWidth, &physicalHeight);
7882
}
83+
84+
if (!physicalWidth || !physicalHeight)
85+
{
86+
if (ffCfDictGetInt(displayInfo, CFSTR(kDisplayHorizontalImageSize), (int*) &physicalWidth) == NULL)
87+
ffCfDictGetInt(displayInfo, CFSTR(kDisplayVerticalImageSize), (int*) &physicalHeight);
88+
}
89+
90+
ffCfDictGetInt(displayInfo, CFSTR("kCGDisplayPixelWidth"), (int*) &preferredWidth);
91+
ffCfDictGetInt(displayInfo, CFSTR("kCGDisplayPixelHeight"), (int*) &preferredHeight);
92+
if (preferredWidth && preferredHeight)
93+
{
94+
FF_CFTYPE_AUTO_RELEASE CFArrayRef allModes = CGDisplayCopyAllDisplayModes(screen, NULL);
95+
if (allModes)
96+
{
97+
for (CFIndex i = 0, count = CFArrayGetCount(allModes); i < count; i++)
98+
{
99+
CGDisplayModeRef modeInfo = (CGDisplayModeRef) CFArrayGetValueAtIndex(allModes, i);
100+
if (CGDisplayModeGetPixelWidth(modeInfo) == preferredWidth && CGDisplayModeGetPixelHeight(modeInfo) == preferredHeight)
101+
{
102+
double rr = CGDisplayModeGetRefreshRate(modeInfo);
103+
if (rr > preferredRefreshRate) preferredRefreshRate = rr;
104+
break;
105+
}
106+
}
107+
}
108+
}
79109
}
80110

81111
if (!physicalWidth || !physicalHeight)
@@ -91,6 +121,9 @@ static void detectDisplays(FFDisplayServerResult* ds)
91121
refreshRate,
92122
(uint32_t)CGDisplayModeGetWidth(mode),
93123
(uint32_t)CGDisplayModeGetHeight(mode),
124+
preferredWidth,
125+
preferredHeight,
126+
preferredRefreshRate,
94127
(uint32_t)CGDisplayRotation(screen),
95128
&buffer,
96129
CGDisplayIsBuiltin(screen) ? FF_DISPLAY_TYPE_BUILTIN : FF_DISPLAY_TYPE_EXTERNAL,

0 commit comments

Comments
 (0)