Display: print physical size

This commit is contained in:
李通洲
2024-07-16 16:11:26 +08:00
parent c795c20723
commit c0781dd5f8
2 changed files with 25 additions and 8 deletions
+2
View File
@@ -1,5 +1,7 @@
#pragma once
#include "util/FFstrbuf.h"
typedef enum FFformatargtype
{
FF_FORMAT_ARG_TYPE_NULL = 0,
+23 -8
View File
@@ -4,7 +4,9 @@
#include "modules/display/display.h"
#include "util/stringUtils.h"
#define FF_DISPLAY_NUM_FORMAT_ARGS 11
#include <math.h>
#define FF_DISPLAY_NUM_FORMAT_ARGS 13
static int sortByNameAsc(FFDisplayResult* a, FFDisplayResult* b)
{
@@ -96,35 +98,44 @@ void ffPrintDisplay(FFDisplayOptions* options)
}));
}
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate();
if(options->moduleArgs.outputFormat.length == 0)
{
ffPrintLogoAndKey(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY);
printf("%ix%i", result->width, result->height);
ffStrbufAppendF(&buffer, "%ix%i", result->width, result->height);
if(result->refreshRate > 0)
{
if(options->preciseRefreshRate)
printf(" @ %gHz", ((int) (result->refreshRate * 1000 + 0.5)) / 1000.0);
ffStrbufAppendF(&buffer, " @ %gHz", ((int) (result->refreshRate * 1000 + 0.5)) / 1000.0);
else
printf(" @ %iHz", (uint32_t) (result->refreshRate + 0.5));
ffStrbufAppendF(&buffer, " @ %iHz", (uint32_t) (result->refreshRate + 0.5));
}
if(
result->scaledWidth > 0 && result->scaledWidth != result->width &&
result->scaledHeight > 0 && result->scaledHeight != result->height)
printf(" (as %ix%i)", result->scaledWidth, result->scaledHeight);
ffStrbufAppendF(&buffer, " (as %ix%i)", result->scaledWidth, result->scaledHeight);
if (result->physicalWidth > 0 && result->physicalHeight > 0)
ffStrbufAppendF(&buffer, " in %ix%i mm", result->physicalWidth, result->physicalHeight);
if(result->type != FF_DISPLAY_TYPE_UNKNOWN)
fputs(result->type == FF_DISPLAY_TYPE_BUILTIN ? " [Built-in]" : " [External]", stdout);
ffStrbufAppendS(&buffer, result->type == FF_DISPLAY_TYPE_BUILTIN ? " [Built-in]" : " [External]");
if(moduleIndex > 0 && result->primary)
printf(" *");
ffStrbufAppendS(&buffer, " *");
putchar('\n');
ffStrbufPutTo(&buffer, stdout);
ffStrbufClear(&buffer);
}
else
{
double inch = sqrt(result->physicalWidth * result->physicalWidth + result->physicalHeight * result->physicalHeight) / 25.4;
double ppi = sqrt(result->width * result->width + result->height * result->height) / inch;
FF_PRINT_FORMAT_CHECKED(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, FF_DISPLAY_NUM_FORMAT_ARGS, ((FFformatarg[]) {
{FF_FORMAT_ARG_TYPE_UINT, &result->width, "width"},
{FF_FORMAT_ARG_TYPE_UINT, &result->height, "height"},
@@ -137,6 +148,8 @@ void ffPrintDisplay(FFDisplayOptions* options)
{FF_FORMAT_ARG_TYPE_BOOL, &result->primary, "is-primary"},
{FF_FORMAT_ARG_TYPE_UINT, &result->physicalWidth, "physical-width"},
{FF_FORMAT_ARG_TYPE_UINT, &result->physicalHeight, "physical-height"},
{FF_FORMAT_ARG_TYPE_DOUBLE, &inch, "inch"},
{FF_FORMAT_ARG_TYPE_DOUBLE, &ppi, "ppi"},
}));
}
}
@@ -327,6 +340,8 @@ void ffPrintDisplayHelpFormat(void)
"True if being the primary screen - is-primary",
"Screen physical width (in millimeters) - physical-width",
"Screen physical height (in millimeters) - physical-height",
"Physical diagonal length in inches - inch",
"Pixels per inch (PPI) - ppi",
}));
}