mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2025-02-20 11:43:27 +08:00
PhycialDisplay: detect phycial size
This commit is contained in:
parent
abae204ab8
commit
008c9a597e
@ -5,6 +5,8 @@ typedef struct FFPhycialDisplayResult
|
||||
FFstrbuf name;
|
||||
uint32_t width; // native / maximum resolution, in pixels
|
||||
uint32_t height; // native / maximum resolution, in pixels
|
||||
uint32_t phycialWidth; // in mm
|
||||
uint32_t phycialHeight; // in mm
|
||||
} FFPhycialDisplayResult;
|
||||
|
||||
const char* ffDetectPhycialDisplay(FFlist* results);
|
||||
|
@ -31,6 +31,10 @@ static const char* detectWithDisplayServices(const FFDisplayServerResult* displa
|
||||
CFDictionaryRef productNames;
|
||||
if(!ffCfDictGetDict(displayInfo, CFSTR(kDisplayProductName), &productNames))
|
||||
ffCfDictGetString(productNames, CFSTR("en_US"), &phycialDisplay->name);
|
||||
|
||||
CGSize size = CGDisplayScreenSize((CGDirectDisplayID) display->id);
|
||||
phycialDisplay->phycialWidth = (uint32_t) (size.width + 0.5);
|
||||
phycialDisplay->phycialHeight = (uint32_t) (size.height + 0.5);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -83,14 +87,16 @@ static const char* detectWithDdcci(FFlist* results)
|
||||
continue;
|
||||
|
||||
uint32_t width, height;
|
||||
ffEdidGetPhycialResolution(CFDataGetBytePtr(edid), &width, &height);
|
||||
const uint8_t* edidData = CFDataGetBytePtr(edid);
|
||||
ffEdidGetPhycialResolution(edidData, &width, &height);
|
||||
if (width == 0 || height == 0) continue;
|
||||
|
||||
FFPhycialDisplayResult* display = (FFPhycialDisplayResult*) ffListAdd(results);
|
||||
display->width = width;
|
||||
display->height = height;
|
||||
ffStrbufInit(&display->name);
|
||||
ffEdidGetName(CFDataGetBytePtr(edid), &display->name);
|
||||
ffEdidGetName(edidData, &display->name);
|
||||
ffEdidGetPhycialSize(edidData, &display->phycialWidth, &display->phycialHeight);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
@ -50,6 +50,7 @@ const char* ffDetectPhycialDisplay(FFlist* results)
|
||||
display->width = width;
|
||||
display->height = height;
|
||||
ffStrbufInitS(&display->name, plainName);
|
||||
ffEdidGetPhycialSize(edidData, &display->phycialWidth, &display->phycialHeight);
|
||||
}
|
||||
|
||||
ffStrbufSubstrBefore(&drmDir, drmDirLength);
|
||||
|
@ -36,13 +36,12 @@ const char* ffDetectPhycialDisplay(FFlist* results)
|
||||
ffEdidGetPhycialResolution(edidData, &width, &height);
|
||||
if (width == 0 || height == 0) continue;
|
||||
|
||||
wchar_t wName[MAX_PATH] = {}; // MONITOR\BOE09F9
|
||||
if (!SetupDiGetDeviceRegistryPropertyW(hdev, &did, SPDRP_HARDWAREID, NULL, (BYTE*) wName, sizeof(wName), NULL)) continue;
|
||||
|
||||
FFPhycialDisplayResult* display = (FFPhycialDisplayResult*) ffListAdd(results);
|
||||
display->width = width;
|
||||
display->height = height;
|
||||
ffStrbufInitWS(&display->name, wcschr(wName, L'\\') + 1);
|
||||
ffStrbufInit(&display->name);
|
||||
ffEdidGetName(edidData, &display->name);
|
||||
ffEdidGetPhycialSize(edidData, &display->phycialWidth, &display->phycialHeight);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
@ -4,6 +4,8 @@
|
||||
#include "modules/phycialdisplay/phycialdisplay.h"
|
||||
#include "util/stringUtils.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#define FF_PHYCIALDISPLAY_DISPLAY_NAME "Phycial Display"
|
||||
#define FF_PHYCIALDISPLAY_NUM_FORMAT_ARGS 3
|
||||
|
||||
@ -29,6 +31,8 @@ void ffPrintPhycialDisplay(FFPhycialDisplayOptions* options)
|
||||
FF_STRBUF_AUTO_DESTROY key = ffStrbufCreate();
|
||||
FF_LIST_FOR_EACH(FFPhycialDisplayResult, display, result)
|
||||
{
|
||||
double inch = sqrt(display->phycialWidth * display->phycialWidth + display->phycialHeight * display->phycialHeight) / 25.4;
|
||||
|
||||
if(options->moduleArgs.outputFormat.length == 0)
|
||||
{
|
||||
ffStrbufClear(&key);
|
||||
@ -44,7 +48,7 @@ void ffPrintPhycialDisplay(FFPhycialDisplayOptions* options)
|
||||
}
|
||||
ffPrintLogoAndKey(key.chars, 0, NULL, &options->moduleArgs.keyColor);
|
||||
|
||||
printf("%ux%u\n", display->width, display->height);
|
||||
printf("%upx x %upx - %umm x %umm (%.2f inches)\n", display->width, display->height, display->phycialWidth, display->phycialHeight, inch);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -52,6 +56,9 @@ void ffPrintPhycialDisplay(FFPhycialDisplayOptions* options)
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &display->name},
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &display->width},
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &display->height},
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &display->phycialWidth},
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &display->phycialHeight},
|
||||
{FF_FORMAT_ARG_TYPE_DOUBLE, &inch},
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -26,3 +26,9 @@ void ffEdidGetName(const uint8_t edid[128], FFstrbuf* name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ffEdidGetPhycialSize(const uint8_t edid[128], uint32_t* width, uint32_t* height)
|
||||
{
|
||||
*width = (((uint32_t) edid[68] & 0xF0) << 4) + edid[66];
|
||||
*height = (((uint32_t) edid[68] & 0x0F) << 8) + edid[67];
|
||||
}
|
||||
|
@ -8,5 +8,6 @@
|
||||
|
||||
void ffEdidGetName(const uint8_t edid[128], FFstrbuf* name);
|
||||
void ffEdidGetPhycialResolution(const uint8_t edid[128], uint32_t* width, uint32_t* height);
|
||||
void ffEdidGetPhycialSize(const uint8_t edid[128], uint32_t* width, uint32_t* height); // in mm
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user