From 7affe5c1bda53a2bb57295b7b6dbe4494e8c007b Mon Sep 17 00:00:00 2001 From: Hristo Venev Date: Sat, 1 Feb 2020 18:08:00 +0100 Subject: swaybar: fix i3bar relative coordinates when scaling is used 24e8ba048aef4751c6fa1d5982ee634f921e6cf6 did not take scaling into account. The hotspot size used pixel coordinates, the absolute coordinates were logical, and the relative coordinates were completely wrong. This commit makes all coordinates use logical values. If `"float_event_coords":true` is sent in the handshake message, coordinates are sent as floating-point values. The "scale" field is an integer containing the scale value. --- swaybar/input.c | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) (limited to 'swaybar/input.c') 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, return false; } -static void process_hotspots(struct swaybar_output *output, +static bool process_hotspots(struct swaybar_output *output, double x, double y, uint32_t button) { - x *= output->scale; - y *= output->scale; + double px = x * output->scale; + double py = y * output->scale; struct swaybar_hotspot *hotspot; wl_list_for_each(hotspot, &output->hotspots, link) { - if (x >= hotspot->x && y >= hotspot->y - && x < hotspot->x + hotspot->width - && y < hotspot->y + hotspot->height) { - if (HOTSPOT_IGNORE == hotspot->callback(output, hotspot, - x / output->scale, y / output->scale, button, hotspot->data)) { - return; + if (px >= hotspot->x && py >= hotspot->y + && px < hotspot->x + hotspot->width + && py < hotspot->y + hotspot->height) { + if (HOTSPOT_IGNORE == hotspot->callback(output, hotspot, x, y, + button, hotspot->data)) { + return true; } } } + + return false; } 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, return; } - struct swaybar_hotspot *hotspot; - wl_list_for_each(hotspot, &output->hotspots, link) { - double x = pointer->x * output->scale; - double y = pointer->y * output->scale; - if (x >= hotspot->x - && y >= hotspot->y - && x < hotspot->x + hotspot->width - && y < hotspot->y + hotspot->height) { - if (HOTSPOT_IGNORE == hotspot->callback(output, hotspot, - pointer->x, pointer->y, button, hotspot->data)) { - return; - } - } + if (process_hotspots(output, pointer->x, pointer->y, button)) { + return; } struct swaybar_config *config = seat->bar->config; -- cgit v1.2.3-54-g00ecf