diff options
-rw-r--r-- | include/swaybar/i3bar.h | 3 | ||||
-rw-r--r-- | include/swaybar/input.h | 3 | ||||
-rw-r--r-- | swaybar/i3bar.c | 7 | ||||
-rw-r--r-- | swaybar/input.c | 8 | ||||
-rw-r--r-- | swaybar/render.c | 9 |
5 files changed, 20 insertions, 10 deletions
diff --git a/include/swaybar/i3bar.h b/include/swaybar/i3bar.h index 3f1ecc25..ab4744a5 100644 --- a/include/swaybar/i3bar.h +++ b/include/swaybar/i3bar.h | |||
@@ -27,6 +27,7 @@ struct i3bar_block { | |||
27 | void i3bar_block_unref(struct i3bar_block *block); | 27 | void i3bar_block_unref(struct i3bar_block *block); |
28 | bool i3bar_handle_readable(struct status_line *status); | 28 | bool i3bar_handle_readable(struct status_line *status); |
29 | enum hotspot_event_handling i3bar_block_send_click(struct status_line *status, | 29 | enum hotspot_event_handling i3bar_block_send_click(struct status_line *status, |
30 | struct i3bar_block *block, int x, int y, enum x11_button button); | 30 | struct i3bar_block *block, int x, int y, int rx, int ry, int w, int h, |
31 | enum x11_button button); | ||
31 | 32 | ||
32 | #endif | 33 | #endif |
diff --git a/include/swaybar/input.h b/include/swaybar/input.h index a552e7ac..390309a0 100644 --- a/include/swaybar/input.h +++ b/include/swaybar/input.h | |||
@@ -37,7 +37,8 @@ struct swaybar_hotspot { | |||
37 | struct wl_list link; // swaybar_output::hotspots | 37 | struct wl_list link; // swaybar_output::hotspots |
38 | int x, y, width, height; | 38 | int x, y, width, height; |
39 | enum hotspot_event_handling (*callback)(struct swaybar_output *output, | 39 | enum hotspot_event_handling (*callback)(struct swaybar_output *output, |
40 | int x, int y, enum x11_button button, void *data); | 40 | struct swaybar_hotspot *hotspot, int x, int y, |
41 | enum x11_button button, void *data); | ||
41 | void (*destroy)(void *data); | 42 | void (*destroy)(void *data); |
42 | void *data; | 43 | void *data; |
43 | }; | 44 | }; |
diff --git a/swaybar/i3bar.c b/swaybar/i3bar.c index 3ea74e13..54607a3a 100644 --- a/swaybar/i3bar.c +++ b/swaybar/i3bar.c | |||
@@ -260,7 +260,8 @@ bool i3bar_handle_readable(struct status_line *status) { | |||
260 | } | 260 | } |
261 | 261 | ||
262 | enum hotspot_event_handling i3bar_block_send_click(struct status_line *status, | 262 | enum hotspot_event_handling i3bar_block_send_click(struct status_line *status, |
263 | struct i3bar_block *block, int x, int y, enum x11_button button) { | 263 | struct i3bar_block *block, int x, int y, int rx, int ry, int w, int h, |
264 | enum x11_button button) { | ||
264 | wlr_log(WLR_DEBUG, "block %s clicked", block->name); | 265 | wlr_log(WLR_DEBUG, "block %s clicked", block->name); |
265 | if (!block->name || !status->click_events) { | 266 | if (!block->name || !status->click_events) { |
266 | return HOTSPOT_PROCESS; | 267 | return HOTSPOT_PROCESS; |
@@ -277,6 +278,10 @@ enum hotspot_event_handling i3bar_block_send_click(struct status_line *status, | |||
277 | json_object_object_add(event_json, "button", json_object_new_int(button)); | 278 | json_object_object_add(event_json, "button", json_object_new_int(button)); |
278 | json_object_object_add(event_json, "x", json_object_new_int(x)); | 279 | json_object_object_add(event_json, "x", json_object_new_int(x)); |
279 | json_object_object_add(event_json, "y", json_object_new_int(y)); | 280 | json_object_object_add(event_json, "y", json_object_new_int(y)); |
281 | json_object_object_add(event_json, "relative_x", json_object_new_int(rx)); | ||
282 | json_object_object_add(event_json, "relative_y", json_object_new_int(ry)); | ||
283 | json_object_object_add(event_json, "width", json_object_new_int(w)); | ||
284 | json_object_object_add(event_json, "height", json_object_new_int(h)); | ||
280 | if (dprintf(status->write_fd, "%s%s\n", status->clicked ? "," : "", | 285 | if (dprintf(status->write_fd, "%s%s\n", status->clicked ? "," : "", |
281 | json_object_to_json_string(event_json)) < 0) { | 286 | json_object_to_json_string(event_json)) < 0) { |
282 | status_error(status, "[failed to write click event]"); | 287 | status_error(status, "[failed to write click event]"); |
diff --git a/swaybar/input.c b/swaybar/input.c index 263d0253..1f8491f6 100644 --- a/swaybar/input.c +++ b/swaybar/input.c | |||
@@ -133,8 +133,8 @@ static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer, | |||
133 | && y >= hotspot->y | 133 | && y >= hotspot->y |
134 | && x < hotspot->x + hotspot->width | 134 | && x < hotspot->x + hotspot->width |
135 | && y < hotspot->y + hotspot->height) { | 135 | && y < hotspot->y + hotspot->height) { |
136 | if (HOTSPOT_IGNORE == hotspot->callback(output, pointer->x, pointer->y, | 136 | if (HOTSPOT_IGNORE == hotspot->callback(output, hotspot, |
137 | wl_button_to_x11_button(button), hotspot->data)) { | 137 | pointer->x, pointer->y, wl_button_to_x11_button(button), hotspot->data)) { |
138 | return; | 138 | return; |
139 | } | 139 | } |
140 | } | 140 | } |
@@ -166,8 +166,8 @@ static void wl_pointer_axis(void *data, struct wl_pointer *wl_pointer, | |||
166 | && y >= hotspot->y | 166 | && y >= hotspot->y |
167 | && x < hotspot->x + hotspot->width | 167 | && x < hotspot->x + hotspot->width |
168 | && y < hotspot->y + hotspot->height) { | 168 | && y < hotspot->y + hotspot->height) { |
169 | if (HOTSPOT_IGNORE == hotspot->callback( | 169 | if (HOTSPOT_IGNORE == hotspot->callback(output, hotspot, |
170 | output, pointer->x, pointer->y, button, hotspot->data)) { | 170 | pointer->x, pointer->y, button, hotspot->data)) { |
171 | return; | 171 | return; |
172 | } | 172 | } |
173 | } | 173 | } |
diff --git a/swaybar/render.c b/swaybar/render.c index 77cfecbf..481e0293 100644 --- a/swaybar/render.c +++ b/swaybar/render.c | |||
@@ -112,10 +112,12 @@ static void render_sharp_line(cairo_t *cairo, uint32_t color, | |||
112 | } | 112 | } |
113 | 113 | ||
114 | static enum hotspot_event_handling block_hotspot_callback(struct swaybar_output *output, | 114 | static enum hotspot_event_handling block_hotspot_callback(struct swaybar_output *output, |
115 | int x, int y, enum x11_button button, void *data) { | 115 | struct swaybar_hotspot *hotspot, |
116 | int x, int y, enum x11_button button, void *data) { | ||
116 | struct i3bar_block *block = data; | 117 | struct i3bar_block *block = data; |
117 | struct status_line *status = output->bar->status; | 118 | struct status_line *status = output->bar->status; |
118 | return i3bar_block_send_click(status, block, x, y, button); | 119 | return i3bar_block_send_click(status, block, x, y, x - hotspot->x, y - hotspot->y, |
120 | hotspot->width, hotspot->height, button); | ||
119 | } | 121 | } |
120 | 122 | ||
121 | static void i3bar_block_unref_callback(void *data) { | 123 | static void i3bar_block_unref_callback(void *data) { |
@@ -343,7 +345,8 @@ static uint32_t render_binding_mode_indicator(cairo_t *cairo, | |||
343 | } | 345 | } |
344 | 346 | ||
345 | static enum hotspot_event_handling workspace_hotspot_callback(struct swaybar_output *output, | 347 | static enum hotspot_event_handling workspace_hotspot_callback(struct swaybar_output *output, |
346 | int x, int y, enum x11_button button, void *data) { | 348 | struct swaybar_hotspot *hotspot, |
349 | int x, int y, enum x11_button button, void *data) { | ||
347 | if (button != LEFT) { | 350 | if (button != LEFT) { |
348 | return HOTSPOT_PROCESS; | 351 | return HOTSPOT_PROCESS; |
349 | } | 352 | } |