aboutsummaryrefslogtreecommitdiff
path: root/i3bar/src/outputs.c
diff options
context:
space:
mode:
Diffstat (limited to 'i3bar/src/outputs.c')
-rw-r--r--i3bar/src/outputs.c21
1 files changed, 9 insertions, 12 deletions
diff --git a/i3bar/src/outputs.c b/i3bar/src/outputs.c
index 168f3eef..5aca53cd 100644
--- a/i3bar/src/outputs.c
+++ b/i3bar/src/outputs.c
@@ -18,10 +18,8 @@
/* A datatype to pass through the callbacks to save the state */
struct outputs_json_params {
- struct outputs_head *outputs;
i3_output *outputs_walk;
char *cur_key;
- char *json;
bool in_rect;
};
@@ -263,21 +261,17 @@ void init_outputs(void) {
}
/*
- * Start parsing the received JSON string
+ * Parse the received JSON string
*
*/
-void parse_outputs_json(char *json) {
+void parse_outputs_json(const unsigned char *json, size_t size) {
struct outputs_json_params params;
params.outputs_walk = NULL;
params.cur_key = NULL;
- params.json = json;
params.in_rect = false;
- yajl_handle handle;
- yajl_status state;
- handle = yajl_alloc(&outputs_callbacks, NULL, (void *)&params);
-
- state = yajl_parse(handle, (const unsigned char *)json, strlen(json));
+ yajl_handle handle = yajl_alloc(&outputs_callbacks, NULL, (void *)&params);
+ yajl_status state = yajl_parse(handle, json, size);
/* FIXME: Proper errorhandling for JSON-parsing */
switch (state) {
@@ -291,6 +285,7 @@ void parse_outputs_json(char *json) {
}
yajl_free(handle);
+ free(params.cur_key);
}
/*
@@ -319,12 +314,14 @@ void free_outputs(void) {
*
*/
i3_output *get_output_by_name(char *name) {
- i3_output *walk;
if (name == NULL) {
return NULL;
}
+ const bool is_primary = !strcasecmp(name, "primary");
+
+ i3_output *walk;
SLIST_FOREACH (walk, outputs, slist) {
- if (!strcmp(walk->name, name)) {
+ if ((is_primary && walk->primary) || !strcmp(walk->name, name)) {
break;
}
}