Skip to content

Commit fa4e11c

Browse files
committed
JsonConfig: write all flags when generating config file
1 parent e753d4d commit fa4e11c

83 files changed

Lines changed: 688 additions & 920 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

doc/json_schema.json

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,25 @@
1010
]
1111
},
1212
"key": {
13-
"description": "Key of the module",
14-
"type": "string"
13+
"description": "Key of the module\nOne whitespace character (` `) can be used to hide the key",
14+
"type": "string",
15+
"minLength": 1
1516
},
1617
"keyColor": {
17-
"description": "Color of the module key. Left empty to use `display.color.keys`",
18+
"description": "Color of the module key to override the global setting `display.color.key`",
1819
"$ref": "#/$defs/colors"
1920
},
2021
"keyWidth": {
21-
"description": "Width of the module key. Use 0 to use `display.keyWidth`",
22+
"description": "Width of the module key to override the global setting `display.keyWidth`",
2223
"type": "integer",
23-
"minimum": 0,
24-
"default": 0
24+
"minimum": 1
2525
},
2626
"keyIcon": {
2727
"description": "Set the icon to be displayed by `display.keyType: \"icon\"`",
2828
"type": "string"
2929
},
3030
"outputColor": {
31-
"description": "Output color of the module. Left empty to use `display.color.output`",
31+
"description": "Output color of the module to override the global setting `display.color.output`",
3232
"$ref": "#/$defs/colors"
3333
},
3434
"percentType": {
@@ -549,7 +549,7 @@
549549
"const": null
550550
},
551551
{
552-
"description": "Set the source file of the logo",
552+
"description": "Set the source file of the logo or built-in ASCII art name",
553553
"type": "string"
554554
},
555555
{
@@ -671,14 +671,30 @@
671671
}
672672
},
673673
"width": {
674-
"type": "integer",
675-
"description": "Set the width of the logo (in characters). Required for iTerm image protocol",
676-
"minimum": 1
674+
"oneOf": [
675+
{
676+
"type": "null",
677+
"description": "Auto detect width (default)"
678+
},
679+
{
680+
"type": "integer",
681+
"description": "Set the width of the logo (in characters). Required for some image protocols",
682+
"minimum": 1
683+
}
684+
]
677685
},
678686
"height": {
679-
"type": "integer",
680-
"description": "Set the height of the logo (in characters). Required for iTerm image protocol",
681-
"minimum": 1
687+
"oneOf": [
688+
{
689+
"type": "null",
690+
"description": "Auto detect width (default)"
691+
},
692+
{
693+
"type": "integer",
694+
"description": "Set the height of the logo (in characters). Required for some image protocols",
695+
"minimum": 1
696+
}
697+
]
682698
},
683699
"padding": {
684700
"type": "object",
@@ -1998,9 +2014,15 @@
19982014
"key": {
19992015
"$ref": "#/$defs/key"
20002016
},
2017+
"keyColor": {
2018+
"$ref": "#/$defs/keyColor"
2019+
},
20012020
"keyIcon": {
20022021
"$ref": "#/$defs/keyIcon"
20032022
},
2023+
"keyWidth": {
2024+
"$ref": "#/$defs/keyWidth"
2025+
},
20042026
"condition": {
20052027
"$ref": "#/$defs/conditions"
20062028
}
@@ -2635,6 +2657,9 @@
26352657
],
26362658
"default": null
26372659
},
2660+
"percent": {
2661+
"$ref": "#/$defs/percent"
2662+
},
26382663
"key": {
26392664
"$ref": "#/$defs/key"
26402665
},

src/common/jsonconfig.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,19 @@ bool ffJsonConfigParseModuleArgs(yyjson_val* key, yyjson_val* val, FFModuleArgs*
5050
return false;
5151
}
5252

53-
void ffJsonConfigGenerateModuleArgsConfig(yyjson_mut_doc* doc, yyjson_mut_val* module, FFModuleArgs* defaultModuleArgs, FFModuleArgs* moduleArgs)
53+
void ffJsonConfigGenerateModuleArgsConfig(yyjson_mut_doc* doc, yyjson_mut_val* module, FFModuleArgs* moduleArgs)
5454
{
55-
if (!ffStrbufEqual(&defaultModuleArgs->key, &moduleArgs->key))
55+
if (moduleArgs->key.length > 0)
5656
yyjson_mut_obj_add_strbuf(doc, module, "key", &moduleArgs->key);
57-
if (!ffStrbufEqual(&defaultModuleArgs->outputFormat, &moduleArgs->outputFormat))
57+
if (moduleArgs->outputFormat.length > 0)
5858
yyjson_mut_obj_add_strbuf(doc, module, "format", &moduleArgs->outputFormat);
59-
if (!ffStrbufEqual(&defaultModuleArgs->keyColor, &moduleArgs->keyColor))
59+
if (moduleArgs->outputColor.length > 0)
60+
yyjson_mut_obj_add_strbuf(doc, module, "outputColor", &moduleArgs->outputColor);
61+
if (moduleArgs->keyColor.length > 0)
6062
yyjson_mut_obj_add_strbuf(doc, module, "keyColor", &moduleArgs->keyColor);
61-
if (moduleArgs->keyWidth != defaultModuleArgs->keyWidth)
63+
if (moduleArgs->keyWidth > 0)
6264
yyjson_mut_obj_add_uint(doc, module, "keyWidth", moduleArgs->keyWidth);
63-
if (!ffStrbufEqual(&defaultModuleArgs->keyIcon, &moduleArgs->keyIcon))
65+
if (moduleArgs->keyIcon.length > 0)
6466
yyjson_mut_obj_add_strbuf(doc, module, "keyIcon", &moduleArgs->keyIcon);
6567
}
6668

src/common/jsonconfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
bool ffJsonConfigParseModuleArgs(yyjson_val* key, yyjson_val* val, FFModuleArgs* moduleArgs);
66
const char* ffJsonConfigParseEnum(yyjson_val* val, int* result, FFKeyValuePair pairs[]);
77
void ffPrintJsonConfig(bool prepare, yyjson_mut_doc* jsonDoc);
8-
void ffJsonConfigGenerateModuleArgsConfig(yyjson_mut_doc* doc, yyjson_mut_val* module, FFModuleArgs* defaultModuleArgs, FFModuleArgs* moduleArgs);
8+
void ffJsonConfigGenerateModuleArgsConfig(yyjson_mut_doc* doc, yyjson_mut_val* module, FFModuleArgs* moduleArgs);
99

1010
yyjson_api_inline yyjson_mut_val* yyjson_mut_strbuf(yyjson_mut_doc *doc, const FFstrbuf* buf) {
1111
return yyjson_mut_strncpy(doc, buf->chars, buf->length);

src/common/percent.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -310,16 +310,10 @@ bool ffPercentParseJsonObject(yyjson_val* key, yyjson_val* value, FFPercentageMo
310310
return true;
311311
}
312312

313-
void ffPercentGenerateJsonConfig(yyjson_mut_doc* doc, yyjson_mut_val* module, FFPercentageModuleConfig defaultConfig, FFPercentageModuleConfig config)
313+
void ffPercentGenerateJsonConfig(yyjson_mut_doc* doc, yyjson_mut_val* module, FFPercentageModuleConfig config)
314314
{
315-
if (config.green == defaultConfig.green && config.yellow == defaultConfig.yellow)
316-
return;
317-
318315
yyjson_mut_val* percent = yyjson_mut_obj_add_obj(doc, module, "percent");
319-
if (config.green != defaultConfig.green)
320-
yyjson_mut_obj_add_uint(doc, percent, "green", config.green);
321-
if (config.yellow != defaultConfig.yellow)
322-
yyjson_mut_obj_add_uint(doc, percent, "yellow", config.yellow);
323-
if (config.type != defaultConfig.type)
324-
yyjson_mut_obj_add_uint(doc, percent, "type", config.type);
316+
yyjson_mut_obj_add_uint(doc, percent, "green", config.green);
317+
yyjson_mut_obj_add_uint(doc, percent, "yellow", config.yellow);
318+
yyjson_mut_obj_add_uint(doc, percent, "type", config.type);
325319
}

src/common/percent.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ typedef enum __attribute__((__packed__)) FFPercentageTypeFlags
1111
FF_PERCENTAGE_TYPE_BAR_BIT = 1 << 1,
1212
FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT = 1 << 2,
1313
FF_PERCENTAGE_TYPE_NUM_COLOR_BIT = 1 << 3,
14-
FF_PERCENTAGE_TYPE_BAR_MONOCHROME_BIT = FF_PERCENTAGE_TYPE_NUM_COLOR_BIT,
14+
FF_PERCENTAGE_TYPE_BAR_MONOCHROME_BIT = 1 << 4,
1515
FF_PERCENTAGE_TYPE_FORCE_UNSIGNED_ = UINT8_MAX,
1616
} FFPercentageTypeFlags;
1717
static_assert(sizeof(FFPercentageTypeFlags) == 1, "");
@@ -41,5 +41,5 @@ typedef struct yyjson_mut_doc yyjson_mut_doc;
4141
typedef struct yyjson_mut_val yyjson_mut_val;
4242
bool ffPercentParseCommandOptions(const char* key, const char* subkey, const char* value, FFPercentageModuleConfig* config);
4343
bool ffPercentParseJsonObject(yyjson_val* key, yyjson_val* value, FFPercentageModuleConfig* config);
44-
void ffPercentGenerateJsonConfig(yyjson_mut_doc* doc, yyjson_mut_val* module, FFPercentageModuleConfig defaultConfig, FFPercentageModuleConfig config);
44+
void ffPercentGenerateJsonConfig(yyjson_mut_doc* doc, yyjson_mut_val* module, FFPercentageModuleConfig config);
4545
const char* ffPercentParseTypeJsonConfig(yyjson_val* value, FFPercentageTypeFlags* result);

src/common/temps.c

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -159,23 +159,14 @@ bool ffTempsParseJsonObject(yyjson_val* key, yyjson_val* value, bool* useTemp, F
159159
return true;
160160
}
161161

162-
void ffTempsGenerateJsonConfig(yyjson_mut_doc* doc, yyjson_mut_val* module, FF_MAYBE_UNUSED bool defaultTemp, FFColorRangeConfig defaultConfig, bool temp, FFColorRangeConfig config)
162+
void ffTempsGenerateJsonConfig(yyjson_mut_doc* doc, yyjson_mut_val* module, bool temp, FFColorRangeConfig config)
163163
{
164-
assert(defaultTemp == false); // assume defaultTemp is always false
165-
166164
if (!temp)
167-
return;
168-
169-
if (config.green != defaultConfig.green || config.yellow != defaultConfig.yellow)
170-
{
171-
yyjson_mut_val* temp = yyjson_mut_obj_add_obj(doc, module, "temp");
172-
if (config.green != defaultConfig.green)
173-
yyjson_mut_obj_add_uint(doc, temp, "green", config.green);
174-
if (config.yellow != defaultConfig.yellow)
175-
yyjson_mut_obj_add_uint(doc, temp, "yellow", config.yellow);
176-
}
165+
yyjson_mut_obj_add_bool(doc, module, "temp", false);
177166
else
178167
{
179-
yyjson_mut_obj_add_bool(doc, module, "temp", true);
168+
yyjson_mut_val* temp = yyjson_mut_obj_add_obj(doc, module, "temp");
169+
yyjson_mut_obj_add_uint(doc, temp, "green", config.green);
170+
yyjson_mut_obj_add_uint(doc, temp, "yellow", config.yellow);
180171
}
181172
}

src/common/temps.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
void ffTempsAppendNum(double celsius, FFstrbuf* buffer, FFColorRangeConfig config, const FFModuleArgs* module);
77
bool ffTempsParseCommandOptions(const char* key, const char* subkey, const char* value, bool* useTemp, FFColorRangeConfig* config);
88
bool ffTempsParseJsonObject(yyjson_val* key, yyjson_val* value, bool* useTemp, FFColorRangeConfig* config);
9-
void ffTempsGenerateJsonConfig(yyjson_mut_doc* doc, yyjson_mut_val* module, FF_MAYBE_UNUSED bool defaultTemp, FFColorRangeConfig defaultConfig, bool temp, FFColorRangeConfig config);
9+
void ffTempsGenerateJsonConfig(yyjson_mut_doc* doc, yyjson_mut_val* module, bool temp, FFColorRangeConfig config);

src/modules/battery/battery.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,19 +188,14 @@ void ffParseBatteryJsonObject(FFBatteryOptions* options, yyjson_val* module)
188188

189189
void ffGenerateBatteryJsonConfig(FFBatteryOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
190190
{
191-
__attribute__((__cleanup__(ffDestroyBatteryOptions))) FFBatteryOptions defaultOptions;
192-
ffInitBatteryOptions(&defaultOptions);
193-
194-
ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs);
191+
ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs);
195192

196193
#ifdef _WIN32
197-
if (defaultOptions.useSetupApi != options->useSetupApi)
198194
yyjson_mut_obj_add_bool(doc, module, "useSetupApi", options->useSetupApi);
199195
#endif
200196

201-
ffTempsGenerateJsonConfig(doc, module, defaultOptions.temp, defaultOptions.tempConfig, options->temp, options->tempConfig);
202-
203-
ffPercentGenerateJsonConfig(doc, module, defaultOptions.percent, options->percent);
197+
ffTempsGenerateJsonConfig(doc, module, options->temp, options->tempConfig);
198+
ffPercentGenerateJsonConfig(doc, module, options->percent);
204199
}
205200

206201
void ffGenerateBatteryJsonResult(FFBatteryOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)

src/modules/bios/bios.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,7 @@ void ffParseBiosJsonObject(FFBiosOptions* options, yyjson_val* module)
9090

9191
void ffGenerateBiosJsonConfig(FFBiosOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
9292
{
93-
__attribute__((__cleanup__(ffDestroyBiosOptions))) FFBiosOptions defaultOptions;
94-
ffInitBiosOptions(&defaultOptions);
95-
96-
ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs);
93+
ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs);
9794
}
9895

9996
void ffGenerateBiosJsonResult(FF_MAYBE_UNUSED FFBiosOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)

src/modules/bluetooth/bluetooth.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,11 @@ void ffParseBluetoothJsonObject(FFBluetoothOptions* options, yyjson_val* module)
121121

122122
void ffGenerateBluetoothJsonConfig(FFBluetoothOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
123123
{
124-
__attribute__((__cleanup__(ffDestroyBluetoothOptions))) FFBluetoothOptions defaultOptions;
125-
ffInitBluetoothOptions(&defaultOptions);
124+
ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs);
126125

127-
ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs);
126+
yyjson_mut_obj_add_bool(doc, module, "showDisconnected", options->showDisconnected);
128127

129-
if (options->showDisconnected != defaultOptions.showDisconnected)
130-
yyjson_mut_obj_add_bool(doc, module, "showDisconnected", options->showDisconnected);
131-
132-
ffPercentGenerateJsonConfig(doc, module, defaultOptions.percent, options->percent);
128+
ffPercentGenerateJsonConfig(doc, module, options->percent);
133129
}
134130

135131
void ffGenerateBluetoothJsonResult(FFBluetoothOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)

0 commit comments

Comments
 (0)