diff options
Diffstat (limited to 'swaybar/status_line.c')
-rw-r--r-- | swaybar/status_line.c | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/swaybar/status_line.c b/swaybar/status_line.c index a9ed8d8c..ee740c6b 100644 --- a/swaybar/status_line.c +++ b/swaybar/status_line.c | |||
@@ -48,7 +48,7 @@ static void free_status_block(void *item) { | |||
48 | free(sb); | 48 | free(sb); |
49 | } | 49 | } |
50 | 50 | ||
51 | static void parse_json(struct swaybar_state *st, const char *text) { | 51 | static void parse_json(struct swaybar_state *state, const char *text) { |
52 | json_object *results = json_tokener_parse(text); | 52 | json_object *results = json_tokener_parse(text); |
53 | if (!results) { | 53 | if (!results) { |
54 | sway_log(L_DEBUG, "Failed to parse json"); | 54 | sway_log(L_DEBUG, "Failed to parse json"); |
@@ -59,12 +59,12 @@ static void parse_json(struct swaybar_state *st, const char *text) { | |||
59 | return; | 59 | return; |
60 | } | 60 | } |
61 | 61 | ||
62 | if (st->status->block_line) { | 62 | if (state->status->block_line) { |
63 | list_foreach(st->status->block_line, free_status_block); | 63 | list_foreach(state->status->block_line, free_status_block); |
64 | list_free(st->status->block_line); | 64 | list_free(state->status->block_line); |
65 | } | 65 | } |
66 | 66 | ||
67 | st->status->block_line = create_list(); | 67 | state->status->block_line = create_list(); |
68 | 68 | ||
69 | int i; | 69 | int i; |
70 | for (i = 0; i < json_object_array_length(results); ++i) { | 70 | for (i = 0; i < json_object_array_length(results); ++i) { |
@@ -108,7 +108,7 @@ static void parse_json(struct swaybar_state *st, const char *text) { | |||
108 | if (color) { | 108 | if (color) { |
109 | new->color = parse_color(json_object_get_string(color)); | 109 | new->color = parse_color(json_object_get_string(color)); |
110 | } else { | 110 | } else { |
111 | new->color = st->config->colors.statusline; | 111 | new->color = state->config->colors.statusline; |
112 | } | 112 | } |
113 | 113 | ||
114 | if (min_width) { | 114 | if (min_width) { |
@@ -188,7 +188,7 @@ static void parse_json(struct swaybar_state *st, const char *text) { | |||
188 | new->border_right = 1; | 188 | new->border_right = 1; |
189 | } | 189 | } |
190 | 190 | ||
191 | list_add(st->status->block_line, new); | 191 | list_add(state->status->block_line, new); |
192 | } | 192 | } |
193 | 193 | ||
194 | json_object_put(results); | 194 | json_object_put(results); |
@@ -369,41 +369,41 @@ static int i3json_handle_data(struct swaybar_state *st, char *data) { | |||
369 | } | 369 | } |
370 | 370 | ||
371 | // read data from fd and parse it. | 371 | // read data from fd and parse it. |
372 | static int i3json_handle_fd(struct swaybar_state *st) { | 372 | static int i3json_handle_fd(struct swaybar_state *state) { |
373 | i3json_ensure_free(10240); | 373 | i3json_ensure_free(10240); |
374 | // get fresh data at the end of the buffer | 374 | // get fresh data at the end of the buffer |
375 | int readlen = read(st->status_read_fd, i3json_state.parserpos, 10239); | 375 | int readlen = read(state->status_read_fd, i3json_state.parserpos, 10239); |
376 | if (readlen < 0) { | 376 | if (readlen < 0) { |
377 | return readlen; | 377 | return readlen; |
378 | } | 378 | } |
379 | i3json_state.parserpos[readlen] = '\0'; | 379 | i3json_state.parserpos[readlen] = '\0'; |
380 | return i3json_parse(st); | 380 | return i3json_parse(state); |
381 | } | 381 | } |
382 | 382 | ||
383 | bool handle_status_line(struct swaybar_state *st) { | 383 | bool handle_status_line(struct swaybar_state *state) { |
384 | bool dirty = false; | 384 | bool dirty = false; |
385 | 385 | ||
386 | switch (st->status->protocol) { | 386 | switch (state->status->protocol) { |
387 | case I3BAR: | 387 | case I3BAR: |
388 | sway_log(L_DEBUG, "Got i3bar protocol."); | 388 | sway_log(L_DEBUG, "Got i3bar protocol."); |
389 | if (i3json_handle_fd(st) > 0) { | 389 | if (i3json_handle_fd(state) > 0) { |
390 | dirty = true; | 390 | dirty = true; |
391 | } | 391 | } |
392 | break; | 392 | break; |
393 | case TEXT: | 393 | case TEXT: |
394 | sway_log(L_DEBUG, "Got text protocol."); | 394 | sway_log(L_DEBUG, "Got text protocol."); |
395 | read_line_tail(st->status_read_fd, line, sizeof(line), line_rest); | 395 | read_line_tail(state->status_read_fd, line, sizeof(line), line_rest); |
396 | dirty = true; | 396 | dirty = true; |
397 | st->status->text_line = line; | 397 | state->status->text_line = line; |
398 | break; | 398 | break; |
399 | case UNDEF: | 399 | case UNDEF: |
400 | sway_log(L_DEBUG, "Detecting protocol..."); | 400 | sway_log(L_DEBUG, "Detecting protocol..."); |
401 | if (read_line_tail(st->status_read_fd, line, sizeof(line), line_rest) < 0) { | 401 | if (read_line_tail(state->status_read_fd, line, sizeof(line), line_rest) < 0) { |
402 | break; | 402 | break; |
403 | } | 403 | } |
404 | dirty = true; | 404 | dirty = true; |
405 | st->status->text_line = line; | 405 | state->status->text_line = line; |
406 | st->status->protocol = TEXT; | 406 | state->status->protocol = TEXT; |
407 | if (line[0] == '{') { | 407 | if (line[0] == '{') { |
408 | // detect i3bar json protocol | 408 | // detect i3bar json protocol |
409 | json_object *proto = json_tokener_parse(line); | 409 | json_object *proto = json_tokener_parse(line); |
@@ -413,8 +413,8 @@ bool handle_status_line(struct swaybar_state *st) { | |||
413 | && json_object_get_int(version) == 1 | 413 | && json_object_get_int(version) == 1 |
414 | ) { | 414 | ) { |
415 | sway_log(L_DEBUG, "Switched to i3bar protocol."); | 415 | sway_log(L_DEBUG, "Switched to i3bar protocol."); |
416 | st->status->protocol = I3BAR; | 416 | state->status->protocol = I3BAR; |
417 | i3json_handle_data(st, line_rest); | 417 | i3json_handle_data(state, line_rest); |
418 | } | 418 | } |
419 | json_object_put(proto); | 419 | json_object_put(proto); |
420 | } | 420 | } |