diff options
-rw-r--r-- | include/swaybar/i3bar.h | 4 | ||||
-rw-r--r-- | include/swaybar/input.h | 2 | ||||
-rw-r--r-- | include/swaybar/status_line.h | 1 | ||||
-rw-r--r-- | swaybar/i3bar.c | 26 | ||||
-rw-r--r-- | swaybar/input.c | 35 | ||||
-rw-r--r-- | swaybar/render.c | 12 | ||||
-rw-r--r-- | swaybar/status_line.c | 7 | ||||
-rw-r--r-- | swaybar/tray/item.c | 2 |
8 files changed, 51 insertions, 38 deletions
diff --git a/include/swaybar/i3bar.h b/include/swaybar/i3bar.h index 0b3bee21..df8cdd09 100644 --- a/include/swaybar/i3bar.h +++ b/include/swaybar/i3bar.h | |||
@@ -28,7 +28,7 @@ struct i3bar_block { | |||
28 | void i3bar_block_unref(struct i3bar_block *block); | 28 | void i3bar_block_unref(struct i3bar_block *block); |
29 | bool i3bar_handle_readable(struct status_line *status); | 29 | bool i3bar_handle_readable(struct status_line *status); |
30 | enum hotspot_event_handling i3bar_block_send_click(struct status_line *status, | 30 | enum hotspot_event_handling i3bar_block_send_click(struct status_line *status, |
31 | struct i3bar_block *block, int x, int y, int rx, int ry, int w, int h, | 31 | struct i3bar_block *block, double x, double y, double rx, double ry, |
32 | uint32_t button); | 32 | double w, double h, int scale, uint32_t button); |
33 | 33 | ||
34 | #endif | 34 | #endif |
diff --git a/include/swaybar/input.h b/include/swaybar/input.h index 6557a29e..65e49218 100644 --- a/include/swaybar/input.h +++ b/include/swaybar/input.h | |||
@@ -44,7 +44,7 @@ struct swaybar_hotspot { | |||
44 | struct wl_list link; // swaybar_output::hotspots | 44 | struct wl_list link; // swaybar_output::hotspots |
45 | int x, y, width, height; | 45 | int x, y, width, height; |
46 | enum hotspot_event_handling (*callback)(struct swaybar_output *output, | 46 | enum hotspot_event_handling (*callback)(struct swaybar_output *output, |
47 | struct swaybar_hotspot *hotspot, int x, int y, uint32_t button, | 47 | struct swaybar_hotspot *hotspot, double x, double y, uint32_t button, |
48 | void *data); | 48 | void *data); |
49 | void (*destroy)(void *data); | 49 | void (*destroy)(void *data); |
50 | void *data; | 50 | void *data; |
diff --git a/include/swaybar/status_line.h b/include/swaybar/status_line.h index 3601a11e..65c3a796 100644 --- a/include/swaybar/status_line.h +++ b/include/swaybar/status_line.h | |||
@@ -28,6 +28,7 @@ struct status_line { | |||
28 | int cont_signal; | 28 | int cont_signal; |
29 | 29 | ||
30 | bool click_events; | 30 | bool click_events; |
31 | bool float_event_coords; | ||
31 | bool clicked; | 32 | bool clicked; |
32 | char *buffer; | 33 | char *buffer; |
33 | size_t buffer_size; | 34 | size_t buffer_size; |
diff --git a/swaybar/i3bar.c b/swaybar/i3bar.c index 5c8b87a2..4bcd5843 100644 --- a/swaybar/i3bar.c +++ b/swaybar/i3bar.c | |||
@@ -267,8 +267,8 @@ bool i3bar_handle_readable(struct status_line *status) { | |||
267 | } | 267 | } |
268 | 268 | ||
269 | enum hotspot_event_handling i3bar_block_send_click(struct status_line *status, | 269 | enum hotspot_event_handling i3bar_block_send_click(struct status_line *status, |
270 | struct i3bar_block *block, int x, int y, int rx, int ry, int w, int h, | 270 | struct i3bar_block *block, double x, double y, double rx, double ry, |
271 | uint32_t button) { | 271 | double w, double h, int scale, uint32_t button) { |
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; |
@@ -285,12 +285,22 @@ enum hotspot_event_handling i3bar_block_send_click(struct status_line *status, | |||
285 | json_object_object_add(event_json, "button", | 285 | json_object_object_add(event_json, "button", |
286 | json_object_new_int(event_to_x11_button(button))); | 286 | json_object_new_int(event_to_x11_button(button))); |
287 | json_object_object_add(event_json, "event", json_object_new_int(button)); | 287 | json_object_object_add(event_json, "event", json_object_new_int(button)); |
288 | json_object_object_add(event_json, "x", json_object_new_int(x)); | 288 | if (status->float_event_coords) { |
289 | json_object_object_add(event_json, "y", json_object_new_int(y)); | 289 | json_object_object_add(event_json, "x", json_object_new_double(x)); |
290 | json_object_object_add(event_json, "relative_x", json_object_new_int(rx)); | 290 | json_object_object_add(event_json, "y", json_object_new_double(y)); |
291 | json_object_object_add(event_json, "relative_y", json_object_new_int(ry)); | 291 | json_object_object_add(event_json, "relative_x", json_object_new_double(rx)); |
292 | json_object_object_add(event_json, "width", json_object_new_int(w)); | 292 | json_object_object_add(event_json, "relative_y", json_object_new_double(ry)); |
293 | json_object_object_add(event_json, "height", json_object_new_int(h)); | 293 | json_object_object_add(event_json, "width", json_object_new_double(w)); |
294 | json_object_object_add(event_json, "height", json_object_new_double(h)); | ||
295 | } else { | ||
296 | json_object_object_add(event_json, "x", json_object_new_int(x)); | ||
297 | json_object_object_add(event_json, "y", json_object_new_int(y)); | ||
298 | json_object_object_add(event_json, "relative_x", json_object_new_int(rx)); | ||
299 | json_object_object_add(event_json, "relative_y", json_object_new_int(ry)); | ||
300 | json_object_object_add(event_json, "width", json_object_new_int(w)); | ||
301 | json_object_object_add(event_json, "height", json_object_new_int(h)); | ||
302 | } | ||
303 | json_object_object_add(event_json, "scale", json_object_new_int(scale)); | ||
294 | if (dprintf(status->write_fd, "%s%s\n", status->clicked ? "," : "", | 304 | if (dprintf(status->write_fd, "%s%s\n", status->clicked ? "," : "", |
295 | json_object_to_json_string(event_json)) < 0) { | 305 | json_object_to_json_string(event_json)) < 0) { |
296 | status_error(status, "[failed to write click event]"); | 306 | status_error(status, "[failed to write click event]"); |
diff --git a/swaybar/input.c b/swaybar/input.c index aa6290fa..c0352300 100644 --- a/swaybar/input.c +++ b/swaybar/input.c | |||
@@ -138,21 +138,23 @@ static bool check_bindings(struct swaybar *bar, uint32_t button, | |||
138 | return false; | 138 | return false; |
139 | } | 139 | } |
140 | 140 | ||
141 | static void process_hotspots(struct swaybar_output *output, | 141 | static bool process_hotspots(struct swaybar_output *output, |
142 | double x, double y, uint32_t button) { | 142 | double x, double y, uint32_t button) { |
143 | x *= output->scale; | 143 | double px = x * output->scale; |
144 | y *= output->scale; | 144 | double py = y * output->scale; |
145 | struct swaybar_hotspot *hotspot; | 145 | struct swaybar_hotspot *hotspot; |
146 | wl_list_for_each(hotspot, &output->hotspots, link) { | 146 | wl_list_for_each(hotspot, &output->hotspots, link) { |
147 | if (x >= hotspot->x && y >= hotspot->y | 147 | if (px >= hotspot->x && py >= hotspot->y |
148 | && x < hotspot->x + hotspot->width | 148 | && px < hotspot->x + hotspot->width |
149 | && y < hotspot->y + hotspot->height) { | 149 | && py < hotspot->y + hotspot->height) { |
150 | if (HOTSPOT_IGNORE == hotspot->callback(output, hotspot, | 150 | if (HOTSPOT_IGNORE == hotspot->callback(output, hotspot, x, y, |
151 | x / output->scale, y / output->scale, button, hotspot->data)) { | 151 | button, hotspot->data)) { |
152 | return; | 152 | return true; |
153 | } | 153 | } |
154 | } | 154 | } |
155 | } | 155 | } |
156 | |||
157 | return false; | ||
156 | } | 158 | } |
157 | 159 | ||
158 | static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer, | 160 | static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer, |
@@ -229,19 +231,8 @@ static void wl_pointer_axis(void *data, struct wl_pointer *wl_pointer, | |||
229 | return; | 231 | return; |
230 | } | 232 | } |
231 | 233 | ||
232 | struct swaybar_hotspot *hotspot; | 234 | if (process_hotspots(output, pointer->x, pointer->y, button)) { |
233 | wl_list_for_each(hotspot, &output->hotspots, link) { | 235 | return; |
234 | double x = pointer->x * output->scale; | ||
235 | double y = pointer->y * output->scale; | ||
236 | if (x >= hotspot->x | ||
237 | && y >= hotspot->y | ||
238 | && x < hotspot->x + hotspot->width | ||
239 | && y < hotspot->y + hotspot->height) { | ||
240 | if (HOTSPOT_IGNORE == hotspot->callback(output, hotspot, | ||
241 | pointer->x, pointer->y, button, hotspot->data)) { | ||
242 | return; | ||
243 | } | ||
244 | } | ||
245 | } | 236 | } |
246 | 237 | ||
247 | struct swaybar_config *config = seat->bar->config; | 238 | struct swaybar_config *config = seat->bar->config; |
diff --git a/swaybar/render.c b/swaybar/render.c index 06efb53c..ea5faef6 100644 --- a/swaybar/render.c +++ b/swaybar/render.c | |||
@@ -131,11 +131,15 @@ static void render_sharp_line(cairo_t *cairo, uint32_t color, | |||
131 | 131 | ||
132 | static enum hotspot_event_handling block_hotspot_callback( | 132 | static enum hotspot_event_handling block_hotspot_callback( |
133 | struct swaybar_output *output, struct swaybar_hotspot *hotspot, | 133 | struct swaybar_output *output, struct swaybar_hotspot *hotspot, |
134 | int x, int y, uint32_t button, void *data) { | 134 | double x, double y, uint32_t button, void *data) { |
135 | struct i3bar_block *block = data; | 135 | struct i3bar_block *block = data; |
136 | struct status_line *status = output->bar->status; | 136 | struct status_line *status = output->bar->status; |
137 | return i3bar_block_send_click(status, block, x, y, x - hotspot->x, | 137 | return i3bar_block_send_click(status, block, x, y, |
138 | y - hotspot->y, hotspot->width, hotspot->height, button); | 138 | x - (double)hotspot->x / output->scale, |
139 | y - (double)hotspot->y / output->scale, | ||
140 | (double)hotspot->width / output->scale, | ||
141 | (double)hotspot->height / output->scale, | ||
142 | output->scale, button); | ||
139 | } | 143 | } |
140 | 144 | ||
141 | static void i3bar_block_unref_callback(void *data) { | 145 | static void i3bar_block_unref_callback(void *data) { |
@@ -540,7 +544,7 @@ static uint32_t render_binding_mode_indicator(cairo_t *cairo, | |||
540 | 544 | ||
541 | static enum hotspot_event_handling workspace_hotspot_callback( | 545 | static enum hotspot_event_handling workspace_hotspot_callback( |
542 | struct swaybar_output *output, struct swaybar_hotspot *hotspot, | 546 | struct swaybar_output *output, struct swaybar_hotspot *hotspot, |
543 | int x, int y, uint32_t button, void *data) { | 547 | double x, double y, uint32_t button, void *data) { |
544 | if (button != BTN_LEFT) { | 548 | if (button != BTN_LEFT) { |
545 | return HOTSPOT_PROCESS; | 549 | return HOTSPOT_PROCESS; |
546 | } | 550 | } |
diff --git a/swaybar/status_line.c b/swaybar/status_line.c index 2a9e1da8..fb9271f8 100644 --- a/swaybar/status_line.c +++ b/swaybar/status_line.c | |||
@@ -85,6 +85,13 @@ bool status_handle_readable(struct status_line *status) { | |||
85 | } | 85 | } |
86 | } | 86 | } |
87 | 87 | ||
88 | json_object *float_event_coords; | ||
89 | if (json_object_object_get_ex(header, "float_event_coords", &float_event_coords) | ||
90 | && json_object_get_boolean(float_event_coords)) { | ||
91 | sway_log(SWAY_DEBUG, "Enabling floating-point coordinates."); | ||
92 | status->float_event_coords = true; | ||
93 | } | ||
94 | |||
88 | json_object *signal; | 95 | json_object *signal; |
89 | if (json_object_object_get_ex(header, "stop_signal", &signal)) { | 96 | if (json_object_object_get_ex(header, "stop_signal", &signal)) { |
90 | status->stop_signal = json_object_get_int(signal); | 97 | status->stop_signal = json_object_get_int(signal); |
diff --git a/swaybar/tray/item.c b/swaybar/tray/item.c index 06a8e5b0..b4238417 100644 --- a/swaybar/tray/item.c +++ b/swaybar/tray/item.c | |||
@@ -377,7 +377,7 @@ static int cmp_sni_id(const void *item, const void *cmp_to) { | |||
377 | 377 | ||
378 | static enum hotspot_event_handling icon_hotspot_callback( | 378 | static enum hotspot_event_handling icon_hotspot_callback( |
379 | struct swaybar_output *output, struct swaybar_hotspot *hotspot, | 379 | struct swaybar_output *output, struct swaybar_hotspot *hotspot, |
380 | int x, int y, uint32_t button, void *data) { | 380 | double x, double y, uint32_t button, void *data) { |
381 | sway_log(SWAY_DEBUG, "Clicked on %s", (char *)data); | 381 | sway_log(SWAY_DEBUG, "Clicked on %s", (char *)data); |
382 | 382 | ||
383 | struct swaybar_tray *tray = output->bar->tray; | 383 | struct swaybar_tray *tray = output->bar->tray; |