diff options
author | Armin Preiml <apreiml@strohwolke.at> | 2018-06-30 10:29:32 +0200 |
---|---|---|
committer | Armin Preiml <apreiml@strohwolke.at> | 2018-06-30 10:29:32 +0200 |
commit | 659871de1eacc7d6ad1a153cae160c818ef1739a (patch) | |
tree | bd342bf852c86da3a0cbfd51d756fa16f4469e87 /swaymsg | |
parent | Merge pull request #2172 from apreiml/fix-keybinding-modifier-handling (diff) | |
download | sway-659871de1eacc7d6ad1a153cae160c818ef1739a.tar.gz sway-659871de1eacc7d6ad1a153cae160c818ef1739a.tar.zst sway-659871de1eacc7d6ad1a153cae160c818ef1739a.zip |
fix swaymsg: errors are displayed again
Command errors didn't get displayed, because the success function didn't
accept objects
Diffstat (limited to 'swaymsg')
-rw-r--r-- | swaymsg/main.c | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/swaymsg/main.c b/swaymsg/main.c index 29f2a907..39882293 100644 --- a/swaymsg/main.c +++ b/swaymsg/main.c | |||
@@ -19,30 +19,44 @@ void sway_terminate(int exit_code) { | |||
19 | exit(exit_code); | 19 | exit(exit_code); |
20 | } | 20 | } |
21 | 21 | ||
22 | static bool success_object(json_object *result) { | ||
23 | json_object *success; | ||
24 | |||
25 | if (!json_object_object_get_ex(result, "success", &success)) { | ||
26 | return false; | ||
27 | } | ||
28 | |||
29 | if (!json_object_get_boolean(success)) { | ||
30 | return false; | ||
31 | } | ||
32 | |||
33 | return true; | ||
34 | } | ||
35 | |||
22 | // Iterate results array and return false if any of them failed | 36 | // Iterate results array and return false if any of them failed |
23 | static bool success(json_object *r, bool fallback) { | 37 | static bool success(json_object *r, bool fallback) { |
24 | if (!json_object_is_type(r, json_type_array)) { | 38 | if (!json_object_is_type(r, json_type_array)) { |
25 | return fallback; | 39 | return fallback; |
26 | } | 40 | } |
41 | |||
27 | size_t results_len = json_object_array_length(r); | 42 | size_t results_len = json_object_array_length(r); |
28 | if (!results_len) { | 43 | if (!results_len) { |
29 | return fallback; | 44 | return fallback; |
30 | } | 45 | } |
46 | |||
31 | for (size_t i = 0; i < results_len; ++i) { | 47 | for (size_t i = 0; i < results_len; ++i) { |
32 | json_object *result = json_object_array_get_idx(r, i); | 48 | json_object *result = json_object_array_get_idx(r, i); |
33 | json_object *success; | 49 | |
34 | if (!json_object_object_get_ex(result, "success", &success)) { | 50 | if (!success_object(result)) { |
35 | return false; | ||
36 | } | ||
37 | if (!json_object_get_boolean(success)) { | ||
38 | return false; | 51 | return false; |
39 | } | 52 | } |
40 | } | 53 | } |
54 | |||
41 | return true; | 55 | return true; |
42 | } | 56 | } |
43 | 57 | ||
44 | static void pretty_print_cmd(json_object *r) { | 58 | static void pretty_print_cmd(json_object *r) { |
45 | if (!success(r, true)) { | 59 | if (!success_object(r)) { |
46 | json_object *error; | 60 | json_object *error; |
47 | if (!json_object_object_get_ex(r, "error", &error)) { | 61 | if (!json_object_object_get_ex(r, "error", &error)) { |
48 | printf("An unknkown error occurred"); | 62 | printf("An unknkown error occurred"); |
@@ -402,6 +416,7 @@ int main(int argc, char **argv) { | |||
402 | } else { | 416 | } else { |
403 | sway_abort("Unknown message type %s", cmdtype); | 417 | sway_abort("Unknown message type %s", cmdtype); |
404 | } | 418 | } |
419 | |||
405 | free(cmdtype); | 420 | free(cmdtype); |
406 | 421 | ||
407 | char *command = NULL; | 422 | char *command = NULL; |