diff options
author | Joan Bruguera <joanbrugueram@gmail.com> | 2021-09-18 22:21:22 +0200 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2022-11-26 10:29:59 +0100 |
commit | 0a9b468540d4be7dbea3b63515b64eaa5c187f0f (patch) | |
tree | 0ad85957876211c887654dd2d8a55fc4d7abbaf8 /swaybar/input.c | |
parent | swaybar: Prioritize hotspot events to bar bindings (diff) | |
download | sway-0a9b468540d4be7dbea3b63515b64eaa5c187f0f.tar.gz sway-0a9b468540d4be7dbea3b63515b64eaa5c187f0f.tar.zst sway-0a9b468540d4be7dbea3b63515b64eaa5c187f0f.zip |
swaybar: Make hotspots block bar release bindings
The previous commit prioritized hotspots before bar bindings for press events,
which matches i3's behaviour. However, since hotspots don't need to do any
processing on release events, those were not handled, and simply fell through
to `bindsym --release` bar bindings (if any).
This is counter-intuitive, and doesn't match i3's behaviour. Instead in case
a hotspot handles the press event, it should also handle the release event,
doing nothing, but blocking the event from triggering a --release bar binding.
E.g., in Sway, without this commit, this config. shows a text on tray clicks:
bar {
# ...
bindsym --release button1 exec swaynag -m I_got_the_release_event.
}
But the same configuration in i3 (with i3-nagbar) doesn't show the text.
Signed-off-by: Joan Bruguera <joanbrugueram@gmail.com>
(cherry picked from commit 94b69acf0d7b26ee5af2172300cb18473508da76)
Diffstat (limited to 'swaybar/input.c')
-rw-r--r-- | swaybar/input.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/swaybar/input.c b/swaybar/input.c index f12eed79..8eccf542 100644 --- a/swaybar/input.c +++ b/swaybar/input.c | |||
@@ -141,14 +141,15 @@ static bool check_bindings(struct swaybar *bar, uint32_t button, | |||
141 | } | 141 | } |
142 | 142 | ||
143 | static bool process_hotspots(struct swaybar_output *output, | 143 | static bool process_hotspots(struct swaybar_output *output, |
144 | double x, double y, uint32_t button) { | 144 | double x, double y, uint32_t button, uint32_t state) { |
145 | bool released = state == WL_POINTER_BUTTON_STATE_RELEASED; | ||
145 | struct swaybar_hotspot *hotspot; | 146 | struct swaybar_hotspot *hotspot; |
146 | wl_list_for_each(hotspot, &output->hotspots, link) { | 147 | wl_list_for_each(hotspot, &output->hotspots, link) { |
147 | if (x >= hotspot->x && y >= hotspot->y | 148 | if (x >= hotspot->x && y >= hotspot->y |
148 | && x < hotspot->x + hotspot->width | 149 | && x < hotspot->x + hotspot->width |
149 | && y < hotspot->y + hotspot->height) { | 150 | && y < hotspot->y + hotspot->height) { |
150 | if (HOTSPOT_IGNORE == hotspot->callback(output, hotspot, x, y, | 151 | if (HOTSPOT_IGNORE == hotspot->callback(output, hotspot, x, y, |
151 | button, hotspot->data)) { | 152 | button, released, hotspot->data)) { |
152 | return true; | 153 | return true; |
153 | } | 154 | } |
154 | } | 155 | } |
@@ -166,10 +167,8 @@ static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer, | |||
166 | return; | 167 | return; |
167 | } | 168 | } |
168 | 169 | ||
169 | if (state == WL_POINTER_BUTTON_STATE_PRESSED) { | 170 | if (process_hotspots(output, pointer->x, pointer->y, button, state)) { |
170 | if (process_hotspots(output, pointer->x, pointer->y, button)) { | 171 | return; |
171 | return; | ||
172 | } | ||
173 | } | 172 | } |
174 | 173 | ||
175 | check_bindings(seat->bar, button, state); | 174 | check_bindings(seat->bar, button, state); |
@@ -222,7 +221,8 @@ static void process_discrete_scroll(struct swaybar_seat *seat, | |||
222 | struct swaybar_output *output, struct swaybar_pointer *pointer, | 221 | struct swaybar_output *output, struct swaybar_pointer *pointer, |
223 | uint32_t axis, wl_fixed_t value) { | 222 | uint32_t axis, wl_fixed_t value) { |
224 | uint32_t button = wl_axis_to_button(axis, value); | 223 | uint32_t button = wl_axis_to_button(axis, value); |
225 | if (process_hotspots(output, pointer->x, pointer->y, button)) { | 224 | if (process_hotspots(output, pointer->x, pointer->y, button, WL_POINTER_BUTTON_STATE_PRESSED)) { |
225 | // (Currently hotspots don't do anything on release events, so no need to emit one) | ||
226 | return; | 226 | return; |
227 | } | 227 | } |
228 | 228 | ||
@@ -401,7 +401,8 @@ static void wl_touch_up(void *data, struct wl_touch *wl_touch, | |||
401 | } | 401 | } |
402 | if (time - slot->time < 500) { | 402 | if (time - slot->time < 500) { |
403 | // Tap, treat it like a pointer click | 403 | // Tap, treat it like a pointer click |
404 | process_hotspots(slot->output, slot->x, slot->y, BTN_LEFT); | 404 | process_hotspots(slot->output, slot->x, slot->y, BTN_LEFT, WL_POINTER_BUTTON_STATE_PRESSED); |
405 | // (Currently hotspots don't do anything on release events, so no need to emit one) | ||
405 | } | 406 | } |
406 | slot->output = NULL; | 407 | slot->output = NULL; |
407 | } | 408 | } |