Skip to content

Commit a622dfd

Browse files
authored
Merge pull request #3969 from LawnGnome/cffi-config-value-json
cffi: always return config values as JSON
2 parents 775067f + 9061704 commit a622dfd

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

resources/custom_modules/cffi_example/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ void onclicked(GtkButton* button) {
1717
}
1818

1919
// You must
20-
const size_t wbcffi_version = 1;
20+
const size_t wbcffi_version = 2;
2121

2222
void* wbcffi_init(const wbcffi_init_info* init_info, const wbcffi_config_entry* config_entries,
2323
size_t config_entries_len) {
@@ -67,4 +67,4 @@ void wbcffi_refresh(void* instance, int signal) {
6767

6868
void wbcffi_doaction(void* instance, const char* name) {
6969
printf("cffi_example inst=%p: doAction(%s)\n", instance, name);
70-
}
70+
}

resources/custom_modules/cffi_example/waybar_cffi_module.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
extern "C" {
88
#endif
99

10-
/// Waybar ABI version. 1 is the latest version
10+
/// Waybar ABI version. 2 is the latest version
1111
extern const size_t wbcffi_version;
1212

1313
/// Private Waybar CFFI module
@@ -35,7 +35,13 @@ typedef struct {
3535
typedef struct {
3636
/// Entry key
3737
const char* key;
38-
/// Entry value as string. JSON object and arrays are serialized.
38+
/// Entry value
39+
///
40+
/// In ABI version 1, this may be either a bare string if the value is a
41+
/// string, or the JSON representation of any other JSON object as a string.
42+
///
43+
/// From ABI version 2 onwards, this is always the JSON representation of the
44+
/// value as a string.
3945
const char* value;
4046
} wbcffi_config_entry;
4147

src/modules/cffi.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ CFFI::CFFI(const std::string& name, const std::string& id, const Json::Value& co
2828
}
2929

3030
// Fetch functions
31-
if (*wbcffi_version == 1) {
31+
if (*wbcffi_version == 1 || *wbcffi_version == 2) {
3232
// Mandatory functions
3333
hooks_.init = reinterpret_cast<InitFn*>(dlsym(handle, "wbcffi_init"));
3434
if (!hooks_.init) {
@@ -58,10 +58,14 @@ CFFI::CFFI(const std::string& name, const std::string& id, const Json::Value& co
5858
const auto& keys = config.getMemberNames();
5959
for (size_t i = 0; i < keys.size(); i++) {
6060
const auto& value = config[keys[i]];
61-
if (value.isConvertibleTo(Json::ValueType::stringValue)) {
62-
config_entries_stringstor.push_back(config[keys[i]].asString());
61+
if (*wbcffi_version == 1) {
62+
if (value.isConvertibleTo(Json::ValueType::stringValue)) {
63+
config_entries_stringstor.push_back(value.asString());
64+
} else {
65+
config_entries_stringstor.push_back(value.toStyledString());
66+
}
6367
} else {
64-
config_entries_stringstor.push_back(config[keys[i]].toStyledString());
68+
config_entries_stringstor.push_back(value.toStyledString());
6569
}
6670
}
6771

0 commit comments

Comments
 (0)