aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/swaybar/bar.h7
-rw-r--r--include/swaybar/status_line.h2
-rw-r--r--swaybar/bar.c14
-rw-r--r--swaybar/i3bar.c5
-rw-r--r--swaybar/render.c10
5 files changed, 26 insertions, 12 deletions
diff --git a/include/swaybar/bar.h b/include/swaybar/bar.h
index f1ff25b2..1cecea71 100644
--- a/include/swaybar/bar.h
+++ b/include/swaybar/bar.h
@@ -29,10 +29,15 @@ enum x11_button {
29 FORWARD, 29 FORWARD,
30}; 30};
31 31
32enum hotspot_event_handling {
33 HOTSPOT_IGNORE,
34 HOTSPOT_PROCESS,
35};
36
32struct swaybar_hotspot { 37struct swaybar_hotspot {
33 struct wl_list link; 38 struct wl_list link;
34 int x, y, width, height; 39 int x, y, width, height;
35 void (*callback)(struct swaybar_output *output, 40 enum hotspot_event_handling (*callback)(struct swaybar_output *output,
36 int x, int y, enum x11_button button, void *data); 41 int x, int y, enum x11_button button, void *data);
37 void (*destroy)(void *data); 42 void (*destroy)(void *data);
38 void *data; 43 void *data;
diff --git a/include/swaybar/status_line.h b/include/swaybar/status_line.h
index 2eaf8140..de9b98d7 100644
--- a/include/swaybar/status_line.h
+++ b/include/swaybar/status_line.h
@@ -71,7 +71,7 @@ void status_error(struct status_line *status, const char *text);
71bool status_handle_readable(struct status_line *status); 71bool status_handle_readable(struct status_line *status);
72void status_line_free(struct status_line *status); 72void status_line_free(struct status_line *status);
73bool i3bar_handle_readable(struct status_line *status); 73bool i3bar_handle_readable(struct status_line *status);
74void i3bar_block_send_click(struct status_line *status, 74enum hotspot_event_handling i3bar_block_send_click(struct status_line *status,
75 struct i3bar_block *block, int x, int y, enum x11_button button); 75 struct i3bar_block *block, int x, int y, enum x11_button button);
76void i3bar_block_free(struct i3bar_block *block); 76void i3bar_block_free(struct i3bar_block *block);
77enum x11_button wl_button_to_x11_button(uint32_t button); 77enum x11_button wl_button_to_x11_button(uint32_t button);
diff --git a/swaybar/bar.c b/swaybar/bar.c
index 94bc48bc..62a7727e 100644
--- a/swaybar/bar.c
+++ b/swaybar/bar.c
@@ -146,8 +146,10 @@ static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
146 && y >= hotspot->y 146 && y >= hotspot->y
147 && x < hotspot->x + hotspot->width 147 && x < hotspot->x + hotspot->width
148 && y < hotspot->y + hotspot->height) { 148 && y < hotspot->y + hotspot->height) {
149 hotspot->callback(output, pointer->x, pointer->y, 149 if (HOTSPOT_IGNORE == hotspot->callback(output, pointer->x, pointer->y,
150 wl_button_to_x11_button(button), hotspot->data); 150 wl_button_to_x11_button(button), hotspot->data)) {
151 return;
152 }
151 } 153 }
152 } 154 }
153} 155}
@@ -169,9 +171,11 @@ static void wl_pointer_axis(void *data, struct wl_pointer *wl_pointer,
169 && y >= hotspot->y 171 && y >= hotspot->y
170 && x < hotspot->x + hotspot->width 172 && x < hotspot->x + hotspot->width
171 && y < hotspot->y + hotspot->height) { 173 && y < hotspot->y + hotspot->height) {
172 hotspot->callback(output, pointer->x, pointer->y, 174 if (HOTSPOT_IGNORE == hotspot->callback(
173 wl_axis_to_x11_button(axis, value), hotspot->data); 175 output, pointer->x, pointer->y,
174 return; 176 wl_axis_to_x11_button(axis, value), hotspot->data)) {
177 return;
178 }
175 } 179 }
176 } 180 }
177 181
diff --git a/swaybar/i3bar.c b/swaybar/i3bar.c
index 78b183ad..ae37eeb9 100644
--- a/swaybar/i3bar.c
+++ b/swaybar/i3bar.c
@@ -192,11 +192,11 @@ bool i3bar_handle_readable(struct status_line *status) {
192 return redraw; 192 return redraw;
193} 193}
194 194
195void i3bar_block_send_click(struct status_line *status, 195enum hotspot_event_handling i3bar_block_send_click(struct status_line *status,
196 struct i3bar_block *block, int x, int y, enum x11_button button) { 196 struct i3bar_block *block, int x, int y, enum x11_button button) {
197 wlr_log(WLR_DEBUG, "block %s clicked", block->name ? block->name : "(nil)"); 197 wlr_log(WLR_DEBUG, "block %s clicked", block->name ? block->name : "(nil)");
198 if (!block->name || !status->i3bar_state.click_events) { 198 if (!block->name || !status->i3bar_state.click_events) {
199 return; 199 return HOTSPOT_PROCESS;
200 } 200 }
201 201
202 struct json_object *event_json = json_object_new_object(); 202 struct json_object *event_json = json_object_new_object();
@@ -215,6 +215,7 @@ void i3bar_block_send_click(struct status_line *status,
215 status_error(status, "[failed to write click event]"); 215 status_error(status, "[failed to write click event]");
216 } 216 }
217 json_object_put(event_json); 217 json_object_put(event_json);
218 return HOTSPOT_IGNORE;
218} 219}
219 220
220enum x11_button wl_button_to_x11_button(uint32_t button) { 221enum x11_button wl_button_to_x11_button(uint32_t button) {
diff --git a/swaybar/render.c b/swaybar/render.c
index d210e25a..6f370077 100644
--- a/swaybar/render.c
+++ b/swaybar/render.c
@@ -108,11 +108,11 @@ static void render_sharp_line(cairo_t *cairo, uint32_t color,
108 } 108 }
109} 109}
110 110
111static void block_hotspot_callback(struct swaybar_output *output, 111static enum hotspot_event_handling block_hotspot_callback(struct swaybar_output *output,
112 int x, int y, enum x11_button button, void *data) { 112 int x, int y, enum x11_button button, void *data) {
113 struct i3bar_block *block = data; 113 struct i3bar_block *block = data;
114 struct status_line *status = output->bar->status; 114 struct status_line *status = output->bar->status;
115 i3bar_block_send_click(status, block, x, y, button); 115 return i3bar_block_send_click(status, block, x, y, button);
116} 116}
117 117
118static uint32_t render_status_block(cairo_t *cairo, 118static uint32_t render_status_block(cairo_t *cairo,
@@ -348,9 +348,13 @@ static const char *strip_workspace_number(const char *ws_name) {
348 return ws_name; 348 return ws_name;
349} 349}
350 350
351static void workspace_hotspot_callback(struct swaybar_output *output, 351static enum hotspot_event_handling workspace_hotspot_callback(struct swaybar_output *output,
352 int x, int y, enum x11_button button, void *data) { 352 int x, int y, enum x11_button button, void *data) {
353 if (button != LEFT) {
354 return HOTSPOT_PROCESS;
355 }
353 ipc_send_workspace_command(output->bar, (const char *)data); 356 ipc_send_workspace_command(output->bar, (const char *)data);
357 return HOTSPOT_IGNORE;
354} 358}
355 359
356static uint32_t render_workspace_button(cairo_t *cairo, 360static uint32_t render_workspace_button(cairo_t *cairo,