aboutsummaryrefslogtreecommitdiffstats
path: root/swaybar/input.c
diff options
context:
space:
mode:
authorLibravatar Hristo Venev <hristo@venev.name>2020-02-01 18:08:00 +0100
committerLibravatar Simon Ser <contact@emersion.fr>2020-02-10 18:58:09 +0100
commit7affe5c1bda53a2bb57295b7b6dbe4494e8c007b (patch)
treed55e64c43a785f15c6abf77d1891bb9d70b3e529 /swaybar/input.c
parentDo not truncate pointer coordinates to int. (diff)
downloadsway-7affe5c1bda53a2bb57295b7b6dbe4494e8c007b.tar.gz
sway-7affe5c1bda53a2bb57295b7b6dbe4494e8c007b.tar.zst
sway-7affe5c1bda53a2bb57295b7b6dbe4494e8c007b.zip
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,
138 return false; 138 return false;
139} 139}
140 140
141static void process_hotspots(struct swaybar_output *output, 141static 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
158static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer, 160static 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;