From c0781dd5f893d6755ebf7bffef42b7ffd8726f1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 16 Jul 2024 16:11:26 +0800 Subject: [PATCH] Display: print physical size --- src/common/format.h | 2 ++ src/modules/display/display.c | 31 +++++++++++++++++++++++-------- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/common/format.h b/src/common/format.h index af1b7ff41..f1b1aede0 100644 --- a/src/common/format.h +++ b/src/common/format.h @@ -1,5 +1,7 @@ #pragma once +#include "util/FFstrbuf.h" + typedef enum FFformatargtype { FF_FORMAT_ARG_TYPE_NULL = 0, diff --git a/src/modules/display/display.c b/src/modules/display/display.c index dcfc6fad8..e902922d3 100644 --- a/src/modules/display/display.c +++ b/src/modules/display/display.c @@ -4,7 +4,9 @@ #include "modules/display/display.h" #include "util/stringUtils.h" -#define FF_DISPLAY_NUM_FORMAT_ARGS 11 +#include + +#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", })); }