cffi: always return config values as JSON

Previously, string JSON values were special cased to be provided as
bare strings, which means that CFFI modules have to either know what
type each value is expected to be, or use a heuristic such as trying to
decode and then treating the value as a string on failure.

Instead, we can always return JSON, and let the downstream consumer
handle deserialising the value into whatever type is expected.

The new behaviour is gated on a new ABI version 2: modules built against
version 1 will continue to get the old behaviour.
This commit is contained in:
Adam Harvey
2025-03-05 16:53:56 -08:00
parent 8490a1d9b9
commit 906170400e
3 changed files with 18 additions and 8 deletions

View File

@ -17,7 +17,7 @@ void onclicked(GtkButton* button) {
}
// You must
const size_t wbcffi_version = 1;
const size_t wbcffi_version = 2;
void* wbcffi_init(const wbcffi_init_info* init_info, const wbcffi_config_entry* config_entries,
size_t config_entries_len) {
@ -67,4 +67,4 @@ void wbcffi_refresh(void* instance, int signal) {
void wbcffi_doaction(void* instance, const char* name) {
printf("cffi_example inst=%p: doAction(%s)\n", instance, name);
}
}

View File

@ -7,7 +7,7 @@
extern "C" {
#endif
/// Waybar ABI version. 1 is the latest version
/// Waybar ABI version. 2 is the latest version
extern const size_t wbcffi_version;
/// Private Waybar CFFI module
@ -35,7 +35,13 @@ typedef struct {
typedef struct {
/// Entry key
const char* key;
/// Entry value as string. JSON object and arrays are serialized.
/// Entry value
///
/// In ABI version 1, this may be either a bare string if the value is a
/// string, or the JSON representation of any other JSON object as a string.
///
/// From ABI version 2 onwards, this is always the JSON representation of the
/// value as a string.
const char* value;
} wbcffi_config_entry;