mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2025-02-20 11:43:27 +08:00
Display: --display-compact-type
support *-with-refresh-rate
Ref: https://github.com/fastfetch-cli/fastfetch/discussions/732
This commit is contained in:
parent
5e7cfe2976
commit
5fb4b6dc04
@ -1101,7 +1101,9 @@
|
||||
"enum": [
|
||||
"none",
|
||||
"original",
|
||||
"scaled"
|
||||
"scaled",
|
||||
"original-with-refresh-rate",
|
||||
"scaled-with-refresh-rate"
|
||||
],
|
||||
"description": "Set if all displays should be printed in one line",
|
||||
"default": "none"
|
||||
|
@ -1033,7 +1033,9 @@
|
||||
"enum": {
|
||||
"none": "Disable this compact mode",
|
||||
"original": "Print original resolutions",
|
||||
"scaled": "Print scaled resolutions"
|
||||
"scaled": "Print scaled resolutions",
|
||||
"original-with-refresh-rate": "Print original resolutions with refresh rate",
|
||||
"scaled-with-refresh-rate": "Print scaled resolutions with refresh rate"
|
||||
},
|
||||
"default": "none"
|
||||
}
|
||||
|
@ -35,21 +35,37 @@ void ffPrintDisplay(FFDisplayOptions* options)
|
||||
{
|
||||
ffPrintLogoAndKey(FF_DISPLAY_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
|
||||
|
||||
int index = 0;
|
||||
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate();
|
||||
FF_LIST_FOR_EACH(FFDisplayResult, result, dsResult->displays)
|
||||
{
|
||||
if (options->compactType & FF_DISPLAY_COMPACT_TYPE_ORIGINAL_BIT)
|
||||
{
|
||||
if (index++) putchar(' ');
|
||||
printf("%ix%i", result->width, result->height);
|
||||
ffStrbufAppendF(&buffer, "%ix%i", result->width, result->height);
|
||||
}
|
||||
if (options->compactType & FF_DISPLAY_COMPACT_TYPE_SCALED_BIT)
|
||||
else
|
||||
{
|
||||
if (index++) putchar(' ');
|
||||
printf("%ix%i", result->scaledWidth, result->scaledHeight);
|
||||
ffStrbufAppendF(&buffer, "%ix%i", result->scaledWidth, result->scaledHeight);
|
||||
}
|
||||
|
||||
if (options->compactType & FF_DISPLAY_COMPACT_TYPE_REFRESH_RATE_BIT)
|
||||
{
|
||||
if (result->refreshRate > 0)
|
||||
{
|
||||
if (options->preciseRefreshRate)
|
||||
ffStrbufAppendF(&buffer, " @ %gHz", result->refreshRate);
|
||||
else
|
||||
ffStrbufAppendF(&buffer, " @ %iHz", (uint32_t) (result->refreshRate + 0.5));
|
||||
}
|
||||
ffStrbufAppendS(&buffer, ", ");
|
||||
}
|
||||
else
|
||||
{
|
||||
ffStrbufAppendC(&buffer, ' ');
|
||||
}
|
||||
}
|
||||
putchar('\n');
|
||||
ffStrbufTrimRight(&buffer, ' ');
|
||||
ffStrbufTrimRight(&buffer, ',');
|
||||
ffStrbufPutTo(&buffer, stdout);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -137,6 +153,8 @@ bool ffParseDisplayCommandOptions(FFDisplayOptions* options, const char* key, co
|
||||
{ "none", FF_DISPLAY_COMPACT_TYPE_NONE },
|
||||
{ "original", FF_DISPLAY_COMPACT_TYPE_ORIGINAL_BIT },
|
||||
{ "scaled", FF_DISPLAY_COMPACT_TYPE_SCALED_BIT },
|
||||
{ "original-with-refresh-rate", FF_DISPLAY_COMPACT_TYPE_ORIGINAL_BIT | FF_DISPLAY_COMPACT_TYPE_REFRESH_RATE_BIT },
|
||||
{ "scaled-with-refresh-rate", FF_DISPLAY_COMPACT_TYPE_SCALED_BIT | FF_DISPLAY_COMPACT_TYPE_REFRESH_RATE_BIT },
|
||||
{},
|
||||
});
|
||||
return true;
|
||||
@ -182,6 +200,8 @@ void ffParseDisplayJsonObject(FFDisplayOptions* options, yyjson_val* module)
|
||||
{ "none", FF_DISPLAY_COMPACT_TYPE_NONE },
|
||||
{ "original", FF_DISPLAY_COMPACT_TYPE_ORIGINAL_BIT },
|
||||
{ "scaled", FF_DISPLAY_COMPACT_TYPE_SCALED_BIT },
|
||||
{ "original-with-refresh-rate", FF_DISPLAY_COMPACT_TYPE_ORIGINAL_BIT | FF_DISPLAY_COMPACT_TYPE_REFRESH_RATE_BIT },
|
||||
{ "scaled-with-refresh-rate", FF_DISPLAY_COMPACT_TYPE_SCALED_BIT | FF_DISPLAY_COMPACT_TYPE_REFRESH_RATE_BIT },
|
||||
{},
|
||||
});
|
||||
if (error)
|
||||
@ -226,7 +246,7 @@ void ffGenerateDisplayJsonConfig(FFDisplayOptions* options, yyjson_mut_doc* doc,
|
||||
|
||||
if (options->compactType != defaultOptions.compactType)
|
||||
{
|
||||
switch (options->compactType)
|
||||
switch ((int) options->compactType)
|
||||
{
|
||||
case FF_DISPLAY_COMPACT_TYPE_NONE:
|
||||
yyjson_mut_obj_add_str(doc, module, "compactType", "none");
|
||||
@ -237,6 +257,12 @@ void ffGenerateDisplayJsonConfig(FFDisplayOptions* options, yyjson_mut_doc* doc,
|
||||
case FF_DISPLAY_COMPACT_TYPE_SCALED_BIT:
|
||||
yyjson_mut_obj_add_str(doc, module, "compactType", "scaled");
|
||||
break;
|
||||
case FF_DISPLAY_COMPACT_TYPE_ORIGINAL_BIT | FF_DISPLAY_COMPACT_TYPE_REFRESH_RATE_BIT:
|
||||
yyjson_mut_obj_add_str(doc, module, "compactType", "original-with-refresh-rate");
|
||||
break;
|
||||
case FF_DISPLAY_COMPACT_TYPE_SCALED_BIT | FF_DISPLAY_COMPACT_TYPE_REFRESH_RATE_BIT:
|
||||
yyjson_mut_obj_add_str(doc, module, "compactType", "scaled-with-refresh-rate");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@ typedef enum FFDisplayCompactType
|
||||
FF_DISPLAY_COMPACT_TYPE_NONE = 0,
|
||||
FF_DISPLAY_COMPACT_TYPE_ORIGINAL_BIT = 1 << 0,
|
||||
FF_DISPLAY_COMPACT_TYPE_SCALED_BIT = 1 << 1,
|
||||
FF_DISPLAY_COMPACT_TYPE_REFRESH_RATE_BIT = 1 << 2,
|
||||
} FFDisplayCompactType;
|
||||
|
||||
typedef enum FFDisplayOrder
|
||||
|
Loading…
x
Reference in New Issue
Block a user