Skip to content

Commit 5e7cfe2

Browse files
committed
Display: add option --display-order
1 parent 77db2d8 commit 5e7cfe2

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed

doc/json_schema.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,6 +1111,15 @@
11111111
"type": "boolean",
11121112
"default": false
11131113
},
1114+
"order": {
1115+
"description": "Set the order should be used when printing",
1116+
"enum": [
1117+
"none",
1118+
"asc",
1119+
"desc"
1120+
],
1121+
"default": "none"
1122+
},
11141123
"key": {
11151124
"$ref": "#/$defs/key"
11161125
},

src/data/help.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,19 @@
10471047
"default": false
10481048
}
10491049
},
1050+
{
1051+
"long": "display-order",
1052+
"desc": "Set the order should be used when printing displays",
1053+
"arg": {
1054+
"type": "enum",
1055+
"enum": {
1056+
"none": "Use the detected order",
1057+
"asc": "Sort by display name ascendingly",
1058+
"desc": "Sort by display name descendingly"
1059+
},
1060+
"default": "none"
1061+
}
1062+
},
10501063
{
10511064
"long": "brightness-ddcci-sleep",
10521065
"desc": "Set the sleep times (in ms) when sending DDC/CI requests",

src/modules/display/display.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@
66

77
#define FF_DISPLAY_NUM_FORMAT_ARGS 8
88

9+
static int sortByNameAsc(FFDisplayResult* a, FFDisplayResult* b)
10+
{
11+
return ffStrbufComp(&a->name, &b->name);
12+
}
13+
14+
static int sortByNameDesc(FFDisplayResult* a, FFDisplayResult* b)
15+
{
16+
return -ffStrbufComp(&a->name, &b->name);
17+
}
18+
919
void ffPrintDisplay(FFDisplayOptions* options)
1020
{
1121
const FFDisplayServerResult* dsResult = ffConnectDisplayServer();
@@ -16,6 +26,11 @@ void ffPrintDisplay(FFDisplayOptions* options)
1626
return;
1727
}
1828

29+
if (options->order != FF_DISPLAY_ORDER_NONE)
30+
{
31+
ffListSort((FFlist*) &dsResult->displays, (void*) (options->order == FF_DISPLAY_ORDER_ASC ? sortByNameAsc : sortByNameDesc));
32+
}
33+
1934
if (options->compactType != FF_DISPLAY_COMPACT_TYPE_NONE)
2035
{
2136
ffPrintLogoAndKey(FF_DISPLAY_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
@@ -133,6 +148,17 @@ bool ffParseDisplayCommandOptions(FFDisplayOptions* options, const char* key, co
133148
return true;
134149
}
135150

151+
if (ffStrEqualsIgnCase(subKey, "order"))
152+
{
153+
options->order = (FFDisplayOrder) ffOptionParseEnum(key, value, (FFKeyValuePair[]) {
154+
{ "asc", FF_DISPLAY_ORDER_ASC },
155+
{ "desc", FF_DISPLAY_ORDER_DESC },
156+
{ "none", FF_DISPLAY_ORDER_NONE },
157+
{},
158+
});
159+
return true;
160+
}
161+
136162
return false;
137163
}
138164

@@ -171,6 +197,22 @@ void ffParseDisplayJsonObject(FFDisplayOptions* options, yyjson_val* module)
171197
continue;
172198
}
173199

200+
if (ffStrEqualsIgnCase(key, "order"))
201+
{
202+
int value;
203+
const char* error = ffJsonConfigParseEnum(val, &value, (FFKeyValuePair[]) {
204+
{ "asc", FF_DISPLAY_ORDER_ASC },
205+
{ "desc", FF_DISPLAY_ORDER_DESC },
206+
{ "none", FF_DISPLAY_ORDER_NONE },
207+
{},
208+
});
209+
if (error)
210+
ffPrintError(FF_DISPLAY_MODULE_NAME, 0, &options->moduleArgs, "Invalid %s value: %s", key, error);
211+
else
212+
options->order = (FFDisplayOrder) value;
213+
continue;
214+
}
215+
174216
ffPrintError(FF_DISPLAY_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key);
175217
}
176218
}

src/modules/display/option.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,19 @@ typedef enum FFDisplayCompactType
1111
FF_DISPLAY_COMPACT_TYPE_SCALED_BIT = 1 << 1,
1212
} FFDisplayCompactType;
1313

14+
typedef enum FFDisplayOrder
15+
{
16+
FF_DISPLAY_ORDER_NONE,
17+
FF_DISPLAY_ORDER_ASC,
18+
FF_DISPLAY_ORDER_DESC,
19+
} FFDisplayOrder;
20+
1421
typedef struct FFDisplayOptions
1522
{
1623
FFModuleBaseInfo moduleInfo;
1724
FFModuleArgs moduleArgs;
1825

1926
FFDisplayCompactType compactType;
2027
bool preciseRefreshRate;
28+
FFDisplayOrder order;
2129
} FFDisplayOptions;

0 commit comments

Comments
 (0)