diff options
author | Ian Fan <ianfan0@gmail.com> | 2018-09-17 14:10:57 +0100 |
---|---|---|
committer | Ian Fan <ianfan0@gmail.com> | 2018-09-18 11:36:33 +0100 |
commit | 7882ac66ef4308922045fd100e6a9e12942a240b (patch) | |
tree | 67ce4f14f56372c86eb9992eef354d1d76f3081d /include/swaybar | |
parent | swaybar: rewrite protocol determination (diff) | |
download | sway-7882ac66ef4308922045fd100e6a9e12942a240b.tar.gz sway-7882ac66ef4308922045fd100e6a9e12942a240b.tar.zst sway-7882ac66ef4308922045fd100e6a9e12942a240b.zip |
swaybar: rewrite i3bar protocol handling
This now correctly handles an incoming json infinite array by shifting
most of the heavy listing to the json-c parser, as well as sending
multiple statuses at once. It also removes the struct
i3bar_protocol_state and moves its members into the status_line struct,
allowing the same buffer to be used for both protocols.
Diffstat (limited to 'include/swaybar')
-rw-r--r-- | include/swaybar/status_line.h | 24 |
1 files changed, 6 insertions, 18 deletions
diff --git a/include/swaybar/status_line.h b/include/swaybar/status_line.h index 857948a5..d3eabdf6 100644 --- a/include/swaybar/status_line.h +++ b/include/swaybar/status_line.h | |||
@@ -1,5 +1,6 @@ | |||
1 | #ifndef _SWAYBAR_STATUS_LINE_H | 1 | #ifndef _SWAYBAR_STATUS_LINE_H |
2 | #define _SWAYBAR_STATUS_LINE_H | 2 | #define _SWAYBAR_STATUS_LINE_H |
3 | #include <json-c/json.h> | ||
3 | #include <stdint.h> | 4 | #include <stdint.h> |
4 | #include <stdio.h> | 5 | #include <stdio.h> |
5 | #include <stdbool.h> | 6 | #include <stdbool.h> |
@@ -12,23 +13,6 @@ enum status_protocol { | |||
12 | PROTOCOL_I3BAR, | 13 | PROTOCOL_I3BAR, |
13 | }; | 14 | }; |
14 | 15 | ||
15 | enum json_node_type { | ||
16 | JSON_NODE_UNKNOWN, | ||
17 | JSON_NODE_ARRAY, | ||
18 | JSON_NODE_STRING, | ||
19 | }; | ||
20 | |||
21 | struct i3bar_protocol_state { | ||
22 | bool click_events; | ||
23 | char *buffer; | ||
24 | size_t buffer_size; | ||
25 | size_t buffer_index; | ||
26 | const char *current_node; | ||
27 | bool escape; | ||
28 | size_t depth; | ||
29 | enum json_node_type nodes[16]; | ||
30 | }; | ||
31 | |||
32 | struct i3bar_block { | 16 | struct i3bar_block { |
33 | struct wl_list link; | 17 | struct wl_list link; |
34 | int ref_count; | 18 | int ref_count; |
@@ -58,9 +42,13 @@ struct status_line { | |||
58 | const char *text; | 42 | const char *text; |
59 | struct wl_list blocks; // i3bar_block::link | 43 | struct wl_list blocks; // i3bar_block::link |
60 | 44 | ||
45 | bool click_events; | ||
61 | char *buffer; | 46 | char *buffer; |
62 | size_t buffer_size; | 47 | size_t buffer_size; |
63 | struct i3bar_protocol_state i3bar_state; | 48 | size_t buffer_index; |
49 | bool started; | ||
50 | bool expecting_comma; | ||
51 | json_tokener *tokener; | ||
64 | }; | 52 | }; |
65 | 53 | ||
66 | struct status_line *status_line_init(char *cmd); | 54 | struct status_line *status_line_init(char *cmd); |