aboutsummaryrefslogtreecommitdiffstats
path: root/swaybar/i3bar.c
diff options
context:
space:
mode:
Diffstat (limited to 'swaybar/i3bar.c')
-rw-r--r--swaybar/i3bar.c39
1 files changed, 22 insertions, 17 deletions
diff --git a/swaybar/i3bar.c b/swaybar/i3bar.c
index 4bcd5843..62c22d43 100644
--- a/swaybar/i3bar.c
+++ b/swaybar/i3bar.c
@@ -1,4 +1,3 @@
1#define _POSIX_C_SOURCE 200809L
2#include <json.h> 1#include <json.h>
3#include <linux/input-event-codes.h> 2#include <linux/input-event-codes.h>
4#include <ctype.h> 3#include <ctype.h>
@@ -28,6 +27,19 @@ void i3bar_block_unref(struct i3bar_block *block) {
28 } 27 }
29} 28}
30 29
30static bool i3bar_parse_json_color(json_object *json, uint32_t *color) {
31 if (!json) {
32 return false;
33 }
34
35 const char *hexstring = json_object_get_string(json);
36 bool color_set = parse_color(hexstring, color);
37 if (!color_set) {
38 sway_log(SWAY_ERROR, "Ignoring invalid block hexadecimal color string: %s", hexstring);
39 }
40 return color_set;
41}
42
31static void i3bar_parse_json(struct status_line *status, 43static void i3bar_parse_json(struct status_line *status,
32 struct json_object *json_array) { 44 struct json_object *json_array) {
33 struct i3bar_block *block, *tmp; 45 struct i3bar_block *block, *tmp;
@@ -68,13 +80,7 @@ static void i3bar_parse_json(struct status_line *status,
68 strdup(json_object_get_string(full_text)) : NULL; 80 strdup(json_object_get_string(full_text)) : NULL;
69 block->short_text = short_text ? 81 block->short_text = short_text ?
70 strdup(json_object_get_string(short_text)) : NULL; 82 strdup(json_object_get_string(short_text)) : NULL;
71 if (color) { 83 block->color_set = i3bar_parse_json_color(color, &block->color);
72 const char *hexstring = json_object_get_string(color);
73 block->color_set = parse_color(hexstring, &block->color);
74 if (!block->color_set) {
75 sway_log(SWAY_ERROR, "Invalid block color: %s", hexstring);
76 }
77 }
78 if (min_width) { 84 if (min_width) {
79 json_type type = json_object_get_type(min_width); 85 json_type type = json_object_get_type(min_width);
80 if (type == json_type_int) { 86 if (type == json_type_int) {
@@ -100,14 +106,8 @@ static void i3bar_parse_json(struct status_line *status,
100 block->separator_block_width = separator_block_width ? 106 block->separator_block_width = separator_block_width ?
101 json_object_get_int(separator_block_width) : 9; 107 json_object_get_int(separator_block_width) : 9;
102 // Airblader features 108 // Airblader features
103 const char *hex = background ? json_object_get_string(background) : NULL; 109 i3bar_parse_json_color(background, &block->background);
104 if (hex && !parse_color(hex, &block->background)) { 110 block->border_set = i3bar_parse_json_color(border, &block->border);
105 sway_log(SWAY_ERROR, "Ignoring invalid block background: %s", hex);
106 }
107 hex = border ? json_object_get_string(border) : NULL;
108 if (hex && !parse_color(hex, &block->border)) {
109 sway_log(SWAY_ERROR, "Ignoring invalid block border: %s", hex);
110 }
111 block->border_top = border_top ? json_object_get_int(border_top) : 1; 111 block->border_top = border_top ? json_object_get_int(border_top) : 1;
112 block->border_bottom = border_bottom ? 112 block->border_bottom = border_bottom ?
113 json_object_get_int(border_bottom) : 1; 113 json_object_get_int(border_bottom) : 1;
@@ -268,11 +268,16 @@ bool i3bar_handle_readable(struct status_line *status) {
268 268
269enum hotspot_event_handling i3bar_block_send_click(struct status_line *status, 269enum hotspot_event_handling i3bar_block_send_click(struct status_line *status,
270 struct i3bar_block *block, double x, double y, double rx, double ry, 270 struct i3bar_block *block, double x, double y, double rx, double ry,
271 double w, double h, int scale, uint32_t button) { 271 double w, double h, int scale, uint32_t button, bool released) {
272 sway_log(SWAY_DEBUG, "block %s clicked", block->name); 272 sway_log(SWAY_DEBUG, "block %s clicked", block->name);
273 if (!block->name || !status->click_events) { 273 if (!block->name || !status->click_events) {
274 return HOTSPOT_PROCESS; 274 return HOTSPOT_PROCESS;
275 } 275 }
276 if (released) {
277 // Since we handle the pressed event, also handle the released event
278 // to block it from falling through to a binding in the bar
279 return HOTSPOT_IGNORE;
280 }
276 281
277 struct json_object *event_json = json_object_new_object(); 282 struct json_object *event_json = json_object_new_object();
278 json_object_object_add(event_json, "name", 283 json_object_object_add(event_json, "name",