mirror of
https://github.com/swaywm/sway.git
synced 2024-11-25 17:31:28 +00:00
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.
This commit is contained in:
parent
fed11d1c7b
commit
55ca16f2d8
|
@ -372,17 +372,20 @@ bool handle_ipc_readable(struct swaybar *bar) {
|
||||||
if (!resp) {
|
if (!resp) {
|
||||||
return false;
|
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) {
|
switch (resp->type) {
|
||||||
case IPC_EVENT_WORKSPACE:
|
case IPC_EVENT_WORKSPACE:
|
||||||
ipc_get_workspaces(bar);
|
ipc_get_workspaces(bar);
|
||||||
break;
|
break;
|
||||||
case IPC_EVENT_MODE: {
|
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;
|
json_object *json_change, *json_pango_markup;
|
||||||
if (json_object_object_get_ex(result, "change", &json_change)) {
|
if (json_object_object_get_ex(result, "change", &json_change)) {
|
||||||
const char *change = json_object_get_string(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;
|
bar->mode = strcmp(change, "default") != 0 ? strdup(change) : NULL;
|
||||||
} else {
|
} else {
|
||||||
wlr_log(WLR_ERROR, "failed to parse response");
|
wlr_log(WLR_ERROR, "failed to parse response");
|
||||||
json_object_put(result);
|
bar_is_dirty = false;
|
||||||
free_ipc_response(resp);
|
break;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
if (json_object_object_get_ex(result,
|
if (json_object_object_get_ex(result,
|
||||||
"pango_markup", &json_pango_markup)) {
|
"pango_markup", &json_pango_markup)) {
|
||||||
bar->mode_pango_markup = json_object_get_boolean(json_pango_markup);
|
bar->mode_pango_markup = json_object_get_boolean(json_pango_markup);
|
||||||
}
|
}
|
||||||
json_object_put(result);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
free_ipc_response(resp);
|
bar_is_dirty = false;
|
||||||
return false;
|
break;
|
||||||
}
|
}
|
||||||
|
json_object_put(result);
|
||||||
free_ipc_response(resp);
|
free_ipc_response(resp);
|
||||||
return true;
|
return bar_is_dirty;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue