diff options
author | 2018-09-21 15:28:53 -0400 | |
---|---|---|
committer | 2018-09-21 15:28:53 -0400 | |
commit | 04862e2121203965dad834b731a5c32b1d1f4e84 (patch) | |
tree | 56f257c17c0d97666c498d2eb35012838c82b451 /swaybar/i3bar.c | |
parent | swaybar: don't wl_display_roundtrip on each frame (diff) | |
parent | Merge pull request #2672 from ianyfan/swaybar (diff) | |
download | sway-04862e2121203965dad834b731a5c32b1d1f4e84.tar.gz sway-04862e2121203965dad834b731a5c32b1d1f4e84.tar.zst sway-04862e2121203965dad834b731a5c32b1d1f4e84.zip |
Merge branch 'master' into swaybar-hotplug
Diffstat (limited to 'swaybar/i3bar.c')
-rw-r--r-- | swaybar/i3bar.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/swaybar/i3bar.c b/swaybar/i3bar.c index 88404703..325aa61a 100644 --- a/swaybar/i3bar.c +++ b/swaybar/i3bar.c | |||
@@ -117,7 +117,9 @@ bool i3bar_handle_readable(struct status_line *status) { | |||
117 | memmove(status->buffer, &status->buffer[c], status->buffer_index); | 117 | memmove(status->buffer, &status->buffer[c], status->buffer_index); |
118 | break; | 118 | break; |
119 | } else if (!isspace(status->buffer[c])) { | 119 | } else if (!isspace(status->buffer[c])) { |
120 | status_error(status, "[invalid json]"); | 120 | wlr_log(WLR_DEBUG, "Invalid i3bar json: expected '[' but encountered '%c'", |
121 | status->buffer[c]); | ||
122 | status_error(status, "[invalid i3bar json]"); | ||
121 | return true; | 123 | return true; |
122 | } | 124 | } |
123 | } | 125 | } |
@@ -155,6 +157,8 @@ bool i3bar_handle_readable(struct status_line *status) { | |||
155 | ++buffer_pos; | 157 | ++buffer_pos; |
156 | break; | 158 | break; |
157 | } else if (!isspace(status->buffer[buffer_pos])) { | 159 | } else if (!isspace(status->buffer[buffer_pos])) { |
160 | wlr_log(WLR_DEBUG, "Invalid i3bar json: expected ',' but encountered '%c'", | ||
161 | status->buffer[buffer_pos]); | ||
158 | status_error(status, "[invalid i3bar json]"); | 162 | status_error(status, "[invalid i3bar json]"); |
159 | return true; | 163 | return true; |
160 | } | 164 | } |
@@ -166,7 +170,8 @@ bool i3bar_handle_readable(struct status_line *status) { | |||
166 | } else { | 170 | } else { |
167 | test_object = json_tokener_parse_ex(status->tokener, | 171 | test_object = json_tokener_parse_ex(status->tokener, |
168 | &status->buffer[buffer_pos], status->buffer_index - buffer_pos); | 172 | &status->buffer[buffer_pos], status->buffer_index - buffer_pos); |
169 | if (json_tokener_get_error(status->tokener) == json_tokener_success) { | 173 | enum json_tokener_error err = json_tokener_get_error(status->tokener); |
174 | if (err == json_tokener_success) { | ||
170 | if (json_object_get_type(test_object) == json_type_array) { | 175 | if (json_object_get_type(test_object) == json_type_array) { |
171 | if (last_object) { | 176 | if (last_object) { |
172 | json_object_put(last_object); | 177 | json_object_put(last_object); |
@@ -198,12 +203,14 @@ bool i3bar_handle_readable(struct status_line *status) { | |||
198 | continue; // look for comma without reading more input | 203 | continue; // look for comma without reading more input |
199 | } | 204 | } |
200 | buffer_pos = status->buffer_index = 0; | 205 | buffer_pos = status->buffer_index = 0; |
201 | } else if (json_tokener_get_error(status->tokener) == json_tokener_continue) { | 206 | } else if (err == json_tokener_continue) { |
207 | json_tokener_reset(status->tokener); | ||
202 | if (status->buffer_index < status->buffer_size) { | 208 | if (status->buffer_index < status->buffer_size) { |
203 | // move the object to the start of the buffer | 209 | // move the object to the start of the buffer |
204 | status->buffer_index -= buffer_pos; | 210 | status->buffer_index -= buffer_pos; |
205 | memmove(status->buffer, &status->buffer[buffer_pos], | 211 | memmove(status->buffer, &status->buffer[buffer_pos], |
206 | status->buffer_index); | 212 | status->buffer_index); |
213 | buffer_pos = 0; | ||
207 | } else { | 214 | } else { |
208 | // expand buffer | 215 | // expand buffer |
209 | status->buffer_size *= 2; | 216 | status->buffer_size *= 2; |
@@ -217,6 +224,10 @@ bool i3bar_handle_readable(struct status_line *status) { | |||
217 | } | 224 | } |
218 | } | 225 | } |
219 | } else { | 226 | } else { |
227 | char last_char = status->buffer[status->buffer_index - 1]; | ||
228 | status->buffer[status->buffer_index - 1] = '\0'; | ||
229 | wlr_log(WLR_DEBUG, "Failed to parse i3bar json - %s: '%s%c'", | ||
230 | json_tokener_error_desc(err), &status->buffer[buffer_pos], last_char); | ||
220 | status_error(status, "[failed to parse i3bar json]"); | 231 | status_error(status, "[failed to parse i3bar json]"); |
221 | return true; | 232 | return true; |
222 | } | 233 | } |