summaryrefslogtreecommitdiff
path: root/swaybar/input.c
diff options
context:
space:
mode:
authorHristo Venev <[email protected]>2020-02-01 18:08:00 +0100
committerSimon Ser <[email protected]>2020-02-10 18:58:09 +0100
commit7affe5c1bda53a2bb57295b7b6dbe4494e8c007b (patch)
treed55e64c43a785f15c6abf77d1891bb9d70b3e529 /swaybar/input.c
parentfca32b6334afe69ea10c88de7670c79ae98ce0fd (diff)
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.
Diffstat (limited to 'swaybar/input.c')
-rw-r--r--swaybar/input.c35
1 files changed, 13 insertions, 22 deletions
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;