mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
Monitor (macOS): detect maximum refresh rate
This commit is contained in:
@@ -5,6 +5,7 @@ typedef struct FFMonitorResult
|
||||
FFstrbuf name;
|
||||
uint32_t width; // native / maximum resolution, in pixels
|
||||
uint32_t height; // native / maximum resolution, in pixels
|
||||
double refreshRate;// maximum refresh rate in native resolution, in Hz
|
||||
uint32_t physicalWidth; // in mm
|
||||
uint32_t physicalHeight; // in mm
|
||||
bool hdrCompatible;
|
||||
|
||||
@@ -102,6 +102,19 @@ const char* ffDetectMonitor(FFlist* results)
|
||||
detectHdrSupportWithNSScreen(display);
|
||||
monitor->serial = CGDisplaySerialNumber((CGDirectDisplayID) display->id);
|
||||
|
||||
FF_CFTYPE_AUTO_RELEASE CFArrayRef modes = CGDisplayCopyAllDisplayModes((CGDirectDisplayID) display->id, NULL);
|
||||
double maxRefreshRate = 0;
|
||||
for (uint32_t j = 0; j < CFArrayGetCount(modes); ++j)
|
||||
{
|
||||
CGDisplayModeRef mode = (CGDisplayModeRef) CFArrayGetValueAtIndex(modes, j);
|
||||
if (CGDisplayModeGetWidth(mode) == (uint32_t) width && CGDisplayModeGetHeight(mode) == (uint32_t) height)
|
||||
{
|
||||
double refreshRate = CGDisplayModeGetRefreshRate(mode);
|
||||
if (refreshRate > maxRefreshRate) maxRefreshRate = refreshRate;
|
||||
}
|
||||
}
|
||||
monitor->refreshRate = maxRefreshRate;
|
||||
|
||||
int64_t year, week;
|
||||
if (ffCfDictGetInt64(displayInfo, CFSTR("DisplayYearManufacture"), &year) == NULL)
|
||||
monitor->manufactureYear = (uint16_t) year;
|
||||
|
||||
@@ -61,6 +61,7 @@ const char* ffDetectMonitor(FFlist* results)
|
||||
ffEdidGetPhysicalSize(edidData, &display->physicalWidth, &display->physicalHeight);
|
||||
ffEdidGetSerialAndManufactureDate(edidData, &display->serial, &display->manufactureYear, &display->manufactureWeek);
|
||||
display->hdrCompatible = ffEdidGetHdrCompatible(edidData, (uint32_t) edidLength);
|
||||
display->refreshRate = 0;
|
||||
}
|
||||
|
||||
ffStrbufSubstrBefore(&drmDir, drmDirLength);
|
||||
|
||||
@@ -49,6 +49,7 @@ const char* ffDetectMonitor(FFlist* results)
|
||||
ffStrbufInit(&display->name);
|
||||
ffEdidGetName(edidData, &display->name);
|
||||
ffEdidGetPhysicalSize(edidData, &display->physicalWidth, &display->physicalHeight);
|
||||
display->refreshRate = 0;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#define FF_MONITOR_NUM_FORMAT_ARGS 10
|
||||
#define FF_MONITOR_NUM_FORMAT_ARGS 11
|
||||
|
||||
void ffPrintMonitor(FFMonitorOptions* options)
|
||||
{
|
||||
@@ -52,6 +52,8 @@ void ffPrintMonitor(FFMonitorOptions* options)
|
||||
ffPrintLogoAndKey(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY);
|
||||
|
||||
printf("%ux%u px", display->width, display->height);
|
||||
if (display->refreshRate > 0)
|
||||
printf(" @ %.2f Hz", display->refreshRate);
|
||||
if (inch > 0)
|
||||
printf(" - %ux%u mm (%.2f inches, %.2f ppi)\n", display->physicalWidth, display->physicalHeight, inch, ppi);
|
||||
else
|
||||
@@ -79,6 +81,7 @@ void ffPrintMonitor(FFMonitorOptions* options)
|
||||
{FF_FORMAT_ARG_TYPE_UINT16, &display->manufactureYear, "manufacture-year"},
|
||||
{FF_FORMAT_ARG_TYPE_UINT16, &display->manufactureWeek, "manufacture-week"},
|
||||
{FF_FORMAT_ARG_TYPE_STRING, buf, "serial"},
|
||||
{FF_FORMAT_ARG_TYPE_DOUBLE, buf, "refresh-rate"},
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -153,6 +156,8 @@ void ffGenerateMonitorJsonResult(FF_MAYBE_UNUSED FFMonitorOptions* options, yyjs
|
||||
yyjson_mut_obj_add_uint(doc, physical, "height", item->physicalHeight);
|
||||
yyjson_mut_obj_add_uint(doc, physical, "width", item->physicalWidth);
|
||||
|
||||
yyjson_mut_obj_add_real(doc, obj, "refreshRate", item->refreshRate);
|
||||
|
||||
if (item->manufactureYear)
|
||||
{
|
||||
yyjson_mut_val* manufactureDate = yyjson_mut_obj_add_obj(doc, obj, "manufactureDate");
|
||||
@@ -190,6 +195,7 @@ void ffPrintMonitorHelpFormat(void)
|
||||
"Year of manufacturing - manufacture-year",
|
||||
"Nth week of manufacturing in the year - manufacture-week",
|
||||
"Serial number - serial",
|
||||
"Maximum refresh rate in Hz - refresh-rate",
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user