Skip to content

Commit 5fb4b6d

Browse files
committed
Display: --display-compact-type support *-with-refresh-rate
Ref: #732
1 parent 5e7cfe2 commit 5fb4b6d

File tree

4 files changed

+41
-10
lines changed

4 files changed

+41
-10
lines changed

doc/json_schema.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1101,7 +1101,9 @@
11011101
"enum": [
11021102
"none",
11031103
"original",
1104-
"scaled"
1104+
"scaled",
1105+
"original-with-refresh-rate",
1106+
"scaled-with-refresh-rate"
11051107
],
11061108
"description": "Set if all displays should be printed in one line",
11071109
"default": "none"

src/data/help.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,9 @@
10331033
"enum": {
10341034
"none": "Disable this compact mode",
10351035
"original": "Print original resolutions",
1036-
"scaled": "Print scaled resolutions"
1036+
"scaled": "Print scaled resolutions",
1037+
"original-with-refresh-rate": "Print original resolutions with refresh rate",
1038+
"scaled-with-refresh-rate": "Print scaled resolutions with refresh rate"
10371039
},
10381040
"default": "none"
10391041
}

src/modules/display/display.c

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,37 @@ void ffPrintDisplay(FFDisplayOptions* options)
3535
{
3636
ffPrintLogoAndKey(FF_DISPLAY_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
3737

38-
int index = 0;
38+
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate();
3939
FF_LIST_FOR_EACH(FFDisplayResult, result, dsResult->displays)
4040
{
4141
if (options->compactType & FF_DISPLAY_COMPACT_TYPE_ORIGINAL_BIT)
4242
{
43-
if (index++) putchar(' ');
44-
printf("%ix%i", result->width, result->height);
43+
ffStrbufAppendF(&buffer, "%ix%i", result->width, result->height);
4544
}
46-
if (options->compactType & FF_DISPLAY_COMPACT_TYPE_SCALED_BIT)
45+
else
4746
{
48-
if (index++) putchar(' ');
49-
printf("%ix%i", result->scaledWidth, result->scaledHeight);
47+
ffStrbufAppendF(&buffer, "%ix%i", result->scaledWidth, result->scaledHeight);
48+
}
49+
50+
if (options->compactType & FF_DISPLAY_COMPACT_TYPE_REFRESH_RATE_BIT)
51+
{
52+
if (result->refreshRate > 0)
53+
{
54+
if (options->preciseRefreshRate)
55+
ffStrbufAppendF(&buffer, " @ %gHz", result->refreshRate);
56+
else
57+
ffStrbufAppendF(&buffer, " @ %iHz", (uint32_t) (result->refreshRate + 0.5));
58+
}
59+
ffStrbufAppendS(&buffer, ", ");
60+
}
61+
else
62+
{
63+
ffStrbufAppendC(&buffer, ' ');
5064
}
5165
}
52-
putchar('\n');
66+
ffStrbufTrimRight(&buffer, ' ');
67+
ffStrbufTrimRight(&buffer, ',');
68+
ffStrbufPutTo(&buffer, stdout);
5369
return;
5470
}
5571

@@ -137,6 +153,8 @@ bool ffParseDisplayCommandOptions(FFDisplayOptions* options, const char* key, co
137153
{ "none", FF_DISPLAY_COMPACT_TYPE_NONE },
138154
{ "original", FF_DISPLAY_COMPACT_TYPE_ORIGINAL_BIT },
139155
{ "scaled", FF_DISPLAY_COMPACT_TYPE_SCALED_BIT },
156+
{ "original-with-refresh-rate", FF_DISPLAY_COMPACT_TYPE_ORIGINAL_BIT | FF_DISPLAY_COMPACT_TYPE_REFRESH_RATE_BIT },
157+
{ "scaled-with-refresh-rate", FF_DISPLAY_COMPACT_TYPE_SCALED_BIT | FF_DISPLAY_COMPACT_TYPE_REFRESH_RATE_BIT },
140158
{},
141159
});
142160
return true;
@@ -182,6 +200,8 @@ void ffParseDisplayJsonObject(FFDisplayOptions* options, yyjson_val* module)
182200
{ "none", FF_DISPLAY_COMPACT_TYPE_NONE },
183201
{ "original", FF_DISPLAY_COMPACT_TYPE_ORIGINAL_BIT },
184202
{ "scaled", FF_DISPLAY_COMPACT_TYPE_SCALED_BIT },
203+
{ "original-with-refresh-rate", FF_DISPLAY_COMPACT_TYPE_ORIGINAL_BIT | FF_DISPLAY_COMPACT_TYPE_REFRESH_RATE_BIT },
204+
{ "scaled-with-refresh-rate", FF_DISPLAY_COMPACT_TYPE_SCALED_BIT | FF_DISPLAY_COMPACT_TYPE_REFRESH_RATE_BIT },
185205
{},
186206
});
187207
if (error)
@@ -226,7 +246,7 @@ void ffGenerateDisplayJsonConfig(FFDisplayOptions* options, yyjson_mut_doc* doc,
226246

227247
if (options->compactType != defaultOptions.compactType)
228248
{
229-
switch (options->compactType)
249+
switch ((int) options->compactType)
230250
{
231251
case FF_DISPLAY_COMPACT_TYPE_NONE:
232252
yyjson_mut_obj_add_str(doc, module, "compactType", "none");
@@ -237,6 +257,12 @@ void ffGenerateDisplayJsonConfig(FFDisplayOptions* options, yyjson_mut_doc* doc,
237257
case FF_DISPLAY_COMPACT_TYPE_SCALED_BIT:
238258
yyjson_mut_obj_add_str(doc, module, "compactType", "scaled");
239259
break;
260+
case FF_DISPLAY_COMPACT_TYPE_ORIGINAL_BIT | FF_DISPLAY_COMPACT_TYPE_REFRESH_RATE_BIT:
261+
yyjson_mut_obj_add_str(doc, module, "compactType", "original-with-refresh-rate");
262+
break;
263+
case FF_DISPLAY_COMPACT_TYPE_SCALED_BIT | FF_DISPLAY_COMPACT_TYPE_REFRESH_RATE_BIT:
264+
yyjson_mut_obj_add_str(doc, module, "compactType", "scaled-with-refresh-rate");
265+
break;
240266
}
241267
}
242268

src/modules/display/option.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ typedef enum FFDisplayCompactType
99
FF_DISPLAY_COMPACT_TYPE_NONE = 0,
1010
FF_DISPLAY_COMPACT_TYPE_ORIGINAL_BIT = 1 << 0,
1111
FF_DISPLAY_COMPACT_TYPE_SCALED_BIT = 1 << 1,
12+
FF_DISPLAY_COMPACT_TYPE_REFRESH_RATE_BIT = 1 << 2,
1213
} FFDisplayCompactType;
1314

1415
typedef enum FFDisplayOrder

0 commit comments

Comments
 (0)