particle/progress-bar: fix ‘where’ tag regression

After implementing support for more mouse buttons (and scrolling), the
‘where’ tag stopped working in the progress-bar.

This patch repairs it.
This commit is contained in:
Daniel Eklöf 2021-08-09 18:21:45 +02:00
parent 3072c2b13f
commit a210d33320
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
2 changed files with 18 additions and 24 deletions

View file

@ -26,6 +26,8 @@
* `yambar --backend=wayland` always erroring out with _”yambar was * `yambar --backend=wayland` always erroring out with _”yambar was
compiled without the Wayland backend”_. compiled without the Wayland backend”_.
* Regression: `{where}` tag not being expanded in progress-bar
`on-click` handlers.
### Security ### Security

View file

@ -87,30 +87,6 @@ static void
on_mouse(struct exposable *exposable, struct bar *bar, enum mouse_event event, on_mouse(struct exposable *exposable, struct bar *bar, enum mouse_event event,
enum mouse_button btn, int x, int y) enum mouse_button btn, int x, int y)
{ {
if ((event == ON_MOUSE_MOTION &&
exposable->particle->have_on_click_template) ||
exposable->on_click[btn] != NULL)
{
exposable_default_on_mouse(exposable, bar, event, btn, x, y);
return;
}
/*
* Hack-warning!
*
* In order to pass the *clicked* position to the on_click
* handler, we expand the handler *again* (first time would be
* when the particle instantiated us).
*
* We pass a single tag, "where", which is a percentage value.
*
* Keep a reference to the un-expanded string, to be able to reset
* it after executing the handler.
*
* Note that we only consider the actual progress bar to be
* clickable. This means we ignore the start and end markers.
*/
const struct particle *p = exposable->particle; const struct particle *p = exposable->particle;
const struct eprivate *e = exposable->private; const struct eprivate *e = exposable->private;
@ -150,6 +126,22 @@ on_mouse(struct exposable *exposable, struct bar *bar, enum mouse_event event,
return; return;
} }
/*
* Hack-warning!
*
* In order to pass the *clicked* position to the on_click
* handler, we expand the handler *again* (first time would be
* when the particle instantiated us).
*
* We pass a single tag, "where", which is a percentage value.
*
* Keep a reference to the un-expanded string, to be able to
* reset it after executing the handler.
*
* Note that we only consider the actual progress bar to be
* clickable. This means we ignore the start and end markers.
*/
/* Remember the original handler, so that we can restore it */ /* Remember the original handler, so that we can restore it */
char *original[MOUSE_BTN_COUNT]; char *original[MOUSE_BTN_COUNT];
for (size_t i = 0; i < MOUSE_BTN_COUNT; i++) for (size_t i = 0; i < MOUSE_BTN_COUNT; i++)