diff options
author | Ian Fan <ianfan0@gmail.com> | 2018-10-12 20:28:04 +0100 |
---|---|---|
committer | Ian Fan <ianfan0@gmail.com> | 2018-10-14 13:33:12 +0100 |
commit | 55ca16f2d83f4d7e14635ac4de3eb67ee2a0787e (patch) | |
tree | c92080e2e054cf0b7b2e33e615b55f6143fcda9f /swaybar | |
parent | fed11d1c7b388e999414dd8cec4b8982ba5ce950 (diff) |
swaybar: streamline ipc handling
The received json is handled outside of the case statement, which will
allow better extensibility.
This commit also introduces the variable bar_is_dirty, the return value
signifying whether the bar requires rendering.
Diffstat (limited to 'swaybar')
-rw-r--r-- | swaybar/ipc.c | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/swaybar/ipc.c b/swaybar/ipc.c index 8568f957..6013c2de 100644 --- a/swaybar/ipc.c +++ b/swaybar/ipc.c @@ -372,17 +372,20 @@ bool handle_ipc_readable(struct swaybar *bar) { if (!resp) { return false; } + + json_object *result = json_tokener_parse(resp->payload); + if (!result) { + wlr_log(WLR_ERROR, "failed to parse payload as json"); + free_ipc_response(resp); + return false; + } + + bool bar_is_dirty = true; switch (resp->type) { case IPC_EVENT_WORKSPACE: ipc_get_workspaces(bar); break; case IPC_EVENT_MODE: { - json_object *result = json_tokener_parse(resp->payload); - if (!result) { - free_ipc_response(resp); - wlr_log(WLR_ERROR, "failed to parse payload as json"); - return false; - } json_object *json_change, *json_pango_markup; if (json_object_object_get_ex(result, "change", &json_change)) { const char *change = json_object_get_string(json_change); @@ -390,21 +393,20 @@ bool handle_ipc_readable(struct swaybar *bar) { bar->mode = strcmp(change, "default") != 0 ? strdup(change) : NULL; } else { wlr_log(WLR_ERROR, "failed to parse response"); - json_object_put(result); - free_ipc_response(resp); - return false; + bar_is_dirty = false; + break; } if (json_object_object_get_ex(result, "pango_markup", &json_pango_markup)) { bar->mode_pango_markup = json_object_get_boolean(json_pango_markup); } - json_object_put(result); break; } default: - free_ipc_response(resp); - return false; + bar_is_dirty = false; + break; } + json_object_put(result); free_ipc_response(resp); - return true; + return bar_is_dirty; } |