diff --git a/src/detection/displayserver/displayserver.c b/src/detection/displayserver/displayserver.c index ddc973962..74898721b 100644 --- a/src/detection/displayserver/displayserver.c +++ b/src/detection/displayserver/displayserver.c @@ -33,7 +33,10 @@ FFDisplayResult* ffdsAppendDisplay( display->primary = primary; display->bitDepth = 0; - display->hdrEnabled = false; + display->hdrStatus = FF_DISPLAY_HDR_STATUS_UNKNOWN; + display->manufactureYear = 0; + display->manufactureWeek = 0; + display->serial = 0; return display; } diff --git a/src/detection/displayserver/displayserver.h b/src/detection/displayserver/displayserver.h index 127dbc5fe..5a030b12a 100644 --- a/src/detection/displayserver/displayserver.h +++ b/src/detection/displayserver/displayserver.h @@ -48,6 +48,14 @@ typedef enum FFDisplayType { FF_DISPLAY_TYPE_EXTERNAL, } FFDisplayType; +typedef enum FFDisplayHdrStatus +{ + FF_DISPLAY_HDR_STATUS_UNKNOWN, + FF_DISPLAY_HDR_STATUS_UNSUPPORTED, + FF_DISPLAY_HDR_STATUS_SUPPORTED, + FF_DISPLAY_HDR_STATUS_ENABLED, +} FFDisplayHdrStatus; + typedef struct FFDisplayResult { uint32_t width; @@ -63,7 +71,10 @@ typedef struct FFDisplayResult uint32_t physicalHeight; bool primary; uint8_t bitDepth; - bool hdrEnabled; + FFDisplayHdrStatus hdrStatus; + uint16_t manufactureYear; + uint16_t manufactureWeek; + uint32_t serial; } FFDisplayResult; typedef struct FFDisplayServerResult diff --git a/src/detection/displayserver/displayserver_apple.c b/src/detection/displayserver/displayserver_apple.c index ab2abe5e2..b419d52c7 100644 --- a/src/detection/displayserver/displayserver_apple.c +++ b/src/detection/displayserver/displayserver_apple.c @@ -8,9 +8,10 @@ #include #include +extern Boolean CoreDisplay_Display_SupportsHDRMode(CGDirectDisplayID display) __attribute__((weak_import)); +extern Boolean CoreDisplay_Display_IsHDRModeEnabled(CGDirectDisplayID display) __attribute__((weak_import)); #ifdef MAC_OS_X_VERSION_10_15 extern CFDictionaryRef CoreDisplay_DisplayCreateInfoDictionary(CGDirectDisplayID display) __attribute__((weak_import)); -extern Boolean CoreDisplay_Display_IsHDRModeEnabled(CGDirectDisplayID display) __attribute__((weak_import)); #else #include #endif @@ -89,12 +90,23 @@ static void detectDisplays(FFDisplayServerResult* ds) display->bitDepth = (uint8_t) bitDepth; } - #ifdef MAC_OS_X_VERSION_10_15 - if (CoreDisplay_Display_IsHDRModeEnabled) + if (display->type == FF_DISPLAY_TYPE_BUILTIN) + display->hdrStatus = CFDictionaryContainsKey(displayInfo, CFSTR("ReferencePeakHDRLuminance")) + ? FF_DISPLAY_HDR_STATUS_SUPPORTED : FF_DISPLAY_HDR_STATUS_UNSUPPORTED; + else if (CoreDisplay_Display_SupportsHDRMode) { - display->hdrEnabled = CoreDisplay_Display_IsHDRModeEnabled(screen); + if (CoreDisplay_Display_SupportsHDRMode(screen)) + { + if (CoreDisplay_Display_IsHDRModeEnabled) + { + display->hdrStatus = CoreDisplay_Display_IsHDRModeEnabled(screen) + ? FF_DISPLAY_HDR_STATUS_ENABLED + : FF_DISPLAY_HDR_STATUS_SUPPORTED; + } + else + display->hdrStatus = FF_DISPLAY_HDR_STATUS_SUPPORTED; + } } - #endif } CGDisplayModeRelease(mode); } diff --git a/src/modules/display/display.c b/src/modules/display/display.c index ff1c93528..91e5719d1 100644 --- a/src/modules/display/display.c +++ b/src/modules/display/display.c @@ -6,7 +6,7 @@ #include -#define FF_DISPLAY_NUM_FORMAT_ARGS 15 +#define FF_DISPLAY_NUM_FORMAT_ARGS 18 static int sortByNameAsc(FFDisplayResult* a, FFDisplayResult* b) { @@ -127,7 +127,7 @@ void ffPrintDisplay(FFDisplayOptions* options) if(result->type != FF_DISPLAY_TYPE_UNKNOWN) ffStrbufAppendS(&buffer, result->type == FF_DISPLAY_TYPE_BUILTIN ? " [Built-in]" : " [External]"); - if (result->hdrEnabled) + if (result->hdrStatus == FF_DISPLAY_HDR_STATUS_ENABLED) ffStrbufAppendS(&buffer, " [HDR]"); if(moduleIndex > 0 && result->primary) @@ -151,6 +151,16 @@ void ffPrintDisplay(FFDisplayOptions* options) else refreshRate[0] = 0; + char buf[32]; + if (result->serial) + { + const uint8_t* nums = (uint8_t*) &result->serial; + snprintf(buf, sizeof(buf), "%2X-%2X-%2X-%2X", nums[0], nums[1], nums[2], nums[3]); + } + else + buf[0] = '\0'; + + bool hdrEnabled = result->hdrStatus == FF_DISPLAY_HDR_STATUS_ENABLED; FF_PRINT_FORMAT_CHECKED(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, FF_DISPLAY_NUM_FORMAT_ARGS, ((FFformatarg[]) { FF_FORMAT_ARG(result->width, "width"), FF_FORMAT_ARG(result->height, "height"), @@ -166,7 +176,10 @@ void ffPrintDisplay(FFDisplayOptions* options) FF_FORMAT_ARG(inch, "inch"), FF_FORMAT_ARG(ppi, "ppi"), FF_FORMAT_ARG(result->bitDepth, "bit-depth"), - FF_FORMAT_ARG(result->hdrEnabled, "hdr-enabled"), + FF_FORMAT_ARG(hdrEnabled, "hdr-enabled"), + FF_FORMAT_ARG(result->manufactureYear, "manufacture-year"), + FF_FORMAT_ARG(result->manufactureWeek, "manufacture-week"), + FF_FORMAT_ARG(buf, "serial"), })); } } @@ -335,7 +348,23 @@ void ffGenerateDisplayJsonResult(FF_MAYBE_UNUSED FFDisplayOptions* options, yyjs yyjson_mut_obj_add_real(doc, obj, "refreshRate", item->refreshRate); yyjson_mut_obj_add_uint(doc, obj, "rotation", item->rotation); yyjson_mut_obj_add_uint(doc, obj, "bitDepth", item->bitDepth); - yyjson_mut_obj_add_bool(doc, obj, "hdrEnabled", item->hdrEnabled); + if (item->hdrStatus == FF_DISPLAY_HDR_STATUS_UNKNOWN) + yyjson_mut_obj_add_null(doc, obj, "hdrStatus"); + else switch (item->hdrStatus) + { + case FF_DISPLAY_HDR_STATUS_UNSUPPORTED: + yyjson_mut_obj_add_str(doc, obj, "hdrStatus", "Unsupported"); + break; + case FF_DISPLAY_HDR_STATUS_SUPPORTED: + yyjson_mut_obj_add_str(doc, obj, "hdrStatus", "Supported"); + break; + case FF_DISPLAY_HDR_STATUS_ENABLED: + yyjson_mut_obj_add_str(doc, obj, "hdrStatus", "Enabled"); + break; + default: + yyjson_mut_obj_add_str(doc, obj, "hdrStatus", "Unknown"); + break; + } switch (item->type) { @@ -349,6 +378,22 @@ void ffGenerateDisplayJsonResult(FF_MAYBE_UNUSED FFDisplayOptions* options, yyjs yyjson_mut_obj_add_str(doc, obj, "type", "Unknown"); break; } + + if (item->manufactureYear) + { + yyjson_mut_val* manufactureDate = yyjson_mut_obj_add_obj(doc, obj, "manufactureDate"); + yyjson_mut_obj_add_uint(doc, manufactureDate, "year", item->manufactureYear); + yyjson_mut_obj_add_uint(doc, manufactureDate, "week", item->manufactureWeek); + } + else + { + yyjson_mut_obj_add_null(doc, obj, "manufactureDate"); + } + + if (item->serial) + yyjson_mut_obj_add_uint(doc, obj, "serial", item->serial); + else + yyjson_mut_obj_add_null(doc, obj, "serial"); } } @@ -369,7 +414,10 @@ void ffPrintDisplayHelpFormat(void) "Physical diagonal length in inches - inch", "Pixels per inch (PPI) - ppi", "Bits per color channel - bit-depth", - "True if high dynamic range (HDR) is enabled - hdr-enabled", + "True if high dynamic range (HDR) mode is enabled - hdr-enabled", + "Year of manufacturing - manufacture-year", + "Nth week of manufacturing in the year - manufacture-week", + "Serial number - serial", })); }